mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Skip messages that don't start with the command prefix
This commit is contained in:
parent
4fd23aa00b
commit
45b6e612b3
3 changed files with 7 additions and 0 deletions
|
@ -108,6 +108,9 @@ class DiscordBot(GenericBot):
|
||||||
# Skip non-text messages
|
# Skip non-text messages
|
||||||
if not text:
|
if not text:
|
||||||
return
|
return
|
||||||
|
# Skip non-command updates
|
||||||
|
if not text.startswith(self.command_prefix):
|
||||||
|
return
|
||||||
# Skip bot messages
|
# Skip bot messages
|
||||||
author: typing.Union[discord.User] = message.author
|
author: typing.Union[discord.User] = message.author
|
||||||
if author.bot:
|
if author.bot:
|
||||||
|
|
|
@ -22,6 +22,7 @@ class GenericBot:
|
||||||
error_command: typing.Type[Command]) -> None:
|
error_command: typing.Type[Command]) -> None:
|
||||||
"""Generate the ``commands`` dictionary required to handle incoming messages, and the ``network_handlers`` dictionary required to handle incoming requests."""
|
"""Generate the ``commands`` dictionary required to handle incoming messages, and the ``network_handlers`` dictionary required to handle incoming requests."""
|
||||||
log.debug(f"Now generating commands")
|
log.debug(f"Now generating commands")
|
||||||
|
self.command_prefix = command_prefix
|
||||||
self.commands: typing.Dict[str, typing.Type[Command]] = {}
|
self.commands: typing.Dict[str, typing.Type[Command]] = {}
|
||||||
self.network_handlers: typing.Dict[str, typing.Type[NetworkHandler]] = {}
|
self.network_handlers: typing.Dict[str, typing.Type[NetworkHandler]] = {}
|
||||||
for command in commands:
|
for command in commands:
|
||||||
|
|
|
@ -105,6 +105,9 @@ class TelegramBot(GenericBot):
|
||||||
# No text or caption, ignore the message
|
# No text or caption, ignore the message
|
||||||
if text is None:
|
if text is None:
|
||||||
return
|
return
|
||||||
|
# Skip non-command updates
|
||||||
|
if not text.startswith(self.command_prefix):
|
||||||
|
return
|
||||||
# Find and clean parameters
|
# Find and clean parameters
|
||||||
command_text, *parameters = text.split(" ")
|
command_text, *parameters = text.split(" ")
|
||||||
command_name = command_text.replace(f"@{self.client.username}", "").lower()
|
command_name = command_text.replace(f"@{self.client.username}", "").lower()
|
||||||
|
|
Loading…
Reference in a new issue