From 337ab947ca1b425d5a3ddd5b4c8a8e369317abf2 Mon Sep 17 00:00:00 2001 From: Panoramic Date: Sat, 17 Aug 2024 19:50:53 +0300 Subject: [PATCH] Add option to send welcome message upon acceptance --- sample.config.yaml | 7 +++++++ vetting_bot/callbacks.py | 15 ++++++++++++++- vetting_bot/config.py | 4 ++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/sample.config.yaml b/sample.config.yaml index d5621f5..18fc7f4 100644 --- a/sample.config.yaml +++ b/sample.config.yaml @@ -52,6 +52,13 @@ vetting: # The bot must be in these rooms and have the invite permission additional_rooms: [] +# Messages to send to the vetting room (optional) +# You can use the following variables: +# {mention} = https://matrix.to/#/@user:exmaple.com +message_on: + # Message to send once the invite has been confirmed + invited: "{mention}, you're in! 😎" + # Logging setup logging: # Logging level diff --git a/vetting_bot/callbacks.py b/vetting_bot/callbacks.py index d3cdeeb..8baa2b5 100644 --- a/vetting_bot/callbacks.py +++ b/vetting_bot/callbacks.py @@ -205,7 +205,7 @@ class Callbacks: if event.key == "confirm": # Check which user the reaction is for (if any) self.store.cursor.execute( - "SELECT mxid FROM vetting WHERE decision_event_id = ?", + "SELECT mxid, room_id FROM vetting WHERE decision_event_id = ?", (event.reacts_to,), ) row = self.store.cursor.fetchone() @@ -213,6 +213,7 @@ class Callbacks: return user_id = row[0] + user_room_id = row[1] # Invite user to main space logger.info("Inviting new user (%s) to the main space.", user_id) @@ -242,6 +243,18 @@ class Callbacks: else: logger.info("Invited %s to %s", user_id, room_id) + # Send message to vetting room notifying of the invite + if self.config.message_on_invited is not None: + invited_message = self.config.message_on_invited.format( + mention=f"https://matrix.to/#/{user_id}" + ) + await send_text_to_room( + self.client, + user_room_id, + invited_message, + notice=False, + ) + async def unknown(self, room: MatrixRoom, event: UnknownEvent) -> None: """Callback for when an event with a type that is unknown to matrix-nio is received. diff --git a/vetting_bot/config.py b/vetting_bot/config.py index c8dfaa9..57b168c 100644 --- a/vetting_bot/config.py +++ b/vetting_bot/config.py @@ -142,6 +142,10 @@ class Config: self._get_cfg(["vetting", "additional_rooms"], required=False, default=[]) ) + self.message_on_invited: str = self._get_cfg( + ["message_on", "invited"], required=False, default=None + ) + def _get_cfg( self, path: List[str],