mirror of
https://github.com/tulir/mautrix-whatsapp
synced 2024-09-28 12:38:54 +02:00
Add ping-matrix command
This commit is contained in:
parent
682c5bff38
commit
1d877771e4
1 changed files with 21 additions and 2 deletions
23
commands.go
23
commands.go
|
@ -100,6 +100,8 @@ func (handler *CommandHandler) CommandMux(ce *CommandEvent) {
|
||||||
switch ce.Command {
|
switch ce.Command {
|
||||||
case "login":
|
case "login":
|
||||||
handler.CommandLogin(ce)
|
handler.CommandLogin(ce)
|
||||||
|
case "ping-matrix":
|
||||||
|
handler.CommandPingMatrix(ce)
|
||||||
case "logout-matrix":
|
case "logout-matrix":
|
||||||
handler.CommandLogoutMatrix(ce)
|
handler.CommandLogoutMatrix(ce)
|
||||||
case "help":
|
case "help":
|
||||||
|
@ -662,6 +664,7 @@ func (handler *CommandHandler) CommandHelp(ce *CommandEvent) {
|
||||||
cmdPrefix + cmdSetRelayHelp,
|
cmdPrefix + cmdSetRelayHelp,
|
||||||
cmdPrefix + cmdUnsetRelayHelp,
|
cmdPrefix + cmdUnsetRelayHelp,
|
||||||
cmdPrefix + cmdLoginMatrixHelp,
|
cmdPrefix + cmdLoginMatrixHelp,
|
||||||
|
cmdPrefix + cmdPingMatrixHelp,
|
||||||
cmdPrefix + cmdLogoutMatrixHelp,
|
cmdPrefix + cmdLogoutMatrixHelp,
|
||||||
cmdPrefix + cmdToggleHelp,
|
cmdPrefix + cmdToggleHelp,
|
||||||
cmdPrefix + cmdListHelp,
|
cmdPrefix + cmdListHelp,
|
||||||
|
@ -940,11 +943,27 @@ func (handler *CommandHandler) CommandLoginMatrix(ce *CommandEvent) {
|
||||||
ce.Reply("Successfully switched puppet")
|
ce.Reply("Successfully switched puppet")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const cmdPingMatrixHelp = `ping-matrix - Check if your double puppet is working correctly.`
|
||||||
|
|
||||||
|
func (handler *CommandHandler) CommandPingMatrix(ce *CommandEvent) {
|
||||||
|
puppet := handler.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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const cmdLogoutMatrixHelp = `logout-matrix - Switch your WhatsApp account's Matrix puppet back to the default one.`
|
const cmdLogoutMatrixHelp = `logout-matrix - Switch your WhatsApp account's Matrix puppet back to the default one.`
|
||||||
|
|
||||||
func (handler *CommandHandler) CommandLogoutMatrix(ce *CommandEvent) {
|
func (handler *CommandHandler) CommandLogoutMatrix(ce *CommandEvent) {
|
||||||
puppet := handler.bridge.GetPuppetByJID(ce.User.JID)
|
puppet := handler.bridge.GetPuppetByCustomMXID(ce.User.MXID)
|
||||||
if len(puppet.CustomMXID) == 0 {
|
if puppet == nil || puppet.CustomIntent() == nil {
|
||||||
ce.Reply("You had not changed your WhatsApp account's Matrix puppet.")
|
ce.Reply("You had not changed your WhatsApp account's Matrix puppet.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue