commit db8c030

delthas  ·  2023-11-13 12:46:49 +0000 UTC
parent 2df2295
Pretty-print channel mode messages
1 files changed,  +32, -2
M app.go
M app.go
+32, -2
 1@@ -7,6 +7,7 @@ import (
 2 	"net"
 3 	"os"
 4 	"os/exec"
 5+	"strconv"
 6 	"strings"
 7 	"sync"
 8 	"time"
 9@@ -1062,13 +1063,42 @@ func (app *App) handleIRCEvent(netID string, ev interface{}) {
10 		if isBlackListed(msg.Command) {
11 			break
12 		}
13-		if ev.Code == "372" {
14+		switch ev.Code {
15+		case "372":
16 			app.win.AddLine(netID, "", ui.Line{
17 				At:   msg.TimeOrNow(),
18 				Head: "MOTD --",
19 				Body: ui.PlainString(ev.Message),
20 			})
21-			break
22+			return
23+		case "324":
24+			channel, line, ok := strings.Cut(ev.Message, " ")
25+			if ok {
26+				text := fmt.Sprintf("%s has modes %s", channel, line)
27+				app.win.AddLine(netID, channel, ui.Line{
28+					At:        time.Now(),
29+					Head:      "--",
30+					HeadColor: app.cfg.Colors.Status,
31+					Body:      ui.Styled(text, tcell.StyleDefault.Foreground(app.cfg.Colors.Status)),
32+				})
33+				return
34+			}
35+		case "329":
36+			channel, line, ok := strings.Cut(ev.Message, " ")
37+			if ok {
38+				creation, err := strconv.ParseInt(line, 10, 64)
39+				if err == nil {
40+					t := time.Unix(creation, 0)
41+					text := fmt.Sprintf("%s was created on %s", channel, t.Local().Format("January 2, 2006"))
42+					app.win.AddLine(netID, channel, ui.Line{
43+						At:        time.Now(),
44+						Head:      "--",
45+						HeadColor: app.cfg.Colors.Status,
46+						Body:      ui.Styled(text, tcell.StyleDefault.Foreground(app.cfg.Colors.Status)),
47+					})
48+					return
49+				}
50+			}
51 		}
52 		var head string
53 		var body string