commands.go 17 KB

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