From 372a719de06ba3fac7b5c28352dfeff98e535f28 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 8 Nov 2024 13:18:28 +0100 Subject: [PATCH] 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. --- src/matrix_applicationbot/classes/bot.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/matrix_applicationbot/classes/bot.py b/src/matrix_applicationbot/classes/bot.py index 8f278e3..8b35d6d 100644 --- a/src/matrix_applicationbot/classes/bot.py +++ b/src/matrix_applicationbot/classes/bot.py @@ -64,7 +64,7 @@ class ApplicationBot: if body and body.startswith("!supportbot"): await self.handle_command(room, sender, body) elif body and body.startswith("!apply"): - await self.process_application(room, sender, body) + await self.process_application(room, sender, event) else: await self.relay_message(room, sender, event) @@ -108,9 +108,7 @@ class ApplicationBot: message_body = event.body sender = event.sender - logging.info( - f"Processing reaction {reaction_key} from {sender} in {room.room_id}" - ) + logging.info(f"Processing reaction {reaction_key} from {sender} in {room.room_id}") logging.info(f"Message: {message_body}") 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 ticket_id = await self.get_ticket_id_from_room(room.room_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): user_id = ( @@ -677,7 +677,7 @@ class ApplicationBot: ) except Exception as 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): if await self.is_operator(sender):