aboutsummaryrefslogtreecommitdiffstats
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
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]>
-rw-r--r--bot/resources/easter/easter_egg_facts.json3
-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
4 files changed, 28 insertions, 26 deletions
diff --git a/bot/resources/easter/easter_egg_facts.json b/bot/resources/easter/easter_egg_facts.json
index ee6d4678..b0650b84 100644
--- a/bot/resources/easter/easter_egg_facts.json
+++ b/bot/resources/easter/easter_egg_facts.json
@@ -13,8 +13,5 @@
"In 2007, an Easter egg covered in diamonds sold for almost £9 million. Every hour, a cockerel made of jewels pops up from the top of the Faberge egg, flaps its wings four times, nods its head three times and makes a crowing noise. The gold-and-pink enamel egg was made by the Russian royal family as an engagement gift for French aristocrat Baron Edouard de Rothschild.",
"The White House held their first official egg roll in 1878 when Rutherford B. Hayes was the President. It is a race in which children push decorated, hard-boiled eggs across the White House lawn as an annual event held the Monday after Easter. In 2009, the Obamas hosted their first Easter egg roll with the theme, \"Let's go play\" which was meant to encourage young people to lead healthy and active lives.",
"80 million chocolate Easter eggs are sold each year. This accounts for 10% of Britain's annual spending on chocolate!",
- "The tradition of giving eggs at Easter has been traced back to Egyptians, Persians, Gauls, Greeks and Romans, who saw the egg as a symbol of life.",
- "Medieval Easter eggs were boiled with onions to give them a golden sheen. Edward I, however, went one better and in 1290 he ordered 450 eggs to be covered in gold leaf and given as Easter gifts.",
- "The first chocolate Easter egg was produced in 1873 by Fry\"s. Before this, people would give hollow cardboard eggs, filled with gifts.",
"John Cadbury soon followed suit and made his first Cadbury Easter egg in 1875. By 1892 the company was producing 19 different lines, all made from dark chocolate."
]
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):