main: Prevent the bot from being triggered accidentally by adding a prefix #1

Merged
Sugary merged 2 commits from werru/nyabot:master into master 2023-08-22 15:24:45 +00:00

10
main.py
View file

@ -253,6 +253,7 @@ async def gif_command_handler(message: discord.Message, command: list[str]):
target = message.author.name target = message.author.name
sender = message.author.name sender = message.author.name
if len(message.mentions) > 0: if len(message.mentions) > 0:
target = message.mentions[0].name target = message.mentions[0].name
@ -290,10 +291,17 @@ async def on_message(message: discord.Message):
if message.author.bot == True: if message.author.bot == True:
return return
# 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
# TODO: Do proper parsing of the message # TODO: Do proper parsing of the message
message_as_command = message.content.split(" ") message_as_command = message.content.split("nya ")
message_as_command = message_as_command[1].split(" ")
command = message_as_command[0] command = message_as_command[0]
if command in GIF_COMMANDS: if command in GIF_COMMANDS:
await gif_command_handler(message, message_as_command) await gif_command_handler(message, message_as_command)