Skip to content

Commit

Permalink
Added more documentation for the yelling decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
49Indium committed Nov 18, 2024
1 parent 84cb77c commit c2f2f88
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions uqcsbot/minecraft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions uqcsbot/voteythumbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand All @@ -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()
Expand All @@ -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
):
Expand Down
4 changes: 1 addition & 3 deletions uqcsbot/whatsdue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions uqcsbot/yelling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c2f2f88

Please sign in to comment.