Browse Source

Move double puppeting commands to mautrix-python

Tulir Asokan 4 years ago
parent
commit
d9db1f8f4d
2 changed files with 5 additions and 32 deletions
  1. 0 32
      mautrix_signal/commands/auth.py
  2. 5 0
      mautrix_signal/user.py

+ 0 - 32
mautrix_signal/commands/auth.py

@@ -17,8 +17,6 @@ from typing import Union
 import io
 
 from mausignald.errors import UnexpectedResponse, TimeoutException
-from mautrix.client import Client
-from mautrix.bridge import custom_puppet as cpu
 from mautrix.appservice import IntentAPI
 from mautrix.types import MediaMessageEventContent, MessageType, ImageInfo
 from mautrix.bridge.commands import HelpSection, command_handler
@@ -138,33 +136,3 @@ async def logout(evt: CommandEvent) -> None:
         return
     await evt.sender.logout()
     await evt.reply("Successfully logged out")
-
-
-@command_handler(needs_auth=True, management_only=True, help_args="<_access token_>",
-                 help_section=SECTION_AUTH, help_text="Replace your Signal account's Matrix puppet"
-                                                      " with your Matrix account")
-async def login_matrix(evt: CommandEvent) -> None:
-    puppet = await pu.Puppet.get_by_address(evt.sender.address)
-    _, homeserver = Client.parse_mxid(evt.sender.mxid)
-    if homeserver != pu.Puppet.hs_domain:
-        await evt.reply("You can't log in with an account on a different homeserver")
-        return
-    try:
-        await puppet.switch_mxid(" ".join(evt.args), evt.sender.mxid)
-        await evt.reply("Successfully replaced your Signal account's "
-                        "Matrix puppet with your Matrix account.")
-    except cpu.OnlyLoginSelf:
-        await evt.reply("You may only log in with your own Matrix account")
-    except cpu.InvalidAccessToken:
-        await evt.reply("Invalid access token")
-
-
-@command_handler(needs_auth=True, management_only=True, help_section=SECTION_AUTH,
-                 help_text="Revert your Signal account's Matrix puppet to the original")
-async def logout_matrix(evt: CommandEvent) -> None:
-    puppet = await pu.Puppet.get_by_address(evt.sender.address)
-    if not puppet.is_real_user:
-        await evt.reply("You're not logged in with your Matrix account")
-        return
-    await puppet.switch_mxid(None, None)
-    await evt.reply("Restored the original puppet for your Signal account")

+ 5 - 0
mautrix_signal/user.py

@@ -113,6 +113,11 @@ class User(DBUser, BaseUser):
             return BridgeState(ok=False, error="signal-not-connected")
         return BridgeState(ok=True)
 
+    async def get_puppet(self) -> Optional['pu.Puppet']:
+        if not self.address:
+            return None
+        return await pu.Puppet.get_by_address(self.address)
+
     async def on_signin(self, account: Account) -> None:
         self.username = account.account_id
         self.uuid = account.address.uuid