From 85116b28ceb3c29fcbda3000f3352f37f265d77b Mon Sep 17 00:00:00 2001 From: Isaac Beh Date: Thu, 7 Mar 2024 08:46:55 +1000 Subject: [PATCH 1/4] Added typing to command_utils.py --- pyproject.toml | 1 - uqcsbot/utils/command_utils.py | 12 +++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2f225a04..b6c2175a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,6 @@ exclude = [ "**/starboard.py", "**/uptime.py", "**/working_on.py", - "**/utils/command_utils.py", "**/utils/snailrace_utils.py", ] diff --git a/uqcsbot/utils/command_utils.py b/uqcsbot/utils/command_utils.py index b81bd74e..9be15258 100644 --- a/uqcsbot/utils/command_utils.py +++ b/uqcsbot/utils/command_utils.py @@ -1,7 +1,8 @@ from random import choice from functools import wraps -from typing import Callable +from typing import Callable, Any from discord.ext import commands +from uqcsbot.bot import UQCSBot LOADING_REACTS = ["⏰", "🕰️", "⏲️", "🕖", "🕔", "🕥"] HYPE_REACTS = [ @@ -16,12 +17,13 @@ ] -def loading_status(command_fn: Callable): +def loading_status(command_fn: Callable[..., Any]): @wraps(command_fn) # Important to preserve name because `command` uses it - async def wrapper(self, ctx: commands.Context, *args): - if ctx.message is None or ctx.bot is None: + # The use of Any in the following seems unavoidable. Using Any for *args is reasonable, as we want any type of arguments to be passed through. For self, it seems like the cleanest option at the moment: https://stackoverflow.com/a/69528375 + async def wrapper(self: Any, ctx: commands.Context[UQCSBot], *args: Any): + # Check for the bot user before reacting to ensure that a loading react is not left on a message + if ctx.bot.user is None: return - react = choice(LOADING_REACTS) await ctx.message.add_reaction(react) res = await command_fn(self, ctx, *args) From 27d6f501a2919b0f69b490e9043233f3697ae784 Mon Sep 17 00:00:00 2001 From: Isaac Beh Date: Thu, 7 Mar 2024 09:59:53 +1000 Subject: [PATCH 2/4] command_utils no longer needed due to interactions --- uqcsbot/utils/command_utils.py | 33 --------------------------------- 1 file changed, 33 deletions(-) delete mode 100644 uqcsbot/utils/command_utils.py diff --git a/uqcsbot/utils/command_utils.py b/uqcsbot/utils/command_utils.py deleted file mode 100644 index 9be15258..00000000 --- a/uqcsbot/utils/command_utils.py +++ /dev/null @@ -1,33 +0,0 @@ -from random import choice -from functools import wraps -from typing import Callable, Any -from discord.ext import commands -from uqcsbot.bot import UQCSBot - -LOADING_REACTS = ["⏰", "🕰️", "⏲️", "🕖", "🕔", "🕥"] -HYPE_REACTS = [ - "blahaj", - "blobhajHeart", - "realheart", - "blobhajInnocent", - "keen", - "bigsippin", - "pog_of_greed", - "blobhajHearts", -] - - -def loading_status(command_fn: Callable[..., Any]): - @wraps(command_fn) # Important to preserve name because `command` uses it - # The use of Any in the following seems unavoidable. Using Any for *args is reasonable, as we want any type of arguments to be passed through. For self, it seems like the cleanest option at the moment: https://stackoverflow.com/a/69528375 - async def wrapper(self: Any, ctx: commands.Context[UQCSBot], *args: Any): - # Check for the bot user before reacting to ensure that a loading react is not left on a message - if ctx.bot.user is None: - return - react = choice(LOADING_REACTS) - await ctx.message.add_reaction(react) - res = await command_fn(self, ctx, *args) - await ctx.message.remove_reaction(react, ctx.bot.user) - return res - - return wrapper From 71e7198e06b55a64a4cc8d759999a9b5279ef154 Mon Sep 17 00:00:00 2001 From: Isaac Beh Date: Thu, 7 Mar 2024 10:03:54 +1000 Subject: [PATCH 3/4] Moved react emojis into holidays.py --- uqcsbot/holidays.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/uqcsbot/holidays.py b/uqcsbot/holidays.py index e8a2f957..4ff5d4b9 100644 --- a/uqcsbot/holidays.py +++ b/uqcsbot/holidays.py @@ -11,13 +11,21 @@ from zoneinfo import ZoneInfo from uqcsbot.bot import UQCSBot -from uqcsbot.utils.command_utils import HYPE_REACTS HOLIDAY_URL = "https://www.timeanddate.com/holidays/fun/" HOLIDAY_CSV_PATH = "uqcsbot/static/geek_holidays.csv" HOLIDAY_MESSAGE = "Today is {}!" GENERAL_CHANNEL = "general" - +HYPE_REACTS = [ + "blahaj", + "blobhajHeart", + "realheart", + "blobhajInnocent", + "keen", + "bigsippin", + "pog_of_greed", + "blobhajHearts", +] class Holiday: def __init__(self, date: datetime, description: str, url: str) -> None: From ee96b2bfef4994c1aa7bf502317b97bce2ee0ece Mon Sep 17 00:00:00 2001 From: Isaac Beh Date: Thu, 7 Mar 2024 10:04:46 +1000 Subject: [PATCH 4/4] Formatting --- uqcsbot/holidays.py | 1 + 1 file changed, 1 insertion(+) diff --git a/uqcsbot/holidays.py b/uqcsbot/holidays.py index 4ff5d4b9..16adb0d2 100644 --- a/uqcsbot/holidays.py +++ b/uqcsbot/holidays.py @@ -27,6 +27,7 @@ "blobhajHearts", ] + class Holiday: def __init__(self, date: datetime, description: str, url: str) -> None: self.date = date