From 400a694362e9b2ceb7ece2c004111111cc37a961 Mon Sep 17 00:00:00 2001 From: Kumi Date: Tue, 12 Nov 2024 20:56:32 +0100 Subject: [PATCH] feat(bot): improve command feedback and logging Enhanced user feedback for 'monitor', 'unmonitor', 'protect', and 'unprotect' commands by sending messages confirming action status in target rooms. Improved clarity and logging for potential errors such as missing room IDs. Provides users with immediate notification of their command's effect, facilitating better user interaction and error handling. --- src/matrix_applicationbot/classes/bot.py | 64 ++++++++++++++++++++---- 1 file changed, 54 insertions(+), 10 deletions(-) diff --git a/src/matrix_applicationbot/classes/bot.py b/src/matrix_applicationbot/classes/bot.py index f2ce7ac..8694d69 100644 --- a/src/matrix_applicationbot/classes/bot.py +++ b/src/matrix_applicationbot/classes/bot.py @@ -66,10 +66,10 @@ class ApplicationBot: mention = body.split()[0] if mention == "!applicationbot" or mention in self.username: return await self.handle_command(room, sender, body.split(" ", 1)[1]) - + if body and body.startswith("!apply") and not sender == self.client.user_id: return await self.process_application(room, sender, event) - + return await self.relay_message(room, sender, event) async def invite_callback(self, room: MatrixRoom, event: InviteMemberEvent): @@ -105,7 +105,9 @@ class ApplicationBot: if key in "🟢🟡🔴": await self.process_reaction(room, message_id, event.sender, key) - async def process_reaction(self, room: MatrixRoom, message_id, sender, reaction_key): + async def process_reaction( + self, room: MatrixRoom, message_id, sender, reaction_key + ): # Get the ticket ID based on the message ID response = await self.client.room_get_state_event( self.operator_room_id, "m.room.application", message_id @@ -139,7 +141,7 @@ class ApplicationBot: command=f"!applicationbot reject {user_id}", approved=False, ) - + elif reaction_key == "🟡": # Invite to ticket room await self.invite_operator_direct(room, ticket_id, sender) @@ -202,21 +204,63 @@ class ApplicationBot: return await self.list_tickets(room) elif command.startswith("monitor"): room_id = self.resolve_room_id(command.split()[1]) - return await self.add_monitored_room(room_id) + await self.add_monitored_room(room_id) + return await self.client.room_send( + room.room_id, + "m.room.message", + { + "msgtype": "m.text", + "body": f"Room {room_id} is now being monitored for applications.", + }, + ) elif command.startswith("unmonitor"): room_id = self.resolve_room_id(command.split()[1]) - return await self.remove_monitored_room(room_id) + await self.remove_monitored_room(room_id) + return await self.client.room_send( + room.room_id, + "m.room.message", + { + "msgtype": "m.text", + "body": f"Room {room_id} is no longer being monitored for applications.", + }, + ) elif command.startswith("monitored"): return await self.list_monitored_rooms(room) elif command.startswith("protect "): try: room_id = await self.resolve_room_id(command.split()[1]) - return await self.add_protected_room(room_id) + await self.add_protected_room(room_id) + return await self.client.room_send( + room.room_id, + "m.room.message", + { + "msgtype": "m.text", + "body": f"Room {room_id} has been protected.", + }, + ) except IndexError: - logging.error(f"No room ID specified for protect command: {command}") + logging.error( + f"No room ID specified for protect command: {command}" + ) + return await self.client.room_send( + room.room_id, + "m.room.message", + { + "msgtype": "m.text", + "body": "Please specify a room ID to protect.", + }, + ) elif command.startswith("unprotect"): room_id = self.resolve_room_id(command.split()[1]) - return await self.remove_protected_room(room_id) + await self.remove_protected_room(room_id) + return await self.client.room_send( + room.room_id, + "m.room.message", + { + "msgtype": "m.text", + "body": f"Room {room_id} has been unprotected.", + }, + ) elif command.startswith("protected"): return await self.list_protected_rooms(room) @@ -768,4 +812,4 @@ class ApplicationBot: if not room_id.startswith("!"): return None - return room_id \ No newline at end of file + return room_id