discord.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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("[#50fa7b::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. // TODO(rigormorrtiss): display the message embed using "special" format
  29. if len(message.Embeds) > 0 {
  30. content.WriteString("\n<EMBED>")
  31. }
  32. attachments := message.Attachments
  33. for i := range attachments {
  34. content.WriteString("\n")
  35. content.WriteString(attachments[i].URL)
  36. }
  37. fmt.Fprintln(messagesTextView, content.String())
  38. }