mirror of https://github.com/fluffle/goirc
Move line parsing done in dispatchEvent into ParseLine().
This commit is contained in:
parent
5e814babc7
commit
33a5bff35b
|
@ -208,7 +208,9 @@ func (conn *Conn) runLoop() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case line := <-conn.in:
|
case line := <-conn.in:
|
||||||
|
if line != nil {
|
||||||
conn.dispatchEvent(line)
|
conn.dispatchEvent(line)
|
||||||
|
}
|
||||||
case <-conn.cLoop:
|
case <-conn.cLoop:
|
||||||
// strobe on control channel, bail out
|
// strobe on control channel, bail out
|
||||||
return
|
return
|
||||||
|
|
|
@ -30,36 +30,6 @@ func (conn *Conn) AddHandler(name string, f func(*Conn, *Line)) {
|
||||||
|
|
||||||
// loops through all event handlers for line.Cmd, running each in a goroutine
|
// loops through all event handlers for line.Cmd, running each in a goroutine
|
||||||
func (conn *Conn) dispatchEvent(line *Line) {
|
func (conn *Conn) dispatchEvent(line *Line) {
|
||||||
// seems that we end up dispatching an event with a nil line when receiving
|
|
||||||
// EOF from the server. Until i've tracked down why....
|
|
||||||
if line == nil {
|
|
||||||
conn.error("irc.dispatchEvent(): buh? line == nil :-(")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// So, I think CTCP and (in particular) CTCP ACTION are better handled as
|
|
||||||
// separate events as opposed to forcing people to have gargantuan PRIVMSG
|
|
||||||
// handlers to cope with the possibilities.
|
|
||||||
if line.Cmd == "PRIVMSG" &&
|
|
||||||
len(line.Args[1]) > 2 &&
|
|
||||||
strings.HasPrefix(line.Args[1], "\001") &&
|
|
||||||
strings.HasSuffix(line.Args[1], "\001") {
|
|
||||||
// WOO, it's a CTCP message
|
|
||||||
t := strings.Split(strings.Trim(line.Args[1], "\001"), " ", 2)
|
|
||||||
if len(t) > 1 {
|
|
||||||
// Replace the line with the unwrapped CTCP
|
|
||||||
line.Args[1] = t[1]
|
|
||||||
}
|
|
||||||
if c := strings.ToUpper(t[0]); c == "ACTION" {
|
|
||||||
// make a CTCP ACTION it's own event a-la PRIVMSG
|
|
||||||
line.Cmd = c
|
|
||||||
} else {
|
|
||||||
// otherwise, dispatch a generic CTCP event that
|
|
||||||
// contains the type of CTCP in line.Args[0]
|
|
||||||
line.Cmd = "CTCP"
|
|
||||||
line.Args = append([]string{c}, line.Args...)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
conn.Registry.Dispatch(line.Cmd, conn, line)
|
conn.Registry.Dispatch(line.Cmd, conn, line)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,30 @@ func parseLine(s string) *Line {
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
line.Args = args[1:]
|
line.Args = args[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// So, I think CTCP and (in particular) CTCP ACTION are better handled as
|
||||||
|
// separate events as opposed to forcing people to have gargantuan PRIVMSG
|
||||||
|
// handlers to cope with the possibilities.
|
||||||
|
if line.Cmd == "PRIVMSG" &&
|
||||||
|
len(line.Args[1]) > 2 &&
|
||||||
|
strings.HasPrefix(line.Args[1], "\001") &&
|
||||||
|
strings.HasSuffix(line.Args[1], "\001") {
|
||||||
|
// WOO, it's a CTCP message
|
||||||
|
t := strings.Split(strings.Trim(line.Args[1], "\001"), " ", 2)
|
||||||
|
if len(t) > 1 {
|
||||||
|
// Replace the line with the unwrapped CTCP
|
||||||
|
line.Args[1] = t[1]
|
||||||
|
}
|
||||||
|
if c := strings.ToUpper(t[0]); c == "ACTION" {
|
||||||
|
// make a CTCP ACTION it's own event a-la PRIVMSG
|
||||||
|
line.Cmd = c
|
||||||
|
} else {
|
||||||
|
// otherwise, dispatch a generic CTCP event that
|
||||||
|
// contains the type of CTCP in line.Args[0]
|
||||||
|
line.Cmd = "CTCP"
|
||||||
|
line.Args = append([]string{c}, line.Args...)
|
||||||
|
}
|
||||||
|
}
|
||||||
return line
|
return line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue