aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons
diff options
context:
space:
mode:
authorGravatar sco1 <[email protected]>2019-07-22 21:09:03 -0400
committerGravatar sco1 <[email protected]>2019-07-22 21:21:05 -0400
commit33fc6c798d6b4e32d028e7a506d056782b15ce12 (patch)
treeca630a87fe8ba9f347ff2b82c40a35be865f0fe9 /bot/seasons
parentApply suggestions from code review (diff)
Additional review comment resolution
* Remove duplicate easter egg facts, fix punctuation * Simplify egg fact JSON load * Simplify egg fact embed generation * Simplify issues command, remove redundant calls, and make some variables more explicit * Truncate issue body if its length is greater than 1024 characters (embed field limitation) Co-Authored-By: Mark <[email protected]>
Diffstat (limited to 'bot/seasons')
-rw-r--r--bot/seasons/easter/easter_riddle.py2
-rw-r--r--bot/seasons/easter/egg_facts.py14
-rw-r--r--bot/seasons/evergreen/issues.py35
3 files changed, 28 insertions, 23 deletions
diff --git a/bot/seasons/easter/easter_riddle.py b/bot/seasons/easter/easter_riddle.py
index d6e6c207..3c24075c 100644
--- a/bot/seasons/easter/easter_riddle.py
+++ b/bot/seasons/easter/easter_riddle.py
@@ -89,8 +89,6 @@ class EasterRiddle(commands.Cog):
if self.bot.user != message.author:
if message.content.lower() == self.correct.lower():
self.winners.append(message.author.mention)
- else:
- return
def setup(bot):
diff --git a/bot/seasons/easter/egg_facts.py b/bot/seasons/easter/egg_facts.py
index 6d70225a..ae08ccd4 100644
--- a/bot/seasons/easter/egg_facts.py
+++ b/bot/seasons/easter/egg_facts.py
@@ -30,8 +30,7 @@ class EasterFacts(commands.Cog):
"""Load a list of easter egg facts from the resource JSON file."""
p = Path("bot/resources/easter/easter_egg_facts.json")
with p.open(encoding="utf8") as f:
- facts = load(f)
- return facts
+ return load(f)
async def send_egg_fact_daily(self):
"""A background task that sends an easter egg fact in the event channel everyday."""
@@ -49,12 +48,11 @@ class EasterFacts(commands.Cog):
def make_embed(self):
"""Makes a nice embed for the message to be sent."""
- embed = discord.Embed()
- embed.colour = Colours.soft_red
- embed.title = 'Easter Egg Fact'
- random_fact = random.choice(self.facts)
- embed.description = random_fact
- return embed
+ return discord.Embed(
+ colour=Colours.soft_red,
+ title="Easter Egg Fact",
+ description=random.choice(self.facts)
+ )
def setup(bot):
diff --git a/bot/seasons/evergreen/issues.py b/bot/seasons/evergreen/issues.py
index c6dbe344..04531c54 100644
--- a/bot/seasons/evergreen/issues.py
+++ b/bot/seasons/evergreen/issues.py
@@ -16,23 +16,32 @@ class Issues(commands.Cog):
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}"
- status = {"404": f"Issue #{str(number)} doesn't exist in the repository {user}/{repository}.",
- "403": f"Rate limit exceeded. Please wait a while before trying again!"}
+ 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:
json_data = await r.json()
+ response_code = r.status
- if str(r.status) in status:
- return await ctx.send(status.get(str(r.status)))
-
- valid = discord.Embed(colour=0x00ff37)
- valid.add_field(name="Repository", value=f"{user}/{repository}", inline=False)
- valid.add_field(name="Issue Number", value=f"#{number}", inline=False)
- valid.add_field(name="Status", value=json_data["state"].title())
- valid.add_field(name="Link", value=url, inline=False)
- if len(json_data.get("body")) < 1024:
- valid.add_field(name="Description", value=json_data.get("body"), inline=False)
- await ctx.send(embed=valid)
+ 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}", 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=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}"
+
+ issue_embed.add_field(name="Description", value=description, inline=False)
+
+ await ctx.send(embed=issue_embed)
def setup(bot):