From c78f2bc4a71c1de05241f5aeae830554fdbb1f3a Mon Sep 17 00:00:00 2001 From: Werru Date: Mon, 21 Aug 2023 14:43:59 -0400 Subject: [PATCH 1/2] main: Prevent the bot from being triggered accidentally by adding a prefix --- main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 7aec409..3e067b7 100755 --- a/main.py +++ b/main.py @@ -249,7 +249,7 @@ async def help(ctx: discord.ApplicationContext): async def gif_command_handler(message: discord.Message, command: list[str]): - command_typed = command[0] + command_typed = command[1] target = message.author.name sender = message.author.name @@ -290,10 +290,15 @@ async def on_message(message: discord.Message): if message.author.bot == True: return - # TODO: Do proper parsing of the message - message_as_command = message.content.split(" ") + # Should prevent the bot from being accidentally triggered from now on. Also will make + # the people here have to say nya more often which is always a bonus. + if message.content.startswith('nya') == False: + return - command = message_as_command[0] + # TODO: Do proper parsing of the message + message_as_command = message.content.split("nya ") + + command = message_as_command[1] if command in GIF_COMMANDS: await gif_command_handler(message, message_as_command) From fa010d901cd434ee93216ffe0a2dc705b916128c Mon Sep 17 00:00:00 2001 From: Werru Date: Tue, 22 Aug 2023 11:13:56 -0400 Subject: [PATCH 2/2] main: Fix bug preventing users from mentioning other users in commands --- main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 3e067b7..612815c 100755 --- a/main.py +++ b/main.py @@ -249,13 +249,14 @@ async def help(ctx: discord.ApplicationContext): async def gif_command_handler(message: discord.Message, command: list[str]): - command_typed = command[1] + command_typed = command[0] target = message.author.name sender = message.author.name + if len(message.mentions) > 0: target = message.mentions[0].name - + if command_typed == "help": await message.reply(HELP_MESSAGE) return @@ -297,8 +298,10 @@ async def on_message(message: discord.Message): # TODO: Do proper parsing of the message message_as_command = message.content.split("nya ") + message_as_command = message_as_command[1].split(" ") + + command = message_as_command[0] - command = message_as_command[1] if command in GIF_COMMANDS: await gif_command_handler(message, message_as_command)