From 16f26119aa31d927c2351b171c1fce75d88af7c8 Mon Sep 17 00:00:00 2001 From: Lukas Nedbalek Date: Sat, 28 Sep 2024 00:33:39 +0200 Subject: [PATCH] rf: command argument checks in command function --- main.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 3180474..720eaaf 100644 --- a/main.py +++ b/main.py @@ -52,7 +52,17 @@ async def on_ready(): @bot.command() async def grant_role(ctx, study_group_name: str): - author_id = ctx.author.id + # Check study group format + if not words[1].startswith('kruh-') or not words[1][5:].isdigit(): + reply_error(ctx, 'Invalid study group format.') + reply(ctx, HELP_MESSAGE) + return False + + # Check UKCO format + if not words[2].isdigit() or not len(words[2]) == 8: + reply_error(ctx, 'Invalid UKCO format.') + reply(ctx, HELP_MESSAGE) + return False for guild_id in server_ids: guild = bot.get_guild(guild_id) @@ -104,17 +114,6 @@ def check_command(message): reply(message.channel, HELP_MESSAGE) return False - # Check study group format - if not words[1].startswith('kruh-') or not words[1][5:].isdigit(): - reply_error(message.channel, 'Invalid study group format.') - reply(message.channel, HELP_MESSAGE) - return False - - if not words[2].isdigit() or not len(words[2]) == 8: - reply_error(message.channel, 'Invalid UKCO format.') - reply(message.channel, HELP_MESSAGE) - return False - return True