refactor/feat: move IRCMessage to irc package; handle NOTICE commands

This commit is contained in:
2025-08-13 13:05:15 +02:00
parent 6c2e54275c
commit 7e2f446671
3 changed files with 101 additions and 73 deletions
+24
View File
@@ -30,6 +30,16 @@ import (
"github.com/illusionman1212/gorc/ui"
)
type Message struct {
Timestamp string
Tags MessageTags // starts with @ | Optional
Source string // starts with : | Optional
Command string // can either be a string or a numeric value | Required
Parameters []string // Optional (Dependant on command)
}
type MessageTags map[string]string
type User struct {
// User prefix in channel
Prefix string
@@ -103,6 +113,20 @@ var dateStyle = lipgloss.NewStyle().Foreground(ui.DateColor)
const CRLF = "\r\n"
func (m *Message) SetTimestamp() {
if serverTime, ok := m.Tags["time"]; ok {
t, err := time.Parse("2006-01-02T15:04:05.000Z", serverTime)
if err != nil {
// TODO: properly handle error
log.Fatalln(err)
}
m.Timestamp = fmt.Sprintf("[%02d:%02d]", t.Local().Hour(), t.Local().Minute())
} else {
now := time.Now()
m.Timestamp = fmt.Sprintf("[%02d:%02d]", now.Hour(), now.Minute())
}
}
func (c *Channel) AppendMsg(timestamp string, fullMsg string, opts MsgFmtOpts) {
prefixes := ""
style := ui.DefaultStyle