discord.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package util
  2. import (
  3. "fmt"
  4. _ "image/jpeg"
  5. _ "image/png"
  6. "strings"
  7. "github.com/bwmarrin/discordgo"
  8. "github.com/rivo/tview"
  9. )
  10. func WriteMessage(messagesTextView *tview.TextView, session *discordgo.Session, message *discordgo.Message) {
  11. var content strings.Builder
  12. if session.State.User.ID == message.Author.ID {
  13. content.WriteString("[#ffb86c::b]")
  14. content.WriteString(message.Author.Username)
  15. content.WriteString("[-:-:-] ")
  16. } else {
  17. content.WriteString("[#ff5555::b]")
  18. content.WriteString(message.Author.Username)
  19. content.WriteString("[-:-:-] ")
  20. }
  21. // If the author of the message is a bot account, add "BOT" beside the username of the author.
  22. if message.Author.Bot {
  23. content.WriteString("[#bd93f9]BOT[-:-:-] ")
  24. }
  25. if message.Content != "" {
  26. content.WriteString(message.Content)
  27. }
  28. if message.EditedTimestamp != "" {
  29. content.WriteString(" [::d](edited)[-:-:-]")
  30. }
  31. // TODO(rigormorrtiss): display the message embed using "special" format
  32. if len(message.Embeds) > 0 {
  33. content.WriteString("\n<EMBED>")
  34. }
  35. attachments := message.Attachments
  36. for i := range attachments {
  37. content.WriteString("\n")
  38. content.WriteString(attachments[i].URL)
  39. }
  40. fmt.Fprintln(messagesTextView, content.String())
  41. }