refactor(bot): update event handling for applications
Revises method signatures to directly utilize the `event` object rather than individual message components, streamlining event processing for command and message relays. This change enhances code clarity and maintains consistency across methods.
This commit is contained in:
parent
7bfa875f05
commit
372a719de0
1 changed files with 7 additions and 7 deletions
|
@ -64,7 +64,7 @@ class ApplicationBot:
|
||||||
if body and body.startswith("!supportbot"):
|
if body and body.startswith("!supportbot"):
|
||||||
await self.handle_command(room, sender, body)
|
await self.handle_command(room, sender, body)
|
||||||
elif body and body.startswith("!apply"):
|
elif body and body.startswith("!apply"):
|
||||||
await self.process_application(room, sender, body)
|
await self.process_application(room, sender, event)
|
||||||
else:
|
else:
|
||||||
await self.relay_message(room, sender, event)
|
await self.relay_message(room, sender, event)
|
||||||
|
|
||||||
|
@ -108,9 +108,7 @@ class ApplicationBot:
|
||||||
message_body = event.body
|
message_body = event.body
|
||||||
sender = event.sender
|
sender = event.sender
|
||||||
|
|
||||||
logging.info(
|
logging.info(f"Processing reaction {reaction_key} from {sender} in {room.room_id}")
|
||||||
f"Processing reaction {reaction_key} from {sender} in {room.room_id}"
|
|
||||||
)
|
|
||||||
logging.info(f"Message: {message_body}")
|
logging.info(f"Message: {message_body}")
|
||||||
|
|
||||||
if message_body.startswith("Application received from"):
|
if message_body.startswith("Application received from"):
|
||||||
|
@ -203,7 +201,9 @@ class ApplicationBot:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async def process_application(self, room: MatrixRoom, sender, message_body):
|
async def process_application(self, room: MatrixRoom, sender, event):
|
||||||
|
message_body = event.body
|
||||||
|
|
||||||
# Check if the message is from a ticket room
|
# Check if the message is from a ticket room
|
||||||
ticket_id = await self.get_ticket_id_from_room(room.room_id)
|
ticket_id = await self.get_ticket_id_from_room(room.room_id)
|
||||||
if ticket_id:
|
if ticket_id:
|
||||||
|
@ -255,7 +255,7 @@ class ApplicationBot:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
await self.relay_message(room, sender, message_body)
|
await self.relay_message(room, sender, event)
|
||||||
|
|
||||||
async def approve_or_reject_application(self, room, sender, command, approved):
|
async def approve_or_reject_application(self, room, sender, command, approved):
|
||||||
user_id = (
|
user_id = (
|
||||||
|
@ -677,7 +677,7 @@ class ApplicationBot:
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Failed to relay message of type {type(event)}: {e}")
|
logging.error(f"Failed to relay message of type {type(event)}: {e}")
|
||||||
logging.debug(f"Event source: {event.source}")
|
logging.debug(f"Event source: {event}")
|
||||||
|
|
||||||
async def help_command(self, room, sender):
|
async def help_command(self, room, sender):
|
||||||
if await self.is_operator(sender):
|
if await self.is_operator(sender):
|
||||||
|
|
Loading…
Reference in a new issue