feat(util): parse referenced messages (#19)
This commit is contained in:
parent
51d19f57b7
commit
3df9adabb3
1 changed files with 39 additions and 16 deletions
|
|
@ -12,19 +12,10 @@ import (
|
|||
func WriteMessage(v *tview.TextView, s *state.State, m discord.Message) {
|
||||
var b strings.Builder
|
||||
|
||||
if s.Ready().User.ID == m.Author.ID {
|
||||
b.WriteString("[#ffb86c::b]")
|
||||
b.WriteString(m.Author.Username)
|
||||
b.WriteString("[-:-:-] ")
|
||||
} else {
|
||||
b.WriteString("[#ff5555::b]")
|
||||
b.WriteString(m.Author.Username)
|
||||
b.WriteString("[-:-:-] ")
|
||||
}
|
||||
|
||||
if m.Author.Bot {
|
||||
b.WriteString("[#bd93f9]BOT[-:-:-] ")
|
||||
}
|
||||
// > AUTHOR_USERNAME MESSAGE_CONTENT
|
||||
writeReferencedMessage(&b, m.ReferencedMessage)
|
||||
// AUTHOR_USERNAME MESSAGE_CONTENT
|
||||
writeAuthor(&b, s, m.Author)
|
||||
|
||||
if m.Content != "" {
|
||||
b.WriteString(m.Content)
|
||||
|
|
@ -39,11 +30,43 @@ func WriteMessage(v *tview.TextView, s *state.State, m discord.Message) {
|
|||
b.WriteString("\n<EMBED(S)>")
|
||||
}
|
||||
|
||||
attachments := m.Attachments
|
||||
writeAttachments(&b, m.Attachments)
|
||||
|
||||
fmt.Fprintln(v, b.String())
|
||||
}
|
||||
|
||||
func writeAttachments(b *strings.Builder, attachments []discord.Attachment) {
|
||||
for i := range attachments {
|
||||
b.WriteString("\n")
|
||||
b.WriteString(attachments[i].URL)
|
||||
}
|
||||
|
||||
fmt.Fprintln(v, b.String())
|
||||
}
|
||||
|
||||
func writeAuthor(b *strings.Builder, s *state.State, u discord.User) {
|
||||
if s.Ready().User.ID == u.ID {
|
||||
b.WriteString("[#ffb86c::b]")
|
||||
b.WriteString(u.Username)
|
||||
} else {
|
||||
b.WriteString("[#ff5555::b]")
|
||||
b.WriteString(u.Username)
|
||||
}
|
||||
|
||||
b.WriteString("[-:-:-] ")
|
||||
|
||||
if u.Bot {
|
||||
b.WriteString("[#bd93f9]BOT[-:-:-] ")
|
||||
}
|
||||
}
|
||||
|
||||
func writeReferencedMessage(b *strings.Builder, rm *discord.Message) {
|
||||
if rm != nil {
|
||||
b.WriteRune('\u256D')
|
||||
b.WriteString(" [#ff5555::d]")
|
||||
b.WriteString(rm.Author.Username)
|
||||
b.WriteString("[-:-:] ")
|
||||
|
||||
b.WriteString(rm.Content)
|
||||
b.WriteString("\n")
|
||||
b.WriteString("[-:-:-]")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue