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
|
@ -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
|
||||
return room_id
|
||||
|
|
Loading…
Reference in a new issue