Changeset 391 in code for trunk


Ignore:
Timestamp:
Aug 17, 2020, 11:55:22 AM (5 years ago)
Author:
contact
Message:

Parse NOTICE messages from logs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/logger.go

    r387 r391  
    145145        line = line[11:]
    146146
    147         // TODO: support NOTICE
    148         if !strings.HasPrefix(line, "<") {
     147        var cmd, suffix string
     148        if strings.HasPrefix(line, "<") {
     149                cmd = "PRIVMSG"
     150                suffix = "> "
     151        } else if strings.HasPrefix(line, "-") {
     152                cmd = "NOTICE"
     153                suffix = "- "
     154        } else {
    149155                return nil, time.Time{}, nil
    150156        }
    151         i := strings.Index(line, "> ")
     157
     158        i := strings.Index(line, suffix)
    152159        if i < 0 {
    153160                return nil, time.Time{}, nil
    154161        }
     162        sender := line[1:i]
     163        text := line[i+2:]
    155164
    156165        year, month, day := ref.Date()
    157166        t := time.Date(year, month, day, hour, minute, second, 0, time.Local)
    158167
    159         sender := line[1:i]
    160         text := line[i+2:]
    161168        msg := &irc.Message{
    162169                Tags: map[string]irc.TagValue{
     
    164171                },
    165172                Prefix:  &irc.Prefix{Name: sender},
    166                 Command: "PRIVMSG",
     173                Command: cmd,
    167174                Params:  []string{entity, text},
    168175        }
Note: See TracChangeset for help on using the changeset viewer.