From 6f5bd7653a79f6a1fb4fbab2e7c4746b44f6e19a Mon Sep 17 00:00:00 2001 From: KKlochko Date: Tue, 20 Jun 2023 14:41:03 +0300 Subject: [PATCH] Refactor the match of commands. --- src/handlers/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/handlers/__init__.py b/src/handlers/__init__.py index b1ce3a3..dd79475 100644 --- a/src/handlers/__init__.py +++ b/src/handlers/__init__.py @@ -10,12 +10,18 @@ def setup(bot: botlib.Bot, prefix: str): async def help_command(room: nio.rooms.MatrixRoom, message: nio.events.room_events.Event): match = botlib.MessageMatch(room, message, bot, prefix=prefix) - if match.is_not_from_this_bot() and match.prefix() and match.command('help'): + if not match.is_not_from_this_bot(): + return + + if not match.prefix(): + return + + if match.command('help'): await help_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id) - if match.is_not_from_this_bot() and match.prefix() and match.command('cities-list'): + if match.command('cities-list'): await list_cities_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id) - if match.is_not_from_this_bot() and match.prefix() and match.command('register'): + if match.command('register'): await register_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id, args=match.args())