mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Allow mixed-case commands
This commit is contained in:
parent
9187d7af59
commit
ad8a0016bc
3 changed files with 7 additions and 4 deletions
|
@ -114,8 +114,10 @@ class DiscordBot(GenericBot):
|
||||||
return
|
return
|
||||||
# Find and clean parameters
|
# Find and clean parameters
|
||||||
command_text, *parameters = text.split(" ")
|
command_text, *parameters = text.split(" ")
|
||||||
|
# Don't use a case-sensitive command name
|
||||||
|
command_name = command_text.lower()
|
||||||
# Call the command
|
# 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:
|
def find_guild_by_name(cli, name: str) -> discord.Guild:
|
||||||
"""Find the Guild with the specified name. Case-insensitive.
|
"""Find the Guild with the specified name. Case-insensitive.
|
||||||
|
|
|
@ -25,7 +25,8 @@ class GenericBot:
|
||||||
self.commands: typing.Dict[str, typing.Type[Command]] = {}
|
self.commands: typing.Dict[str, typing.Type[Command]] = {}
|
||||||
self.network_handlers: typing.Dict[typing.Type[Message], typing.Type[NetworkHandler]] = {}
|
self.network_handlers: typing.Dict[typing.Type[Message], typing.Type[NetworkHandler]] = {}
|
||||||
for command in commands:
|
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.network_handlers = {**self.network_handlers, **command.network_handler_dict()}
|
||||||
self.missing_command: typing.Type[Command] = missing_command
|
self.missing_command: typing.Type[Command] = missing_command
|
||||||
self.error_command: typing.Type[Command] = error_command
|
self.error_command: typing.Type[Command] = error_command
|
||||||
|
|
|
@ -106,9 +106,9 @@ class TelegramBot(GenericBot):
|
||||||
return
|
return
|
||||||
# Find and clean parameters
|
# Find and clean parameters
|
||||||
command_text, *parameters = text.split(" ")
|
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
|
# 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):
|
async def run(self):
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Reference in a new issue