diff --git a/client/handlers.go b/client/handlers.go index adb9298..08f786c 100644 --- a/client/handlers.go +++ b/client/handlers.go @@ -43,10 +43,10 @@ func (conn *Conn) dispatchEvent(line *Line) { // handlers to cope with the possibilities. if line.Cmd == "PRIVMSG" && len(line.Args[1]) > 2 && - line.Args[1][0] == '\001' && - line.Args[1][len(line.Args[1])-1] == '\001' { + strings.HasPrefix(line.Args[1], "\001") && + strings.HasSuffix(line.Args[1], "\001") { // 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 { // Replace the line with the unwrapped CTCP line.Args[1] = t[1] @@ -197,7 +197,7 @@ func (conn *Conn) h_QUIT(line *Line) { func (conn *Conn) h_MODE(line *Line) { // channel modes first 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 { // nick mode change, should be us if n != conn.Me { @@ -232,9 +232,8 @@ func (conn *Conn) h_311(line *Line) { // Handle 324 mode reply func (conn *Conn) h_324(line *Line) { - // XXX: copypasta from MODE, needs tidying. 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 { 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 { case '~', '&', '@', '%', '+': - nick = nick[1:len(nick)] + nick = nick[1:] fallthrough default: n := conn.GetNick(nick) diff --git a/client/line.go b/client/line.go index 07116a7..bb39ec4 100644 --- a/client/line.go +++ b/client/line.go @@ -22,10 +22,10 @@ func parseLine(s string) *Line { if s[0] == ':' { // remove a source and parse it 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 { // pretty sure we shouldn't get here ... - line.Src = s[1:len(s)] + line.Src = s[1:] return line } @@ -33,9 +33,9 @@ func parseLine(s string) *Line { line.Host = line.Src nidx, uidx := strings.Index(line.Src, "!"), strings.Index(line.Src, "@") if uidx != -1 && nidx != -1 { - line.Nick = line.Src[0:nidx] - line.Ident = line.Src[nidx+1 : uidx] - line.Host = line.Src[uidx+1 : len(line.Src)] + line.Nick = line.Src[:nidx] + line.Ident = line.Src[nidx+1:uidx] + line.Host = line.Src[uidx+1:] } } @@ -49,7 +49,7 @@ func parseLine(s string) *Line { } line.Cmd = strings.ToUpper(args[0]) if len(args) > 1 { - line.Args = args[1:len(args)] + line.Args = args[1:] } return line } diff --git a/client/nickchan.go b/client/nickchan.go index fdf79b1..f2e0fc2 100644 --- a/client/nickchan.go +++ b/client/nickchan.go @@ -127,14 +127,14 @@ func (conn *Conn) ParseChannelModes(ch *Channel, modes string, modeargs []string ch.Modes.OperOnly = modeop case 'k': if len(modeargs) != 0 { - ch.Modes.Key, modeargs = modeargs[0], modeargs[1:len(modeargs)] + ch.Modes.Key, modeargs = modeargs[0], modeargs[1:] } else { conn.error("irc.ParseChanModes(): buh? not enough arguments to process MODE %s %s%s", ch.Name, modestr, m) } case 'l': if len(modeargs) != 0 { ch.Modes.Limit, _ = strconv.Atoi(modeargs[0]) - modeargs = modeargs[1:len(modeargs)] + modeargs = modeargs[1:] } else { 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': p.Voice = modeop } - modeargs = modeargs[1:len(modeargs)] + modeargs = modeargs[1:] } else { conn.error("irc.ParseChanModes(): MODE %s %s%s %s: buh? state tracking failure.", ch.Name, modestr, m, modeargs[0]) }