1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Allow mixed-case commands

This commit is contained in:
Steffo 2019-04-20 12:34:18 +02:00
parent 9187d7af59
commit ad8a0016bc
3 changed files with 7 additions and 4 deletions

View file

@ -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.

View file

@ -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

View file

@ -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: