Bläddra i källkod

Add default relaybot config option (#293)

Malte E 2 år sedan
förälder
incheckning
56c96d47e8
3 ändrade filer med 18 tillägg och 0 borttagningar
  1. 1 0
      mautrix_signal/config.py
  2. 4 0
      mautrix_signal/example-config.yaml
  3. 13 0
      mautrix_signal/portal.py

+ 1 - 0
mautrix_signal/config.py

@@ -101,6 +101,7 @@ class Config(BaseBridgeConfig):
 
         copy("bridge.relay.enabled")
         copy_dict("bridge.relay.message_formats")
+        copy("bridge.relay.relaybot")
         copy("bridge.bridge_matrix_leave")
         copy("bridge.location_format")
 

+ 4 - 0
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}'

+ 13 - 0
mautrix_signal/portal.py

@@ -862,6 +862,19 @@ class Portal(DBPortal, BasePortal):
             )
         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: