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.
This commit is contained in:
Kumi 2024-11-12 20:56:32 +01:00
parent 6b8ccd0336
commit 400a694362
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -66,10 +66,10 @@ class ApplicationBot:
mention = body.split()[0] mention = body.split()[0]
if mention == "!applicationbot" or mention in self.username: if mention == "!applicationbot" or mention in self.username:
return await self.handle_command(room, sender, body.split(" ", 1)[1]) return await self.handle_command(room, sender, body.split(" ", 1)[1])
if body and body.startswith("!apply") and not sender == self.client.user_id: if body and body.startswith("!apply") and not sender == self.client.user_id:
return await self.process_application(room, sender, event) return await self.process_application(room, sender, event)
return await self.relay_message(room, sender, event) return await self.relay_message(room, sender, event)
async def invite_callback(self, room: MatrixRoom, event: InviteMemberEvent): async def invite_callback(self, room: MatrixRoom, event: InviteMemberEvent):
@ -105,7 +105,9 @@ class ApplicationBot:
if key in "🟢🟡🔴": if key in "🟢🟡🔴":
await self.process_reaction(room, message_id, event.sender, key) 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 # Get the ticket ID based on the message ID
response = await self.client.room_get_state_event( response = await self.client.room_get_state_event(
self.operator_room_id, "m.room.application", message_id self.operator_room_id, "m.room.application", message_id
@ -139,7 +141,7 @@ class ApplicationBot:
command=f"!applicationbot reject {user_id}", command=f"!applicationbot reject {user_id}",
approved=False, approved=False,
) )
elif reaction_key == "🟡": # Invite to ticket room elif reaction_key == "🟡": # Invite to ticket room
await self.invite_operator_direct(room, ticket_id, sender) await self.invite_operator_direct(room, ticket_id, sender)
@ -202,21 +204,63 @@ class ApplicationBot:
return await self.list_tickets(room) return await self.list_tickets(room)
elif command.startswith("monitor"): elif command.startswith("monitor"):
room_id = self.resolve_room_id(command.split()[1]) 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"): elif command.startswith("unmonitor"):
room_id = self.resolve_room_id(command.split()[1]) 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"): elif command.startswith("monitored"):
return await self.list_monitored_rooms(room) return await self.list_monitored_rooms(room)
elif command.startswith("protect "): elif command.startswith("protect "):
try: try:
room_id = await self.resolve_room_id(command.split()[1]) 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: 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"): elif command.startswith("unprotect"):
room_id = self.resolve_room_id(command.split()[1]) 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"): elif command.startswith("protected"):
return await self.list_protected_rooms(room) return await self.list_protected_rooms(room)
@ -768,4 +812,4 @@ class ApplicationBot:
if not room_id.startswith("!"): if not room_id.startswith("!"):
return None return None
return room_id return room_id