From c2f2f88657ebfbbc53fcb529e3975520d2f82dc8 Mon Sep 17 00:00:00 2001 From: Isaac Beh Date: Mon, 18 Nov 2024 21:44:09 +1000 Subject: [PATCH] Added more documentation for the yelling decorator --- uqcsbot/minecraft.py | 3 +++ uqcsbot/voteythumbs.py | 3 +++ uqcsbot/whatsdue.py | 4 +--- uqcsbot/yelling.py | 7 +++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/uqcsbot/minecraft.py b/uqcsbot/minecraft.py index 5c863dc..dcfdee9 100644 --- a/uqcsbot/minecraft.py +++ b/uqcsbot/minecraft.py @@ -11,6 +11,7 @@ from uqcsbot.bot import UQCSBot from uqcsbot.models import MCWhitelist from uqcsbot.utils.err_log_utils import FatalErrorWithLog +from uqcsbot.yelling import yelling_exemptor RCON_ADDRESS = os.environ.get("MC_RCON_ADDRESS") RCON_PORT = os.environ.get("MC_RCON_PORT") @@ -74,6 +75,7 @@ async def mcplayers(self, interaction: discord.Interaction): @app_commands.command() @app_commands.describe(username="Minecraft username to whitelist.") + @yelling_exemptor(input_args=["username"]) async def mcwhitelist(self, interaction: discord.Interaction, username: str): """Adds a username to the whitelist for the UQCS server.""" db_session = self.bot.create_db_session() @@ -118,6 +120,7 @@ async def mcwhitelist(self, interaction: discord.Interaction, username: str): @app_commands.command() @app_commands.describe(username="Minecraft username to unwhitelist.") + @yelling_exemptor(input_args=["username"]) async def mcunwhitelist(self, interaction: discord.Interaction, username: str): """Removes a username from the whitelist for the UQCS server.""" db_session = self.bot.create_db_session() diff --git a/uqcsbot/voteythumbs.py b/uqcsbot/voteythumbs.py index d35994a..b8b1941 100644 --- a/uqcsbot/voteythumbs.py +++ b/uqcsbot/voteythumbs.py @@ -93,6 +93,7 @@ async def voteythumbs_command( @app_commands.command(name="voteyrachels") @app_commands.describe(question="The question that shall be voted upon") + @yelling_exemptor(input_args=["question"]) async def voteyrachels_command( self, interaction: discord.Interaction, question: str ): @@ -117,6 +118,7 @@ async def voteyrachels_command( @app_commands.command(name="voteytoms") @app_commands.describe(question="The question that shall be voted upon") + @yelling_exemptor(input_args=["question"]) async def voteytoms_command(self, interaction: discord.Interaction, question: str): """Starts a vote with Tom faces.""" await interaction.response.defer() @@ -139,6 +141,7 @@ async def voteytoms_command(self, interaction: discord.Interaction, question: st @app_commands.command(name="voteyjimmys") @app_commands.describe(question="The question that shall be voted upon") + @yelling_exemptor(input_args=["question"]) async def voteyjimmys_command( self, interaction: discord.Interaction, question: str ): diff --git a/uqcsbot/whatsdue.py b/uqcsbot/whatsdue.py index d20cf88..587cc8d 100644 --- a/uqcsbot/whatsdue.py +++ b/uqcsbot/whatsdue.py @@ -59,9 +59,7 @@ def __init__(self, bot: commands.Bot): reverse_sort="Whether to reverse the sort order. Defaults to false.", show_ecp_links="Show the first ECP link for each course page. Defaults to false.", ) - @yelling_exemptor( - input_args=["course1", "course2", "course3", "course4", "course5", "course6"] - ) + @yelling_exemptor(input_args=["courses"]) async def whatsdue( self, interaction: discord.Interaction, diff --git a/uqcsbot/yelling.py b/uqcsbot/yelling.py index 90660be..21907ad 100644 --- a/uqcsbot/yelling.py +++ b/uqcsbot/yelling.py @@ -12,6 +12,13 @@ from functools import wraps +""" +This decorator that ensures that certain arguments of a command are checked if used in the #yelling channel. +Provide it with the list of names of keyword arguments that the #yelling check should be applied to. +Use after the decorator @app_commands.command(). +""" + + def yelling_exemptor(input_args: List[str] = ["text"]) -> Callable[..., Any]: def handler(func: Callable[..., Any]): @wraps(func)