diff options
| author | 2019-07-31 17:47:20 -0400 | |
|---|---|---|
| committer | 2019-07-31 17:47:20 -0400 | |
| commit | bbe4347efc53c020e0df0ee80969202ce4f7619c (patch) | |
| tree | 794ac7c6829f7687d3799522b9fc7ae26e618d8c /bot | |
| parent | Apply issue embed suggestions from code review (diff) | |
Additional review comment resolution
* Fix line length & broken f string
* Use correct URLs for GH access
* Align GH issue description truncation placeholder with textwrap.TextWrapper for consistency
* Utilize color constant rather than hex code
* Flatten logic blocks by reversing logic
* Additional minor syntax changes
Co-Authored-By: Ava <[email protected]>
Diffstat (limited to '')
| -rw-r--r-- | bot/seasons/easter/easter_riddle.py | 84 | ||||
| -rw-r--r-- | bot/seasons/evergreen/issues.py | 17 | 
2 files changed, 54 insertions, 47 deletions
diff --git a/bot/seasons/easter/easter_riddle.py b/bot/seasons/easter/easter_riddle.py index 3c24075c..56555586 100644 --- a/bot/seasons/easter/easter_riddle.py +++ b/bot/seasons/easter/easter_riddle.py @@ -33,62 +33,66 @@ class EasterRiddle(commands.Cog):          The duration of the hint interval can be configured by changing the TIMELIMIT constant in this file.          """ -        if not self.current_channel: -            self.current_channel = ctx.message.channel +        if self.current_channel: +            return await ctx.send(f"A riddle is already being solved in {self.current_channel.mention}!") -            random_question = random.choice(RIDDLE_QUESTIONS) -            question = random_question["question"] -            hints = random_question["riddles"] -            self.correct = random_question["correct_answer"] +        self.current_channel = ctx.message.channel -            description = f"You have {TIMELIMIT} seconds before the first hint.\n\n" +        random_question = random.choice(RIDDLE_QUESTIONS) +        question = random_question["question"] +        hints = random_question["riddles"] +        self.correct = random_question["correct_answer"] -            riddle_embed = discord.Embed(title=question, description=description, colour=Colours.pink) +        description = f"You have {TIMELIMIT} seconds before the first hint." -            await ctx.send(embed=riddle_embed) -            await asyncio.sleep(TIMELIMIT) +        riddle_embed = discord.Embed(title=question, description=description, colour=Colours.pink) -            hint_embed = discord.Embed( -                title=f"Here's a hint: {hints[0]}!", -                colour=Colours.pink -            ) +        await ctx.send(embed=riddle_embed) +        await asyncio.sleep(TIMELIMIT) -            await ctx.send(embed=hint_embed) -            await asyncio.sleep(TIMELIMIT) +        hint_embed = discord.Embed( +            title=f"Here's a hint: {hints[0]}!", +            colour=Colours.pink +        ) -            hint_embed = discord.Embed( -                title=f"Here's a hint: {hints[1]}!", -                colour=Colours.pink -            ) +        await ctx.send(embed=hint_embed) +        await asyncio.sleep(TIMELIMIT) -            await ctx.send(embed=hint_embed) -            await asyncio.sleep(TIMELIMIT) +        hint_embed = discord.Embed( +            title=f"Here's a hint: {hints[1]}!", +            colour=Colours.pink +        ) -            if self.winners: -                win_list = " ".join(self.winners) -                content = f"Well done {win_list} for getting it right!" -                self.winners = [] -            else: -                content = "Nobody got it right..." +        await ctx.send(embed=hint_embed) +        await asyncio.sleep(TIMELIMIT) -            answer_embed = discord.Embed( -                title=f"The answer is: {self.correct}!", -                colour=Colours.pink -            ) +        if self.winners: +            win_list = " ".join(self.winners) +            content = f"Well done {win_list} for getting it right!" +        else: +            content = "Nobody got it right..." -            await ctx.send(content, embed=answer_embed) +        answer_embed = discord.Embed( +            title=f"The answer is: {self.correct}!", +            colour=Colours.pink +        ) -            self.current_channel = None -        else: -            await ctx.send(f"A riddle is already being solved in {self.current_channel.mention}!") +        await ctx.send(content, embed=answer_embed) + +        self.winners = [] +        self.current_channel = None      @commands.Cog.listener()      async def on_message(self, message):          """If a non-bot user enters a correct answer, their username gets added to self.winners""" -        if self.current_channel == message.channel: -            if self.bot.user != message.author: -                if message.content.lower() == self.correct.lower(): -                    self.winners.append(message.author.mention) +        if self.current_channel != message.channel: +            return + +        if self.bot.user == message.author: +            return + +        if message.content.lower() == self.correct.lower(): +            self.winners.append(message.author.mention)  def setup(bot): diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py index 13665782..2a31a2e1 100644 --- a/bot/seasons/evergreen/issues.py +++ b/bot/seasons/evergreen/issues.py @@ -3,6 +3,8 @@ import logging  import discord  from discord.ext import commands +from bot.constants import Colours +  log = logging.getLogger(__name__) @@ -15,29 +17,30 @@ class Issues(commands.Cog):      @commands.command(aliases=("issues",))      async def issue(self, ctx, number: int, repository: str = "seasonalbot", user: str = "python-discord"):          """Command to retrieve issues from a GitHub repository.""" -        url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}" +        api_url = f"https://api.github.com/repos/{user}/{repository}/issues/{number}"          failed_status = {              404: f"Issue #{number} doesn't exist in the repository {user}/{repository}.",              403: f"Rate limit exceeded. Please wait a while before trying again!"          } -        async with self.bot.http_session.get(url) as r: +        async with self.bot.http_session.get(api_url) as r:              json_data = await r.json()              response_code = r.status          if response_code in failed_status:              return await ctx.send(failed_status[response_code]) -        issue_embed = discord.Embed(colour=0x00ff37) -        issue_embed.add_field(name="Repository", value=f"[{user}/{repository}](json_data['repository_url'])", inline=False) +        repo_url = f"https://github.com/{user}/{repository}" +        issue_embed = discord.Embed(colour=Colours.bright_green) +        issue_embed.add_field(name="Repository", value=f"[{user}/{repository}]({repo_url})", inline=False)          issue_embed.add_field(name="Issue Number", value=f"#{number}", inline=False)          issue_embed.add_field(name="Status", value=json_data["state"].title()) -        issue_embed.add_field(name="Link", value=json_data["url"], inline=False) +        issue_embed.add_field(name="Link", value=json_data["html_url"], inline=False)          description = json_data["body"]          if len(description) > 1024: -            truncation_message = "** ...\n\nContent truncated, please follow the link for more!**" -            description = f"{description[:1024 - len(truncation_message)]}{truncation_message}" +            placeholder = " [...]" +            description = f"{description[:1024 - len(placeholder)]}{placeholder}"          issue_embed.add_field(name="Description", value=description, inline=False)  |