Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added more documentation for the yelling decorator #210

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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