commands.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. // mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
  2. // Copyright (C) 2019 Tulir Asokan
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. package main
  17. import (
  18. "fmt"
  19. "strings"
  20. "github.com/Rhymen/go-whatsapp"
  21. "maunium.net/go/maulogger/v2"
  22. "maunium.net/go/mautrix"
  23. "maunium.net/go/mautrix-appservice"
  24. "maunium.net/go/mautrix/format"
  25. "maunium.net/go/mautrix-whatsapp/database"
  26. "maunium.net/go/mautrix-whatsapp/types"
  27. "maunium.net/go/mautrix-whatsapp/whatsapp-ext"
  28. )
  29. type CommandHandler struct {
  30. bridge *Bridge
  31. log maulogger.Logger
  32. }
  33. // NewCommandHandler creates a CommandHandler
  34. func NewCommandHandler(bridge *Bridge) *CommandHandler {
  35. return &CommandHandler{
  36. bridge: bridge,
  37. log: bridge.Log.Sub("Command handler"),
  38. }
  39. }
  40. // CommandEvent stores all data which might be used to handle commands
  41. type CommandEvent struct {
  42. Bot *appservice.IntentAPI
  43. Bridge *Bridge
  44. Handler *CommandHandler
  45. RoomID types.MatrixRoomID
  46. User *User
  47. Command string
  48. Args []string
  49. }
  50. // Reply sends a reply to command as notice
  51. func (ce *CommandEvent) Reply(msg string, args ...interface{}) {
  52. content := format.RenderMarkdown(fmt.Sprintf(msg, args...))
  53. content.MsgType = mautrix.MsgNotice
  54. room := ce.User.ManagementRoom
  55. if len(room) == 0 {
  56. room = ce.RoomID
  57. }
  58. _, err := ce.Bot.SendMessageEvent(room, mautrix.EventMessage, content)
  59. if err != nil {
  60. ce.Handler.log.Warnfln("Failed to reply to command from %s: %v", ce.User.MXID, err)
  61. }
  62. }
  63. // Handle handles messages to the bridge
  64. func (handler *CommandHandler) Handle(roomID types.MatrixRoomID, user *User, message string) {
  65. args := strings.Split(message, " ")
  66. ce := &CommandEvent{
  67. Bot: handler.bridge.Bot,
  68. Bridge: handler.bridge,
  69. Handler: handler,
  70. RoomID: roomID,
  71. User: user,
  72. Command: strings.ToLower(args[0]),
  73. Args: args[1:],
  74. }
  75. handler.log.Debugfln("%s sent '%s' in %s", user.MXID, message, roomID)
  76. if roomID == handler.bridge.Config.Bridge.Relaybot.ManagementRoom {
  77. handler.CommandRelaybot(ce)
  78. } else {
  79. handler.CommandMux(ce)
  80. }
  81. }
  82. func (handler *CommandHandler) CommandMux(ce *CommandEvent) {
  83. switch ce.Command {
  84. case "relaybot":
  85. handler.CommandRelaybot(ce)
  86. case "login":
  87. handler.CommandLogin(ce)
  88. case "logout-matrix":
  89. handler.CommandLogoutMatrix(ce)
  90. case "help":
  91. handler.CommandHelp(ce)
  92. case "reconnect":
  93. handler.CommandReconnect(ce)
  94. case "disconnect":
  95. handler.CommandDisconnect(ce)
  96. case "ping":
  97. handler.CommandPing(ce)
  98. case "delete-connection":
  99. handler.CommandDeleteConnection(ce)
  100. case "delete-session":
  101. handler.CommandDeleteSession(ce)
  102. case "delete-portal":
  103. handler.CommandDeletePortal(ce)
  104. case "delete-all-portals":
  105. handler.CommandDeleteAllPortals(ce)
  106. case "dev-test":
  107. handler.CommandDevTest(ce)
  108. case "login-matrix", "logout", "sync", "list", "open", "pm":
  109. if !ce.User.HasSession() {
  110. ce.Reply("You are not logged in. Use the `login` command to log into WhatsApp.")
  111. return
  112. } else if !ce.User.IsConnected() {
  113. ce.Reply("You are not connected to WhatsApp. Use the `reconnect` command to reconnect.")
  114. return
  115. }
  116. switch ce.Command {
  117. case "login-matrix":
  118. handler.CommandLoginMatrix(ce)
  119. case "logout":
  120. handler.CommandLogout(ce)
  121. case "sync":
  122. handler.CommandSync(ce)
  123. case "list":
  124. handler.CommandList(ce)
  125. case "open":
  126. handler.CommandOpen(ce)
  127. case "pm":
  128. handler.CommandPM(ce)
  129. }
  130. default:
  131. ce.Reply("Unknown Command")
  132. }
  133. }
  134. func (handler *CommandHandler) CommandRelaybot(ce *CommandEvent) {
  135. if handler.bridge.Relaybot == nil {
  136. ce.Reply("The relaybot is disabled")
  137. } else if !ce.User.Admin {
  138. ce.Reply("Only admins can manage the relaybot")
  139. } else {
  140. if ce.Command == "relaybot" {
  141. if len(ce.Args) == 0 {
  142. ce.Reply("**Usage:** `relaybot <command>`")
  143. return
  144. }
  145. ce.Command = strings.ToLower(ce.Args[0])
  146. ce.Args = ce.Args[1:]
  147. }
  148. ce.User = handler.bridge.Relaybot
  149. handler.CommandMux(ce)
  150. }
  151. }
  152. func (handler *CommandHandler) CommandDevTest(ce *CommandEvent) {
  153. }
  154. const cmdLoginHelp = `login - Authenticate this Bridge as WhatsApp Web Client`
  155. // CommandLogin handles login command
  156. func (handler *CommandHandler) CommandLogin(ce *CommandEvent) {
  157. if !ce.User.Connect(true) {
  158. ce.User.log.Debugln("Connect() returned false, assuming error was logged elsewhere and canceling login.")
  159. return
  160. }
  161. ce.User.Login(ce)
  162. }
  163. const cmdLogoutHelp = `logout - Logout from WhatsApp`
  164. // CommandLogout handles !logout command
  165. func (handler *CommandHandler) CommandLogout(ce *CommandEvent) {
  166. if ce.User.Session == nil {
  167. ce.Reply("You're not logged in.")
  168. return
  169. }
  170. err := ce.User.Conn.Logout()
  171. if err != nil {
  172. ce.User.log.Warnln("Error while logging out:", err)
  173. ce.Reply("Unknown error while logging out: %v", err)
  174. return
  175. }
  176. _, err = ce.User.Conn.Disconnect()
  177. if err != nil {
  178. ce.User.log.Warnln("Error while disconnecting after logout:", err)
  179. }
  180. ce.User.Conn.RemoveHandlers()
  181. ce.User.Conn = nil
  182. ce.User.SetSession(nil)
  183. ce.Reply("Logged out successfully.")
  184. }
  185. const cmdDeleteSessionHelp = `delete-session - Delete session information and disconnect from WhatsApp without sending a logout request`
  186. func (handler *CommandHandler) CommandDeleteSession(ce *CommandEvent) {
  187. if ce.User.Session == nil && ce.User.Conn == nil {
  188. ce.Reply("Nothing to purge: no session information stored and no active connection.")
  189. return
  190. }
  191. ce.User.SetSession(nil)
  192. if ce.User.Conn != nil {
  193. _, _ = ce.User.Conn.Disconnect()
  194. ce.User.Conn.RemoveHandlers()
  195. ce.User.Conn = nil
  196. }
  197. ce.Reply("Session information purged")
  198. }
  199. const cmdReconnectHelp = `reconnect - Reconnect to WhatsApp`
  200. func (handler *CommandHandler) CommandReconnect(ce *CommandEvent) {
  201. if ce.User.Conn == nil {
  202. if ce.User.Session == nil {
  203. ce.Reply("No existing connection and no session. Did you mean `login`?")
  204. } else {
  205. ce.Reply("No existing connection, creating one...")
  206. ce.User.Connect(false)
  207. }
  208. return
  209. }
  210. wasConnected := true
  211. sess, err := ce.User.Conn.Disconnect()
  212. if err == whatsapp.ErrNotConnected {
  213. wasConnected = false
  214. } else if err != nil {
  215. ce.User.log.Warnln("Error while disconnecting:", err)
  216. } else if len(sess.Wid) > 0 {
  217. ce.User.SetSession(&sess)
  218. }
  219. err = ce.User.Conn.Restore()
  220. if err == whatsapp.ErrInvalidSession {
  221. if ce.User.Session != nil {
  222. ce.User.log.Debugln("Got invalid session error when reconnecting, but user has session. Retrying using RestoreWithSession()...")
  223. var sess whatsapp.Session
  224. sess, err = ce.User.Conn.RestoreWithSession(*ce.User.Session)
  225. if err == nil {
  226. ce.User.SetSession(&sess)
  227. }
  228. } else {
  229. ce.Reply("You are not logged in.")
  230. return
  231. }
  232. } else if err == whatsapp.ErrLoginInProgress {
  233. ce.Reply("A login or reconnection is already in progress.")
  234. return
  235. } else if err == whatsapp.ErrAlreadyLoggedIn {
  236. ce.Reply("You were already connected.")
  237. return
  238. }
  239. if err != nil {
  240. ce.User.log.Warnln("Error while reconnecting:", err)
  241. if err.Error() == "restore session connection timed out" {
  242. ce.Reply("Reconnection timed out. Is WhatsApp on your phone reachable?")
  243. } else {
  244. ce.Reply("Unknown error while reconnecting: %v", err)
  245. }
  246. ce.User.log.Debugln("Disconnecting due to failed session restore in reconnect command...")
  247. sess, err := ce.User.Conn.Disconnect()
  248. if err != nil {
  249. ce.User.log.Errorln("Failed to disconnect after failed session restore in reconnect command:", err)
  250. } else if len(sess.Wid) > 0 {
  251. ce.User.SetSession(&sess)
  252. }
  253. return
  254. }
  255. ce.User.ConnectionErrors = 0
  256. var msg string
  257. if wasConnected {
  258. msg = "Reconnected successfully."
  259. } else {
  260. msg = "Connected successfully."
  261. }
  262. ce.Reply(msg)
  263. ce.User.PostLogin()
  264. }
  265. func (handler *CommandHandler) CommandDeleteConnection(ce *CommandEvent) {
  266. if ce.User.Conn == nil {
  267. ce.Reply("You don't have a WhatsApp connection.")
  268. return
  269. }
  270. sess, err := ce.User.Conn.Disconnect()
  271. if err == nil && len(sess.Wid) > 0 {
  272. ce.User.SetSession(&sess)
  273. }
  274. ce.User.Conn.RemoveHandlers()
  275. ce.User.Conn = nil
  276. ce.Reply("Successfully disconnected. Use the `reconnect` command to reconnect.")
  277. }
  278. const cmdDisconnectHelp = `disconnect - Disconnect from WhatsApp (without logging out)`
  279. func (handler *CommandHandler) CommandDisconnect(ce *CommandEvent) {
  280. if ce.User.Conn == nil {
  281. ce.Reply("You don't have a WhatsApp connection.")
  282. return
  283. }
  284. sess, err := ce.User.Conn.Disconnect()
  285. if err == whatsapp.ErrNotConnected {
  286. ce.Reply("You were not connected.")
  287. return
  288. } else if err != nil {
  289. ce.User.log.Warnln("Error while disconnecting:", err)
  290. ce.Reply("Unknown error while disconnecting: %v", err)
  291. return
  292. } else if len(sess.Wid) > 0 {
  293. ce.User.SetSession(&sess)
  294. }
  295. ce.Reply("Successfully disconnected. Use the `reconnect` command to reconnect.")
  296. }
  297. const cmdPingHelp = `ping - Check your connection to WhatsApp.`
  298. func (handler *CommandHandler) CommandPing(ce *CommandEvent) {
  299. if ce.User.Session == nil {
  300. if ce.User.IsLoginInProgress() {
  301. ce.Reply("You're not logged into WhatsApp, but there's a login in progress.")
  302. } else {
  303. ce.Reply("You're not logged into WhatsApp.")
  304. }
  305. } else if ce.User.Conn == nil {
  306. ce.Reply("You don't have a WhatsApp connection.")
  307. } else if ok, err := ce.User.Conn.AdminTest(); err != nil {
  308. if ce.User.IsLoginInProgress() {
  309. ce.Reply("Connection not OK: %v, but login in progress", err)
  310. } else {
  311. ce.Reply("Connection not OK: %v", err)
  312. }
  313. } else if !ok {
  314. if ce.User.IsLoginInProgress() {
  315. ce.Reply("Connection not OK, but no error received and login in progress")
  316. } else {
  317. ce.Reply("Connection not OK, but no error received")
  318. }
  319. } else {
  320. ce.Reply("Connection to WhatsApp OK")
  321. }
  322. }
  323. const cmdHelpHelp = `help - Prints this help`
  324. // CommandHelp handles help command
  325. func (handler *CommandHandler) CommandHelp(ce *CommandEvent) {
  326. cmdPrefix := ""
  327. if ce.User.ManagementRoom != ce.RoomID || ce.User.IsRelaybot {
  328. cmdPrefix = handler.bridge.Config.Bridge.CommandPrefix + " "
  329. }
  330. ce.Reply("* " + strings.Join([]string{
  331. cmdPrefix + cmdHelpHelp,
  332. cmdPrefix + cmdLoginHelp,
  333. cmdPrefix + cmdLogoutHelp,
  334. cmdPrefix + cmdDeleteSessionHelp,
  335. cmdPrefix + cmdReconnectHelp,
  336. cmdPrefix + cmdDisconnectHelp,
  337. cmdPrefix + cmdPingHelp,
  338. cmdPrefix + cmdLoginMatrixHelp,
  339. cmdPrefix + cmdLogoutMatrixHelp,
  340. cmdPrefix + cmdSyncHelp,
  341. cmdPrefix + cmdListHelp,
  342. cmdPrefix + cmdOpenHelp,
  343. cmdPrefix + cmdPMHelp,
  344. }, "\n* "))
  345. }
  346. const cmdSyncHelp = `sync [--create-all] - Synchronize contacts from phone and optionally create portals for group chats.`
  347. // CommandSync handles sync command
  348. func (handler *CommandHandler) CommandSync(ce *CommandEvent) {
  349. user := ce.User
  350. create := len(ce.Args) > 0 && ce.Args[0] == "--create-all"
  351. ce.Reply("Updating contact and chat list...")
  352. handler.log.Debugln("Importing contacts of", user.MXID)
  353. _, err := user.Conn.Contacts()
  354. if err != nil {
  355. user.log.Errorln("Error updating contacts:", err)
  356. ce.Reply("Failed to sync contact list (see logs for details)")
  357. return
  358. }
  359. handler.log.Debugln("Importing chats of", user.MXID)
  360. _, err = user.Conn.Chats()
  361. if err != nil {
  362. user.log.Errorln("Error updating chats:", err)
  363. ce.Reply("Failed to sync chat list (see logs for details)")
  364. return
  365. }
  366. ce.Reply("Syncing contacts...")
  367. user.syncPuppets(nil)
  368. ce.Reply("Syncing chats...")
  369. user.syncPortals(nil, create)
  370. ce.Reply("Sync complete.")
  371. }
  372. func (handler *CommandHandler) CommandDeletePortal(ce *CommandEvent) {
  373. if !ce.User.Admin {
  374. ce.Reply("Only bridge admins can delete portals")
  375. return
  376. }
  377. portal := ce.Bridge.GetPortalByMXID(ce.RoomID)
  378. if portal == nil {
  379. ce.Reply("You must be in a portal room to use that command")
  380. return
  381. }
  382. portal.log.Infoln(ce.User.MXID, "requested deletion of portal.")
  383. portal.Delete()
  384. portal.Cleanup(false)
  385. }
  386. func (handler *CommandHandler) CommandDeleteAllPortals(ce *CommandEvent) {
  387. portals := ce.User.GetPortals()
  388. portalsToDelete := make([]*Portal, 0, len(portals))
  389. for _, portal := range portals {
  390. users := portal.GetUserIDs()
  391. if len(users) == 1 && users[0] == ce.User.MXID {
  392. portalsToDelete = append(portalsToDelete, portal)
  393. }
  394. }
  395. leave := func(portal *Portal) {
  396. if len(portal.MXID) > 0 {
  397. _, _ = portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{
  398. Reason: "Deleting portal",
  399. UserID: ce.User.MXID,
  400. })
  401. }
  402. }
  403. customPuppet := handler.bridge.GetPuppetByCustomMXID(ce.User.MXID)
  404. if customPuppet != nil && customPuppet.CustomIntent() != nil {
  405. intent := customPuppet.CustomIntent()
  406. leave = func(portal *Portal) {
  407. if len(portal.MXID) > 0 {
  408. _, _ = intent.LeaveRoom(portal.MXID)
  409. _, _ = intent.ForgetRoom(portal.MXID)
  410. }
  411. }
  412. }
  413. ce.Reply("Found %d portals with no other users, deleting...", len(portalsToDelete))
  414. for _, portal := range portalsToDelete {
  415. portal.Delete()
  416. leave(portal)
  417. }
  418. ce.Reply("Finished deleting portal info. Now cleaning up rooms in background. " +
  419. "You may already continue using the bridge. Use `sync` to recreate portals.")
  420. go func() {
  421. for _, portal := range portalsToDelete {
  422. portal.Cleanup(false)
  423. }
  424. ce.Reply("Finished background cleanup of deleted portal rooms.")
  425. }()
  426. }
  427. const cmdListHelp = `list - Get a list of all contacts and groups.`
  428. func (handler *CommandHandler) CommandList(ce *CommandEvent) {
  429. var contacts strings.Builder
  430. var groups strings.Builder
  431. for jid, contact := range ce.User.Conn.Store.Contacts {
  432. if strings.HasSuffix(jid, whatsappExt.NewUserSuffix) {
  433. _, _ = fmt.Fprintf(&contacts, "* %s / %s - `%s`\n", contact.Name, contact.Notify, contact.Jid[:len(contact.Jid)-len(whatsappExt.NewUserSuffix)])
  434. } else {
  435. _, _ = fmt.Fprintf(&groups, "* %s - `%s`\n", contact.Name, contact.Jid)
  436. }
  437. }
  438. ce.Reply("### Contacts\n%s\n\n### Groups\n%s", contacts.String(), groups.String())
  439. }
  440. const cmdOpenHelp = `open <_group JID_> - Open a group chat portal.`
  441. func (handler *CommandHandler) CommandOpen(ce *CommandEvent) {
  442. if len(ce.Args) == 0 {
  443. ce.Reply("**Usage:** `open <group JID>`")
  444. return
  445. }
  446. user := ce.User
  447. jid := ce.Args[0]
  448. if strings.HasSuffix(jid, whatsappExt.NewUserSuffix) {
  449. ce.Reply("That looks like a user JID. Did you mean `pm %s`?", jid[:len(jid)-len(whatsappExt.NewUserSuffix)])
  450. return
  451. }
  452. contact, ok := user.Conn.Store.Contacts[jid]
  453. if !ok {
  454. ce.Reply("Group JID not found in contacts. Try syncing contacts with `sync` first.")
  455. return
  456. }
  457. handler.log.Debugln("Importing", jid, "for", user)
  458. portal := user.bridge.GetPortalByJID(database.GroupPortalKey(jid))
  459. if len(portal.MXID) > 0 {
  460. portal.Sync(user, contact)
  461. ce.Reply("Portal room synced.")
  462. } else {
  463. portal.Sync(user, contact)
  464. ce.Reply("Portal room created.")
  465. }
  466. }
  467. const cmdPMHelp = `pm [--force] <_international phone number_> - Open a private chat with the given phone number.`
  468. func (handler *CommandHandler) CommandPM(ce *CommandEvent) {
  469. if len(ce.Args) == 0 {
  470. ce.Reply("**Usage:** `pm [--force] <international phone number>`")
  471. return
  472. }
  473. force := ce.Args[0] == "--force"
  474. if force {
  475. ce.Args = ce.Args[1:]
  476. }
  477. user := ce.User
  478. number := strings.Join(ce.Args, "")
  479. if number[0] == '+' {
  480. number = number[1:]
  481. }
  482. for _, char := range number {
  483. if char < '0' || char > '9' {
  484. ce.Reply("Invalid phone number.")
  485. return
  486. }
  487. }
  488. jid := number + whatsappExt.NewUserSuffix
  489. handler.log.Debugln("Importing", jid, "for", user)
  490. contact, ok := user.Conn.Store.Contacts[jid]
  491. if !ok {
  492. if !force {
  493. ce.Reply("Phone number not found in contacts. Try syncing contacts with `sync` first. " +
  494. "To create a portal anyway, use `pm --force <number>`.")
  495. return
  496. }
  497. contact = whatsapp.Contact{Jid: jid}
  498. }
  499. puppet := user.bridge.GetPuppetByJID(contact.Jid)
  500. puppet.Sync(user, contact)
  501. portal := user.bridge.GetPortalByJID(database.NewPortalKey(contact.Jid, user.JID))
  502. if len(portal.MXID) > 0 {
  503. _, err := portal.MainIntent().InviteUser(portal.MXID, &mautrix.ReqInviteUser{UserID: user.MXID})
  504. if err != nil {
  505. fmt.Println(err)
  506. } else {
  507. ce.Reply("Existing portal room found, invited you to it.")
  508. }
  509. return
  510. }
  511. err := portal.CreateMatrixRoom(user)
  512. if err != nil {
  513. ce.Reply("Failed to create portal room: %v", err)
  514. return
  515. }
  516. ce.Reply("Created portal room and invited you to it.")
  517. }
  518. const cmdLoginMatrixHelp = `login-matrix <_access token_> - Replace your WhatsApp account's Matrix puppet with your real Matrix account.'`
  519. func (handler *CommandHandler) CommandLoginMatrix(ce *CommandEvent) {
  520. if len(ce.Args) == 0 {
  521. ce.Reply("**Usage:** `login-matrix <access token>`")
  522. return
  523. }
  524. puppet := handler.bridge.GetPuppetByJID(ce.User.JID)
  525. err := puppet.SwitchCustomMXID(ce.Args[0], ce.User.MXID)
  526. if err != nil {
  527. ce.Reply("Failed to switch puppet: %v", err)
  528. return
  529. }
  530. ce.Reply("Successfully switched puppet")
  531. }
  532. const cmdLogoutMatrixHelp = `logout-matrix - Switch your WhatsApp account's Matrix puppet back to the default one.`
  533. func (handler *CommandHandler) CommandLogoutMatrix(ce *CommandEvent) {
  534. puppet := handler.bridge.GetPuppetByJID(ce.User.JID)
  535. if len(puppet.CustomMXID) == 0 {
  536. ce.Reply("You had not changed your WhatsApp account's Matrix puppet.")
  537. return
  538. }
  539. err := puppet.SwitchCustomMXID("", "")
  540. if err != nil {
  541. ce.Reply("Failed to remove custom puppet: %v", err)
  542. return
  543. }
  544. ce.Reply("Successfully removed custom puppet")
  545. }