Skip to content

Commit

Permalink
Added typing to command_utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
49Indium committed Mar 6, 2024
1 parent ce8fd88 commit 85116b2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ exclude = [
"**/starboard.py",
"**/uptime.py",
"**/working_on.py",
"**/utils/command_utils.py",
"**/utils/snailrace_utils.py",
]

12 changes: 7 additions & 5 deletions uqcsbot/utils/command_utils.py
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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)
Expand Down

0 comments on commit 85116b2

Please sign in to comment.