Parse NOTICE messages from logs

This commit is contained in:
Simon Ser 2020-08-17 13:55:22 +02:00
parent 0831dbe6f1
commit 3d8ed90055
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

View File

@ -144,26 +144,33 @@ func parseMessage(line, entity string, ref time.Time) (*irc.Message, time.Time,
} }
line = line[11:] line = line[11:]
// TODO: support NOTICE var cmd, suffix string
if !strings.HasPrefix(line, "<") { if strings.HasPrefix(line, "<") {
cmd = "PRIVMSG"
suffix = "> "
} else if strings.HasPrefix(line, "-") {
cmd = "NOTICE"
suffix = "- "
} else {
return nil, time.Time{}, nil return nil, time.Time{}, nil
} }
i := strings.Index(line, "> ")
i := strings.Index(line, suffix)
if i < 0 { if i < 0 {
return nil, time.Time{}, nil return nil, time.Time{}, nil
} }
sender := line[1:i]
text := line[i+2:]
year, month, day := ref.Date() year, month, day := ref.Date()
t := time.Date(year, month, day, hour, minute, second, 0, time.Local) t := time.Date(year, month, day, hour, minute, second, 0, time.Local)
sender := line[1:i]
text := line[i+2:]
msg := &irc.Message{ msg := &irc.Message{
Tags: map[string]irc.TagValue{ Tags: map[string]irc.TagValue{
"time": irc.TagValue(t.UTC().Format(serverTimeLayout)), "time": irc.TagValue(t.UTC().Format(serverTimeLayout)),
}, },
Prefix: &irc.Prefix{Name: sender}, Prefix: &irc.Prefix{Name: sender},
Command: "PRIVMSG", Command: cmd,
Params: []string{entity, text}, Params: []string{entity, text},
} }
return msg, t, nil return msg, t, nil