commands.go 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. // mautrix-whatsapp - A Matrix-WhatsApp puppeting bridge.
  2. // Copyright (C) 2021 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. "context"
  19. "encoding/json"
  20. "errors"
  21. "fmt"
  22. "html"
  23. "math"
  24. "sort"
  25. "strconv"
  26. "strings"
  27. "time"
  28. "github.com/skip2/go-qrcode"
  29. "github.com/tidwall/gjson"
  30. "go.mau.fi/whatsmeow"
  31. "go.mau.fi/whatsmeow/appstate"
  32. "go.mau.fi/whatsmeow/types"
  33. "maunium.net/go/mautrix"
  34. "maunium.net/go/mautrix/bridge"
  35. "maunium.net/go/mautrix/bridge/commands"
  36. "maunium.net/go/mautrix/bridge/status"
  37. "maunium.net/go/mautrix/event"
  38. "maunium.net/go/mautrix/id"
  39. "maunium.net/go/mautrix-whatsapp/database"
  40. )
  41. type WrappedCommandEvent struct {
  42. *commands.Event
  43. Bridge *WABridge
  44. User *User
  45. Portal *Portal
  46. }
  47. func (br *WABridge) RegisterCommands() {
  48. proc := br.CommandProcessor.(*commands.Processor)
  49. proc.AddHandlers(
  50. cmdSetRelay,
  51. cmdUnsetRelay,
  52. cmdInviteLink,
  53. cmdResolveLink,
  54. cmdJoin,
  55. cmdAccept,
  56. cmdCreate,
  57. cmdLogin,
  58. cmdLogout,
  59. cmdTogglePresence,
  60. cmdDeleteSession,
  61. cmdReconnect,
  62. cmdDisconnect,
  63. cmdPing,
  64. cmdDeletePortal,
  65. cmdDeleteAllPortals,
  66. cmdBackfill,
  67. cmdList,
  68. cmdSearch,
  69. cmdOpen,
  70. cmdPM,
  71. cmdSync,
  72. cmdDisappearingTimer,
  73. )
  74. }
  75. func wrapCommand(handler func(*WrappedCommandEvent)) func(*commands.Event) {
  76. return func(ce *commands.Event) {
  77. user := ce.User.(*User)
  78. var portal *Portal
  79. if ce.Portal != nil {
  80. portal = ce.Portal.(*Portal)
  81. }
  82. br := ce.Bridge.Child.(*WABridge)
  83. handler(&WrappedCommandEvent{ce, br, user, portal})
  84. }
  85. }
  86. var (
  87. HelpSectionConnectionManagement = commands.HelpSection{Name: "Connection management", Order: 11}
  88. HelpSectionCreatingPortals = commands.HelpSection{Name: "Creating portals", Order: 15}
  89. HelpSectionPortalManagement = commands.HelpSection{Name: "Portal management", Order: 20}
  90. HelpSectionInvites = commands.HelpSection{Name: "Group invites", Order: 25}
  91. HelpSectionMiscellaneous = commands.HelpSection{Name: "Miscellaneous", Order: 30}
  92. )
  93. var cmdSetRelay = &commands.FullHandler{
  94. Func: wrapCommand(fnSetRelay),
  95. Name: "set-relay",
  96. Help: commands.HelpMeta{
  97. Section: HelpSectionPortalManagement,
  98. Description: "Relay messages in this room through your WhatsApp account.",
  99. },
  100. RequiresPortal: true,
  101. RequiresLogin: true,
  102. }
  103. func fnSetRelay(ce *WrappedCommandEvent) {
  104. if !ce.Bridge.Config.Bridge.Relay.Enabled {
  105. ce.Reply("Relay mode is not enabled on this instance of the bridge")
  106. } else if ce.Bridge.Config.Bridge.Relay.AdminOnly && !ce.User.Admin {
  107. ce.Reply("Only admins are allowed to enable relay mode on this instance of the bridge")
  108. } else {
  109. ce.Portal.RelayUserID = ce.User.MXID
  110. ce.Portal.Update(nil)
  111. ce.Reply("Messages from non-logged-in users in this room will now be bridged through your WhatsApp account")
  112. }
  113. }
  114. var cmdUnsetRelay = &commands.FullHandler{
  115. Func: wrapCommand(fnUnsetRelay),
  116. Name: "unset-relay",
  117. Help: commands.HelpMeta{
  118. Section: HelpSectionPortalManagement,
  119. Description: "Stop relaying messages in this room.",
  120. },
  121. RequiresPortal: true,
  122. }
  123. func fnUnsetRelay(ce *WrappedCommandEvent) {
  124. if !ce.Bridge.Config.Bridge.Relay.Enabled {
  125. ce.Reply("Relay mode is not enabled on this instance of the bridge")
  126. } else if ce.Bridge.Config.Bridge.Relay.AdminOnly && !ce.User.Admin {
  127. ce.Reply("Only admins are allowed to enable relay mode on this instance of the bridge")
  128. } else {
  129. ce.Portal.RelayUserID = ""
  130. ce.Portal.Update(nil)
  131. ce.Reply("Messages from non-logged-in users will no longer be bridged in this room")
  132. }
  133. }
  134. var cmdInviteLink = &commands.FullHandler{
  135. Func: wrapCommand(fnInviteLink),
  136. Name: "invite-link",
  137. Help: commands.HelpMeta{
  138. Section: HelpSectionInvites,
  139. Description: "Get an invite link to the current group chat, optionally regenerating the link and revoking the old link.",
  140. Args: "[--reset]",
  141. },
  142. RequiresPortal: true,
  143. RequiresLogin: true,
  144. }
  145. func fnInviteLink(ce *WrappedCommandEvent) {
  146. reset := len(ce.Args) > 0 && strings.ToLower(ce.Args[0]) == "--reset"
  147. if ce.Portal.IsPrivateChat() {
  148. ce.Reply("Can't get invite link to private chat")
  149. } else if ce.Portal.IsBroadcastList() {
  150. ce.Reply("Can't get invite link to broadcast list")
  151. } else if link, err := ce.User.Client.GetGroupInviteLink(ce.Portal.Key.JID, reset); err != nil {
  152. ce.Reply("Failed to get invite link: %v", err)
  153. } else {
  154. ce.Reply(link)
  155. }
  156. }
  157. var cmdResolveLink = &commands.FullHandler{
  158. Func: wrapCommand(fnResolveLink),
  159. Name: "resolve-link",
  160. Help: commands.HelpMeta{
  161. Section: HelpSectionInvites,
  162. Description: "Resolve a WhatsApp group invite or business message link.",
  163. Args: "<_group or message link_>",
  164. },
  165. RequiresLogin: true,
  166. }
  167. func fnResolveLink(ce *WrappedCommandEvent) {
  168. if len(ce.Args) == 0 {
  169. ce.Reply("**Usage:** `resolve-link <group or message link>`")
  170. return
  171. }
  172. if strings.HasPrefix(ce.Args[0], whatsmeow.InviteLinkPrefix) {
  173. group, err := ce.User.Client.GetGroupInfoFromLink(ce.Args[0])
  174. if err != nil {
  175. ce.Reply("Failed to get group info: %v", err)
  176. return
  177. }
  178. ce.Reply("That invite link points at %s (`%s`)", group.Name, group.JID)
  179. } else if strings.HasPrefix(ce.Args[0], whatsmeow.BusinessMessageLinkPrefix) || strings.HasPrefix(ce.Args[0], whatsmeow.BusinessMessageLinkDirectPrefix) {
  180. target, err := ce.User.Client.ResolveBusinessMessageLink(ce.Args[0])
  181. if err != nil {
  182. ce.Reply("Failed to get business info: %v", err)
  183. return
  184. }
  185. message := ""
  186. if len(target.Message) > 0 {
  187. parts := strings.Split(target.Message, "\n")
  188. for i, part := range parts {
  189. parts[i] = "> " + html.EscapeString(part)
  190. }
  191. message = fmt.Sprintf(" The following prefilled message is attached:\n\n%s", strings.Join(parts, "\n"))
  192. }
  193. ce.Reply("That link points at %s (+%s).%s", target.PushName, target.JID.User, message)
  194. } else {
  195. ce.Reply("That doesn't look like a group invite link nor a business message link.")
  196. }
  197. }
  198. var cmdJoin = &commands.FullHandler{
  199. Func: wrapCommand(fnJoin),
  200. Name: "join",
  201. Help: commands.HelpMeta{
  202. Section: HelpSectionInvites,
  203. Description: "Join a group chat with an invite link.",
  204. Args: "<_invite link_>",
  205. },
  206. RequiresLogin: true,
  207. }
  208. func fnJoin(ce *WrappedCommandEvent) {
  209. if len(ce.Args) == 0 {
  210. ce.Reply("**Usage:** `join <invite link>`")
  211. return
  212. } else if !strings.HasPrefix(ce.Args[0], whatsmeow.InviteLinkPrefix) {
  213. ce.Reply("That doesn't look like a WhatsApp invite link")
  214. return
  215. }
  216. jid, err := ce.User.Client.JoinGroupWithLink(ce.Args[0])
  217. if err != nil {
  218. ce.Reply("Failed to join group: %v", err)
  219. return
  220. }
  221. ce.Log.Debugln("%s successfully joined group %s", ce.User.MXID, jid)
  222. ce.Reply("Successfully joined group `%s`, the portal should be created momentarily", jid)
  223. }
  224. func tryDecryptEvent(crypto bridge.Crypto, evt *event.Event) (json.RawMessage, error) {
  225. var data json.RawMessage
  226. if evt.Type != event.EventEncrypted {
  227. data = evt.Content.VeryRaw
  228. } else {
  229. err := evt.Content.ParseRaw(evt.Type)
  230. if err != nil && !errors.Is(err, event.ErrContentAlreadyParsed) {
  231. return nil, err
  232. }
  233. decrypted, err := crypto.Decrypt(evt)
  234. if err != nil {
  235. return nil, err
  236. }
  237. data = decrypted.Content.VeryRaw
  238. }
  239. return data, nil
  240. }
  241. func parseInviteMeta(data json.RawMessage) (*InviteMeta, error) {
  242. result := gjson.GetBytes(data, escapedInviteMetaField)
  243. if !result.Exists() || !result.IsObject() {
  244. return nil, nil
  245. }
  246. var meta InviteMeta
  247. err := json.Unmarshal([]byte(result.Raw), &meta)
  248. if err != nil {
  249. return nil, nil
  250. }
  251. return &meta, nil
  252. }
  253. var cmdAccept = &commands.FullHandler{
  254. Func: wrapCommand(fnAccept),
  255. Name: "accept",
  256. Help: commands.HelpMeta{
  257. Section: HelpSectionInvites,
  258. Description: "Accept a group invite. This can only be used in reply to a group invite message.",
  259. },
  260. RequiresLogin: true,
  261. RequiresPortal: true,
  262. }
  263. func fnAccept(ce *WrappedCommandEvent) {
  264. if len(ce.ReplyTo) == 0 {
  265. ce.Reply("You must reply to a group invite message when using this command.")
  266. } else if evt, err := ce.Portal.MainIntent().GetEvent(ce.RoomID, ce.ReplyTo); err != nil {
  267. ce.Log.Errorln("Failed to get event %s to handle !wa accept command: %v", ce.ReplyTo, err)
  268. ce.Reply("Failed to get reply event")
  269. } else if rawContent, err := tryDecryptEvent(ce.Bridge.Crypto, evt); err != nil {
  270. ce.Log.Errorln("Failed to decrypt event %s to handle !wa accept command: %v", ce.ReplyTo, err)
  271. ce.Reply("Failed to decrypt reply event")
  272. } else if meta, err := parseInviteMeta(rawContent); err != nil || meta == nil {
  273. ce.Reply("That doesn't look like a group invite message.")
  274. } else if meta.Inviter.User == ce.User.JID.User {
  275. ce.Reply("You can't accept your own invites")
  276. } else if err = ce.User.Client.JoinGroupWithInvite(meta.JID, meta.Inviter, meta.Code, meta.Expiration); err != nil {
  277. ce.Reply("Failed to accept group invite: %v", err)
  278. } else {
  279. ce.Reply("Successfully accepted the invite, the portal should be created momentarily")
  280. }
  281. }
  282. var cmdCreate = &commands.FullHandler{
  283. Func: wrapCommand(fnCreate),
  284. Name: "create",
  285. Help: commands.HelpMeta{
  286. Section: HelpSectionCreatingPortals,
  287. Description: "Create a WhatsApp group chat for the current Matrix room.",
  288. },
  289. RequiresLogin: true,
  290. }
  291. func fnCreate(ce *WrappedCommandEvent) {
  292. if ce.Portal != nil {
  293. ce.Reply("This is already a portal room")
  294. return
  295. }
  296. members, err := ce.Bot.JoinedMembers(ce.RoomID)
  297. if err != nil {
  298. ce.Reply("Failed to get room members: %v", err)
  299. return
  300. }
  301. var roomNameEvent event.RoomNameEventContent
  302. err = ce.Bot.StateEvent(ce.RoomID, event.StateRoomName, "", &roomNameEvent)
  303. if err != nil && !errors.Is(err, mautrix.MNotFound) {
  304. ce.Log.Errorln("Failed to get room name to create group:", err)
  305. ce.Reply("Failed to get room name")
  306. return
  307. } else if len(roomNameEvent.Name) == 0 {
  308. ce.Reply("Please set a name for the room first")
  309. return
  310. }
  311. var encryptionEvent event.EncryptionEventContent
  312. err = ce.Bot.StateEvent(ce.RoomID, event.StateEncryption, "", &encryptionEvent)
  313. if err != nil && !errors.Is(err, mautrix.MNotFound) {
  314. ce.Reply("Failed to get room encryption status")
  315. return
  316. }
  317. var participants []types.JID
  318. participantDedup := make(map[types.JID]bool)
  319. participantDedup[ce.User.JID.ToNonAD()] = true
  320. participantDedup[types.EmptyJID] = true
  321. for userID := range members.Joined {
  322. jid, ok := ce.Bridge.ParsePuppetMXID(userID)
  323. if !ok {
  324. user := ce.Bridge.GetUserByMXID(userID)
  325. if user != nil && !user.JID.IsEmpty() {
  326. jid = user.JID.ToNonAD()
  327. }
  328. }
  329. if !participantDedup[jid] {
  330. participantDedup[jid] = true
  331. participants = append(participants, jid)
  332. }
  333. }
  334. ce.Log.Infofln("Creating group for %s with name %s and participants %+v", ce.RoomID, roomNameEvent.Name, participants)
  335. resp, err := ce.User.Client.CreateGroup(roomNameEvent.Name, participants, "")
  336. if err != nil {
  337. ce.Reply("Failed to create group: %v", err)
  338. return
  339. }
  340. portal := ce.User.GetPortalByJID(resp.JID)
  341. portal.roomCreateLock.Lock()
  342. defer portal.roomCreateLock.Unlock()
  343. if len(portal.MXID) != 0 {
  344. portal.log.Warnln("Detected race condition in room creation")
  345. // TODO race condition, clean up the old room
  346. }
  347. portal.MXID = ce.RoomID
  348. portal.Name = roomNameEvent.Name
  349. portal.Encrypted = encryptionEvent.Algorithm == id.AlgorithmMegolmV1
  350. if !portal.Encrypted && ce.Bridge.Config.Bridge.Encryption.Default {
  351. _, err = portal.MainIntent().SendStateEvent(portal.MXID, event.StateEncryption, "", portal.GetEncryptionEventContent())
  352. if err != nil {
  353. portal.log.Warnln("Failed to enable encryption in room:", err)
  354. if errors.Is(err, mautrix.MForbidden) {
  355. ce.Reply("I don't seem to have permission to enable encryption in this room.")
  356. } else {
  357. ce.Reply("Failed to enable encryption in room: %v", err)
  358. }
  359. }
  360. portal.Encrypted = true
  361. }
  362. portal.Update(nil)
  363. portal.UpdateBridgeInfo()
  364. ce.Reply("Successfully created WhatsApp group %s", portal.Key.JID)
  365. }
  366. var cmdLogin = &commands.FullHandler{
  367. Func: wrapCommand(fnLogin),
  368. Name: "login",
  369. Help: commands.HelpMeta{
  370. Section: commands.HelpSectionAuth,
  371. Description: "Link the bridge to your WhatsApp account as a web client.",
  372. },
  373. }
  374. func fnLogin(ce *WrappedCommandEvent) {
  375. if ce.User.Session != nil {
  376. if ce.User.IsConnected() {
  377. ce.Reply("You're already logged in")
  378. } else {
  379. ce.Reply("You're already logged in. Perhaps you wanted to `reconnect`?")
  380. }
  381. return
  382. }
  383. qrChan, err := ce.User.Login(context.Background())
  384. if err != nil {
  385. ce.User.log.Errorf("Failed to log in:", err)
  386. ce.Reply("Failed to log in: %v", err)
  387. return
  388. }
  389. var qrEventID id.EventID
  390. for item := range qrChan {
  391. switch item.Event {
  392. case whatsmeow.QRChannelSuccess.Event:
  393. jid := ce.User.Client.Store.ID
  394. ce.Reply("Successfully logged in as +%s (device #%d)", jid.User, jid.Device)
  395. case whatsmeow.QRChannelTimeout.Event:
  396. ce.Reply("QR code timed out. Please restart the login.")
  397. case whatsmeow.QRChannelErrUnexpectedEvent.Event:
  398. ce.Reply("Failed to log in: unexpected connection event from server")
  399. case whatsmeow.QRChannelClientOutdated.Event:
  400. ce.Reply("Failed to log in: outdated client. The bridge must be updated to continue.")
  401. case whatsmeow.QRChannelScannedWithoutMultidevice.Event:
  402. ce.Reply("Please enable the WhatsApp multidevice beta and scan the QR code again.")
  403. case "error":
  404. ce.Reply("Failed to log in: %v", item.Error)
  405. case "code":
  406. qrEventID = ce.User.sendQR(ce, item.Code, qrEventID)
  407. }
  408. }
  409. _, _ = ce.Bot.RedactEvent(ce.RoomID, qrEventID)
  410. }
  411. func (user *User) sendQR(ce *WrappedCommandEvent, code string, prevEvent id.EventID) id.EventID {
  412. url, ok := user.uploadQR(ce, code)
  413. if !ok {
  414. return prevEvent
  415. }
  416. content := event.MessageEventContent{
  417. MsgType: event.MsgImage,
  418. Body: code,
  419. URL: url.CUString(),
  420. }
  421. if len(prevEvent) != 0 {
  422. content.SetEdit(prevEvent)
  423. }
  424. resp, err := ce.Bot.SendMessageEvent(ce.RoomID, event.EventMessage, &content)
  425. if err != nil {
  426. user.log.Errorln("Failed to send edited QR code to user:", err)
  427. } else if len(prevEvent) == 0 {
  428. prevEvent = resp.EventID
  429. }
  430. return prevEvent
  431. }
  432. func (user *User) uploadQR(ce *WrappedCommandEvent, code string) (id.ContentURI, bool) {
  433. qrCode, err := qrcode.Encode(code, qrcode.Low, 256)
  434. if err != nil {
  435. user.log.Errorln("Failed to encode QR code:", err)
  436. ce.Reply("Failed to encode QR code: %v", err)
  437. return id.ContentURI{}, false
  438. }
  439. bot := user.bridge.AS.BotClient()
  440. resp, err := bot.UploadBytes(qrCode, "image/png")
  441. if err != nil {
  442. user.log.Errorln("Failed to upload QR code:", err)
  443. ce.Reply("Failed to upload QR code: %v", err)
  444. return id.ContentURI{}, false
  445. }
  446. return resp.ContentURI, true
  447. }
  448. var cmdLogout = &commands.FullHandler{
  449. Func: wrapCommand(fnLogout),
  450. Name: "logout",
  451. Help: commands.HelpMeta{
  452. Section: commands.HelpSectionAuth,
  453. Description: "Unlink the bridge from your WhatsApp account.",
  454. },
  455. }
  456. func fnLogout(ce *WrappedCommandEvent) {
  457. if ce.User.Session == nil {
  458. ce.Reply("You're not logged in.")
  459. return
  460. } else if !ce.User.IsLoggedIn() {
  461. ce.Reply("You are not connected to WhatsApp. Use the `reconnect` command to reconnect, or `delete-session` to forget all login information.")
  462. return
  463. }
  464. puppet := ce.Bridge.GetPuppetByJID(ce.User.JID)
  465. if puppet.CustomMXID != "" {
  466. err := puppet.SwitchCustomMXID("", "")
  467. if err != nil {
  468. ce.User.log.Warnln("Failed to logout-matrix while logging out of WhatsApp:", err)
  469. }
  470. }
  471. err := ce.User.Client.Logout()
  472. if err != nil {
  473. ce.User.log.Warnln("Error while logging out:", err)
  474. ce.Reply("Unknown error while logging out: %v", err)
  475. return
  476. }
  477. ce.User.Session = nil
  478. ce.User.removeFromJIDMap(status.BridgeState{StateEvent: status.StateLoggedOut})
  479. ce.User.DeleteConnection()
  480. ce.User.DeleteSession()
  481. ce.Reply("Logged out successfully.")
  482. }
  483. var cmdTogglePresence = &commands.FullHandler{
  484. Func: wrapCommand(fnTogglePresence),
  485. Name: "toggle-presence",
  486. Help: commands.HelpMeta{
  487. Section: HelpSectionConnectionManagement,
  488. Description: "Toggle bridging of presence or read receipts.",
  489. },
  490. }
  491. func fnTogglePresence(ce *WrappedCommandEvent) {
  492. if ce.User.Session == nil {
  493. ce.Reply("You're not logged in.")
  494. return
  495. }
  496. customPuppet := ce.Bridge.GetPuppetByCustomMXID(ce.User.MXID)
  497. if customPuppet == nil {
  498. ce.Reply("You're not logged in with your Matrix account.")
  499. return
  500. }
  501. customPuppet.EnablePresence = !customPuppet.EnablePresence
  502. var newPresence types.Presence
  503. if customPuppet.EnablePresence {
  504. newPresence = types.PresenceAvailable
  505. ce.Reply("Enabled presence bridging")
  506. } else {
  507. newPresence = types.PresenceUnavailable
  508. ce.Reply("Disabled presence bridging")
  509. }
  510. if ce.User.IsLoggedIn() {
  511. err := ce.User.Client.SendPresence(newPresence)
  512. if err != nil {
  513. ce.User.log.Warnln("Failed to set presence:", err)
  514. }
  515. }
  516. customPuppet.Update()
  517. }
  518. var cmdDeleteSession = &commands.FullHandler{
  519. Func: wrapCommand(fnDeleteSession),
  520. Name: "delete-session",
  521. Help: commands.HelpMeta{
  522. Section: commands.HelpSectionAuth,
  523. Description: "Delete session information and disconnect from WhatsApp without sending a logout request.",
  524. },
  525. }
  526. func fnDeleteSession(ce *WrappedCommandEvent) {
  527. if ce.User.Session == nil && ce.User.Client == nil {
  528. ce.Reply("Nothing to purge: no session information stored and no active connection.")
  529. return
  530. }
  531. ce.User.removeFromJIDMap(status.BridgeState{StateEvent: status.StateLoggedOut})
  532. ce.User.DeleteConnection()
  533. ce.User.DeleteSession()
  534. ce.Reply("Session information purged")
  535. }
  536. var cmdReconnect = &commands.FullHandler{
  537. Func: wrapCommand(fnReconnect),
  538. Name: "reconnect",
  539. Help: commands.HelpMeta{
  540. Section: HelpSectionConnectionManagement,
  541. Description: "Reconnect to WhatsApp.",
  542. },
  543. }
  544. func fnReconnect(ce *WrappedCommandEvent) {
  545. if ce.User.Client == nil {
  546. if ce.User.Session == nil {
  547. ce.Reply("You're not logged into WhatsApp. Please log in first.")
  548. } else {
  549. ce.User.Connect()
  550. ce.Reply("Started connecting to WhatsApp")
  551. }
  552. } else {
  553. ce.User.DeleteConnection()
  554. ce.User.BridgeState.Send(status.BridgeState{StateEvent: status.StateTransientDisconnect, Error: WANotConnected})
  555. ce.User.Connect()
  556. ce.Reply("Restarted connection to WhatsApp")
  557. }
  558. }
  559. var cmdDisconnect = &commands.FullHandler{
  560. Func: wrapCommand(fnDisconnect),
  561. Name: "disconnect",
  562. Help: commands.HelpMeta{
  563. Section: HelpSectionConnectionManagement,
  564. Description: "Disconnect from WhatsApp (without logging out).",
  565. },
  566. }
  567. func fnDisconnect(ce *WrappedCommandEvent) {
  568. if ce.User.Client == nil {
  569. ce.Reply("You don't have a WhatsApp connection.")
  570. return
  571. }
  572. ce.User.DeleteConnection()
  573. ce.Reply("Successfully disconnected. Use the `reconnect` command to reconnect.")
  574. ce.User.BridgeState.Send(status.BridgeState{StateEvent: status.StateBadCredentials, Error: WANotConnected})
  575. }
  576. var cmdPing = &commands.FullHandler{
  577. Func: wrapCommand(fnPing),
  578. Name: "ping",
  579. Help: commands.HelpMeta{
  580. Section: HelpSectionConnectionManagement,
  581. Description: "Check your connection to WhatsApp.",
  582. },
  583. }
  584. func fnPing(ce *WrappedCommandEvent) {
  585. if ce.User.Session == nil {
  586. if ce.User.Client != nil {
  587. ce.Reply("Connected to WhatsApp, but not logged in.")
  588. } else {
  589. ce.Reply("You're not logged into WhatsApp.")
  590. }
  591. } else if ce.User.Client == nil || !ce.User.Client.IsConnected() {
  592. ce.Reply("You're logged in as +%s (device #%d), but you don't have a WhatsApp connection.", ce.User.JID.User, ce.User.JID.Device)
  593. } else {
  594. ce.Reply("Logged in as +%s (device #%d), connection to WhatsApp OK (probably)", ce.User.JID.User, ce.User.JID.Device)
  595. if !ce.User.PhoneRecentlySeen(false) {
  596. ce.Reply("Phone hasn't been seen in %s", formatDisconnectTime(time.Now().Sub(ce.User.PhoneLastSeen)))
  597. }
  598. }
  599. }
  600. func canDeletePortal(portal *Portal, userID id.UserID) bool {
  601. if len(portal.MXID) == 0 {
  602. return false
  603. }
  604. members, err := portal.MainIntent().JoinedMembers(portal.MXID)
  605. if err != nil {
  606. portal.log.Errorfln("Failed to get joined members to check if portal can be deleted by %s: %v", userID, err)
  607. return false
  608. }
  609. for otherUser := range members.Joined {
  610. _, isPuppet := portal.bridge.ParsePuppetMXID(otherUser)
  611. if isPuppet || otherUser == portal.bridge.Bot.UserID || otherUser == userID {
  612. continue
  613. }
  614. user := portal.bridge.GetUserByMXID(otherUser)
  615. if user != nil && user.Session != nil {
  616. return false
  617. }
  618. }
  619. return true
  620. }
  621. var cmdDeletePortal = &commands.FullHandler{
  622. Func: wrapCommand(fnDeletePortal),
  623. Name: "delete-portal",
  624. Help: commands.HelpMeta{
  625. Section: HelpSectionPortalManagement,
  626. Description: "Delete the current portal. If the portal is used by other people, this is limited to bridge admins.",
  627. },
  628. RequiresPortal: true,
  629. }
  630. func fnDeletePortal(ce *WrappedCommandEvent) {
  631. if !ce.User.Admin && !canDeletePortal(ce.Portal, ce.User.MXID) {
  632. ce.Reply("Only bridge admins can delete portals with other Matrix users")
  633. return
  634. }
  635. ce.Portal.log.Infoln(ce.User.MXID, "requested deletion of portal.")
  636. ce.Portal.Delete()
  637. ce.Portal.Cleanup(false)
  638. }
  639. var cmdDeleteAllPortals = &commands.FullHandler{
  640. Func: wrapCommand(fnDeleteAllPortals),
  641. Name: "delete-all-portals",
  642. Help: commands.HelpMeta{
  643. Section: HelpSectionPortalManagement,
  644. Description: "Delete all portals.",
  645. },
  646. }
  647. func fnDeleteAllPortals(ce *WrappedCommandEvent) {
  648. portals := ce.Bridge.GetAllPortals()
  649. var portalsToDelete []*Portal
  650. if ce.User.Admin {
  651. portalsToDelete = portals
  652. } else {
  653. portalsToDelete = portals[:0]
  654. for _, portal := range portals {
  655. if canDeletePortal(portal, ce.User.MXID) {
  656. portalsToDelete = append(portalsToDelete, portal)
  657. }
  658. }
  659. }
  660. if len(portalsToDelete) == 0 {
  661. ce.Reply("Didn't find any portals to delete")
  662. return
  663. }
  664. leave := func(portal *Portal) {
  665. if len(portal.MXID) > 0 {
  666. _, _ = portal.MainIntent().KickUser(portal.MXID, &mautrix.ReqKickUser{
  667. Reason: "Deleting portal",
  668. UserID: ce.User.MXID,
  669. })
  670. }
  671. }
  672. customPuppet := ce.Bridge.GetPuppetByCustomMXID(ce.User.MXID)
  673. if customPuppet != nil && customPuppet.CustomIntent() != nil {
  674. intent := customPuppet.CustomIntent()
  675. leave = func(portal *Portal) {
  676. if len(portal.MXID) > 0 {
  677. _, _ = intent.LeaveRoom(portal.MXID)
  678. _, _ = intent.ForgetRoom(portal.MXID)
  679. }
  680. }
  681. }
  682. ce.Reply("Found %d portals, deleting...", len(portalsToDelete))
  683. for _, portal := range portalsToDelete {
  684. portal.Delete()
  685. leave(portal)
  686. }
  687. ce.Reply("Finished deleting portal info. Now cleaning up rooms in background.")
  688. go func() {
  689. for _, portal := range portalsToDelete {
  690. portal.Cleanup(false)
  691. }
  692. ce.Reply("Finished background cleanup of deleted portal rooms.")
  693. }()
  694. }
  695. var cmdBackfill = &commands.FullHandler{
  696. Func: wrapCommand(fnBackfill),
  697. Name: "backfill",
  698. Help: commands.HelpMeta{
  699. Section: HelpSectionPortalManagement,
  700. Description: "Backfill all messages the portal.",
  701. Args: "[_batch size_] [_batch delay_]",
  702. },
  703. RequiresPortal: true,
  704. }
  705. func fnBackfill(ce *WrappedCommandEvent) {
  706. if !ce.Bridge.Config.Bridge.HistorySync.Backfill {
  707. ce.Reply("Backfill is not enabled for this bridge.")
  708. return
  709. }
  710. batchSize := 100
  711. batchDelay := 5
  712. if len(ce.Args) >= 1 {
  713. var err error
  714. batchSize, err = strconv.Atoi(ce.Args[0])
  715. if err != nil || batchSize < 1 {
  716. ce.Reply("\"%s\" isn't a valid batch size", ce.Args[0])
  717. return
  718. }
  719. }
  720. if len(ce.Args) >= 2 {
  721. var err error
  722. batchDelay, err = strconv.Atoi(ce.Args[0])
  723. if err != nil || batchSize < 0 {
  724. ce.Reply("\"%s\" isn't a valid batch delay", ce.Args[1])
  725. return
  726. }
  727. }
  728. backfillMessages := ce.Portal.bridge.DB.Backfill.NewWithValues(ce.User.MXID, database.BackfillImmediate, 0, &ce.Portal.Key, nil, batchSize, -1, batchDelay)
  729. backfillMessages.Insert()
  730. ce.User.BackfillQueue.ReCheck()
  731. }
  732. func matchesQuery(str string, query string) bool {
  733. if query == "" {
  734. return true
  735. }
  736. return strings.Contains(strings.ToLower(str), query)
  737. }
  738. func formatContacts(bridge *WABridge, input map[types.JID]types.ContactInfo, query string) (result []string) {
  739. hasQuery := len(query) > 0
  740. for jid, contact := range input {
  741. if len(contact.FullName) == 0 {
  742. continue
  743. }
  744. puppet := bridge.GetPuppetByJID(jid)
  745. pushName := contact.PushName
  746. if len(pushName) == 0 {
  747. pushName = contact.FullName
  748. }
  749. if !hasQuery || matchesQuery(pushName, query) || matchesQuery(contact.FullName, query) || matchesQuery(jid.User, query) {
  750. result = append(result, fmt.Sprintf("* %s / [%s](https://matrix.to/#/%s) - `+%s`", contact.FullName, pushName, puppet.MXID, jid.User))
  751. }
  752. }
  753. sort.Sort(sort.StringSlice(result))
  754. return
  755. }
  756. func formatGroups(input []*types.GroupInfo, query string) (result []string) {
  757. hasQuery := len(query) > 0
  758. for _, group := range input {
  759. if !hasQuery || matchesQuery(group.GroupName.Name, query) || matchesQuery(group.JID.User, query) {
  760. result = append(result, fmt.Sprintf("* %s - `%s`", group.GroupName.Name, group.JID.User))
  761. }
  762. }
  763. sort.Sort(sort.StringSlice(result))
  764. return
  765. }
  766. var cmdList = &commands.FullHandler{
  767. Func: wrapCommand(fnList),
  768. Name: "list",
  769. Help: commands.HelpMeta{
  770. Section: HelpSectionMiscellaneous,
  771. Description: "Get a list of all contacts and groups.",
  772. Args: "<`contacts`|`groups`> [_page_] [_items per page_]",
  773. },
  774. RequiresLogin: true,
  775. }
  776. func fnList(ce *WrappedCommandEvent) {
  777. if len(ce.Args) == 0 {
  778. ce.Reply("**Usage:** `list <contacts|groups> [page] [items per page]`")
  779. return
  780. }
  781. mode := strings.ToLower(ce.Args[0])
  782. if mode[0] != 'g' && mode[0] != 'c' {
  783. ce.Reply("**Usage:** `list <contacts|groups> [page] [items per page]`")
  784. return
  785. }
  786. var err error
  787. page := 1
  788. max := 100
  789. if len(ce.Args) > 1 {
  790. page, err = strconv.Atoi(ce.Args[1])
  791. if err != nil || page <= 0 {
  792. ce.Reply("\"%s\" isn't a valid page number", ce.Args[1])
  793. return
  794. }
  795. }
  796. if len(ce.Args) > 2 {
  797. max, err = strconv.Atoi(ce.Args[2])
  798. if err != nil || max <= 0 {
  799. ce.Reply("\"%s\" isn't a valid number of items per page", ce.Args[2])
  800. return
  801. } else if max > 400 {
  802. ce.Reply("Warning: a high number of items per page may fail to send a reply")
  803. }
  804. }
  805. contacts := mode[0] == 'c'
  806. typeName := "Groups"
  807. var result []string
  808. if contacts {
  809. typeName = "Contacts"
  810. contactList, err := ce.User.Client.Store.Contacts.GetAllContacts()
  811. if err != nil {
  812. ce.Reply("Failed to get contacts: %s", err)
  813. return
  814. }
  815. result = formatContacts(ce.User.bridge, contactList, "")
  816. } else {
  817. groupList, err := ce.User.Client.GetJoinedGroups()
  818. if err != nil {
  819. ce.Reply("Failed to get groups: %s", err)
  820. return
  821. }
  822. result = formatGroups(groupList, "")
  823. }
  824. if len(result) == 0 {
  825. ce.Reply("No %s found", strings.ToLower(typeName))
  826. return
  827. }
  828. pages := int(math.Ceil(float64(len(result)) / float64(max)))
  829. if (page-1)*max >= len(result) {
  830. if pages == 1 {
  831. ce.Reply("There is only 1 page of %s", strings.ToLower(typeName))
  832. } else {
  833. ce.Reply("There are %d pages of %s", pages, strings.ToLower(typeName))
  834. }
  835. return
  836. }
  837. lastIndex := page * max
  838. if lastIndex > len(result) {
  839. lastIndex = len(result)
  840. }
  841. result = result[(page-1)*max : lastIndex]
  842. ce.Reply("### %s (page %d of %d)\n\n%s", typeName, page, pages, strings.Join(result, "\n"))
  843. }
  844. var cmdSearch = &commands.FullHandler{
  845. Func: wrapCommand(fnSearch),
  846. Name: "search",
  847. Help: commands.HelpMeta{
  848. Section: HelpSectionMiscellaneous,
  849. Description: "Search for contacts or groups.",
  850. Args: "<_query_>",
  851. },
  852. RequiresLogin: true,
  853. }
  854. func fnSearch(ce *WrappedCommandEvent) {
  855. if len(ce.Args) == 0 {
  856. ce.Reply("**Usage:** `search <query>`")
  857. return
  858. }
  859. contactList, err := ce.User.Client.Store.Contacts.GetAllContacts()
  860. if err != nil {
  861. ce.Reply("Failed to get contacts: %s", err)
  862. return
  863. }
  864. groupList, err := ce.User.Client.GetJoinedGroups()
  865. if err != nil {
  866. ce.Reply("Failed to get groups: %s", err)
  867. return
  868. }
  869. query := strings.ToLower(strings.TrimSpace(strings.Join(ce.Args, " ")))
  870. formattedContacts := strings.Join(formatContacts(ce.User.bridge, contactList, query), "\n")
  871. formattedGroups := strings.Join(formatGroups(groupList, query), "\n")
  872. result := make([]string, 0, 2)
  873. if len(formattedContacts) > 0 {
  874. result = append(result, "### Contacts\n\n"+formattedContacts)
  875. }
  876. if len(formattedGroups) > 0 {
  877. result = append(result, "### Groups\n\n"+formattedGroups)
  878. }
  879. if len(result) == 0 {
  880. ce.Reply("No contacts or groups found")
  881. return
  882. }
  883. ce.Reply(strings.Join(result, "\n\n"))
  884. }
  885. var cmdOpen = &commands.FullHandler{
  886. Func: wrapCommand(fnOpen),
  887. Name: "open",
  888. Help: commands.HelpMeta{
  889. Section: HelpSectionCreatingPortals,
  890. Description: "Open a group chat portal.",
  891. Args: "<_group JID_>",
  892. },
  893. RequiresLogin: true,
  894. }
  895. func fnOpen(ce *WrappedCommandEvent) {
  896. if len(ce.Args) == 0 {
  897. ce.Reply("**Usage:** `open <group JID>`")
  898. return
  899. }
  900. var jid types.JID
  901. if strings.ContainsRune(ce.Args[0], '@') {
  902. jid, _ = types.ParseJID(ce.Args[0])
  903. } else {
  904. jid = types.NewJID(ce.Args[0], types.GroupServer)
  905. }
  906. if jid.Server != types.GroupServer || (!strings.ContainsRune(jid.User, '-') && len(jid.User) < 15) {
  907. ce.Reply("That does not look like a group JID")
  908. return
  909. }
  910. info, err := ce.User.Client.GetGroupInfo(jid)
  911. if err != nil {
  912. ce.Reply("Failed to get group info: %v", err)
  913. return
  914. }
  915. ce.Log.Debugln("Importing", jid, "for", ce.User.MXID)
  916. portal := ce.User.GetPortalByJID(info.JID)
  917. if len(portal.MXID) > 0 {
  918. portal.UpdateMatrixRoom(ce.User, info)
  919. ce.Reply("Portal room synced.")
  920. } else {
  921. err = portal.CreateMatrixRoom(ce.User, info, true, true)
  922. if err != nil {
  923. ce.Reply("Failed to create room: %v", err)
  924. } else {
  925. ce.Reply("Portal room created.")
  926. }
  927. }
  928. }
  929. var cmdPM = &commands.FullHandler{
  930. Func: wrapCommand(fnPM),
  931. Name: "pm",
  932. Help: commands.HelpMeta{
  933. Section: HelpSectionCreatingPortals,
  934. Description: "Open a private chat with the given phone number.",
  935. Args: "<_international phone number_>",
  936. },
  937. RequiresLogin: true,
  938. }
  939. func fnPM(ce *WrappedCommandEvent) {
  940. if len(ce.Args) == 0 {
  941. ce.Reply("**Usage:** `pm <international phone number>`")
  942. return
  943. }
  944. user := ce.User
  945. number := strings.Join(ce.Args, "")
  946. resp, err := ce.User.Client.IsOnWhatsApp([]string{number})
  947. if err != nil {
  948. ce.Reply("Failed to check if user is on WhatsApp: %v", err)
  949. return
  950. } else if len(resp) == 0 {
  951. ce.Reply("Didn't get a response to checking if the user is on WhatsApp")
  952. return
  953. }
  954. targetUser := resp[0]
  955. if !targetUser.IsIn {
  956. ce.Reply("The server said +%s is not on WhatsApp", targetUser.JID.User)
  957. return
  958. }
  959. portal, puppet, justCreated, err := user.StartPM(targetUser.JID, "manual PM command")
  960. if err != nil {
  961. ce.Reply("Failed to create portal room: %v", err)
  962. } else if !justCreated {
  963. ce.Reply("You already have a private chat portal with +%s at [%s](https://matrix.to/#/%s)", puppet.JID.User, puppet.Displayname, portal.MXID)
  964. } else {
  965. ce.Reply("Created portal room with +%s and invited you to it.", puppet.JID.User)
  966. }
  967. }
  968. var cmdSync = &commands.FullHandler{
  969. Func: wrapCommand(fnSync),
  970. Name: "sync",
  971. Help: commands.HelpMeta{
  972. Section: HelpSectionMiscellaneous,
  973. Description: "Synchronize data from WhatsApp.",
  974. Args: "<appstate/contacts/groups/space> [--create-portals]",
  975. },
  976. RequiresLogin: true,
  977. }
  978. func fnSync(ce *WrappedCommandEvent) {
  979. if len(ce.Args) == 0 {
  980. ce.Reply("**Usage:** `sync <appstate/contacts/avatars/groups/space> [--contact-avatars] [--create-portals]`")
  981. return
  982. }
  983. args := strings.ToLower(strings.Join(ce.Args, " "))
  984. contacts := strings.Contains(args, "contacts")
  985. appState := strings.Contains(args, "appstate")
  986. space := strings.Contains(args, "space")
  987. groups := strings.Contains(args, "groups") || space
  988. createPortals := strings.Contains(args, "--create-portals")
  989. contactAvatars := strings.Contains(args, "--contact-avatars")
  990. if contactAvatars && (!contacts || appState) {
  991. ce.Reply("`--contact-avatars` can only be used with `sync contacts`")
  992. return
  993. }
  994. if appState {
  995. for _, name := range appstate.AllPatchNames {
  996. err := ce.User.Client.FetchAppState(name, true, false)
  997. if errors.Is(err, appstate.ErrKeyNotFound) {
  998. ce.Reply("Key not found error syncing app state %s: %v\n\nKey requests are sent automatically, and the sync should happen in the background after your phone responds.", name, err)
  999. return
  1000. } else if err != nil {
  1001. ce.Reply("Error syncing app state %s: %v", name, err)
  1002. } else if name == appstate.WAPatchCriticalUnblockLow {
  1003. ce.Reply("Synced app state %s, contact sync running in background", name)
  1004. } else {
  1005. ce.Reply("Synced app state %s", name)
  1006. }
  1007. }
  1008. } else if contacts {
  1009. err := ce.User.ResyncContacts(contactAvatars)
  1010. if err != nil {
  1011. ce.Reply("Error resyncing contacts: %v", err)
  1012. } else {
  1013. ce.Reply("Resynced contacts")
  1014. }
  1015. }
  1016. if space {
  1017. if !ce.Bridge.Config.Bridge.PersonalFilteringSpaces {
  1018. ce.Reply("Personal filtering spaces are not enabled on this instance of the bridge")
  1019. return
  1020. }
  1021. keys := ce.Bridge.DB.Portal.FindPrivateChatsNotInSpace(ce.User.JID)
  1022. count := 0
  1023. for _, key := range keys {
  1024. portal := ce.Bridge.GetPortalByJID(key)
  1025. portal.addToSpace(ce.User)
  1026. count++
  1027. }
  1028. plural := "s"
  1029. if count == 1 {
  1030. plural = ""
  1031. }
  1032. ce.Reply("Added %d DM room%s to space", count, plural)
  1033. }
  1034. if groups {
  1035. err := ce.User.ResyncGroups(createPortals)
  1036. if err != nil {
  1037. ce.Reply("Error resyncing groups: %v", err)
  1038. } else {
  1039. ce.Reply("Resynced groups")
  1040. }
  1041. }
  1042. }
  1043. var cmdDisappearingTimer = &commands.FullHandler{
  1044. Func: wrapCommand(fnDisappearingTimer),
  1045. Name: "disappearing-timer",
  1046. Aliases: []string{"disappear-timer"},
  1047. Help: commands.HelpMeta{
  1048. Section: HelpSectionPortalManagement,
  1049. Description: "Set future messages in the room to disappear after the given time.",
  1050. Args: "<off/1d/7d/90d>",
  1051. },
  1052. RequiresLogin: true,
  1053. RequiresPortal: true,
  1054. }
  1055. func fnDisappearingTimer(ce *WrappedCommandEvent) {
  1056. if len(ce.Args) == 0 {
  1057. ce.Reply("**Usage:** `disappearing-timer <off/1d/7d/90d>`")
  1058. return
  1059. }
  1060. duration, ok := whatsmeow.ParseDisappearingTimerString(ce.Args[0])
  1061. if !ok {
  1062. ce.Reply("Invalid timer '%s'", ce.Args[0])
  1063. return
  1064. }
  1065. prevExpirationTime := ce.Portal.ExpirationTime
  1066. ce.Portal.ExpirationTime = uint32(duration.Seconds())
  1067. err := ce.User.Client.SetDisappearingTimer(ce.Portal.Key.JID, duration)
  1068. if err != nil {
  1069. ce.Reply("Failed to set disappearing timer: %v", err)
  1070. ce.Portal.ExpirationTime = prevExpirationTime
  1071. return
  1072. }
  1073. ce.Portal.Update(nil)
  1074. if !ce.Portal.IsPrivateChat() && !ce.Bridge.Config.Bridge.DisappearingMessagesInGroups {
  1075. ce.Reply("Disappearing timer changed successfully, but this bridge is not configured to disappear messages in group chats.")
  1076. } else {
  1077. ce.React("✅")
  1078. }
  1079. }