| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package util
- import (
- "fmt"
- "strings"
- "github.com/diamondburned/arikawa/v3/discord"
- "github.com/diamondburned/arikawa/v3/state"
- "github.com/rivo/tview"
- )
- func WriteMessage(v *tview.TextView, s *state.State, m discord.Message) {
- var b strings.Builder
- // $ ╭ AUTHOR_USERNAME (BOT) MESSAGE_CONTENT*linebreak*
- writeReferencedMessage(&b, s, m.ReferencedMessage)
- // $ AUTHOR_USERNAME (BOT)*spacee*
- writeAuthor(&b, s, m.Author)
- // $ MESSAGE_CONTENT
- writeContent(&b, m.Content)
- // $ *space*(edited)
- if m.EditedTimestamp.IsValid() {
- b.WriteString(" [::d](edited)[-:-:-]")
- }
- // $ *linebreak*EMBED
- writeEmbeds(&b, m.Embeds)
- // $ *linebreak*ATTACHMENT_URL
- writeAttachments(&b, m.Attachments)
- fmt.Fprintln(v, b.String())
- }
- func writeEmbeds(b *strings.Builder, embeds []discord.Embed) {
- for range embeds {
- b.WriteString("\n<EMBED>")
- }
- }
- func writeAttachments(b *strings.Builder, attachments []discord.Attachment) {
- for i := range attachments {
- a := attachments[i]
- b.WriteString("\n")
- b.WriteString("[")
- b.WriteString(a.Filename)
- b.WriteString("]: ")
- b.WriteString(a.URL)
- }
- }
- func writeAuthor(b *strings.Builder, s *state.State, u discord.User) {
- if s.Ready().User.ID == u.ID {
- b.WriteString("[#59E3E3]")
- } else {
- b.WriteString("[#E95678]")
- }
- b.WriteString(u.Username)
- b.WriteString("[-:-:-] ")
- if u.Bot {
- b.WriteString("[#59E3E3]BOT[-:-:-] ")
- }
- }
- func writeReferencedMessage(b *strings.Builder, s *state.State, rm *discord.Message) {
- if rm != nil {
- b.WriteRune(' ')
- b.WriteRune('\u256D')
- b.WriteRune(' ')
- if s.Ready().User.ID == rm.Author.ID {
- b.WriteString("[#59E3E3::d]")
- } else {
- b.WriteString("[#E95678::d]")
- }
- b.WriteString(rm.Author.Username)
- // Reset foreground
- b.WriteString("[-::] ")
- writeContent(b, rm.Content)
- b.WriteString("[-:-:-]\n")
- }
- }
- func writeContent(b *strings.Builder, c string) {
- if c != "" {
- c = tview.Escape(c)
- b.WriteString(c)
- }
- }
|