aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/christmas/advent_of_code
diff options
context:
space:
mode:
authorGravatar Matteo Bertucci <[email protected]>2021-05-15 23:41:20 +0200
committerGravatar GitHub <[email protected]>2021-05-15 23:41:20 +0200
commite6e280cd13236647ffcaa35f522baeb747fbf97e (patch)
treea888762bcd97704f57ad33e8e1bd0d179c3abd2b /bot/exts/christmas/advent_of_code
parentMerge pull request #737 from python-discord/latex-don't-load-cog (diff)
parentchore: Apply Iceman's suggestions (diff)
Spring cleanup (#718)
This PR changes a ton of various different bits and pieces. Please see #718 for more information.
Diffstat (limited to 'bot/exts/christmas/advent_of_code')
-rw-r--r--bot/exts/christmas/advent_of_code/_cog.py25
-rw-r--r--bot/exts/christmas/advent_of_code/_helpers.py8
2 files changed, 19 insertions, 14 deletions
diff --git a/bot/exts/christmas/advent_of_code/_cog.py b/bot/exts/christmas/advent_of_code/_cog.py
index 8376987d..ead84544 100644
--- a/bot/exts/christmas/advent_of_code/_cog.py
+++ b/bot/exts/christmas/advent_of_code/_cog.py
@@ -72,11 +72,15 @@ class AdventOfCode(commands.Cog):
if role not in ctx.author.roles:
await ctx.author.add_roles(role)
- await ctx.send("Okay! You have been __subscribed__ to notifications about new Advent of Code tasks. "
- f"You can run `{unsubscribe_command}` to disable them again for you.")
+ await ctx.send(
+ "Okay! You have been __subscribed__ to notifications about new Advent of Code tasks. "
+ f"You can run `{unsubscribe_command}` to disable them again for you."
+ )
else:
- await ctx.send("Hey, you already are receiving notifications about new Advent of Code tasks. "
- f"If you don't want them any more, run `{unsubscribe_command}` instead.")
+ await ctx.send(
+ "Hey, you already are receiving notifications about new Advent of Code tasks. "
+ f"If you don't want them any more, run `{unsubscribe_command}` instead."
+ )
@in_month(Month.DECEMBER)
@adventofcode_group.command(name="unsubscribe", aliases=("unsub",), brief="Notifications for new days")
@@ -110,8 +114,10 @@ class AdventOfCode(commands.Cog):
else:
delta_str = f"{delta.days} days"
- await ctx.send(f"The Advent of Code event is not currently running. "
- f"The next event will start in {delta_str}.")
+ await ctx.send(
+ "The Advent of Code event is not currently running. "
+ f"The next event will start in {delta_str}."
+ )
return
tomorrow, time_left = _helpers.time_left_to_est_midnight()
@@ -124,7 +130,7 @@ class AdventOfCode(commands.Cog):
@whitelist_override(channels=AOC_WHITELIST)
async def about_aoc(self, ctx: commands.Context) -> None:
"""Respond with an explanation of all things Advent of Code."""
- await ctx.send("", embed=self.cached_about_aoc)
+ await ctx.send(embed=self.cached_about_aoc)
@adventofcode_group.command(name="join", aliases=("j",), brief="Learn how to join the leaderboard (via DM)")
@whitelist_override(channels=AOC_WHITELIST)
@@ -135,7 +141,7 @@ class AdventOfCode(commands.Cog):
await ctx.send(f"The Python Discord leaderboard for {current_year} is not yet available!")
return
- author = ctx.message.author
+ author = ctx.author
log.info(f"{author.name} ({author.id}) has requested a PyDis AoC leaderboard code")
if AocConfig.staff_leaderboard_id and any(r.id == Roles.helpers for r in author.roles):
@@ -273,8 +279,7 @@ class AdventOfCode(commands.Cog):
def _build_about_embed(self) -> discord.Embed:
"""Build and return the informational "About AoC" embed from the resources file."""
- with self.about_aoc_filepath.open("r", encoding="utf8") as f:
- embed_fields = json.load(f)
+ embed_fields = json.loads(self.about_aoc_filepath.read_text("utf8"))
about_embed = discord.Embed(
title=self._base_url,
diff --git a/bot/exts/christmas/advent_of_code/_helpers.py b/bot/exts/christmas/advent_of_code/_helpers.py
index a16a4871..f4a258c0 100644
--- a/bot/exts/christmas/advent_of_code/_helpers.py
+++ b/bot/exts/christmas/advent_of_code/_helpers.py
@@ -108,7 +108,7 @@ def _parse_raw_leaderboard_data(raw_leaderboard_data: dict) -> dict:
# star view. We need that per star view to compute rank scores per star.
for member in raw_leaderboard_data.values():
name = member["name"] if member["name"] else f"Anonymous #{member['id']}"
- member_id = member['id']
+ member_id = member["id"]
leaderboard[member_id] = {"name": name, "score": 0, "star_1": 0, "star_2": 0}
# Iterate over all days for this participant
@@ -119,7 +119,7 @@ def _parse_raw_leaderboard_data(raw_leaderboard_data: dict) -> dict:
leaderboard[member_id][f"star_{star}"] += 1
# Record completion datetime for this participant for this day/star
- completion_time = datetime.datetime.fromtimestamp(int(data['get_star_ts']))
+ completion_time = datetime.datetime.fromtimestamp(int(data["get_star_ts"]))
star_results[(day, star)].append(
StarResult(member_id=member_id, completion_time=completion_time)
)
@@ -133,7 +133,7 @@ def _parse_raw_leaderboard_data(raw_leaderboard_data: dict) -> dict:
if day in AdventOfCode.ignored_days:
continue
- sorted_result = sorted(results, key=operator.attrgetter('completion_time'))
+ sorted_result = sorted(results, key=operator.attrgetter("completion_time"))
for rank, star_result in enumerate(sorted_result):
leaderboard[star_result.member_id]["score"] += max_score - rank
@@ -307,7 +307,7 @@ async def fetch_leaderboard(invalidate_cache: bool = False) -> dict:
def get_summary_embed(leaderboard: dict) -> discord.Embed:
"""Get an embed with the current summary stats of the leaderboard."""
- leaderboard_url = leaderboard['full_leaderboard_url']
+ leaderboard_url = leaderboard["full_leaderboard_url"]
refresh_minutes = AdventOfCode.leaderboard_cache_expiry_seconds // 60
aoc_embed = discord.Embed(