From ad8a0016bc88f6512b512dce066eb758aeed385e Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 20 Apr 2019 12:34:18 +0200 Subject: [PATCH] Allow mixed-case commands --- royalnet/bots/discord.py | 4 +++- royalnet/bots/generic.py | 3 ++- royalnet/bots/telegram.py | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/royalnet/bots/discord.py b/royalnet/bots/discord.py index 9b17f0c6..35d60c83 100644 --- a/royalnet/bots/discord.py +++ b/royalnet/bots/discord.py @@ -114,8 +114,10 @@ class DiscordBot(GenericBot): return # Find and clean parameters command_text, *parameters = text.split(" ") + # Don't use a case-sensitive command name + command_name = command_text.lower() # Call the command - await self.call(command_text, message.channel, parameters, message=message) + await self.call(command_name, message.channel, parameters, message=message) def find_guild_by_name(cli, name: str) -> discord.Guild: """Find the Guild with the specified name. Case-insensitive. diff --git a/royalnet/bots/generic.py b/royalnet/bots/generic.py index 20b3b2ae..41d82f8f 100644 --- a/royalnet/bots/generic.py +++ b/royalnet/bots/generic.py @@ -25,7 +25,8 @@ class GenericBot: self.commands: typing.Dict[str, typing.Type[Command]] = {} self.network_handlers: typing.Dict[typing.Type[Message], typing.Type[NetworkHandler]] = {} for command in commands: - self.commands[f"{command_prefix}{command.command_name}"] = command + lower_command_name = command.command_name.lower() + self.commands[f"{command_prefix}{lower_command_name}"] = command self.network_handlers = {**self.network_handlers, **command.network_handler_dict()} self.missing_command: typing.Type[Command] = missing_command self.error_command: typing.Type[Command] = error_command diff --git a/royalnet/bots/telegram.py b/royalnet/bots/telegram.py index 8a611dc3..d7b76b18 100644 --- a/royalnet/bots/telegram.py +++ b/royalnet/bots/telegram.py @@ -106,9 +106,9 @@ class TelegramBot(GenericBot): return # Find and clean parameters command_text, *parameters = text.split(" ") - command_text.replace(f"@{self.client.username}", "") + command_name = command_text.replace(f"@{self.client.username}", "").lower() # Call the command - await self.call(command_text, update.message.chat, parameters, update=update) + await self.call(command_name, update.message.chat, parameters, update=update) async def run(self): while True: