From 9e4e964112ae1c2b1b670328266d360f2391d7d6 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 22 May 2022 19:11:08 +0300 Subject: [PATCH] Move login-matrix commands to mautrix-go --- commands.go | 77 ----------------------------------------------------- puppet.go | 11 ++++++++ 2 files changed, 11 insertions(+), 77 deletions(-) diff --git a/commands.go b/commands.go index 4a67b26..12535e4 100644 --- a/commands.go +++ b/commands.go @@ -76,9 +76,6 @@ func (br *WABridge) RegisterCommands() { cmdOpen, cmdPM, cmdSync, - cmdLoginMatrix, - cmdPingMatrix, - cmdLogoutMatrix, cmdDisappearingTimer, ) } @@ -499,7 +496,6 @@ var cmdLogout = &commands.FullHandler{ }, } -// CommandLogout handles !logout command func fnLogout(ce *WrappedCommandEvent) { if ce.User.Session == nil { ce.Reply("You're not logged in.") @@ -1133,79 +1129,6 @@ func fnSync(ce *WrappedCommandEvent) { } } -var cmdLoginMatrix = &commands.FullHandler{ - Func: wrapCommand(fnLoginMatrix), - Name: "login-matrix", - Help: commands.HelpMeta{ - Section: commands.HelpSectionAuth, - Description: "Replace your WhatsApp account's Matrix puppet with your real Matrix account.", - Args: "<_access token_>", - }, - RequiresLogin: true, -} - -func fnLoginMatrix(ce *WrappedCommandEvent) { - if len(ce.Args) == 0 { - ce.Reply("**Usage:** `login-matrix `") - return - } - puppet := ce.Bridge.GetPuppetByJID(ce.User.JID) - err := puppet.SwitchCustomMXID(ce.Args[0], ce.User.MXID) - if err != nil { - ce.Reply("Failed to switch puppet: %v", err) - return - } - ce.Reply("Successfully switched puppet") -} - -var cmdPingMatrix = &commands.FullHandler{ - Func: wrapCommand(fnPingMatrix), - Name: "ping-matrix", - Help: commands.HelpMeta{ - Section: commands.HelpSectionAuth, - Description: "Check if your double puppet is working correctly.", - }, - RequiresLogin: true, -} - -func fnPingMatrix(ce *WrappedCommandEvent) { - puppet := ce.Bridge.GetPuppetByCustomMXID(ce.User.MXID) - if puppet == nil || puppet.CustomIntent() == nil { - ce.Reply("You have not changed your WhatsApp account's Matrix puppet.") - return - } - resp, err := puppet.CustomIntent().Whoami() - if err != nil { - ce.Reply("Failed to validate Matrix login: %v", err) - } else { - ce.Reply("Confirmed valid access token for %s / %s", resp.UserID, resp.DeviceID) - } -} - -var cmdLogoutMatrix = &commands.FullHandler{ - Func: wrapCommand(fnLogoutMatrix), - Name: "logout-matrix", - Help: commands.HelpMeta{ - Section: commands.HelpSectionAuth, - Description: "Switch your WhatsApp account's Matrix puppet back to the default one.", - }, - RequiresLogin: true, -} - -func fnLogoutMatrix(ce *WrappedCommandEvent) { - puppet := ce.Bridge.GetPuppetByCustomMXID(ce.User.MXID) - if puppet == nil || puppet.CustomIntent() == nil { - ce.Reply("You had not changed your WhatsApp account's Matrix puppet.") - return - } - err := puppet.SwitchCustomMXID("", "") - if err != nil { - ce.Reply("Failed to remove custom puppet: %v", err) - return - } - ce.Reply("Successfully removed custom puppet") -} - var cmdDisappearingTimer = &commands.FullHandler{ Func: wrapCommand(fnDisappearingTimer), Name: "disappearing-timer", diff --git a/puppet.go b/puppet.go index 4ffb970..414b7a1 100644 --- a/puppet.go +++ b/puppet.go @@ -107,6 +107,17 @@ func (br *WABridge) GetPuppetByCustomMXID(mxid id.UserID) *Puppet { func (user *User) GetIDoublePuppet() bridge.DoublePuppet { p := user.bridge.GetPuppetByCustomMXID(user.MXID) + if p == nil || p.CustomIntent() == nil { + return nil + } + return p +} + +func (user *User) GetIGhost() bridge.Ghost { + if user.JID.IsEmpty() { + return nil + } + p := user.bridge.GetPuppetByJID(user.JID) if p == nil { return nil }