|
@@ -2,16 +2,21 @@ package main
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "strings"
|
|
|
|
|
|
|
+ "sync"
|
|
|
|
|
+ "text/template"
|
|
|
|
|
|
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
"github.com/diamondburned/arikawa/v3/discord"
|
|
|
"github.com/rivo/tview"
|
|
"github.com/rivo/tview"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+var p = sync.Pool{
|
|
|
|
|
+ New: func() any {
|
|
|
|
|
+ return new(template.Template)
|
|
|
|
|
+ },
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
type MessagesText struct {
|
|
type MessagesText struct {
|
|
|
*tview.TextView
|
|
*tview.TextView
|
|
|
-
|
|
|
|
|
- builder strings.Builder
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func newMessagesText() *MessagesText {
|
|
func newMessagesText() *MessagesText {
|
|
@@ -28,18 +33,26 @@ func newMessagesText() *MessagesText {
|
|
|
return mt
|
|
return mt
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (mt *MessagesText) newMessage(m *discord.Message) {
|
|
|
|
|
|
|
+func (mt *MessagesText) newMessage(m *discord.Message) error {
|
|
|
switch m.Type {
|
|
switch m.Type {
|
|
|
case discord.DefaultMessage:
|
|
case discord.DefaultMessage:
|
|
|
- {
|
|
|
|
|
- mt.builder.WriteString("[blue::b]")
|
|
|
|
|
- mt.builder.WriteString(m.Author.Username)
|
|
|
|
|
- mt.builder.WriteString("[-:-:-]")
|
|
|
|
|
|
|
+ // Region tags are square brackets that contain a region ID in double quotes
|
|
|
|
|
+ // https://pkg.go.dev/github.com/rivo/tview#hdr-Regions_and_Highlights
|
|
|
|
|
+ fmt.Fprintf(mt, `["%s"]`, m.ID)
|
|
|
|
|
+
|
|
|
|
|
+ if m.ReferencedMessage != nil {
|
|
|
|
|
+ fmt.Fprintf(mt, "[blue::bd]%s[-:-:-] [::-]", m.ReferencedMessage.Author.Username)
|
|
|
|
|
+ fmt.Fprint(mt, m.ReferencedMessage.Content)
|
|
|
|
|
+ fmt.Fprintln(mt)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- mt.builder.WriteByte('\n')
|
|
|
|
|
- mt.builder.WriteByte('\n')
|
|
|
|
|
|
|
+ fmt.Fprintf(mt, "[blue::b]%s[-:-:-] ", m.Author.Username)
|
|
|
|
|
+ fmt.Fprint(mt, m.Content)
|
|
|
|
|
+ // Tags with no region ID ([""]) don't start new regions. They can therefore be used to mark the end of a region.
|
|
|
|
|
+ fmt.Fprint(mt, `[""]`)
|
|
|
|
|
+
|
|
|
|
|
+ fmt.Fprintln(mt)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- fmt.Fprintln(mt, mt.builder.String())
|
|
|
|
|
|
|
+ return nil
|
|
|
}
|
|
}
|