mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-12-14 17:33:48 +01:00
Move login-matrix commands to mautrix-go
This commit is contained in:
parent
15129c0acc
commit
9e4e964112
2 changed files with 11 additions and 77 deletions
77
commands.go
77
commands.go
|
@ -76,9 +76,6 @@ func (br *WABridge) RegisterCommands() {
|
||||||
cmdOpen,
|
cmdOpen,
|
||||||
cmdPM,
|
cmdPM,
|
||||||
cmdSync,
|
cmdSync,
|
||||||
cmdLoginMatrix,
|
|
||||||
cmdPingMatrix,
|
|
||||||
cmdLogoutMatrix,
|
|
||||||
cmdDisappearingTimer,
|
cmdDisappearingTimer,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -499,7 +496,6 @@ var cmdLogout = &commands.FullHandler{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
// CommandLogout handles !logout command
|
|
||||||
func fnLogout(ce *WrappedCommandEvent) {
|
func fnLogout(ce *WrappedCommandEvent) {
|
||||||
if ce.User.Session == nil {
|
if ce.User.Session == nil {
|
||||||
ce.Reply("You're not logged in.")
|
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 <access token>`")
|
|
||||||
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{
|
var cmdDisappearingTimer = &commands.FullHandler{
|
||||||
Func: wrapCommand(fnDisappearingTimer),
|
Func: wrapCommand(fnDisappearingTimer),
|
||||||
Name: "disappearing-timer",
|
Name: "disappearing-timer",
|
||||||
|
|
11
puppet.go
11
puppet.go
|
@ -107,6 +107,17 @@ func (br *WABridge) GetPuppetByCustomMXID(mxid id.UserID) *Puppet {
|
||||||
|
|
||||||
func (user *User) GetIDoublePuppet() bridge.DoublePuppet {
|
func (user *User) GetIDoublePuppet() bridge.DoublePuppet {
|
||||||
p := user.bridge.GetPuppetByCustomMXID(user.MXID)
|
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 {
|
if p == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue