-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
49 lines (44 loc) · 1012 Bytes
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package gobot
import (
"log"
"strconv"
)
// RFC 2812
const (
RPL_ENDOFMOTD = 376
ERR_NOMOTD = 422
)
type Client struct {
bot *Bot
}
func NewClient(bot *Bot) *Client {
return &Client{bot}
}
func (self *Client) Process(msg *Message, quit chan bool) {
log.Printf("<-- %v\n", msg)
c, err := strconv.Atoi(msg.Command)
if err == nil {
switch c {
case ERR_NOMOTD, RPL_ENDOFMOTD:
self.bot.Join(self.bot.Channel)
}
} else {
switch msg.Command {
case "PING":
self.bot.Pong(msg.Args(2))
case "KICK":
log.Printf("*** %s is leaving %s\n", msg.Args(1), msg.Where())
quit <- true
case "PRIVMSG":
log.Printf("*** Heard %s say \"%s\" in %s\n", msg.Prefix, msg.Content(), msg.Where())
self.bot.Handle(msg)
case "QUIT":
log.Printf("*** %s quit.\n", msg.Prefix)
case "PART":
log.Printf("*** %s left %s.\n", msg.Prefix, msg.Where())
default:
// TODO most stuff isn't implemented yet, so just ignore.
log.Printf("*** Unhandled Command: %s.\n", msg.Command)
}
}
}