message_input.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. package chat
  2. import (
  3. "bytes"
  4. "io"
  5. "log/slog"
  6. "os"
  7. "path/filepath"
  8. "regexp"
  9. "slices"
  10. "strings"
  11. "sync"
  12. "time"
  13. "unicode"
  14. "github.com/ayn2op/discordo/internal/cache"
  15. "github.com/ayn2op/discordo/internal/clipboard"
  16. "github.com/ayn2op/discordo/internal/config"
  17. "github.com/ayn2op/discordo/internal/consts"
  18. "github.com/ayn2op/discordo/internal/ui"
  19. "github.com/ayn2op/tview"
  20. "github.com/ayn2op/tview/layers"
  21. "github.com/diamondburned/arikawa/v3/api"
  22. "github.com/diamondburned/arikawa/v3/discord"
  23. "github.com/diamondburned/arikawa/v3/state"
  24. "github.com/diamondburned/arikawa/v3/utils/json/option"
  25. "github.com/diamondburned/arikawa/v3/utils/sendpart"
  26. "github.com/diamondburned/ningen/v3"
  27. "github.com/diamondburned/ningen/v3/discordmd"
  28. "github.com/gdamore/tcell/v3"
  29. "github.com/ncruces/zenity"
  30. "github.com/sahilm/fuzzy"
  31. "github.com/yuin/goldmark/ast"
  32. )
  33. const tmpFilePattern = consts.Name + "_*.md"
  34. var mentionRegex = regexp.MustCompile("@[a-zA-Z0-9._]+")
  35. type messageInput struct {
  36. *tview.TextArea
  37. cfg *config.Config
  38. chatView *View
  39. edit bool
  40. sendMessageData *api.SendMessageData
  41. cache *cache.Cache
  42. mentionsList *mentionsList
  43. lastSearch time.Time
  44. typingTimerMu sync.Mutex
  45. typingTimer *time.Timer
  46. }
  47. func newMessageInput(cfg *config.Config, chatView *View) *messageInput {
  48. mi := &messageInput{
  49. TextArea: tview.NewTextArea(),
  50. cfg: cfg,
  51. chatView: chatView,
  52. sendMessageData: &api.SendMessageData{},
  53. cache: cache.NewCache(),
  54. mentionsList: newMentionsList(cfg),
  55. }
  56. mi.Box = ui.ConfigureBox(mi.Box, &cfg.Theme)
  57. mi.SetInputCapture(mi.onInputCapture)
  58. mi.
  59. SetPlaceholder(tview.NewLine(tview.NewSegment("Select a channel to start chatting", tcell.StyleDefault.Dim(true)))).
  60. SetClipboard(
  61. func(s string) { clipboard.Write(clipboard.FmtText, []byte(s)) },
  62. func() string { return string(clipboard.Read(clipboard.FmtText)) },
  63. ).
  64. SetDisabled(true)
  65. return mi
  66. }
  67. func (mi *messageInput) reset() {
  68. mi.edit = false
  69. mi.sendMessageData = &api.SendMessageData{}
  70. mi.SetTitle("")
  71. mi.SetFooter("")
  72. mi.SetText("", true)
  73. }
  74. func (mi *messageInput) stopTypingTimer() {
  75. if mi.typingTimer != nil {
  76. mi.typingTimer.Stop()
  77. mi.typingTimer = nil
  78. }
  79. }
  80. func (mi *messageInput) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
  81. switch event.Name() {
  82. case mi.cfg.Keybinds.MessageInput.Paste:
  83. mi.paste()
  84. return tcell.NewEventKey(tcell.KeyCtrlV, "", tcell.ModNone)
  85. case mi.cfg.Keybinds.MessageInput.Send:
  86. if mi.chatView.GetVisible(mentionsListLayerName) {
  87. mi.tabComplete()
  88. return nil
  89. }
  90. mi.send()
  91. return nil
  92. case mi.cfg.Keybinds.MessageInput.OpenEditor:
  93. mi.stopTabCompletion()
  94. mi.editor()
  95. return nil
  96. case mi.cfg.Keybinds.MessageInput.OpenFilePicker:
  97. mi.stopTabCompletion()
  98. mi.openFilePicker()
  99. return nil
  100. case mi.cfg.Keybinds.MessageInput.Cancel:
  101. if mi.chatView.GetVisible(mentionsListLayerName) {
  102. mi.stopTabCompletion()
  103. } else {
  104. mi.reset()
  105. }
  106. return nil
  107. case mi.cfg.Keybinds.MessageInput.TabComplete:
  108. go mi.chatView.app.QueueUpdateDraw(func() { mi.tabComplete() })
  109. return nil
  110. default:
  111. if mi.cfg.TypingIndicator.Send && mi.typingTimer == nil {
  112. mi.typingTimer = time.AfterFunc(typingDuration, func() {
  113. mi.typingTimerMu.Lock()
  114. mi.typingTimer = nil
  115. mi.typingTimerMu.Unlock()
  116. })
  117. if selectedChannel := mi.chatView.SelectedChannel(); selectedChannel != nil {
  118. go mi.chatView.state.Typing(selectedChannel.ID)
  119. }
  120. }
  121. }
  122. if mi.cfg.AutocompleteLimit > 0 {
  123. if mi.chatView.GetVisible(mentionsListLayerName) {
  124. handler := mi.mentionsList.InputHandler()
  125. switch event.Name() {
  126. case mi.cfg.Keybinds.MentionsList.Up:
  127. handler(tcell.NewEventKey(tcell.KeyUp, "", tcell.ModNone), nil)
  128. return nil
  129. case mi.cfg.Keybinds.MentionsList.Down:
  130. handler(tcell.NewEventKey(tcell.KeyDown, "", tcell.ModNone), nil)
  131. return nil
  132. case mi.cfg.Keybinds.MentionsList.Top:
  133. handler(tcell.NewEventKey(tcell.KeyHome, "", tcell.ModNone), nil)
  134. return nil
  135. case mi.cfg.Keybinds.MentionsList.Bottom:
  136. handler(tcell.NewEventKey(tcell.KeyEnd, "", tcell.ModNone), nil)
  137. return nil
  138. }
  139. }
  140. go mi.chatView.app.QueueUpdateDraw(func() { mi.tabSuggestion() })
  141. }
  142. return event
  143. }
  144. func (mi *messageInput) paste() {
  145. if data := clipboard.Read(clipboard.FmtImage); data != nil {
  146. name := "clipboard.png"
  147. mi.attach(name, bytes.NewReader(data))
  148. }
  149. }
  150. func (mi *messageInput) send() {
  151. selected := mi.chatView.SelectedChannel()
  152. if selected == nil {
  153. return
  154. }
  155. text := strings.TrimSpace(mi.GetText())
  156. if text == "" && len(mi.sendMessageData.Files) == 0 {
  157. return
  158. }
  159. // Close attached files on return
  160. defer func() {
  161. for _, file := range mi.sendMessageData.Files {
  162. if closer, ok := file.Reader.(io.Closer); ok {
  163. closer.Close()
  164. }
  165. }
  166. }()
  167. text = mi.processText(selected, []byte(text))
  168. if mi.edit {
  169. m, err := mi.chatView.messagesList.selectedMessage()
  170. if err != nil {
  171. slog.Error("failed to get selected message", "err", err)
  172. return
  173. }
  174. data := api.EditMessageData{Content: option.NewNullableString(text)}
  175. if _, err := mi.chatView.state.EditMessageComplex(m.ChannelID, m.ID, data); err != nil {
  176. slog.Error("failed to edit message", "err", err)
  177. }
  178. mi.edit = false
  179. } else {
  180. data := mi.sendMessageData
  181. data.Content = text
  182. if _, err := mi.chatView.state.SendMessageComplex(selected.ID, *data); err != nil {
  183. slog.Error("failed to send message in channel", "channel_id", selected.ID, "err", err)
  184. }
  185. }
  186. if mi.typingTimer != nil {
  187. mi.typingTimer.Stop()
  188. mi.typingTimer = nil
  189. }
  190. mi.reset()
  191. mi.chatView.messagesList.clearSelection()
  192. mi.chatView.messagesList.ScrollToEnd()
  193. }
  194. func (mi *messageInput) processText(channel *discord.Channel, src []byte) string {
  195. // Fast path: no mentions to expand.
  196. if bytes.IndexByte(src, '@') == -1 {
  197. return string(src)
  198. }
  199. // Fast path: no back ticks (code blocks), so expand mentions directly.
  200. if bytes.IndexByte(src, '`') == -1 {
  201. return string(mi.expandMentions(channel, src))
  202. }
  203. var (
  204. ranges [][2]int
  205. canMention = true
  206. )
  207. ast.Walk(discordmd.Parse(src), func(node ast.Node, enter bool) (ast.WalkStatus, error) {
  208. switch node := node.(type) {
  209. case *ast.CodeBlock, *ast.FencedCodeBlock:
  210. canMention = !enter
  211. case *discordmd.Inline:
  212. if (node.Attr & discordmd.AttrMonospace) != 0 {
  213. canMention = !enter
  214. }
  215. case *ast.Text:
  216. if canMention {
  217. ranges = append(ranges, [2]int{node.Segment.Start,
  218. node.Segment.Stop})
  219. }
  220. }
  221. return ast.WalkContinue, nil
  222. })
  223. for _, rng := range ranges {
  224. src = slices.Replace(src, rng[0], rng[1], mi.expandMentions(channel, src[rng[0]:rng[1]])...)
  225. }
  226. return string(src)
  227. }
  228. func (mi *messageInput) expandMentions(c *discord.Channel, src []byte) []byte {
  229. state := mi.chatView.state
  230. return mentionRegex.ReplaceAllFunc(src, func(input []byte) []byte {
  231. output := input
  232. name := string(input[1:])
  233. if c.Type == discord.DirectMessage || c.Type == discord.GroupDM {
  234. for _, user := range c.DMRecipients {
  235. if strings.EqualFold(user.Username, name) {
  236. return []byte(user.ID.Mention())
  237. }
  238. }
  239. // self ping
  240. me, _ := state.Cabinet.Me()
  241. if strings.EqualFold(me.Username, name) {
  242. return []byte(me.ID.Mention())
  243. }
  244. return output
  245. }
  246. state.MemberStore.Each(c.GuildID, func(m *discord.Member) bool {
  247. if strings.EqualFold(m.User.Username, name) {
  248. if channelHasUser(state, c.ID, m.User.ID) {
  249. output = []byte(m.User.ID.Mention())
  250. }
  251. return true
  252. }
  253. return false
  254. })
  255. return output
  256. })
  257. }
  258. func (mi *messageInput) tabComplete() {
  259. posEnd, name, r := mi.GetWordUnderCursor(func(r rune) bool {
  260. return unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' || r == '.'
  261. })
  262. if r != '@' {
  263. mi.stopTabCompletion()
  264. return
  265. }
  266. pos := posEnd - (len(name) + 1)
  267. selected := mi.chatView.SelectedChannel()
  268. if selected == nil {
  269. return
  270. }
  271. gID := selected.GuildID
  272. if mi.cfg.AutocompleteLimit == 0 {
  273. if !gID.IsValid() {
  274. users := selected.DMRecipients
  275. res := fuzzy.FindFrom(name, userList(users))
  276. if len(res) > 0 {
  277. mi.Replace(pos, posEnd, "@"+users[res[0].Index].Username+" ")
  278. }
  279. } else {
  280. mi.searchMember(gID, name)
  281. members, err := mi.chatView.state.Cabinet.Members(gID)
  282. if err != nil {
  283. slog.Error("failed to get members from state", "guild_id", gID, "err", err)
  284. return
  285. }
  286. res := fuzzy.FindFrom(name, memberList(members))
  287. for _, r := range res {
  288. if channelHasUser(mi.chatView.state, selected.ID, members[r.Index].User.ID) {
  289. mi.Replace(pos, posEnd, "@"+members[r.Index].User.Username+" ")
  290. return
  291. }
  292. }
  293. }
  294. return
  295. }
  296. if mi.mentionsList.itemCount() == 0 {
  297. return
  298. }
  299. name, ok := mi.mentionsList.selectedInsertText()
  300. if !ok {
  301. return
  302. }
  303. mi.Replace(pos, posEnd, "@"+name+" ")
  304. mi.stopTabCompletion()
  305. }
  306. func (mi *messageInput) tabSuggestion() {
  307. _, name, r := mi.GetWordUnderCursor(func(r rune) bool {
  308. return unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' || r == '.'
  309. })
  310. if r != '@' {
  311. mi.stopTabCompletion()
  312. return
  313. }
  314. selected := mi.chatView.SelectedChannel()
  315. if selected == nil {
  316. return
  317. }
  318. gID := selected.GuildID
  319. cID := selected.ID
  320. mi.mentionsList.clear()
  321. var shown map[string]struct{}
  322. var userDone struct{}
  323. if name == "" {
  324. shown = make(map[string]struct{})
  325. // Don't show @me in the list of recent authors
  326. me, _ := mi.chatView.state.Cabinet.Me()
  327. shown[me.Username] = userDone
  328. }
  329. // DMs have recipients, not members
  330. if !gID.IsValid() {
  331. if name == "" { // show recent messages' authors
  332. msgs, err := mi.chatView.state.Cabinet.Messages(cID)
  333. if err != nil {
  334. return
  335. }
  336. for _, m := range msgs {
  337. if _, ok := shown[m.Author.Username]; ok {
  338. continue
  339. }
  340. shown[m.Author.Username] = userDone
  341. mi.addMentionUser(&m.Author)
  342. }
  343. } else {
  344. users := selected.DMRecipients
  345. me, _ := mi.chatView.state.Cabinet.Me()
  346. users = append(users, *me)
  347. res := fuzzy.FindFrom(name, userList(users))
  348. for _, r := range res {
  349. mi.addMentionUser(&users[r.Index])
  350. }
  351. }
  352. } else if name == "" { // show recent messages' authors
  353. msgs, err := mi.chatView.state.Cabinet.Messages(cID)
  354. if err != nil {
  355. return
  356. }
  357. for _, m := range msgs {
  358. if _, ok := shown[m.Author.Username]; ok {
  359. continue
  360. }
  361. shown[m.Author.Username] = userDone
  362. mi.chatView.state.MemberState.RequestMember(gID, m.Author.ID)
  363. if mem, err := mi.chatView.state.Cabinet.Member(gID, m.Author.ID); err == nil {
  364. if mi.addMentionMember(gID, mem) {
  365. break
  366. }
  367. }
  368. }
  369. } else {
  370. mi.searchMember(gID, name)
  371. mems, err := mi.chatView.state.Cabinet.Members(gID)
  372. if err != nil {
  373. slog.Error("fetching members failed", "err", err)
  374. return
  375. }
  376. res := fuzzy.FindFrom(name, memberList(mems))
  377. if len(res) > int(mi.cfg.AutocompleteLimit) {
  378. res = res[:int(mi.cfg.AutocompleteLimit)]
  379. }
  380. for _, r := range res {
  381. if channelHasUser(mi.chatView.state, cID, mems[r.Index].User.ID) &&
  382. mi.addMentionMember(gID, &mems[r.Index]) {
  383. break
  384. }
  385. }
  386. }
  387. if mi.mentionsList.itemCount() == 0 {
  388. mi.stopTabCompletion()
  389. return
  390. }
  391. mi.mentionsList.rebuild()
  392. mi.showMentionList()
  393. }
  394. type memberList []discord.Member
  395. type userList []discord.User
  396. func (ml memberList) String(i int) string {
  397. return ml[i].Nick + ml[i].User.DisplayName + ml[i].User.Tag()
  398. }
  399. func (ml memberList) Len() int {
  400. return len(ml)
  401. }
  402. func (ul userList) String(i int) string {
  403. return ul[i].DisplayName + ul[i].Tag()
  404. }
  405. func (ul userList) Len() int {
  406. return len(ul)
  407. }
  408. // channelHasUser checks if a user has permission to view the specified channel
  409. func channelHasUser(state *ningen.State, channelID discord.ChannelID, userID discord.UserID) bool {
  410. perms, err := state.Permissions(channelID, userID)
  411. if err != nil {
  412. slog.Error("failed to get permissions", "err", err, "channel", channelID, "user", userID)
  413. return false
  414. }
  415. return perms.Has(discord.PermissionViewChannel)
  416. }
  417. func (mi *messageInput) searchMember(gID discord.GuildID, name string) {
  418. key := gID.String() + " " + name
  419. if mi.cache.Exists(key) {
  420. return
  421. }
  422. // If searching for "ab" returns less than SearchLimit,
  423. // then "abc" would not return anything new because we already searched
  424. // everything starting with "ab". This will still be true even if a new
  425. // member joins because arikawa loads new members into the state.
  426. if k := key[:len(key)-1]; mi.cache.Exists(k) {
  427. if c := mi.cache.Get(k); c < mi.chatView.state.MemberState.SearchLimit {
  428. mi.cache.Create(key, c)
  429. return
  430. }
  431. }
  432. // Rate limit on our side because we can't distinguish between a successful search and SearchMember not doing anything because of its internal rate limit that we can't detect
  433. if mi.lastSearch.Add(mi.chatView.state.MemberState.SearchFrequency).After(time.Now()) {
  434. return
  435. }
  436. mi.lastSearch = time.Now()
  437. mi.chatView.messagesList.waitForChunkEvent()
  438. mi.chatView.messagesList.setFetchingChunk(true, 0)
  439. mi.chatView.state.MemberState.SearchMember(gID, name)
  440. mi.cache.Create(key, mi.chatView.messagesList.waitForChunkEvent())
  441. }
  442. func (mi *messageInput) showMentionList() {
  443. borders := 0
  444. if mi.cfg.Theme.Border.Enabled {
  445. borders = 1
  446. }
  447. l := mi.mentionsList
  448. x, _, _, _ := mi.GetInnerRect()
  449. _, y, _, _ := mi.GetRect()
  450. _, _, maxW, maxH := mi.chatView.messagesList.GetInnerRect()
  451. if t := int(mi.cfg.Theme.MentionsList.MaxHeight); t != 0 {
  452. maxH = min(maxH, t)
  453. }
  454. count := mi.mentionsList.itemCount() + borders
  455. h := min(count, maxH) + borders + mi.cfg.Theme.Border.Padding[1]
  456. y -= h
  457. w := int(mi.cfg.Theme.MentionsList.MinWidth)
  458. if w == 0 {
  459. w = maxW
  460. } else {
  461. w = max(w, mi.mentionsList.maxDisplayWidth())
  462. w = min(w+borders*2, maxW)
  463. _, col, _, _ := mi.GetCursor()
  464. x += min(col, maxW-w)
  465. }
  466. l.SetRect(x, y, w, h)
  467. mi.chatView.
  468. AddLayer(l,
  469. layers.WithName(mentionsListLayerName),
  470. layers.WithResize(false),
  471. layers.WithVisible(true),
  472. ).
  473. SendToFront(mentionsListLayerName)
  474. mi.chatView.app.SetFocus(mi)
  475. }
  476. func (mi *messageInput) addMentionMember(gID discord.GuildID, m *discord.Member) bool {
  477. if m == nil {
  478. return false
  479. }
  480. name := m.User.DisplayOrUsername()
  481. if m.Nick != "" {
  482. name = m.Nick
  483. }
  484. style := tcell.StyleDefault
  485. // This avoids a slower member color lookup path.
  486. color, ok := state.MemberColor(m, func(id discord.RoleID) *discord.Role {
  487. r, _ := mi.chatView.state.Cabinet.Role(gID, id)
  488. return r
  489. })
  490. if ok {
  491. style = style.Foreground(tcell.NewHexColor(int32(color)))
  492. }
  493. presence, err := mi.chatView.state.Cabinet.Presence(gID, m.User.ID)
  494. if err != nil {
  495. slog.Info("failed to get presence from state", "guild_id", gID, "user_id", m.User.ID, "err", err)
  496. } else if presence.Status == discord.OfflineStatus {
  497. style = style.Dim(true)
  498. }
  499. mi.mentionsList.append(mentionsListItem{
  500. insertText: name,
  501. displayText: name,
  502. style: style,
  503. })
  504. return mi.mentionsList.itemCount() > int(mi.cfg.AutocompleteLimit)
  505. }
  506. func (mi *messageInput) addMentionUser(user *discord.User) {
  507. if user == nil {
  508. return
  509. }
  510. name := user.DisplayOrUsername()
  511. style := tcell.StyleDefault
  512. presence, err := mi.chatView.state.Cabinet.Presence(discord.NullGuildID, user.ID)
  513. if err != nil {
  514. slog.Info("failed to get presence from state", "user_id", user.ID, "err", err)
  515. } else if presence.Status == discord.OfflineStatus {
  516. style = style.Dim(true)
  517. }
  518. mi.mentionsList.append(mentionsListItem{
  519. insertText: name,
  520. displayText: name,
  521. style: style,
  522. })
  523. }
  524. // used by chatView
  525. func (mi *messageInput) removeMentionsList() {
  526. mi.chatView.
  527. RemoveLayer(mentionsListLayerName)
  528. }
  529. func (mi *messageInput) stopTabCompletion() {
  530. if mi.cfg.AutocompleteLimit > 0 {
  531. mi.mentionsList.clear()
  532. mi.removeMentionsList()
  533. mi.chatView.app.SetFocus(mi)
  534. }
  535. }
  536. func (mi *messageInput) editor() {
  537. file, err := os.CreateTemp("", tmpFilePattern)
  538. if err != nil {
  539. slog.Error("failed to create tmp file", "err", err)
  540. return
  541. }
  542. defer file.Close()
  543. defer os.Remove(file.Name())
  544. file.WriteString(mi.GetText())
  545. if mi.cfg.Editor == "" {
  546. slog.Warn("Attempt to open file with editor, but no editor is set")
  547. return
  548. }
  549. cmd := mi.cfg.CreateEditorCommand(file.Name())
  550. if cmd == nil {
  551. return
  552. }
  553. cmd.Stdin = os.Stdin
  554. cmd.Stdout = os.Stdout
  555. cmd.Stderr = os.Stderr
  556. mi.chatView.app.Suspend(func() {
  557. err := cmd.Run()
  558. if err != nil {
  559. slog.Error("failed to run command", "args", cmd.Args, "err", err)
  560. return
  561. }
  562. })
  563. msg, err := os.ReadFile(file.Name())
  564. if err != nil {
  565. slog.Error("failed to read tmp file", "name", file.Name(), "err", err)
  566. return
  567. }
  568. mi.SetText(strings.TrimSpace(string(msg)), true)
  569. }
  570. func (mi *messageInput) openFilePicker() {
  571. if mi.chatView.SelectedChannel() == nil {
  572. return
  573. }
  574. paths, err := zenity.SelectFileMultiple()
  575. if err != nil {
  576. slog.Error("failed to open file dialog", "err", err)
  577. return
  578. }
  579. for _, path := range paths {
  580. file, err := os.Open(path)
  581. if err != nil {
  582. slog.Error("failed to open file", "path", path, "err", err)
  583. continue
  584. }
  585. name := filepath.Base(path)
  586. mi.attach(name, file)
  587. }
  588. }
  589. func (mi *messageInput) attach(name string, reader io.Reader) {
  590. mi.sendMessageData.Files = append(mi.sendMessageData.Files, sendpart.File{Name: name, Reader: reader})
  591. var names []string
  592. for _, file := range mi.sendMessageData.Files {
  593. names = append(names, file.Name)
  594. }
  595. mi.SetFooter("Attached " + humanJoin(names))
  596. }