From 71d800add94df3d678786ab482747ae904290129 Mon Sep 17 00:00:00 2001 From: Izan Date: Fri, 8 Oct 2021 15:04:35 +0100 Subject: Rename `Roles.admin` to `Roles.admins` --- bot/exts/events/advent_of_code/_cog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index ca60e517..4d811fa4 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -251,7 +251,7 @@ class AdventOfCode(commands.Cog): info_embed = _helpers.get_summary_embed(leaderboard) await ctx.send(f"```\n{table}\n```", embed=info_embed) - @with_role(Roles.admin) + @with_role(Roles.admins) @adventofcode_group.command( name="refresh", aliases=("fetch",), -- cgit v1.2.3 From aa272dbe789e86013969bc6f4e506d70ddfc63be Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 11 Oct 2021 14:47:16 +0100 Subject: Check role id in STAFF_ROLES instead of comparing to helpers --- bot/exts/events/advent_of_code/_cog.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 4d811fa4..0a18c261 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -9,7 +9,7 @@ from discord.ext import commands from bot.bot import Bot from bot.constants import ( - AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS, + AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, STAFF_ROLES, WHITELISTED_CHANNELS, ) from bot.exts.events.advent_of_code import _helpers from bot.utils.decorators import InChannelCheckFailure, in_month, whitelist_override, with_role @@ -145,7 +145,7 @@ class AdventOfCode(commands.Cog): 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): + if AocConfig.staff_leaderboard_id and any(r.id in STAFF_ROLES for r in author.roles): join_code = AocConfig.leaderboards[AocConfig.staff_leaderboard_id].join_code else: try: -- cgit v1.2.3 From a94ce986832694a572ce31b8fedd2b98c2c7747a Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 11 Oct 2021 14:59:31 +0100 Subject: Make certain AOC commands guild-only --- bot/exts/events/advent_of_code/_cog.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 0a18c261..3bd4873c 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -55,6 +55,7 @@ class AdventOfCode(commands.Cog): if not ctx.invoked_subcommand: await invoke_help_command(ctx) + @commands.guild_only() @adventofcode_group.command( name="subscribe", aliases=("sub", "notifications", "notify", "notifs"), @@ -84,6 +85,7 @@ class AdventOfCode(commands.Cog): ) @in_month(Month.DECEMBER) + @commands.guild_only() @adventofcode_group.command(name="unsubscribe", aliases=("unsub",), brief="Notifications for new days") @whitelist_override(channels=AOC_WHITELIST) async def aoc_unsubscribe(self, ctx: commands.Context) -> None: @@ -133,6 +135,7 @@ class AdventOfCode(commands.Cog): """Respond with an explanation of all things Advent of Code.""" await ctx.send(embed=self.cached_about_aoc) + @commands.guild_only() @adventofcode_group.command(name="join", aliases=("j",), brief="Learn how to join the leaderboard (via DM)") @whitelist_override(channels=AOC_WHITELIST) async def join_leaderboard(self, ctx: commands.Context) -> None: -- cgit v1.2.3 From f18e9c3dda721b9bbbba884e31b34e4ae2831ffc Mon Sep 17 00:00:00 2001 From: D0rs4n <41237606+D0rs4n@users.noreply.github.com> Date: Thu, 14 Oct 2021 21:55:41 +0200 Subject: Add support to query AoC results in respect of days and stars (#857) * Add support to query AoC results in respect of days and stars From now on the AoC leaderboard command accepts a total of 2 optional arguments a day and star string (eg.: 1-2, for the second star of the first day) and a number of results they would like to see, with a total maximum of 15. This commit also introduces a few minor fixes in the AoC helper. * Improve overall code consitency in the AoC event Cog and helpers * Improve indenting and code consistency in the AoC cog * Improve code transparency in the AoC helpers * Patch various inconsistencies in the AoC cog and helpers * Migrate AoC Day and Star statistics filtering to Dropdowns From now on when the AoC leadearboard command is used with the DayAndStar argument(bool) the bot will send a View with two dropdowns and a button to Fetch the data based on the value of the Dropdowns. * Improve code and comment consistency in the AoC views and helpers * Patch logic errors, improve consistency in the AoC cog and view. * Add support to delete view from the message after timeout in the AoC cog * Move the day_and_star logic out of the typing context manager in the AoC cog * Revert season-locker in the AoC cog * Improve overall code transparency and indenting in the AoC cog and views * Remove unnecessary returns in the AoC cog and view --- bot/constants.py | 1 + bot/exts/events/advent_of_code/_cog.py | 45 ++++++++++++-- bot/exts/events/advent_of_code/_helpers.py | 9 ++- .../events/advent_of_code/views/dayandstarview.py | 71 ++++++++++++++++++++++ 4 files changed, 119 insertions(+), 7 deletions(-) create mode 100644 bot/exts/events/advent_of_code/views/dayandstarview.py (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/constants.py b/bot/constants.py index 567daadd..0720dd20 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -88,6 +88,7 @@ class AdventOfCode: ignored_days = environ.get("AOC_IGNORED_DAYS", "").split(",") leaderboard_displayed_members = 10 leaderboard_cache_expiry_seconds = 1800 + max_day_and_star_results = 15 year = int(environ.get("AOC_YEAR", datetime.utcnow().year)) role_id = int(environ.get("AOC_ROLE_ID", 518565788744024082)) diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index ca60e517..7dd967ec 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -2,6 +2,7 @@ import json import logging from datetime import datetime, timedelta from pathlib import Path +from typing import Optional import arrow import discord @@ -12,6 +13,7 @@ from bot.constants import ( AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS, ) from bot.exts.events.advent_of_code import _helpers +from bot.exts.events.advent_of_code.views.dayandstarview import AoCDropdownView from bot.utils.decorators import InChannelCheckFailure, in_month, whitelist_override, with_role from bot.utils.extensions import invoke_help_command @@ -150,7 +152,7 @@ class AdventOfCode(commands.Cog): else: try: join_code = await _helpers.get_public_join_code(author) - except _helpers.FetchingLeaderboardFailed: + except _helpers.FetchingLeaderboardFailedError: await ctx.send(":x: Failed to get join code! Notified maintainers.") return @@ -185,14 +187,29 @@ class AdventOfCode(commands.Cog): brief="Get a snapshot of the PyDis private AoC leaderboard", ) @whitelist_override(channels=AOC_WHITELIST_RESTRICTED) - async def aoc_leaderboard(self, ctx: commands.Context) -> None: - """Get the current top scorers of the Python Discord Leaderboard.""" + async def aoc_leaderboard( + self, + ctx: commands.Context, + day_and_star: Optional[bool] = False, + maximum_scorers: Optional[int] = 10 + ) -> None: + """ + Get the current top scorers of the Python Discord Leaderboard. + + Additionally, you can provide an argument `day_and_star` (Boolean) to have the bot send a View + that will let you filter by day and star. + """ + if maximum_scorers > AocConfig.max_day_and_star_results or maximum_scorers <= 0: + raise commands.BadArgument( + f"The maximum number of results you can query is {AocConfig.max_day_and_star_results}" + ) async with ctx.typing(): try: leaderboard = await _helpers.fetch_leaderboard() - except _helpers.FetchingLeaderboardFailed: + except _helpers.FetchingLeaderboardFailedError: await ctx.send(":x: Unable to fetch leaderboard!") return + if not day_and_star: number_of_participants = leaderboard["number_of_participants"] @@ -203,6 +220,22 @@ class AdventOfCode(commands.Cog): info_embed = _helpers.get_summary_embed(leaderboard) await ctx.send(content=f"{header}\n\n{table}", embed=info_embed) + return + + # This is a dictionary that contains solvers in respect of day, and star. + # e.g. 1-1 means the solvers of the first star of the first day and their completion time + per_day_and_star = json.loads(leaderboard['leaderboard_per_day_and_star']) + view = AoCDropdownView( + day_and_star_data=per_day_and_star, + maximum_scorers=maximum_scorers, + original_author=ctx.author + ) + message = await ctx.send( + content="Please select a day and a star to filter by!", + view=view + ) + await view.wait() + await message.edit(view=None) @in_month(Month.DECEMBER) @adventofcode_group.command( @@ -231,7 +264,7 @@ class AdventOfCode(commands.Cog): """Send an embed with daily completion statistics for the Python Discord leaderboard.""" try: leaderboard = await _helpers.fetch_leaderboard() - except _helpers.FetchingLeaderboardFailed: + except _helpers.FetchingLeaderboardFailedError: await ctx.send(":x: Can't fetch leaderboard for stats right now!") return @@ -267,7 +300,7 @@ class AdventOfCode(commands.Cog): async with ctx.typing(): try: await _helpers.fetch_leaderboard(invalidate_cache=True) - except _helpers.FetchingLeaderboardFailed: + except _helpers.FetchingLeaderboardFailedError: await ctx.send(":x: Something went wrong while trying to refresh the cache!") else: await ctx.send("\N{OK Hand Sign} Refreshed leaderboard cache!") diff --git a/bot/exts/events/advent_of_code/_helpers.py b/bot/exts/events/advent_of_code/_helpers.py index 5fedb60f..af64bc81 100644 --- a/bot/exts/events/advent_of_code/_helpers.py +++ b/bot/exts/events/advent_of_code/_helpers.py @@ -105,6 +105,7 @@ def _parse_raw_leaderboard_data(raw_leaderboard_data: dict) -> dict: # The data we get from the AoC website is structured by member, not by day/star, # which means we need to iterate over the members to transpose the data to a per # star view. We need that per star view to compute rank scores per star. + per_day_star_stats = collections.defaultdict(list) for member in raw_leaderboard_data.values(): name = member["name"] if member["name"] else f"Anonymous #{member['id']}" member_id = member["id"] @@ -122,6 +123,11 @@ def _parse_raw_leaderboard_data(raw_leaderboard_data: dict) -> dict: star_results[(day, star)].append( StarResult(member_id=member_id, completion_time=completion_time) ) + per_day_star_stats[f"{day}-{star}"].append( + {'completion_time': int(data["get_star_ts"]), 'member_name': name} + ) + for key in per_day_star_stats: + per_day_star_stats[key] = sorted(per_day_star_stats[key], key=operator.itemgetter('completion_time')) # Now that we have a transposed dataset that holds the completion time of all # participants per star, we can compute the rank-based scores each participant @@ -151,7 +157,7 @@ def _parse_raw_leaderboard_data(raw_leaderboard_data: dict) -> dict: # this data to JSON in order to cache it in Redis. daily_stats[day] = {"star_one": star_one, "star_two": star_two} - return {"daily_stats": daily_stats, "leaderboard": sorted_leaderboard} + return {"daily_stats": daily_stats, "leaderboard": sorted_leaderboard, 'per_day_and_star': per_day_star_stats} def _format_leaderboard(leaderboard: dict[str, dict]) -> str: @@ -289,6 +295,7 @@ async def fetch_leaderboard(invalidate_cache: bool = False) -> dict: "leaderboard_fetched_at": leaderboard_fetched_at, "number_of_participants": number_of_participants, "daily_stats": json.dumps(parsed_leaderboard_data["daily_stats"]), + "leaderboard_per_day_and_star": json.dumps(parsed_leaderboard_data["per_day_and_star"]) } # Store the new values in Redis diff --git a/bot/exts/events/advent_of_code/views/dayandstarview.py b/bot/exts/events/advent_of_code/views/dayandstarview.py new file mode 100644 index 00000000..243db32e --- /dev/null +++ b/bot/exts/events/advent_of_code/views/dayandstarview.py @@ -0,0 +1,71 @@ +from datetime import datetime + +import discord + +AOC_DAY_AND_STAR_TEMPLATE = "{rank: >4} | {name:25.25} | {completion_time: >10}" + + +class AoCDropdownView(discord.ui.View): + """Interactive view to filter AoC stats by Day and Star.""" + + def __init__(self, original_author: discord.Member, day_and_star_data: dict[str: dict], maximum_scorers: int): + super().__init__() + self.day = 0 + self.star = 0 + self.data = day_and_star_data + self.maximum_scorers = maximum_scorers + self.original_author = original_author + + def generate_output(self) -> str: + """Generates a formatted codeblock with AoC statistics based on the currently selected day and star.""" + header = AOC_DAY_AND_STAR_TEMPLATE.format( + rank="Rank", + name="Name", completion_time="Completion time (UTC)" + ) + lines = [f"{header}\n{'-' * (len(header) + 2)}"] + + for rank, scorer in enumerate(self.data[f"{self.day}-{self.star}"][:self.maximum_scorers]): + time_data = datetime.fromtimestamp(scorer['completion_time']).strftime("%I:%M:%S %p") + lines.append(AOC_DAY_AND_STAR_TEMPLATE.format( + datastamp="", + rank=rank + 1, + name=scorer['member_name'], + completion_time=time_data) + ) + joined_lines = "\n".join(lines) + return f"Statistics for Day: {self.day}, Star: {self.star}.\n ```\n{joined_lines}\n```" + + async def interaction_check(self, interaction: discord.Interaction) -> bool: + """Global check to ensure that the interacting user is the user who invoked the command originally.""" + return interaction.user == self.original_author + + @discord.ui.select( + placeholder="Day", + options=[discord.SelectOption(label=str(i)) for i in range(1, 26)], + custom_id="day_select" + ) + async def day_select(self, select: discord.ui.Select, interaction: discord.Interaction) -> None: + """Dropdown to choose a Day of the AoC.""" + self.day = select.values[0] + + @discord.ui.select( + placeholder="Star", + options=[discord.SelectOption(label=str(i)) for i in range(1, 3)], + custom_id="star_select" + ) + async def star_select(self, select: discord.ui.Select, interaction: discord.Interaction) -> None: + """Dropdown to choose either the first or the second star.""" + self.star = select.values[0] + + @discord.ui.button(label="Fetch", style=discord.ButtonStyle.blurple) + async def fetch(self, button: discord.ui.Button, interaction: discord.Interaction) -> None: + """Button that fetches the statistics based on the dropdown values.""" + if self.day == 0 or self.star == 0: + await interaction.response.send_message( + "You have to select a value from both of the dropdowns!", + ephemeral=True + ) + else: + await interaction.response.edit_message(content=self.generate_output()) + self.day = 0 + self.star = 0 -- cgit v1.2.3 From cdaa77830f9bce1529d93990f00415dbde33a0cd Mon Sep 17 00:00:00 2001 From: Matteo Bertucci Date: Fri, 22 Oct 2021 07:25:39 +0000 Subject: Isort: give the codebase a sort --- bot/__init__.py | 1 - bot/exts/core/help.py | 5 +---- bot/exts/core/internal_eval/_internal_eval.py | 1 + bot/exts/events/advent_of_code/_cog.py | 4 +--- bot/exts/holidays/easter/earth_photos.py | 3 +-- bot/exts/holidays/halloween/scarymovie.py | 1 + bot/exts/utilities/issues.py | 9 +-------- bot/utils/checks.py | 9 +-------- bot/utils/halloween/spookifications.py | 3 +-- 9 files changed, 8 insertions(+), 28 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/__init__.py b/bot/__init__.py index db576cb2..cfaee9f8 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -18,7 +18,6 @@ from discord.ext import commands from bot import monkey_patches from bot.constants import Client - # Configure the "TRACE" logging level (e.g. "log.trace(message)") logging.TRACE = 5 logging.addLevelName(logging.TRACE, "TRACE") diff --git a/bot/exts/core/help.py b/bot/exts/core/help.py index 4b766b50..db3c2aa6 100644 --- a/bot/exts/core/help.py +++ b/bot/exts/core/help.py @@ -13,10 +13,7 @@ from rapidfuzz import process from bot import constants from bot.bot import Bot from bot.constants import Emojis -from bot.utils.pagination import ( - FIRST_EMOJI, LAST_EMOJI, - LEFT_EMOJI, LinePaginator, RIGHT_EMOJI, -) +from bot.utils.pagination import FIRST_EMOJI, LAST_EMOJI, LEFT_EMOJI, LinePaginator, RIGHT_EMOJI DELETE_EMOJI = Emojis.trashcan diff --git a/bot/exts/core/internal_eval/_internal_eval.py b/bot/exts/core/internal_eval/_internal_eval.py index 4f6b4321..12a860fa 100644 --- a/bot/exts/core/internal_eval/_internal_eval.py +++ b/bot/exts/core/internal_eval/_internal_eval.py @@ -10,6 +10,7 @@ from bot.bot import Bot from bot.constants import Client, Roles from bot.utils.decorators import with_role from bot.utils.extensions import invoke_help_command + from ._helpers import EvalContext __all__ = ["InternalEval"] diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 7dd967ec..2c1f4541 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -9,9 +9,7 @@ import discord from discord.ext import commands from bot.bot import Bot -from bot.constants import ( - AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS, -) +from bot.constants import AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS from bot.exts.events.advent_of_code import _helpers from bot.exts.events.advent_of_code.views.dayandstarview import AoCDropdownView from bot.utils.decorators import InChannelCheckFailure, in_month, whitelist_override, with_role diff --git a/bot/exts/holidays/easter/earth_photos.py b/bot/exts/holidays/easter/earth_photos.py index f65790af..27442f1c 100644 --- a/bot/exts/holidays/easter/earth_photos.py +++ b/bot/exts/holidays/easter/earth_photos.py @@ -4,8 +4,7 @@ import discord from discord.ext import commands from bot.bot import Bot -from bot.constants import Colours -from bot.constants import Tokens +from bot.constants import Colours, Tokens log = logging.getLogger(__name__) diff --git a/bot/exts/holidays/halloween/scarymovie.py b/bot/exts/holidays/halloween/scarymovie.py index 33659fd8..89310b97 100644 --- a/bot/exts/holidays/halloween/scarymovie.py +++ b/bot/exts/holidays/halloween/scarymovie.py @@ -6,6 +6,7 @@ from discord.ext import commands from bot.bot import Bot from bot.constants import Tokens + log = logging.getLogger(__name__) diff --git a/bot/exts/utilities/issues.py b/bot/exts/utilities/issues.py index 36655e1b..b6d5a43e 100644 --- a/bot/exts/utilities/issues.py +++ b/bot/exts/utilities/issues.py @@ -9,14 +9,7 @@ from discord.ext import commands from bot.bot import Bot from bot.constants import ( - Categories, - Channels, - Colours, - ERROR_REPLIES, - Emojis, - NEGATIVE_REPLIES, - Tokens, - WHITELISTED_CHANNELS + Categories, Channels, Colours, ERROR_REPLIES, Emojis, NEGATIVE_REPLIES, Tokens, WHITELISTED_CHANNELS ) from bot.utils.decorators import whitelist_override from bot.utils.extensions import invoke_help_command diff --git a/bot/utils/checks.py b/bot/utils/checks.py index 612d1ed6..8c426ed7 100644 --- a/bot/utils/checks.py +++ b/bot/utils/checks.py @@ -4,14 +4,7 @@ from collections.abc import Container, Iterable from typing import Callable, Optional from discord.ext.commands import ( - BucketType, - CheckFailure, - Cog, - Command, - CommandOnCooldown, - Context, - Cooldown, - CooldownMapping, + BucketType, CheckFailure, Cog, Command, CommandOnCooldown, Context, Cooldown, CooldownMapping ) from bot import constants diff --git a/bot/utils/halloween/spookifications.py b/bot/utils/halloween/spookifications.py index 93c5ddb9..c45ef8dc 100644 --- a/bot/utils/halloween/spookifications.py +++ b/bot/utils/halloween/spookifications.py @@ -1,8 +1,7 @@ import logging from random import choice, randint -from PIL import Image -from PIL import ImageOps +from PIL import Image, ImageOps log = logging.getLogger() -- cgit v1.2.3 From c56c5a9ab01a45a50877c228843fa27625f03512 Mon Sep 17 00:00:00 2001 From: D0rs4n <41237606+D0rs4n@users.noreply.github.com> Date: Thu, 18 Nov 2021 21:02:15 +0100 Subject: Introduce command changes in the AoC Cog - The AoC day and star browser has been separated from the leaderboard command, from now on it's a separate command - The leaderboard command has a new `self_placement_name` option, that shows the personal stats for the specified profile name. --- bot/exts/events/advent_of_code/_cog.py | 72 +++++++++++++++++++----------- bot/exts/events/advent_of_code/_helpers.py | 25 +++++++++-- 2 files changed, 66 insertions(+), 31 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 2c1f4541..7f35c306 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -180,24 +180,18 @@ class AdventOfCode(commands.Cog): @in_month(Month.DECEMBER) @adventofcode_group.command( - name="leaderboard", - aliases=("board", "lb"), - brief="Get a snapshot of the PyDis private AoC leaderboard", + name="dayandstar", + aliases=("daynstar", "daystar"), + brief="Get a view that lets you filter the leaderboard by day and star", ) @whitelist_override(channels=AOC_WHITELIST_RESTRICTED) - async def aoc_leaderboard( + async def aoc_day_and_star_leaderboard( self, ctx: commands.Context, - day_and_star: Optional[bool] = False, - maximum_scorers: Optional[int] = 10 + maximum_scorers_day_and_star: Optional[int] = 10 ) -> None: - """ - Get the current top scorers of the Python Discord Leaderboard. - - Additionally, you can provide an argument `day_and_star` (Boolean) to have the bot send a View - that will let you filter by day and star. - """ - if maximum_scorers > AocConfig.max_day_and_star_results or maximum_scorers <= 0: + """Have the bot send a View that will let you filter the leaderboard by day and star.""" + if maximum_scorers_day_and_star > AocConfig.max_day_and_star_results or maximum_scorers_day_and_star <= 0: raise commands.BadArgument( f"The maximum number of results you can query is {AocConfig.max_day_and_star_results}" ) @@ -207,25 +201,12 @@ class AdventOfCode(commands.Cog): except _helpers.FetchingLeaderboardFailedError: await ctx.send(":x: Unable to fetch leaderboard!") return - if not day_and_star: - - number_of_participants = leaderboard["number_of_participants"] - - top_count = min(AocConfig.leaderboard_displayed_members, number_of_participants) - header = f"Here's our current top {top_count}! {Emojis.christmas_tree * 3}" - - table = f"```\n{leaderboard['top_leaderboard']}\n```" - info_embed = _helpers.get_summary_embed(leaderboard) - - await ctx.send(content=f"{header}\n\n{table}", embed=info_embed) - return - # This is a dictionary that contains solvers in respect of day, and star. # e.g. 1-1 means the solvers of the first star of the first day and their completion time per_day_and_star = json.loads(leaderboard['leaderboard_per_day_and_star']) view = AoCDropdownView( day_and_star_data=per_day_and_star, - maximum_scorers=maximum_scorers, + maximum_scorers=maximum_scorers_day_and_star, original_author=ctx.author ) message = await ctx.send( @@ -235,6 +216,43 @@ class AdventOfCode(commands.Cog): await view.wait() await message.edit(view=None) + @in_month(Month.DECEMBER) + @adventofcode_group.command( + name="leaderboard", + aliases=("board", "lb"), + brief="Get a snapshot of the PyDis private AoC leaderboard", + ) + @whitelist_override(channels=AOC_WHITELIST_RESTRICTED) + async def aoc_leaderboard( + self, + ctx: commands.Context, + self_placement_name: Optional[str] = None, + ) -> None: + """ + Get the current top scorers of the Python Discord Leaderboard. + + Additionaly you can specify a `self_placement_name` + that will append the specified profile's personal stats to the top of the leaderboard + """ + async with ctx.typing(): + try: + leaderboard = await _helpers.fetch_leaderboard(self_placement_name=self_placement_name) + except _helpers.FetchingLeaderboardFailedError: + await ctx.send(":x: Unable to fetch leaderboard!") + return + + number_of_participants = leaderboard["number_of_participants"] + + top_count = min(AocConfig.leaderboard_displayed_members, number_of_participants) + self_placement_header = "(and your personal stats compared to the top 10)" if self_placement_name else "" + header = f"Here's our current top {top_count}{self_placement_header}! {Emojis.christmas_tree * 3}" + + table = f"```\n{leaderboard['top_leaderboard']}\n```" + info_embed = _helpers.get_summary_embed(leaderboard) + + await ctx.send(content=f"{header}\n\n{table}", embed=info_embed) + return + @in_month(Month.DECEMBER) @adventofcode_group.command( name="global", diff --git a/bot/exts/events/advent_of_code/_helpers.py b/bot/exts/events/advent_of_code/_helpers.py index af64bc81..58fc3054 100644 --- a/bot/exts/events/advent_of_code/_helpers.py +++ b/bot/exts/events/advent_of_code/_helpers.py @@ -10,6 +10,7 @@ from typing import Any, Optional import aiohttp import arrow import discord +from discord.ext import commands from bot.bot import Bot from bot.constants import AdventOfCode, Channels, Colours @@ -160,10 +161,23 @@ def _parse_raw_leaderboard_data(raw_leaderboard_data: dict) -> dict: return {"daily_stats": daily_stats, "leaderboard": sorted_leaderboard, 'per_day_and_star': per_day_star_stats} -def _format_leaderboard(leaderboard: dict[str, dict]) -> str: +def _format_leaderboard(leaderboard: dict[str, dict], self_placement_name: str = None) -> str: """Format the leaderboard using the AOC_TABLE_TEMPLATE.""" leaderboard_lines = [HEADER] + self_placement_exists = False for rank, data in enumerate(leaderboard.values(), start=1): + if self_placement_name and data["name"].lower() == self_placement_name.lower(): + leaderboard_lines.insert( + 1, + AOC_TABLE_TEMPLATE.format( + rank=rank, + name=f"(You) {data['name']}", + score=str(data["score"]), + stars=f"({data['star_1']}, {data['star_2']})" + ) + ) + self_placement_exists = True + continue leaderboard_lines.append( AOC_TABLE_TEMPLATE.format( rank=rank, @@ -172,7 +186,10 @@ def _format_leaderboard(leaderboard: dict[str, dict]) -> str: stars=f"({data['star_1']}, {data['star_2']})" ) ) - + if self_placement_name and not self_placement_exists: + raise commands.BadArgument( + "Sorry, your profile does not exist in this leaderboard." + ) return "\n".join(leaderboard_lines) @@ -260,7 +277,7 @@ def _get_top_leaderboard(full_leaderboard: str) -> str: @_caches.leaderboard_cache.atomic_transaction -async def fetch_leaderboard(invalidate_cache: bool = False) -> dict: +async def fetch_leaderboard(invalidate_cache: bool = False, self_placement_name: str = None) -> dict: """ Get the current Python Discord combined leaderboard. @@ -284,7 +301,7 @@ async def fetch_leaderboard(invalidate_cache: bool = False) -> dict: leaderboard = parsed_leaderboard_data["leaderboard"] number_of_participants = len(leaderboard) - formatted_leaderboard = _format_leaderboard(leaderboard) + formatted_leaderboard = _format_leaderboard(leaderboard, self_placement_name) full_leaderboard_url = await _upload_leaderboard(formatted_leaderboard) leaderboard_fetched_at = datetime.datetime.utcnow().isoformat() -- cgit v1.2.3 From ad66899453b027f3a5522cc103f5c128456144c4 Mon Sep 17 00:00:00 2001 From: D0rs4n <41237606+D0rs4n@users.noreply.github.com> Date: Fri, 19 Nov 2021 18:06:52 +0100 Subject: Update Caching logic in AoC helpers - This commit adds a new set of leaderboard data to the cache so that it calculates the correct information if issued with either a `self_placement_name` or not. - It also introduces code consistency upgrades Co-Authored-By: Johannes Christ --- bot/exts/events/advent_of_code/_cog.py | 7 +++--- bot/exts/events/advent_of_code/_helpers.py | 39 +++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 7f35c306..cd41e9ce 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -231,7 +231,7 @@ class AdventOfCode(commands.Cog): """ Get the current top scorers of the Python Discord Leaderboard. - Additionaly you can specify a `self_placement_name` + Additionally you can specify a `self_placement_name` that will append the specified profile's personal stats to the top of the leaderboard """ async with ctx.typing(): @@ -246,8 +246,9 @@ class AdventOfCode(commands.Cog): top_count = min(AocConfig.leaderboard_displayed_members, number_of_participants) self_placement_header = "(and your personal stats compared to the top 10)" if self_placement_name else "" header = f"Here's our current top {top_count}{self_placement_header}! {Emojis.christmas_tree * 3}" - - table = f"```\n{leaderboard['top_leaderboard']}\n```" + table = "```\n" \ + f"{leaderboard['placement_leaderboard'] if self_placement_name else leaderboard['top_leaderboard']}" \ + "\n```" info_embed = _helpers.get_summary_embed(leaderboard) await ctx.send(content=f"{header}\n\n{table}", embed=info_embed) diff --git a/bot/exts/events/advent_of_code/_helpers.py b/bot/exts/events/advent_of_code/_helpers.py index 58fc3054..35258544 100644 --- a/bot/exts/events/advent_of_code/_helpers.py +++ b/bot/exts/events/advent_of_code/_helpers.py @@ -71,6 +71,33 @@ class FetchingLeaderboardFailedError(Exception): """Raised when one or more leaderboards could not be fetched at all.""" +def _format_leaderboard_line(rank: int, data: dict[str, Any], *, is_author: bool) -> str: + """ + Build a string representing a line of the leaderboard. + + Parameters: + rank: + Rank in the leaderboard of this entry. + + data: + Mapping with entry information. + + Keyword arguments: + is_author: + Whether to address the name displayed in the returned line + personally. + + Returns: + A formatted line for the leaderboard. + """ + return AOC_TABLE_TEMPLATE.format( + rank=rank, + name=data['name'] if not is_author else f"(You) {data['name']}", + score=str(data['score']), + stars=f"({data['star_1']}, {data['star_2']})" + ) + + def leaderboard_sorting_function(entry: tuple[str, dict]) -> tuple[int, int]: """ Provide a sorting value for our leaderboard. @@ -287,7 +314,6 @@ async def fetch_leaderboard(invalidate_cache: bool = False, self_placement_name: miss, this function is locked to one call at a time using a decorator. """ cached_leaderboard = await _caches.leaderboard_cache.to_dict() - # Check if the cached leaderboard contains everything we expect it to. If it # does not, this probably means the cache has not been created yet or has # expired in Redis. This check also accounts for a malformed cache. @@ -301,11 +327,12 @@ async def fetch_leaderboard(invalidate_cache: bool = False, self_placement_name: leaderboard = parsed_leaderboard_data["leaderboard"] number_of_participants = len(leaderboard) - formatted_leaderboard = _format_leaderboard(leaderboard, self_placement_name) + formatted_leaderboard = _format_leaderboard(leaderboard) full_leaderboard_url = await _upload_leaderboard(formatted_leaderboard) leaderboard_fetched_at = datetime.datetime.utcnow().isoformat() cached_leaderboard = { + "placement_leaderboard": json.dumps(raw_leaderboard_data), "full_leaderboard": formatted_leaderboard, "top_leaderboard": _get_top_leaderboard(formatted_leaderboard), "full_leaderboard_url": full_leaderboard_url, @@ -324,7 +351,13 @@ async def fetch_leaderboard(invalidate_cache: bool = False, self_placement_name: _caches.leaderboard_cache.namespace, AdventOfCode.leaderboard_cache_expiry_seconds ) - + if self_placement_name: + formatted_placement_leaderboard = _parse_raw_leaderboard_data( + json.loads(cached_leaderboard["placement_leaderboard"]) + )["leaderboard"] + cached_leaderboard["placement_leaderboard"] = _get_top_leaderboard( + _format_leaderboard(formatted_placement_leaderboard, self_placement_name=self_placement_name) + ) return cached_leaderboard -- cgit v1.2.3 From 19a21dc6b07a6c7947fbde1de9c6aee21ccc0ef8 Mon Sep 17 00:00:00 2001 From: D0rs4n <41237606+D0rs4n@users.noreply.github.com> Date: Sun, 21 Nov 2021 11:20:13 +0100 Subject: Add check to ensure the day-and-star data exists --- bot/exts/events/advent_of_code/views/dayandstarview.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/views/dayandstarview.py b/bot/exts/events/advent_of_code/views/dayandstarview.py index 243db32e..a0bfa316 100644 --- a/bot/exts/events/advent_of_code/views/dayandstarview.py +++ b/bot/exts/events/advent_of_code/views/dayandstarview.py @@ -17,14 +17,19 @@ class AoCDropdownView(discord.ui.View): self.original_author = original_author def generate_output(self) -> str: - """Generates a formatted codeblock with AoC statistics based on the currently selected day and star.""" + """ + Generates a formatted codeblock with AoC statistics based on the currently selected day and star. + + Optionally, when the requested day and star data does not exist yet it returns an error message. + """ header = AOC_DAY_AND_STAR_TEMPLATE.format( rank="Rank", name="Name", completion_time="Completion time (UTC)" ) lines = [f"{header}\n{'-' * (len(header) + 2)}"] - - for rank, scorer in enumerate(self.data[f"{self.day}-{self.star}"][:self.maximum_scorers]): + if not (day_and_star_data := self.data.get(f"{self.day}-{self.star}")): + return ":x: The requested data for the specified day and star does not exist yet." + for rank, scorer in enumerate(day_and_star_data[:self.maximum_scorers]): time_data = datetime.fromtimestamp(scorer['completion_time']).strftime("%I:%M:%S %p") lines.append(AOC_DAY_AND_STAR_TEMPLATE.format( datastamp="", -- cgit v1.2.3 From a958d1c1f6a3308b5ffd03cb7f9ef846b0871265 Mon Sep 17 00:00:00 2001 From: Izan Date: Mon, 29 Nov 2021 09:34:31 +0000 Subject: Revert change to if statement checking if staff in `.aoc join` --- bot/exts/events/advent_of_code/_cog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index c3073fd5..34ade5b1 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -148,7 +148,7 @@ class AdventOfCode(commands.Cog): 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 in STAFF_ROLES for r in author.roles): + if AocConfig.staff_leaderboard_id and any(r.id == Roles.helpers for r in author.roles): join_code = AocConfig.leaderboards[AocConfig.staff_leaderboard_id].join_code else: try: -- cgit v1.2.3 From 338fc7a0b37483feba56a8810cd2e1a344ab8b22 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Mon, 29 Nov 2021 10:48:26 +0000 Subject: Swap conditional in aoc count This is so that there is less code within the if block, making it easier to parse the whole command by eye. --- bot/exts/events/advent_of_code/_cog.py | 41 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index cd41e9ce..c91a5019 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -100,32 +100,31 @@ class AdventOfCode(commands.Cog): @whitelist_override(channels=AOC_WHITELIST) async def aoc_countdown(self, ctx: commands.Context) -> None: """Return time left until next day.""" - if not _helpers.is_in_advent(): - datetime_now = arrow.now(_helpers.EST) - - # Calculate the delta to this & next year's December 1st to see which one is closest and not in the past - this_year = arrow.get(datetime(datetime_now.year, 12, 1), _helpers.EST) - next_year = arrow.get(datetime(datetime_now.year + 1, 12, 1), _helpers.EST) - deltas = (dec_first - datetime_now for dec_first in (this_year, next_year)) - delta = min(delta for delta in deltas if delta >= timedelta()) # timedelta() gives 0 duration delta - - # Add a finer timedelta if there's less than a day left - if delta.days == 0: - delta_str = f"approximately {delta.seconds // 3600} hours" - else: - delta_str = f"{delta.days} days" + if _helpers.is_in_advent(): + tomorrow, time_left = _helpers.time_left_to_est_midnight() + hours, minutes = time_left.seconds // 3600, time_left.seconds // 60 % 60 - await ctx.send( - "The Advent of Code event is not currently running. " - f"The next event will start in {delta_str}." - ) + await ctx.send(f"There are {hours} hours and {minutes} minutes left until day {tomorrow.day}.") return - tomorrow, time_left = _helpers.time_left_to_est_midnight() + datetime_now = arrow.now(_helpers.EST) - hours, minutes = time_left.seconds // 3600, time_left.seconds // 60 % 60 + # Calculate the delta to this & next year's December 1st to see which one is closest and not in the past + this_year = arrow.get(datetime(datetime_now.year, 12, 1), _helpers.EST) + next_year = arrow.get(datetime(datetime_now.year + 1, 12, 1), _helpers.EST) + deltas = (dec_first - datetime_now for dec_first in (this_year, next_year)) + delta = min(delta for delta in deltas if delta >= timedelta()) # timedelta() gives 0 duration delta - await ctx.send(f"There are {hours} hours and {minutes} minutes left until day {tomorrow.day}.") + # Add a finer timedelta if there's less than a day left + if delta.days == 0: + delta_str = f"approximately {delta.seconds // 3600} hours" + else: + delta_str = f"{delta.days} days" + + await ctx.send( + "The Advent of Code event is not currently running. " + f"The next event will start in {delta_str}." + ) @adventofcode_group.command(name="about", aliases=("ab", "info"), brief="Learn about Advent of Code") @whitelist_override(channels=AOC_WHITELIST) -- cgit v1.2.3 From 790bcdf2fedc8dd7aac8c5a2610dc8395852bce0 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Mon, 29 Nov 2021 10:49:28 +0000 Subject: Use a Discord timestamp to show countdown This gives the user the ability to hover the timestamp with their mouse to get an exact date and time. --- bot/exts/events/advent_of_code/_cog.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index c91a5019..94722005 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -115,15 +115,11 @@ class AdventOfCode(commands.Cog): deltas = (dec_first - datetime_now for dec_first in (this_year, next_year)) delta = min(delta for delta in deltas if delta >= timedelta()) # timedelta() gives 0 duration delta - # Add a finer timedelta if there's less than a day left - if delta.days == 0: - delta_str = f"approximately {delta.seconds // 3600} hours" - else: - delta_str = f"{delta.days} days" + next_aoc_timestamp = int((datetime_now + delta).timestamp()) await ctx.send( "The Advent of Code event is not currently running. " - f"The next event will start in {delta_str}." + f"The next event will start ." ) @adventofcode_group.command(name="about", aliases=("ab", "info"), brief="Learn about Advent of Code") -- cgit v1.2.3 From c81d30357db2c0950d5e781cdd5e9053907b228d Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Mon, 29 Nov 2021 15:10:29 +0000 Subject: Use Discord timestamps for aoc next day messages countdowns --- bot/exts/events/advent_of_code/_cog.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 94722005..af1cbcf5 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -101,14 +101,13 @@ class AdventOfCode(commands.Cog): async def aoc_countdown(self, ctx: commands.Context) -> None: """Return time left until next day.""" if _helpers.is_in_advent(): - tomorrow, time_left = _helpers.time_left_to_est_midnight() - hours, minutes = time_left.seconds // 3600, time_left.seconds // 60 % 60 + tomorrow, _ = _helpers.time_left_to_est_midnight() + next_day_timestamp = int(tomorrow.timestamp()) - await ctx.send(f"There are {hours} hours and {minutes} minutes left until day {tomorrow.day}.") + await ctx.send(f"Day {tomorrow.day} starts .") return datetime_now = arrow.now(_helpers.EST) - # Calculate the delta to this & next year's December 1st to see which one is closest and not in the past this_year = arrow.get(datetime(datetime_now.year, 12, 1), _helpers.EST) next_year = arrow.get(datetime(datetime_now.year + 1, 12, 1), _helpers.EST) -- cgit v1.2.3 From eba75f73964a258119e16ba2abfc181055281022 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Wed, 1 Dec 2021 22:41:07 -0500 Subject: Add `.aoc link` command This new command will allow people to associate their Discord ID with their Advent of Code name. This Redis Cache idea was taken from the hacktoberfest stats command, which allows people to associate their github username to then pull the correct stats. This does not check if the name exists on the leaderboard and that is intentional. Due to the cooldown on the leaderboard I don't want to rely on that before someone can link their account. Additionally, someone may change their display name on the Advent of Code side and I don't think validation of it existing on the leaderboard gets us anything. The usefulness of this function will not be apparent in this cog, but it is necessary for something fun I'd like to do. --- bot/exts/events/advent_of_code/_cog.py | 69 ++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index af1cbcf5..1b1cd9f8 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -6,6 +6,7 @@ from typing import Optional import arrow import discord +from async_rediscache import RedisCache from discord.ext import commands from bot.bot import Bot @@ -29,6 +30,8 @@ AOC_WHITELIST = AOC_WHITELIST_RESTRICTED + (Channels.advent_of_code,) class AdventOfCode(commands.Cog): """Advent of Code festivities! Ho Ho Ho!""" + account_links = RedisCache() + def __init__(self, bot: Bot): self.bot = bot @@ -172,6 +175,72 @@ class AdventOfCode(commands.Cog): else: await ctx.message.add_reaction(Emojis.envelope) + @in_month(Month.NOVEMBER, Month.DECEMBER) + @adventofcode_group.command( + name="link", + aliases=("connect",), + brief="Tie your Discord account with your Advent of Code name." + ) + @whitelist_override(channels=AOC_WHITELIST) + async def aoc_link_account(self, ctx: commands.Context, aoc_name: str = None) -> None: + """ + Link your Discord Account to your Advent of Code name. + + Stored in a Redis Cache, Discord ID: Advent of Code Name + """ + cache_items = await self.account_links.items() + + # A short circuit in case the cache is empty + if len(cache_items) == 0 and aoc_name: + log.info(f"{ctx.author} ({ctx.author.id}) is now linked to {aoc_name}.") + await self.account_links.set(ctx.author.id, aoc_name) + await ctx.reply(f"You have linked your Discord ID to {aoc_name}.") + return + elif len(cache_items) == 0: + await ctx.reply( + "You have not linked an Advent of Code account." + "Please re-run the command with one specified." + ) + return + + cache_aoc_name = [value for _, value in cache_items] + + if aoc_name: + # Let's check the current values in the cache to make sure it isn't already tied to a different account + if aoc_name == await self.account_links.get(ctx.author.id): + await ctx.reply(f"{aoc_name} is already tied to your account.") + return + elif aoc_name in cache_aoc_name: + log.info( + f"{ctx.author} ({ctx.author.id}) tried to connect their account to {aoc_name}," + " but it's already connected to another user." + ) + await ctx.reply( + f"{aoc_name} is already tied to another account." + " Please contact an admin if you believe this is an error." + ) + return + + # Update an existing link + if old_aoc_name := await self.account_links.get(ctx.author.id): + log.info(f"{ctx.author} ({ctx.author.id}) has changed their link from {old_aoc_name} to {aoc_name}.") + await self.account_links.set(ctx.author.id, aoc_name) + await ctx.reply(f"Your linked account has been changed to {aoc_name}.") + else: + # Create a new link + log.info(f"{ctx.author} ({ctx.author.id}) is now linked to {aoc_name}.") + await self.account_links.set(ctx.author.id, aoc_name) + await ctx.reply(f"You have linked your Discord ID to {aoc_name}.") + else: + # User has not supplied a name, let's check if they're in the cache or not + if cache_name := await self.account_links.get(ctx.author.id): + await ctx.reply(f"You have already linked an Advent of Code account: {cache_name}.") + else: + await ctx.reply( + "You have not linked an Advent of Code account." + " Please re-run the command with one specified." + ) + @in_month(Month.DECEMBER) @adventofcode_group.command( name="dayandstar", -- cgit v1.2.3 From 1dba7a7a7132839230f776a8ecb73b9def93174f Mon Sep 17 00:00:00 2001 From: Ben Soyka Date: Wed, 1 Dec 2021 20:44:46 -0700 Subject: Make self_placement_name keyword-only in .aoc lb --- bot/exts/events/advent_of_code/_cog.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index af1cbcf5..900c3469 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -220,6 +220,7 @@ class AdventOfCode(commands.Cog): async def aoc_leaderboard( self, ctx: commands.Context, + *, self_placement_name: Optional[str] = None, ) -> None: """ -- cgit v1.2.3 From 4959f085537421814159734070b74dadd566501f Mon Sep 17 00:00:00 2001 From: Ben Soyka Date: Wed, 1 Dec 2021 21:16:49 -0700 Subject: Strip quotes from start/end of the username for .aoc lb --- bot/exts/events/advent_of_code/_cog.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 900c3469..c6225356 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -229,6 +229,10 @@ class AdventOfCode(commands.Cog): Additionally you can specify a `self_placement_name` that will append the specified profile's personal stats to the top of the leaderboard """ + # Strip quotes from the self placement name if needed (e.g. "My Name" -> My Name) + if self_placement_name and self_placement_name[0] == self_placement_name[-1] == '"': + self_placement_name = self_placement_name[1:-1] + async with ctx.typing(): try: leaderboard = await _helpers.fetch_leaderboard(self_placement_name=self_placement_name) -- cgit v1.2.3 From aea61a096bfbf60fab9711698c9353635b13ea0c Mon Sep 17 00:00:00 2001 From: Ben Soyka Date: Wed, 1 Dec 2021 21:43:17 -0700 Subject: Shorten parameter name for .aoc lb --- bot/exts/events/advent_of_code/_cog.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index c6225356..0f6739fc 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -217,25 +217,20 @@ class AdventOfCode(commands.Cog): brief="Get a snapshot of the PyDis private AoC leaderboard", ) @whitelist_override(channels=AOC_WHITELIST_RESTRICTED) - async def aoc_leaderboard( - self, - ctx: commands.Context, - *, - self_placement_name: Optional[str] = None, - ) -> None: + async def aoc_leaderboard(self, ctx: commands.Context, *, aoc_name: Optional[str] = None) -> None: """ Get the current top scorers of the Python Discord Leaderboard. - Additionally you can specify a `self_placement_name` - that will append the specified profile's personal stats to the top of the leaderboard + Additionally you can specify an `aoc_name` that will append the + specified profile's personal stats to the top of the leaderboard """ # Strip quotes from the self placement name if needed (e.g. "My Name" -> My Name) - if self_placement_name and self_placement_name[0] == self_placement_name[-1] == '"': - self_placement_name = self_placement_name[1:-1] + if aoc_name and aoc_name.startswith('"') and aoc_name.endswith('"'): + aoc_name = aoc_name[1:-1] async with ctx.typing(): try: - leaderboard = await _helpers.fetch_leaderboard(self_placement_name=self_placement_name) + leaderboard = await _helpers.fetch_leaderboard(self_placement_name=aoc_name) except _helpers.FetchingLeaderboardFailedError: await ctx.send(":x: Unable to fetch leaderboard!") return @@ -243,10 +238,10 @@ class AdventOfCode(commands.Cog): number_of_participants = leaderboard["number_of_participants"] top_count = min(AocConfig.leaderboard_displayed_members, number_of_participants) - self_placement_header = "(and your personal stats compared to the top 10)" if self_placement_name else "" + self_placement_header = "(and your personal stats compared to the top 10)" if aoc_name else "" header = f"Here's our current top {top_count}{self_placement_header}! {Emojis.christmas_tree * 3}" table = "```\n" \ - f"{leaderboard['placement_leaderboard'] if self_placement_name else leaderboard['top_leaderboard']}" \ + f"{leaderboard['placement_leaderboard'] if aoc_name else leaderboard['top_leaderboard']}" \ "\n```" info_embed = _helpers.get_summary_embed(leaderboard) -- cgit v1.2.3 From 4a06ec80cc9e78294475ab23c41649d47798cca4 Mon Sep 17 00:00:00 2001 From: Ben Soyka Date: Thu, 2 Dec 2021 15:33:29 -0700 Subject: Note that only one layer of quotes is stripped in .aoc lb --- bot/exts/events/advent_of_code/_cog.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 0f6739fc..9ae2d059 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -224,7 +224,9 @@ class AdventOfCode(commands.Cog): Additionally you can specify an `aoc_name` that will append the specified profile's personal stats to the top of the leaderboard """ - # Strip quotes from the self placement name if needed (e.g. "My Name" -> My Name) + # Strip quotes from the AoC username if needed (e.g. "My Name" -> My Name) + # Note: only strips one layer of quotes to allow names with quotes at the start and end + # e.g. ""My Name"" -> "My Name" if aoc_name and aoc_name.startswith('"') and aoc_name.endswith('"'): aoc_name = aoc_name[1:-1] -- cgit v1.2.3 From 914e4abe1f168167d8b1126adeb1bc27bff28e6d Mon Sep 17 00:00:00 2001 From: Ben Soyka Date: Thu, 2 Dec 2021 15:34:45 -0700 Subject: Note why .aoc lb strips quotes from names --- bot/exts/events/advent_of_code/_cog.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 9ae2d059..3f9f5787 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -225,6 +225,7 @@ class AdventOfCode(commands.Cog): specified profile's personal stats to the top of the leaderboard """ # Strip quotes from the AoC username if needed (e.g. "My Name" -> My Name) + # This is to keep compatibility with those already used to wrapping the AoC name in quotes # Note: only strips one layer of quotes to allow names with quotes at the start and end # e.g. ""My Name"" -> "My Name" if aoc_name and aoc_name.startswith('"') and aoc_name.endswith('"'): -- cgit v1.2.3 From 846c34fd8988eaede08186fa9fb342213dc85585 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Fri, 3 Dec 2021 18:46:39 -0500 Subject: Remove unneeded check and add comments Removes the unneeded check for if the cache is empty. Also adds a seconds comment about the format of the contents of the Redis cache. --- bot/exts/events/advent_of_code/_cog.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 1b1cd9f8..8d87b5bc 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -30,6 +30,7 @@ AOC_WHITELIST = AOC_WHITELIST_RESTRICTED + (Channels.advent_of_code,) class AdventOfCode(commands.Cog): """Advent of Code festivities! Ho Ho Ho!""" + # Redis Cache for linking Discord IDs to Advent of Code usernames account_links = RedisCache() def __init__(self, bot: Bot): @@ -186,23 +187,9 @@ class AdventOfCode(commands.Cog): """ Link your Discord Account to your Advent of Code name. - Stored in a Redis Cache, Discord ID: Advent of Code Name + Stored in a Redis Cache with the format of `Discord ID: Advent of Code Name` """ cache_items = await self.account_links.items() - - # A short circuit in case the cache is empty - if len(cache_items) == 0 and aoc_name: - log.info(f"{ctx.author} ({ctx.author.id}) is now linked to {aoc_name}.") - await self.account_links.set(ctx.author.id, aoc_name) - await ctx.reply(f"You have linked your Discord ID to {aoc_name}.") - return - elif len(cache_items) == 0: - await ctx.reply( - "You have not linked an Advent of Code account." - "Please re-run the command with one specified." - ) - return - cache_aoc_name = [value for _, value in cache_items] if aoc_name: -- cgit v1.2.3 From 1ac965f67fea8e5dd0e0f026aca27e3368f4e44e Mon Sep 17 00:00:00 2001 From: Janine vN Date: Fri, 3 Dec 2021 20:50:17 -0500 Subject: Add unlink AoC command Adds the ability for the user to unlink their advent of code name. It will delete the entry in the cache if it exists. --- bot/exts/events/advent_of_code/_cog.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 8d87b5bc..7f904f6b 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -228,6 +228,27 @@ class AdventOfCode(commands.Cog): " Please re-run the command with one specified." ) + @in_month(Month.NOVEMBER, Month.DECEMBER) + @adventofcode_group.command( + name="unlink", + aliases=("disconnect",), + brief="Tie your Discord account with your Advent of Code name." + ) + @whitelist_override(channels=AOC_WHITELIST) + async def aoc_unlink_account(self, ctx: commands.Context) -> None: + """ + Unlink your Discord ID with your Advent of Code leaderboard name. + + Deletes the entry that was Stored in the Redis cache. + """ + if aoc_cache_name := await self.account_links.get(ctx.author.id): + log.info(f"Unlinking {ctx.author} ({ctx.author.id}) from Advent of Code account {aoc_cache_name}") + await self.account_links.delete(ctx.author.id) + await ctx.reply(f"We have removed the link between your Discord ID and {aoc_cache_name}.") + else: + log.info(f"Attempted to unlink {ctx.author} ({ctx.author.id}), but not link was found.") + await ctx.reply("You don't have an Advent of Code account linked.") + @in_month(Month.DECEMBER) @adventofcode_group.command( name="dayandstar", -- cgit v1.2.3 From 00e3fe5bede6f8310405e143179530df0ad3ca95 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Fri, 3 Dec 2021 20:53:59 -0500 Subject: Adjust wording on log statements to present tense --- bot/exts/events/advent_of_code/_cog.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 7f904f6b..b7d26cb9 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -210,12 +210,12 @@ class AdventOfCode(commands.Cog): # Update an existing link if old_aoc_name := await self.account_links.get(ctx.author.id): - log.info(f"{ctx.author} ({ctx.author.id}) has changed their link from {old_aoc_name} to {aoc_name}.") + log.info(f"Changing link for{ctx.author} ({ctx.author.id}) from {old_aoc_name} to {aoc_name}.") await self.account_links.set(ctx.author.id, aoc_name) await ctx.reply(f"Your linked account has been changed to {aoc_name}.") else: # Create a new link - log.info(f"{ctx.author} ({ctx.author.id}) is now linked to {aoc_name}.") + log.info(f"Linking {ctx.author} ({ctx.author.id}) to account {aoc_name}.") await self.account_links.set(ctx.author.id, aoc_name) await ctx.reply(f"You have linked your Discord ID to {aoc_name}.") else: @@ -246,7 +246,7 @@ class AdventOfCode(commands.Cog): await self.account_links.delete(ctx.author.id) await ctx.reply(f"We have removed the link between your Discord ID and {aoc_cache_name}.") else: - log.info(f"Attempted to unlink {ctx.author} ({ctx.author.id}), but not link was found.") + log.info(f"Attempted to unlink {ctx.author} ({ctx.author.id}), but no link was found.") await ctx.reply("You don't have an Advent of Code account linked.") @in_month(Month.DECEMBER) -- cgit v1.2.3 From b3a7c79ffb1f4220bad8ca3814d594a9b1b00826 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Fri, 3 Dec 2021 21:02:28 -0500 Subject: Make aoc_name a keyword arguemnt to accept spaces Makes `aoc_name` in the link command a keyword only argument. This allows users to link accounts with spaces in the name without having to use quotes. --- bot/exts/events/advent_of_code/_cog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index b7d26cb9..55fd0ac6 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -183,7 +183,7 @@ class AdventOfCode(commands.Cog): brief="Tie your Discord account with your Advent of Code name." ) @whitelist_override(channels=AOC_WHITELIST) - async def aoc_link_account(self, ctx: commands.Context, aoc_name: str = None) -> None: + async def aoc_link_account(self, ctx: commands.Context, *, aoc_name: str = None) -> None: """ Link your Discord Account to your Advent of Code name. -- cgit v1.2.3 From b134010e1682a40d2aa9e3ce893c274388896680 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Fri, 3 Dec 2021 21:29:01 -0500 Subject: Adjust `.aoc lb` to use linked account in cache If the user has not supplied a name to use for the leaderboard, then code will check if they have an account linked. If they do, it will use the linked account in the leaderboard to show placement. --- bot/exts/events/advent_of_code/_cog.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 16176c69..49b604ab 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -311,6 +311,10 @@ class AdventOfCode(commands.Cog): if aoc_name and aoc_name.startswith('"') and aoc_name.endswith('"'): aoc_name = aoc_name[1:-1] + # Check if an advent of code account is linked in the Redis Cache if aoc_name is not given + if (aoc_cache_name := await self.account_links.get(ctx.author.id)) and aoc_name is None: + aoc_name = aoc_cache_name + async with ctx.typing(): try: leaderboard = await _helpers.fetch_leaderboard(self_placement_name=aoc_name) @@ -321,7 +325,7 @@ class AdventOfCode(commands.Cog): number_of_participants = leaderboard["number_of_participants"] top_count = min(AocConfig.leaderboard_displayed_members, number_of_participants) - self_placement_header = "(and your personal stats compared to the top 10)" if aoc_name else "" + self_placement_header = " (and your personal stats compared to the top 10)" if aoc_name else "" header = f"Here's our current top {top_count}{self_placement_header}! {Emojis.christmas_tree * 3}" table = "```\n" \ f"{leaderboard['placement_leaderboard'] if aoc_name else leaderboard['top_leaderboard']}" \ -- cgit v1.2.3 From f4324a0f447a7791743ce9a5c4f0957f32738b78 Mon Sep 17 00:00:00 2001 From: Janine vN Date: Sat, 4 Dec 2021 10:55:49 -0500 Subject: Adjust variable name for clarity and add space --- bot/exts/events/advent_of_code/_cog.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 49b604ab..52254ea1 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -193,14 +193,14 @@ class AdventOfCode(commands.Cog): Stored in a Redis Cache with the format of `Discord ID: Advent of Code Name` """ cache_items = await self.account_links.items() - cache_aoc_name = [value for _, value in cache_items] + cache_aoc_names = [value for _, value in cache_items] if aoc_name: # Let's check the current values in the cache to make sure it isn't already tied to a different account if aoc_name == await self.account_links.get(ctx.author.id): await ctx.reply(f"{aoc_name} is already tied to your account.") return - elif aoc_name in cache_aoc_name: + elif aoc_name in cache_aoc_names: log.info( f"{ctx.author} ({ctx.author.id}) tried to connect their account to {aoc_name}," " but it's already connected to another user." @@ -213,7 +213,7 @@ class AdventOfCode(commands.Cog): # Update an existing link if old_aoc_name := await self.account_links.get(ctx.author.id): - log.info(f"Changing link for{ctx.author} ({ctx.author.id}) from {old_aoc_name} to {aoc_name}.") + log.info(f"Changing link for {ctx.author} ({ctx.author.id}) from {old_aoc_name} to {aoc_name}.") await self.account_links.set(ctx.author.id, aoc_name) await ctx.reply(f"Your linked account has been changed to {aoc_name}.") else: -- cgit v1.2.3 From 03b5464e6e37f625ba7a590d45120f4b46b1d0aa Mon Sep 17 00:00:00 2001 From: Janine vN Date: Sat, 4 Dec 2021 11:00:48 -0500 Subject: Add more information to `.aoc lb` error embed Advent of Code Leaderboard BadArgument error embed now mentions to join the leaderboard and to wait up to 30 minutes if you've joined recently. --- bot/exts/events/advent_of_code/_helpers.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_helpers.py b/bot/exts/events/advent_of_code/_helpers.py index 35258544..807cc275 100644 --- a/bot/exts/events/advent_of_code/_helpers.py +++ b/bot/exts/events/advent_of_code/_helpers.py @@ -216,6 +216,9 @@ def _format_leaderboard(leaderboard: dict[str, dict], self_placement_name: str = if self_placement_name and not self_placement_exists: raise commands.BadArgument( "Sorry, your profile does not exist in this leaderboard." + "\n\n" + "To join our leaderboard, run the command `.aoc join`." + " If you've joined recently, please wait up to 30 minutes for our leaderboard to refresh." ) return "\n".join(leaderboard_lines) -- cgit v1.2.3 From 21518aed7b3cfb9c2ec4fa1722689a6c4df56372 Mon Sep 17 00:00:00 2001 From: ChrisLovering Date: Sat, 25 Dec 2021 22:23:12 +0000 Subject: Add hourly task to assign AoC completer role This task uses the cached leaderboard to see who has all 50 stars and assigns them a role to highlight them as completers. --- bot/constants.py | 1 + bot/exts/events/advent_of_code/_cog.py | 60 ++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/constants.py b/bot/constants.py index 854fbe55..01f825a0 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -291,6 +291,7 @@ class Roles(NamedTuple): helpers = int(environ.get("ROLE_HELPERS", 267630620367257601)) core_developers = 587606783669829632 everyone = int(environ.get("BOT_GUILD", 267624335836053506)) + aoc_completionist = int(environ.get("AOC_COMPLETIONIST_ROLE_ID", 916691790181056532)) class Tokens(NamedTuple): diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 52254ea1..6974d89c 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -7,12 +7,15 @@ from typing import Optional import arrow import discord from async_rediscache import RedisCache -from discord.ext import commands +from discord.ext import commands, tasks from bot.bot import Bot -from bot.constants import AdventOfCode as AocConfig, Channels, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS +from bot.constants import ( + AdventOfCode as AocConfig, Channels, Client, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS +) from bot.exts.events.advent_of_code import _helpers from bot.exts.events.advent_of_code.views.dayandstarview import AoCDropdownView +from bot.utils import members from bot.utils.decorators import InChannelCheckFailure, in_month, whitelist_override, with_role from bot.utils.extensions import invoke_help_command @@ -31,6 +34,7 @@ class AdventOfCode(commands.Cog): """Advent of Code festivities! Ho Ho Ho!""" # Redis Cache for linking Discord IDs to Advent of Code usernames + # RedisCache[member_id: aoc_username_string] account_links = RedisCache() def __init__(self, bot: Bot): @@ -52,6 +56,57 @@ class AdventOfCode(commands.Cog): self.status_task.set_name("AoC Status Countdown") self.status_task.add_done_callback(_helpers.background_task_callback) + self.completionist_task.start() + + @tasks.loop(minutes=10.0) + async def completionist_task(self) -> None: + """ + Give members who have completed all 50 AoC stars the completionist role. + + Runs on a schedule, as defined in the task.loop decorator. + """ + await self.bot.wait_until_guild_available() + guild = self.bot.get_guild(Client.guild) + completionist_role = guild.get_role(Roles.aoc_completionist) + if completionist_role is None: + log.warning("Could not find the AoC completionist role; cancelling completionist task.") + self.completer_task.cancel() + return + + aoc_name_to_member_id = { + aoc_name: member_id + for member_id, aoc_name in await self.account_links.items() + } + + try: + leaderboard = await _helpers.fetch_leaderboard() + except _helpers.FetchingLeaderboardFailedError: + await self.bot.send_log("Unable to fetch AoC leaderboard during role sync.") + return + + placement_leaderboard = json.loads(leaderboard["placement_leaderboard"]) + + for member_aoc_info in placement_leaderboard.values(): + if not member_aoc_info["stars"] == 50: + # Only give the role to people who have completed all 50 stars + continue + + member_id = aoc_name_to_member_id[member_aoc_info["name"]] + if not member_id: + continue + + member = members.get_or_fetch_member(guild, member_id) + if member is None: + continue + + if completionist_role in member.roles: + continue + + if await self.completionist_block_list.contains(member_id): + continue + + await members.handle_role_change(member, member.add_roles, completionist_role) + @commands.group(name="adventofcode", aliases=("aoc",)) @whitelist_override(channels=AOC_WHITELIST) async def adventofcode_group(self, ctx: commands.Context) -> None: @@ -408,6 +463,7 @@ class AdventOfCode(commands.Cog): log.debug("Unloading the cog and canceling the background task.") self.notification_task.cancel() self.status_task.cancel() + self.completionist_task.cancel() def _build_about_embed(self) -> discord.Embed: """Build and return the informational "About AoC" embed from the resources file.""" -- cgit v1.2.3 From e44460d56364ff45ab19352af9719da5def4161f Mon Sep 17 00:00:00 2001 From: ChrisLovering Date: Sat, 25 Dec 2021 22:28:10 +0000 Subject: Ability to block users from AoC completer role --- bot/exts/events/advent_of_code/_cog.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 6974d89c..67d43556 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -37,6 +37,10 @@ class AdventOfCode(commands.Cog): # RedisCache[member_id: aoc_username_string] account_links = RedisCache() + # A dict with keys of member_ids to block from getting the role + # RedisCache[member_id: None] + completionist_block_list = RedisCache() + def __init__(self, bot: Bot): self.bot = bot @@ -91,11 +95,11 @@ class AdventOfCode(commands.Cog): # Only give the role to people who have completed all 50 stars continue - member_id = aoc_name_to_member_id[member_aoc_info["name"]] + member_id = aoc_name_to_member_id.get(member_aoc_info["name"], None) if not member_id: continue - member = members.get_or_fetch_member(guild, member_id) + member = await members.get_or_fetch_member(guild, member_id) if member is None: continue @@ -114,6 +118,19 @@ class AdventOfCode(commands.Cog): if not ctx.invoked_subcommand: await invoke_help_command(ctx) + @with_role(Roles.admins) + @adventofcode_group.command( + name="block", + brief="Block a user from getting the completionist role.", + ) + async def block_from_role(self, ctx: commands.Context, member: discord.Member) -> None: + """Block the given member from receiving the AoC completionist role, removing it from them if needed.""" + completionist_role = ctx.guild.get_role(Roles.aoc_completionist) + if completionist_role in member.roles: + await member.remove_roles(completionist_role) + + await self.completionist_block_list.set(member.id, "sentinel") + @commands.guild_only() @adventofcode_group.command( name="subscribe", -- cgit v1.2.3 From d55cbc8e4ed371f0ca11b97b1dd6e41cf8f6719c Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 28 Dec 2021 22:20:01 +0000 Subject: Condense conditional logic in AoC completionist role task --- bot/exts/events/advent_of_code/_cog.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 67d43556..9d412adf 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -100,16 +100,11 @@ class AdventOfCode(commands.Cog): continue member = await members.get_or_fetch_member(guild, member_id) - if member is None: + if member is None or completionist_role in member.roles: continue - if completionist_role in member.roles: - continue - - if await self.completionist_block_list.contains(member_id): - continue - - await members.handle_role_change(member, member.add_roles, completionist_role) + if not await self.completionist_block_list.contains(member_id): + await members.handle_role_change(member, member.add_roles, completionist_role) @commands.group(name="adventofcode", aliases=("aoc",)) @whitelist_override(channels=AOC_WHITELIST) -- cgit v1.2.3 From dc2e3a72cf7958d9410d3b1f1e9d13d1eadcef89 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Tue, 28 Dec 2021 22:41:20 +0000 Subject: Inform invoker after successfully blocking a user from AoC comp. role --- bot/exts/events/advent_of_code/_cog.py | 1 + 1 file changed, 1 insertion(+) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 9d412adf..30bcaae6 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -125,6 +125,7 @@ class AdventOfCode(commands.Cog): await member.remove_roles(completionist_role) await self.completionist_block_list.set(member.id, "sentinel") + await ctx.send(f":+1: Blocked {member.mention} from getting the AoC completionist role.") @commands.guild_only() @adventofcode_group.command( -- cgit v1.2.3 From 4ecec867d9f1d06f23d7fd7216dd0902de82cfa0 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Wed, 29 Dec 2021 13:34:24 +0000 Subject: Add logging to AoC role task to help debugging issues --- bot/exts/events/advent_of_code/_cog.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 30bcaae6..c597fd0e 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -74,7 +74,7 @@ class AdventOfCode(commands.Cog): completionist_role = guild.get_role(Roles.aoc_completionist) if completionist_role is None: log.warning("Could not find the AoC completionist role; cancelling completionist task.") - self.completer_task.cancel() + self.completionist_task.cancel() return aoc_name_to_member_id = { @@ -97,13 +97,20 @@ class AdventOfCode(commands.Cog): member_id = aoc_name_to_member_id.get(member_aoc_info["name"], None) if not member_id: + log.debug(f"Could not find member_id for {member_aoc_info['name']}, not giving role.") continue member = await members.get_or_fetch_member(guild, member_id) - if member is None or completionist_role in member.roles: + if member is None: + log.debug(f"Could not find {member_id}, not giving role.") + continue + + if completionist_role in member.roles: + log.debug(f"{member.name} ({member.mention}) already has the completionist role.") continue if not await self.completionist_block_list.contains(member_id): + log.debug(f"Giving completionist role to {member.name} ({member.mention}).") await members.handle_role_change(member, member.add_roles, completionist_role) @commands.group(name="adventofcode", aliases=("aoc",)) -- cgit v1.2.3 From 8907a96b6a2a26ab8885cd5dd7bec0874f419e3e Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 1 Jan 2022 14:24:24 +0000 Subject: Allow AoC commands to be run in January --- bot/exts/events/advent_of_code/_cog.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index c597fd0e..493d58b2 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -254,7 +254,7 @@ class AdventOfCode(commands.Cog): else: await ctx.message.add_reaction(Emojis.envelope) - @in_month(Month.NOVEMBER, Month.DECEMBER) + @in_month(Month.NOVEMBER, Month.DECEMBER, Month.JANUARY) @adventofcode_group.command( name="link", aliases=("connect",), @@ -306,7 +306,7 @@ class AdventOfCode(commands.Cog): " Please re-run the command with one specified." ) - @in_month(Month.NOVEMBER, Month.DECEMBER) + @in_month(Month.NOVEMBER, Month.DECEMBER, Month.JANUARY) @adventofcode_group.command( name="unlink", aliases=("disconnect",), @@ -327,7 +327,7 @@ class AdventOfCode(commands.Cog): log.info(f"Attempted to unlink {ctx.author} ({ctx.author.id}), but no link was found.") await ctx.reply("You don't have an Advent of Code account linked.") - @in_month(Month.DECEMBER) + @in_month(Month.DECEMBER, Month.JANUARY) @adventofcode_group.command( name="dayandstar", aliases=("daynstar", "daystar"), @@ -365,7 +365,7 @@ class AdventOfCode(commands.Cog): await view.wait() await message.edit(view=None) - @in_month(Month.DECEMBER) + @in_month(Month.DECEMBER, Month.JANUARY) @adventofcode_group.command( name="leaderboard", aliases=("board", "lb"), @@ -410,7 +410,7 @@ class AdventOfCode(commands.Cog): await ctx.send(content=f"{header}\n\n{table}", embed=info_embed) return - @in_month(Month.DECEMBER) + @in_month(Month.DECEMBER, Month.JANUARY) @adventofcode_group.command( name="global", aliases=("globalboard", "gb"), -- cgit v1.2.3 From d32c15206be6a1a726a57eea614de4856d5473d8 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sat, 1 Jan 2022 14:26:34 +0000 Subject: Allow AoC join to be ran in the month before and after the event --- bot/exts/events/advent_of_code/_cog.py | 10 +++++++--- tox.ini | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 493d58b2..a9625153 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -213,9 +213,13 @@ class AdventOfCode(commands.Cog): @whitelist_override(channels=AOC_WHITELIST) async def join_leaderboard(self, ctx: commands.Context) -> None: """DM the user the information for joining the Python Discord leaderboard.""" - current_year = datetime.now().year - if current_year != AocConfig.year: - await ctx.send(f"The Python Discord leaderboard for {current_year} is not yet available!") + current_date = datetime.now() + if ( + current_date.month not in (Month.NOVEMBER, Month.DECEMBER) and current_date.year != AocConfig.year or + current_date.month != Month.JANUARY and current_date.year != AocConfig.year + 1 + ): + # Only allow joining the leaderboard in the run up to AOC and the January following. + await ctx.send(f"The Python Discord leaderboard for {current_date.year} is not yet available!") return author = ctx.author diff --git a/tox.ini b/tox.ini index af87e6fc..f561fcd9 100644 --- a/tox.ini +++ b/tox.ini @@ -11,9 +11,11 @@ ignore= # Docstring Quotes D301,D302, # Docstring Content - D400,D401,D402,D404,D405,D406,D407,D408,D409,D410,D411,D412,D413,D414,D416,D417 + D400,D401,D402,D404,D405,D406,D407,D408,D409,D410,D411,D412,D413,D414,D416,D417, # Type Annotations - ANN002,ANN003,ANN101,ANN102,ANN204,ANN206 + ANN002,ANN003,ANN101,ANN102,ANN204,ANN206, + # Binary operators over multiple lines + W504, exclude= __pycache__,.cache, venv,.venv, -- cgit v1.2.3 From 7cc3e1ceeee906c649013bd9d205b50cb5dcad59 Mon Sep 17 00:00:00 2001 From: onerandomusername Date: Fri, 3 Dec 2021 14:55:50 -0500 Subject: nit: make last refreshed time above the rest of the embed --- bot/exts/events/advent_of_code/_helpers.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_helpers.py b/bot/exts/events/advent_of_code/_helpers.py index 807cc275..ac2a0f6b 100644 --- a/bot/exts/events/advent_of_code/_helpers.py +++ b/bot/exts/events/advent_of_code/_helpers.py @@ -368,11 +368,13 @@ 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"] refresh_minutes = AdventOfCode.leaderboard_cache_expiry_seconds // 60 + refreshed_unix = int(datetime.datetime.fromisoformat(leaderboard["leaderboard_fetched_at"]).timestamp()) - aoc_embed = discord.Embed( - colour=Colours.soft_green, - timestamp=datetime.datetime.fromisoformat(leaderboard["leaderboard_fetched_at"]), - description=f"*The leaderboard is refreshed every {refresh_minutes} minutes.*" + aoc_embed = discord.Embed(colour=Colours.soft_green) + + aoc_embed.description = ( + f"The leaderboard is refreshed every {refresh_minutes} minutes.\n" + f"Last Updated: " ) aoc_embed.add_field( name="Number of Participants", @@ -386,7 +388,6 @@ def get_summary_embed(leaderboard: dict) -> discord.Embed: inline=True, ) aoc_embed.set_author(name="Advent of Code", url=leaderboard_url) - aoc_embed.set_footer(text="Last Updated") aoc_embed.set_thumbnail(url=AOC_EMBED_THUMBNAIL) return aoc_embed -- cgit v1.2.3 From 4c451b170e0005726dac2489835045c1dc43ce62 Mon Sep 17 00:00:00 2001 From: onerandomusername Date: Sun, 2 Jan 2022 01:23:27 -0500 Subject: fix: don't rely on the current timezone --- bot/exts/events/advent_of_code/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_helpers.py b/bot/exts/events/advent_of_code/_helpers.py index ac2a0f6b..15b1329d 100644 --- a/bot/exts/events/advent_of_code/_helpers.py +++ b/bot/exts/events/advent_of_code/_helpers.py @@ -332,7 +332,7 @@ async def fetch_leaderboard(invalidate_cache: bool = False, self_placement_name: number_of_participants = len(leaderboard) formatted_leaderboard = _format_leaderboard(leaderboard) full_leaderboard_url = await _upload_leaderboard(formatted_leaderboard) - leaderboard_fetched_at = datetime.datetime.utcnow().isoformat() + leaderboard_fetched_at = datetime.datetime.now(datetime.timezone.utc).isoformat() cached_leaderboard = { "placement_leaderboard": json.dumps(raw_leaderboard_data), -- cgit v1.2.3 From c7b93780e509e05121ce1c3deacc38c6f884a6c9 Mon Sep 17 00:00:00 2001 From: aru Date: Sun, 2 Jan 2022 15:16:35 -0500 Subject: Yank aoc subscribe (#972) --- bot/exts/events/advent_of_code/_cog.py | 45 +++++++--------------------------- 1 file changed, 9 insertions(+), 36 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index a9625153..a5410871 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -11,12 +11,13 @@ from discord.ext import commands, tasks from bot.bot import Bot from bot.constants import ( - AdventOfCode as AocConfig, Channels, Client, Colours, Emojis, Month, Roles, WHITELISTED_CHANNELS + AdventOfCode as AocConfig, Channels, Client, Colours, Emojis, Month, PYTHON_PREFIX, Roles, WHITELISTED_CHANNELS ) from bot.exts.events.advent_of_code import _helpers from bot.exts.events.advent_of_code.views.dayandstarview import AoCDropdownView from bot.utils import members from bot.utils.decorators import InChannelCheckFailure, in_month, whitelist_override, with_role +from bot.utils.exceptions import MovedCommandError from bot.utils.extensions import invoke_help_command log = logging.getLogger(__name__) @@ -137,45 +138,17 @@ class AdventOfCode(commands.Cog): @commands.guild_only() @adventofcode_group.command( name="subscribe", - aliases=("sub", "notifications", "notify", "notifs"), - brief="Notifications for new days" + aliases=("sub", "notifications", "notify", "notifs", "unsubscribe", "unsub"), + help=f"NOTE: This command has been moved to {PYTHON_PREFIX}subscribe", ) @whitelist_override(channels=AOC_WHITELIST) async def aoc_subscribe(self, ctx: commands.Context) -> None: - """Assign the role for notifications about new days being ready.""" - current_year = datetime.now().year - if current_year != AocConfig.year: - await ctx.send(f"You can't subscribe to {current_year}'s Advent of Code announcements yet!") - return - - role = ctx.guild.get_role(AocConfig.role_id) - unsubscribe_command = f"{ctx.prefix}{ctx.command.root_parent} unsubscribe" - - 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." - ) - 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." - ) - - @in_month(Month.DECEMBER) - @commands.guild_only() - @adventofcode_group.command(name="unsubscribe", aliases=("unsub",), brief="Notifications for new days") - @whitelist_override(channels=AOC_WHITELIST) - async def aoc_unsubscribe(self, ctx: commands.Context) -> None: - """Remove the role for notifications about new days being ready.""" - role = ctx.guild.get_role(AocConfig.role_id) + """ + Deprecated role command. - if role in ctx.author.roles: - await ctx.author.remove_roles(role) - await ctx.send("Okay! You have been __unsubscribed__ from notifications about new Advent of Code tasks.") - else: - await ctx.send("Hey, you don't even get any notifications about new Advent of Code tasks currently anyway.") + This command has been moved to bot, and will be removed in the future. + """ + raise MovedCommandError(f"{PYTHON_PREFIX}subscribe") @adventofcode_group.command(name="countdown", aliases=("count", "c"), brief="Return time left until next day") @whitelist_override(channels=AOC_WHITELIST) -- cgit v1.2.3 From 5276045e3594c8851b83dd8b8fd8e7ba014ac3b2 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Sun, 9 Jan 2022 19:06:36 +0000 Subject: Fix aoc join in date logic --- bot/exts/events/advent_of_code/_cog.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index a5410871..01161f26 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -187,9 +187,10 @@ class AdventOfCode(commands.Cog): async def join_leaderboard(self, ctx: commands.Context) -> None: """DM the user the information for joining the Python Discord leaderboard.""" current_date = datetime.now() - if ( - current_date.month not in (Month.NOVEMBER, Month.DECEMBER) and current_date.year != AocConfig.year or - current_date.month != Month.JANUARY and current_date.year != AocConfig.year + 1 + allowed_months = (Month.NOVEMBER.value, Month.DECEMBER.value) + if not ( + current_date.month in allowed_months and current_date.year == AocConfig.year or + current_date.month == Month.JANUARY.value and current_date.year == AocConfig.year + 1 ): # Only allow joining the leaderboard in the run up to AOC and the January following. await ctx.send(f"The Python Discord leaderboard for {current_date.year} is not yet available!") -- cgit v1.2.3 From 5ef4b73a9d6f3d15d6fb22874e7de3af7d2928e3 Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Wed, 12 Jan 2022 14:06:50 +0000 Subject: Fix AoC name lookup for anon users When a user doesn't set a name, the AoC API doesn't return a name key at all, so we need to make use of the ID field instead, to build the name based on a similar tempalte that AoC uses for it's leaderboard. Co-authored-by: ToxicKidz <78174417+ToxicKidz@users.noreply.github.com> --- bot/exts/events/advent_of_code/_cog.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 01161f26..3acfef39 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -96,7 +96,9 @@ class AdventOfCode(commands.Cog): # Only give the role to people who have completed all 50 stars continue - member_id = aoc_name_to_member_id.get(member_aoc_info["name"], None) + aoc_name = member_aoc_info["name"] or f"Anonymous #{member_aoc_info['id']}" + + member_id = aoc_name_to_member_id.get(aoc_name) if not member_id: log.debug(f"Could not find member_id for {member_aoc_info['name']}, not giving role.") continue -- cgit v1.2.3 From dc8c63fa92fbf8b74aafb17b5f58d67e079633b4 Mon Sep 17 00:00:00 2001 From: D0rs4n <41237606+D0rs4n@users.noreply.github.com> Date: Mon, 17 Jan 2022 00:10:39 +0100 Subject: Make error messages more consistent in the AoC daystar view (#973) From now on, when the interacting user and the original author of the view is different, the bot will send an ephemeral message regarding the issue. --- bot/exts/events/advent_of_code/views/dayandstarview.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/views/dayandstarview.py b/bot/exts/events/advent_of_code/views/dayandstarview.py index a0bfa316..5529c12b 100644 --- a/bot/exts/events/advent_of_code/views/dayandstarview.py +++ b/bot/exts/events/advent_of_code/views/dayandstarview.py @@ -42,7 +42,13 @@ class AoCDropdownView(discord.ui.View): async def interaction_check(self, interaction: discord.Interaction) -> bool: """Global check to ensure that the interacting user is the user who invoked the command originally.""" - return interaction.user == self.original_author + if interaction.user != self.original_author: + await interaction.response.send_message( + ":x: You can't interact with someone else's response. Please run the command yourself!", + ephemeral=True + ) + return False + return True @discord.ui.select( placeholder="Day", -- cgit v1.2.3 From 335620341046e3b7be547ac9f18d25d1fb9bec55 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Tue, 25 Jan 2022 12:15:50 +0300 Subject: Reduce AOC Logging Output The AOC cog produces a lot of large logs very frequently which have minimal value, causing the logs to be significantly harder to navigate. Signed-off-by: Hassan Abouelela --- bot/constants.py | 2 +- bot/exts/events/advent_of_code/_helpers.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/constants.py b/bot/constants.py index 7e7ee749..d39f7361 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -55,7 +55,7 @@ class AdventOfCodeLeaderboard: def session(self) -> str: """Return either the actual `session` cookie or the fallback cookie.""" if self.use_fallback_session: - log.info(f"Returning fallback cookie for board `{self.id}`.") + log.trace(f"Returning fallback cookie for board `{self.id}`.") return AdventOfCode.fallback_session return self._session diff --git a/bot/exts/events/advent_of_code/_helpers.py b/bot/exts/events/advent_of_code/_helpers.py index 15b1329d..6c004901 100644 --- a/bot/exts/events/advent_of_code/_helpers.py +++ b/bot/exts/events/advent_of_code/_helpers.py @@ -255,7 +255,7 @@ async def _fetch_leaderboard_data() -> dict[str, Any]: # Two attempts, one with the original session cookie and one with the fallback session for attempt in range(1, 3): - log.info(f"Attempting to fetch leaderboard `{leaderboard.id}` ({attempt}/2)") + log.debug(f"Attempting to fetch leaderboard `{leaderboard.id}` ({attempt}/2)") cookies = {"session": leaderboard.session} try: raw_data = await _leaderboard_request(leaderboard_url, leaderboard.id, cookies) -- cgit v1.2.3 From 833d2e5201028e90dfb9e84da4766fba498dc04a Mon Sep 17 00:00:00 2001 From: ChrisJL Date: Tue, 15 Feb 2022 11:27:11 +0000 Subject: Disable AoC completionist task This disabled the completionist task that checks the leaderboard for people who have 50 stars and gives out the role. Since the event is running, we are not keeping the session cookies up to date, so this is flooding #dev-log with errors. This task should be altered in preparation for next event so that commenting out this line isn't required. Co-authored-by: ToxicKidz <78174417+ToxicKidz@users.noreply.github.com> --- bot/exts/events/advent_of_code/_cog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'bot/exts/events/advent_of_code') diff --git a/bot/exts/events/advent_of_code/_cog.py b/bot/exts/events/advent_of_code/_cog.py index 3acfef39..518841d4 100644 --- a/bot/exts/events/advent_of_code/_cog.py +++ b/bot/exts/events/advent_of_code/_cog.py @@ -61,7 +61,8 @@ class AdventOfCode(commands.Cog): self.status_task.set_name("AoC Status Countdown") self.status_task.add_done_callback(_helpers.background_task_callback) - self.completionist_task.start() + # Don't start task while event isn't running + # self.completionist_task.start() @tasks.loop(minutes=10.0) async def completionist_task(self) -> None: -- cgit v1.2.3