-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.go
More file actions
40 lines (33 loc) · 796 Bytes
/
command.go
File metadata and controls
40 lines (33 loc) · 796 Bytes
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
package main
import (
"container/list"
"strings"
)
type callback func(*IRCEvent)
func (irc *IRC) AddCallback(key string, value callback) {
l, ok := irc.Callbacks[key]
if !ok || l == nil {
l = list.New()
irc.Callbacks[key] = l
}
l.PushBack(value)
}
func (irc *IRC) addcallbacks() {
if irc.Callbacks == nil {
irc.Callbacks = make(map[string]*list.List)
}
// Ping
irc.AddCallback("PING", func(e *IRCEvent) {
irc.SendRaw("Pong :%s" + strings.Join(e.Args, " "))
})
irc.AddCallback("PRIVMSG", func(e *IRCEvent) {
irc.Privmsg(e.Args[0], strings.Join(e.Args[1:], " "))
})
}
func (irc *IRC) runcallback(e *IRCEvent) {
if l, ok := irc.Callbacks[e.Command]; ok {
for v := l.Front(); v != nil; v = v.Next() {
v.Value.(callback)(e)
}
}
}