mirror of https://github.com/fluffle/goirc
Tidy up old-style slice syntax, and use string methods for CTCP parsing.
This commit is contained in:
parent
65ae4394fc
commit
d2cfe6eb6f
|
@ -43,10 +43,10 @@ func (conn *Conn) dispatchEvent(line *Line) {
|
||||||
// handlers to cope with the possibilities.
|
// handlers to cope with the possibilities.
|
||||||
if line.Cmd == "PRIVMSG" &&
|
if line.Cmd == "PRIVMSG" &&
|
||||||
len(line.Args[1]) > 2 &&
|
len(line.Args[1]) > 2 &&
|
||||||
line.Args[1][0] == '\001' &&
|
strings.HasPrefix(line.Args[1], "\001") &&
|
||||||
line.Args[1][len(line.Args[1])-1] == '\001' {
|
strings.HasSuffix(line.Args[1], "\001") {
|
||||||
// WOO, it's a CTCP message
|
// WOO, it's a CTCP message
|
||||||
t := strings.SplitN(line.Args[1][1:len(line.Args[1])-1], " ", 2)
|
t := strings.SplitN(strings.Trim(line.Args[1], "\001"), " ", 2)
|
||||||
if len(t) > 1 {
|
if len(t) > 1 {
|
||||||
// Replace the line with the unwrapped CTCP
|
// Replace the line with the unwrapped CTCP
|
||||||
line.Args[1] = t[1]
|
line.Args[1] = t[1]
|
||||||
|
@ -197,7 +197,7 @@ func (conn *Conn) h_QUIT(line *Line) {
|
||||||
func (conn *Conn) h_MODE(line *Line) {
|
func (conn *Conn) h_MODE(line *Line) {
|
||||||
// channel modes first
|
// channel modes first
|
||||||
if ch := conn.GetChannel(line.Args[0]); ch != nil {
|
if ch := conn.GetChannel(line.Args[0]); ch != nil {
|
||||||
conn.ParseChannelModes(ch, line.Args[1], line.Args[2:len(line.Args)])
|
conn.ParseChannelModes(ch, line.Args[1], line.Args[2:])
|
||||||
} else if n := conn.GetNick(line.Args[0]); n != nil {
|
} else if n := conn.GetNick(line.Args[0]); n != nil {
|
||||||
// nick mode change, should be us
|
// nick mode change, should be us
|
||||||
if n != conn.Me {
|
if n != conn.Me {
|
||||||
|
@ -232,9 +232,8 @@ func (conn *Conn) h_311(line *Line) {
|
||||||
|
|
||||||
// Handle 324 mode reply
|
// Handle 324 mode reply
|
||||||
func (conn *Conn) h_324(line *Line) {
|
func (conn *Conn) h_324(line *Line) {
|
||||||
// XXX: copypasta from MODE, needs tidying.
|
|
||||||
if ch := conn.GetChannel(line.Args[1]); ch != nil {
|
if ch := conn.GetChannel(line.Args[1]); ch != nil {
|
||||||
conn.ParseChannelModes(ch, line.Args[2], line.Args[3:len(line.Args)])
|
conn.ParseChannelModes(ch, line.Args[2], line.Args[3:])
|
||||||
} else {
|
} else {
|
||||||
conn.error("irc.324(): buh? received MODE settings for unknown channel %s", line.Args[1])
|
conn.error("irc.324(): buh? received MODE settings for unknown channel %s", line.Args[1])
|
||||||
}
|
}
|
||||||
|
@ -281,7 +280,7 @@ func (conn *Conn) h_353(line *Line) {
|
||||||
}
|
}
|
||||||
switch c := nick[0]; c {
|
switch c := nick[0]; c {
|
||||||
case '~', '&', '@', '%', '+':
|
case '~', '&', '@', '%', '+':
|
||||||
nick = nick[1:len(nick)]
|
nick = nick[1:]
|
||||||
fallthrough
|
fallthrough
|
||||||
default:
|
default:
|
||||||
n := conn.GetNick(nick)
|
n := conn.GetNick(nick)
|
||||||
|
|
|
@ -22,10 +22,10 @@ func parseLine(s string) *Line {
|
||||||
if s[0] == ':' {
|
if s[0] == ':' {
|
||||||
// remove a source and parse it
|
// remove a source and parse it
|
||||||
if idx := strings.Index(s, " "); idx != -1 {
|
if idx := strings.Index(s, " "); idx != -1 {
|
||||||
line.Src, s = s[1:idx], s[idx+1:len(s)]
|
line.Src, s = s[1:idx], s[idx+1:]
|
||||||
} else {
|
} else {
|
||||||
// pretty sure we shouldn't get here ...
|
// pretty sure we shouldn't get here ...
|
||||||
line.Src = s[1:len(s)]
|
line.Src = s[1:]
|
||||||
return line
|
return line
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,9 +33,9 @@ func parseLine(s string) *Line {
|
||||||
line.Host = line.Src
|
line.Host = line.Src
|
||||||
nidx, uidx := strings.Index(line.Src, "!"), strings.Index(line.Src, "@")
|
nidx, uidx := strings.Index(line.Src, "!"), strings.Index(line.Src, "@")
|
||||||
if uidx != -1 && nidx != -1 {
|
if uidx != -1 && nidx != -1 {
|
||||||
line.Nick = line.Src[0:nidx]
|
line.Nick = line.Src[:nidx]
|
||||||
line.Ident = line.Src[nidx+1 : uidx]
|
line.Ident = line.Src[nidx+1:uidx]
|
||||||
line.Host = line.Src[uidx+1 : len(line.Src)]
|
line.Host = line.Src[uidx+1:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ func parseLine(s string) *Line {
|
||||||
}
|
}
|
||||||
line.Cmd = strings.ToUpper(args[0])
|
line.Cmd = strings.ToUpper(args[0])
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
line.Args = args[1:len(args)]
|
line.Args = args[1:]
|
||||||
}
|
}
|
||||||
return line
|
return line
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,14 +127,14 @@ func (conn *Conn) ParseChannelModes(ch *Channel, modes string, modeargs []string
|
||||||
ch.Modes.OperOnly = modeop
|
ch.Modes.OperOnly = modeop
|
||||||
case 'k':
|
case 'k':
|
||||||
if len(modeargs) != 0 {
|
if len(modeargs) != 0 {
|
||||||
ch.Modes.Key, modeargs = modeargs[0], modeargs[1:len(modeargs)]
|
ch.Modes.Key, modeargs = modeargs[0], modeargs[1:]
|
||||||
} else {
|
} else {
|
||||||
conn.error("irc.ParseChanModes(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
|
conn.error("irc.ParseChanModes(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
|
||||||
}
|
}
|
||||||
case 'l':
|
case 'l':
|
||||||
if len(modeargs) != 0 {
|
if len(modeargs) != 0 {
|
||||||
ch.Modes.Limit, _ = strconv.Atoi(modeargs[0])
|
ch.Modes.Limit, _ = strconv.Atoi(modeargs[0])
|
||||||
modeargs = modeargs[1:len(modeargs)]
|
modeargs = modeargs[1:]
|
||||||
} else {
|
} else {
|
||||||
conn.error("irc.ParseChanModes(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
|
conn.error("irc.ParseChanModes(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m)
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@ func (conn *Conn) ParseChannelModes(ch *Channel, modes string, modeargs []string
|
||||||
case 'v':
|
case 'v':
|
||||||
p.Voice = modeop
|
p.Voice = modeop
|
||||||
}
|
}
|
||||||
modeargs = modeargs[1:len(modeargs)]
|
modeargs = modeargs[1:]
|
||||||
} else {
|
} else {
|
||||||
conn.error("irc.ParseChanModes(): MODE %s %s%s %s: buh? state tracking failure.", ch.Name, modestr, m, modeargs[0])
|
conn.error("irc.ParseChanModes(): MODE %s %s%s %s: buh? state tracking failure.", ch.Name, modestr, m, modeargs[0])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue