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.
This commit is contained in:
Kumi 2024-11-08 08:28:53 +01:00
parent ac18806308
commit c5acd76c0a
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

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