commit f27f70d
Hubert Hirtz
·
2020-08-01 16:28:28 +0000 UTC
parent f6ed228
Show incoming NOTICEs
3 files changed,
+42,
-7
+36,
-5
1@@ -82,9 +82,17 @@ func handleIRCEvent(app *ui.UI, ev irc.Event) {
2 line := fmt.Sprintf("\x034-\x0314%s", ev.Nick)
3 app.AddLine(ev.Channel, line, ev.Time, true)
4 case irc.QueryMessageEvent:
5- line := formatIRCMessage(ev.Nick, ev.Content)
6- app.AddLine("home", line, ev.Time, false)
7- app.TypingStop("home", ev.Nick)
8+ if ev.Command == "PRIVMSG" {
9+ line := formatIRCMessage(ev.Nick, ev.Content)
10+ app.AddLine("home", line, ev.Time, false)
11+ app.TypingStop("home", ev.Nick)
12+ } else if ev.Command == "NOTICE" {
13+ line := formatIRCNotice(ev.Nick, ev.Content)
14+ app.AddLine(app.CurrentBuffer(), line, ev.Time, false)
15+ app.TypingStop(app.CurrentBuffer(), ev.Nick)
16+ } else {
17+ panic("unknown command")
18+ }
19 case irc.ChannelMessageEvent:
20 line := formatIRCMessage(ev.Nick, ev.Content)
21 app.AddLine(ev.Channel, line, ev.Time, false)
22@@ -270,7 +278,7 @@ func formatIRCMessage(nick, content string) (line string) {
23 c := color(nick)
24
25 if content == "" {
26- line = fmt.Sprintf("%s%s\x00:", string(c[:]), nick)
27+ line = fmt.Sprintf("%s%s\x00:", c, nick)
28 return
29 }
30
31@@ -286,7 +294,30 @@ func formatIRCMessage(nick, content string) (line string) {
32 return
33 }
34
35- line = fmt.Sprintf("%s%s\x00: %s", string(c[:]), nick, content)
36+ line = fmt.Sprintf("%s%s\x00: %s", c, nick, content)
37+
38+ return
39+}
40+
41+func formatIRCNotice(nick, content string) (line string) {
42+ c := color(nick)
43+
44+ if content == "" {
45+ line = fmt.Sprintf("(%s%s\x00: )", c, nick)
46+ return
47+ }
48+
49+ if content[0] == 1 {
50+ content = strings.TrimSuffix(content[1:], "\x01")
51+
52+ if strings.HasPrefix(content, "ACTION") {
53+ line = fmt.Sprintf("(%s%s\x00%s)", c, nick, content[6:])
54+ } else {
55+ line = fmt.Sprintf("(\x1dCTCP request from\x1d %s%s\x00: %s)", c, nick, content)
56+ }
57+ } else {
58+ line = fmt.Sprintf("(%s%s\x00: %s)", c, nick, content)
59+ }
60
61 return
62 }
+2,
-0
1@@ -51,6 +51,7 @@ type SelfJoinEvent struct {
2
3 type QueryMessageEvent struct {
4 UserEvent
5+ Command string
6 Content string
7 Time time.Time
8 }
9@@ -58,6 +59,7 @@ type QueryMessageEvent struct {
10 type ChannelMessageEvent struct {
11 UserEvent
12 ChannelEvent
13+ Command string
14 Content string
15 Time time.Time
16 }
+4,
-2
1@@ -661,7 +661,7 @@ func (s *Session) handle(msg Message) (err error) {
2 if c, ok := s.channels[channel]; ok {
3 c.Topic = msg.Params[2]
4 }
5- case "PRIVMSG":
6+ case "PRIVMSG", "NOTICE":
7 s.evts <- s.privmsgToEvent(msg)
8 case "TAGMSG":
9 nick, _, _ := FullMask(msg.Prefix)
10@@ -753,10 +753,11 @@ func (s *Session) privmsgToEvent(msg Message) (ev Event) {
11 t = time.Now()
12 }
13
14- if target == s.lNick {
15+ if !s.IsChannel(target) {
16 // PRIVMSG to self
17 ev = QueryMessageEvent{
18 UserEvent: UserEvent{Nick: nick},
19+ Command: msg.Command,
20 Content: msg.Params[1],
21 Time: t,
22 }
23@@ -765,6 +766,7 @@ func (s *Session) privmsgToEvent(msg Message) (ev Event) {
24 ev = ChannelMessageEvent{
25 UserEvent: UserEvent{Nick: nick},
26 ChannelEvent: ChannelEvent{Channel: msg.Params[0]},
27+ Command: msg.Command,
28 Content: msg.Params[1],
29 Time: t,
30 }