Line parsing needs to handle CTCPREPLY too.

This commit is contained in:
Alex Bramley 2011-08-22 23:21:30 +01:00
parent 5c347008fb
commit 48ad9bfa4a
1 changed files with 9 additions and 5 deletions

View File

@ -61,9 +61,9 @@ func parseLine(s string) *Line {
} }
// So, I think CTCP and (in particular) CTCP ACTION are better handled as // So, I think CTCP and (in particular) CTCP ACTION are better handled as
// separate events as opposed to forcing people to have gargantuan PRIVMSG // separate events as opposed to forcing people to have gargantuan
// handlers to cope with the possibilities. // handlers to cope with the possibilities.
if line.Cmd == "PRIVMSG" && if (line.Cmd == "PRIVMSG" || line.Cmd == "NOTICE") &&
len(line.Args[1]) > 2 && len(line.Args[1]) > 2 &&
strings.HasPrefix(line.Args[1], "\001") && strings.HasPrefix(line.Args[1], "\001") &&
strings.HasSuffix(line.Args[1], "\001") { strings.HasSuffix(line.Args[1], "\001") {
@ -73,13 +73,17 @@ func parseLine(s string) *Line {
// Replace the line with the unwrapped CTCP // Replace the line with the unwrapped CTCP
line.Args[1] = t[1] line.Args[1] = t[1]
} }
if c := strings.ToUpper(t[0]); c == "ACTION" { if c := strings.ToUpper(t[0]); c == "ACTION" && line.Cmd == "PRIVMSG" {
// make a CTCP ACTION it's own event a-la PRIVMSG // make a CTCP ACTION it's own event a-la PRIVMSG
line.Cmd = c line.Cmd = c
} else { } else {
// otherwise, dispatch a generic CTCP event that // otherwise, dispatch a generic CTCP/CTCPREPLY event that
// contains the type of CTCP in line.Args[0] // contains the type of CTCP in line.Args[0]
if line.Cmd == "PRIVMSG" {
line.Cmd = "CTCP" line.Cmd = "CTCP"
} else {
line.Cmd = "CTCPREPLY"
}
line.Args = append([]string{c}, line.Args...) line.Args = append([]string{c}, line.Args...)
} }
} }