replaced some numeric handling
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b86c11aee1
commit
a89349d1e3
8
irc.go
8
irc.go
@ -225,10 +225,10 @@ func (c *Connection) parseMessage(line string) {
|
|||||||
cmd := params[1]
|
cmd := params[1]
|
||||||
args := params[2]
|
args := params[2]
|
||||||
|
|
||||||
if _, e := strconv.Atoi(cmd); e == nil {
|
if code, e := strconv.Atoi(cmd); e == nil {
|
||||||
//numeric message
|
//numeric message
|
||||||
if !c.joined {
|
if !c.joined {
|
||||||
if cmd == "376" {
|
if code == RPL_ENDOFMOTD {
|
||||||
for _, v := range c.channels {
|
for _, v := range c.channels {
|
||||||
c.SendJoin(v)
|
c.SendJoin(v)
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ func (c *Connection) parseMessage(line string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cmd == "353" {
|
if code == RPL_NAMREPLY {
|
||||||
params := strings.SplitN(args, " ", 4)
|
params := strings.SplitN(args, " ", 4)
|
||||||
target := strings.TrimSpace(params[2])
|
target := strings.TrimSpace(params[2])
|
||||||
c.updateNicks(target, strings.Split(params[3][1:], " "))
|
c.updateNicks(target, strings.Split(params[3][1:], " "))
|
||||||
@ -289,7 +289,7 @@ func (c *Connection) parseMessage(line string) {
|
|||||||
c.NickCallback(from, msg)
|
c.NickCallback(from, msg)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
log.Printf("unhandled command: %s %s %s", cmd, target, msg)
|
//log.Printf("unhandled command: %s %s %s", cmd, target, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,4 +2,8 @@ package irc
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
RPL_LUSERCLIENT = 251
|
RPL_LUSERCLIENT = 251
|
||||||
|
RPL_NAMREPLY = 353
|
||||||
|
RPL_ENDOFMOTD = 376
|
||||||
|
|
||||||
|
ERR_NOSUCHNICK = 401
|
||||||
)
|
)
|
||||||
|
12
irc_test.go
12
irc_test.go
@ -1,7 +1,9 @@
|
|||||||
package irc
|
package irc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -39,6 +41,16 @@ func TestLusers(t *testing.T) {
|
|||||||
con.NumericCallback = func(from string, i int, args string) {
|
con.NumericCallback = func(from string, i int, args string) {
|
||||||
if i == RPL_LUSERCLIENT {
|
if i == RPL_LUSERCLIENT {
|
||||||
log.Printf("luser reply: %s\n", args)
|
log.Printf("luser reply: %s\n", args)
|
||||||
|
con.SendJoin(channel)
|
||||||
|
|
||||||
|
s := strings.Split(args, ":")
|
||||||
|
if len(s) > 1 {
|
||||||
|
users := 0
|
||||||
|
invis := 0
|
||||||
|
servers := 0
|
||||||
|
fmt.Sscanf(s[1], "There are %d users and %d invisible on %d servers", &users, &invis, &servers)
|
||||||
|
con.SendPrivmsg(channel, fmt.Sprintf("total users on network: %d, invisible %d, servers %d", users, invis, servers))
|
||||||
|
}
|
||||||
con.SendQuit("scan complete")
|
con.SendQuit("scan complete")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user