From 56c96d47e8fb628eb694e26a63e909caa7885044 Mon Sep 17 00:00:00 2001 From: Malte E <97891689+maltee1@users.noreply.github.com> Date: Tue, 23 Aug 2022 20:53:06 +0200 Subject: [PATCH] Add default relaybot config option (#293) --- mautrix_signal/config.py | 1 + mautrix_signal/example-config.yaml | 4 ++++ mautrix_signal/portal.py | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/mautrix_signal/config.py b/mautrix_signal/config.py index cf6fa9f5..2307b752 100644 --- a/mautrix_signal/config.py +++ b/mautrix_signal/config.py @@ -101,6 +101,7 @@ def do_update(self, helper: ConfigUpdateHelper) -> None: copy("bridge.relay.enabled") copy_dict("bridge.relay.message_formats") + copy("bridge.relay.relaybot") copy("bridge.bridge_matrix_leave") copy("bridge.location_format") diff --git a/mautrix_signal/example-config.yaml b/mautrix_signal/example-config.yaml index fe1ebd11..6f7071f8 100644 --- a/mautrix_signal/example-config.yaml +++ b/mautrix_signal/example-config.yaml @@ -299,6 +299,10 @@ bridge: m.audio: '$sender_displayname sent an audio file' m.video: '$sender_displayname sent a video' m.location: '$sender_displayname sent a location' + # Specify a dedicated relay account. Must be a regular matrix account logged into this bridge + # and double puppeting working to auto-accept invites. When this user is invited to a room + # it will automatically be set as the relay user. May be overridden with `set-relay` or `unset-relay` + relaybot: '@relaybot:example.com' # Format for generting URLs from location messages for sending to Signal # Google Maps: 'https://www.google.com/maps/place/{lat},{long}' diff --git a/mautrix_signal/portal.py b/mautrix_signal/portal.py index 8c8907e1..5ea3eb30 100644 --- a/mautrix_signal/portal.py +++ b/mautrix_signal/portal.py @@ -862,6 +862,19 @@ async def handle_matrix_invite(self, invited_by: u.User, user: u.User | p.Puppet ) except RPCError as e: raise RejectMatrixInvite(str(e)) from e + if user.mxid == self.config["bridge.relay.relaybot"] != "@relaybot:example.com": + if not self.config["bridge.relay.enabled"]: + await self.main_intent.send_notice( + self.mxid, "Relay mode is not enabled in this instance of the bridge." + ) + else: + await self.set_relay_user(user) + await self.main_intent.send_notice( + self.mxid, + "Messages from non-logged-in users in this room will now be bridged " + "through the relaybot's Signal account.", + ) + power_levels = await self.main_intent.get_power_levels(self.mxid) invitee_pl = power_levels.get_user_level(user.mxid) if invitee_pl >= 50: