From c5acd76c0a2036601be4cc460240c5cf5278e93a Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 8 Nov 2024 08:28:53 +0100 Subject: [PATCH] fix(bot): ensure command handling returns awaitables Refactored command handling methods to return awaitables directly rather than awaiting them in place. This approach facilitates easier testing and future integration with event loop management strategies. Improves asynchronous function chaining and consistent handling of command execution results. --- src/matrix_applicationbot/classes/bot.py | 27 ++++++++++++------------ 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/matrix_applicationbot/classes/bot.py b/src/matrix_applicationbot/classes/bot.py index df36872..8451160 100644 --- a/src/matrix_applicationbot/classes/bot.py +++ b/src/matrix_applicationbot/classes/bot.py @@ -88,37 +88,36 @@ class ApplicationBot: async def handle_command(self, room, sender, command): if command == "!supportbot help": - await self.help_command(room, sender) + return await self.help_command(room, sender) elif command == "!supportbot openticket": - await self.open_ticket(room, sender) + return await self.open_ticket(room, sender) elif await self.is_operator(sender): if command.startswith("!supportbot invite"): - await self.invite_operator(room, sender, command) + return await self.invite_operator(room, sender, command) elif command.startswith("!supportbot close"): - await self.close_ticket(room, sender, command) + return await self.close_ticket(room, sender, command) elif command.startswith("!supportbot approve"): - await self.approve_or_reject_application( + return await self.approve_or_reject_application( room, sender, command, approved=True ) elif command.startswith("!supportbot reject"): - await self.approve_or_reject_application( + return await self.approve_or_reject_application( room, sender, command, approved=False ) elif command == "!supportbot list": - await self.list_tickets(room) + return await self.list_tickets(room) elif command.startswith("!supportbot monitor"): - await self.add_monitored_room(command.split()[2]) + return await self.add_monitored_room(command.split()[2]) elif command.startswith("!supportbot unmonitor"): - await self.remove_monitored_room(command.split()[2]) + return await self.remove_monitored_room(command.split()[2]) elif command.startswith("!supportbot monitored"): - await self.list_monitored_rooms(room) + return await self.list_monitored_rooms(room) elif command.startswith("!supportbot protect"): - await self.add_protected_room(command.split()[2]) + return await self.add_protected_room(command.split()[2]) elif command.startswith("!supportbot unprotect"): - await self.remove_protected_room(command.split()[2]) + return await self.remove_protected_room(command.split()[2]) elif command.startswith("!supportbot protected"): - await self.list_protected_rooms(room) - return + return await self.list_protected_rooms(room) await self.client.room_send( room.room_id,