discord.go 1.3 KB

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