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:
parent
6b8ccd0336
commit
400a694362
1 changed files with 54 additions and 10 deletions
|
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue