From aeb3ce4af9613325d23d590f3123192f9b991c2b Mon Sep 17 00:00:00 2001 From: ToxicKidz Date: Sun, 16 May 2021 17:01:16 -0400 Subject: fix: Send the help for the right command in .src help --- bot/exts/evergreen/source.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'bot/exts') diff --git a/bot/exts/evergreen/source.py b/bot/exts/evergreen/source.py index 8fb72143..fc209bc3 100644 --- a/bot/exts/evergreen/source.py +++ b/bot/exts/evergreen/source.py @@ -33,7 +33,8 @@ class BotSource(commands.Cog): Raise BadArgument if `source_item` is a dynamically-created object (e.g. via internal eval). """ if isinstance(source_item, commands.Command): - src = source_item.callback.__code__ + callback = inspect.unwrap(source_item.callback) + src = callback.__code__ filename = src.co_filename else: src = type(source_item) @@ -64,12 +65,8 @@ class BotSource(commands.Cog): url, location, first_line = self.get_source_link(source_object) if isinstance(source_object, commands.Command): - if source_object.cog_name == "Help": - title = "Help Command" - description = source_object.__doc__.splitlines()[1] - else: - description = source_object.short_doc - title = f"Command: {source_object.qualified_name}" + description = source_object.short_doc + title = f"Command: {source_object.qualified_name}" else: title = f"Cog: {source_object.qualified_name}" description = source_object.description.splitlines()[0] -- cgit v1.2.3 From 00a4c148ff8754272921527410d35b0c3c27e44c Mon Sep 17 00:00:00 2001 From: ToxicKidz Date: Mon, 17 May 2021 11:17:35 -0400 Subject: fix: Handle a KeyError when using .quiz stop --- bot/exts/evergreen/trivia_quiz.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'bot/exts') diff --git a/bot/exts/evergreen/trivia_quiz.py b/bot/exts/evergreen/trivia_quiz.py index 419126dc..a8d10afd 100644 --- a/bot/exts/evergreen/trivia_quiz.py +++ b/bot/exts/evergreen/trivia_quiz.py @@ -465,22 +465,24 @@ class TriviaQuiz(commands.Cog): Note: Only mods or the owner of the quiz can stop it. """ - if self.game_status[ctx.channel.id] is True: - # Check if the author is the game starter or a moderator. - if ctx.author == self.game_owners[ctx.channel.id] or any( - Roles.moderator == role.id for role in ctx.author.roles - ): - - await ctx.send("Quiz stopped.") - await self.declare_winner(ctx.channel, self.game_player_scores[ctx.channel.id]) - - self.game_status[ctx.channel.id] = False - del self.game_owners[ctx.channel.id] - self.game_player_scores[ctx.channel.id] = {} + try: + if self.game_status[ctx.channel.id]: + # Check if the author is the game starter or a moderator. + if ctx.author == self.game_owners[ctx.channel.id] or any( + Roles.moderator == role.id for role in ctx.author.roles + ): + self.game_status[ctx.channel.id] = False + del self.game_owners[ctx.channel.id] + self.game_player_scores[ctx.channel.id] = {} + + await ctx.send("Quiz stopped.") + await self.declare_winner(ctx.channel, self.game_player_scores[ctx.channel.id]) + else: + await ctx.send(f"{ctx.author.mention}, you are not authorised to stop this game :ghost:!") else: - await ctx.send(f"{ctx.author.mention}, you are not authorised to stop this game :ghost:!") - else: + await ctx.send("No quiz running.") + except KeyError: await ctx.send("No quiz running.") @quiz_game.command(name="leaderboard") -- cgit v1.2.3 From 1b21117a300d9191dec9f286e3bbd1c8e336e340 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 17 May 2021 22:35:58 +0100 Subject: Change AoC helpers to use arrow over pytz This is the only place in the codebase that uses pytz, so we can remove the dependancy by chaging this to use arrow. I chose to use America/Chicago arbitrarily, for no other reason that being the first tz google returned that was in EST. --- bot/exts/christmas/advent_of_code/_helpers.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'bot/exts') diff --git a/bot/exts/christmas/advent_of_code/_helpers.py b/bot/exts/christmas/advent_of_code/_helpers.py index f4a258c0..99688400 100644 --- a/bot/exts/christmas/advent_of_code/_helpers.py +++ b/bot/exts/christmas/advent_of_code/_helpers.py @@ -9,8 +9,8 @@ import typing from typing import Tuple import aiohttp +import arrow import discord -import pytz from bot.bot import Bot from bot.constants import AdventOfCode, Channels, Colours @@ -48,7 +48,7 @@ AOC_EMBED_THUMBNAIL = ( ) # Create an easy constant for the EST timezone -EST = pytz.timezone("EST") +EST = "America/Chicago" # Step size for the challenge countdown status COUNTDOWN_STEP = 60 * 5 @@ -395,13 +395,13 @@ def is_in_advent() -> bool: something for the next Advent of Code challenge should run. As the puzzle published on the 25th is the last puzzle, this check excludes that date. """ - return datetime.datetime.now(EST).day in range(1, 25) and datetime.datetime.now(EST).month == 12 + return arrow.now(EST).day in range(1, 25) and arrow.now(EST).month == 12 def time_left_to_est_midnight() -> Tuple[datetime.datetime, datetime.timedelta]: """Calculate the amount of time left until midnight EST/UTC-5.""" # Change all time properties back to 00:00 - todays_midnight = datetime.datetime.now(EST).replace( + todays_midnight = arrow.now(EST).replace( microsecond=0, second=0, minute=0, @@ -412,7 +412,7 @@ def time_left_to_est_midnight() -> Tuple[datetime.datetime, datetime.timedelta]: tomorrow = todays_midnight + datetime.timedelta(days=1) # Calculate the timedelta between the current time and midnight - return tomorrow, tomorrow - datetime.datetime.now(EST) + return tomorrow, tomorrow - arrow.now(EST) async def wait_for_advent_of_code(*, hours_before: int = 1) -> None: @@ -430,9 +430,9 @@ async def wait_for_advent_of_code(*, hours_before: int = 1) -> None: if we're already past the Advent of Code edition the bot is currently configured for. """ - start = datetime.datetime(AdventOfCode.year, 12, 1, 0, 0, 0, tzinfo=EST) + start = arrow.get(datetime.datetime(AdventOfCode.year, 12, 1), EST) target = start - datetime.timedelta(hours=hours_before) - now = datetime.datetime.now(EST) + now = arrow.now(EST) # If we've already reached or passed to target, we # simply return immediately. @@ -474,10 +474,10 @@ async def countdown_status(bot: Bot) -> None: # sleeping for the entire year, it will only wait in the currently # configured year. This means that the task will only start hibernating once # we start preparing the next event by changing environment variables. - last_challenge = datetime.datetime(AdventOfCode.year, 12, 25, 0, 0, 0, tzinfo=EST) + last_challenge = arrow.get(datetime.datetime(AdventOfCode.year, 12, 25), EST) end = last_challenge + datetime.timedelta(hours=1) - while datetime.datetime.now(EST) < end: + while arrow.now(EST) < end: _, time_left = time_left_to_est_midnight() aligned_seconds = int(math.ceil(time_left.seconds / COUNTDOWN_STEP)) * COUNTDOWN_STEP @@ -534,8 +534,8 @@ async def new_puzzle_notification(bot: Bot) -> None: # The last event day is 25 December, so we only have to schedule # a reminder if the current day is before 25 December. - end = datetime.datetime(AdventOfCode.year, 12, 25, tzinfo=EST) - while datetime.datetime.now(EST) < end: + end = arrow.get(datetime.datetime(AdventOfCode.year, 12, 25), EST) + while arrow.now(EST) < end: log.trace("Started puzzle notification loop.") tomorrow, time_left = time_left_to_est_midnight() -- cgit v1.2.3 From 38e7ca7e8530fc9175b79724812892eb82907228 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 17 May 2021 23:58:47 +0100 Subject: Update references using EST const to use arrow --- bot/exts/christmas/advent_of_code/_cog.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'bot/exts') diff --git a/bot/exts/christmas/advent_of_code/_cog.py b/bot/exts/christmas/advent_of_code/_cog.py index ead84544..3d61753b 100644 --- a/bot/exts/christmas/advent_of_code/_cog.py +++ b/bot/exts/christmas/advent_of_code/_cog.py @@ -3,6 +3,7 @@ import logging from datetime import datetime, timedelta from pathlib import Path +import arrow import discord from discord.ext import commands @@ -100,11 +101,11 @@ class AdventOfCode(commands.Cog): async def aoc_countdown(self, ctx: commands.Context) -> None: """Return time left until next day.""" if not _helpers.is_in_advent(): - datetime_now = datetime.now(_helpers.EST) + 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 = datetime(datetime_now.year, 12, 1, tzinfo=_helpers.EST) - next_year = datetime(datetime_now.year + 1, 12, 1, tzinfo=_helpers.EST) + 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 -- cgit v1.2.3 From b55df6ce4987159970115aeccab1c01fc1c03c8e Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 18 May 2021 09:53:46 +0100 Subject: Use an actual EST timezone Timezones are hard :( --- bot/exts/christmas/advent_of_code/_helpers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot/exts') diff --git a/bot/exts/christmas/advent_of_code/_helpers.py b/bot/exts/christmas/advent_of_code/_helpers.py index 99688400..96de90c4 100644 --- a/bot/exts/christmas/advent_of_code/_helpers.py +++ b/bot/exts/christmas/advent_of_code/_helpers.py @@ -48,7 +48,7 @@ AOC_EMBED_THUMBNAIL = ( ) # Create an easy constant for the EST timezone -EST = "America/Chicago" +EST = "America/New_York" # Step size for the challenge countdown status COUNTDOWN_STEP = 60 * 5 -- cgit v1.2.3