-
Notifications
You must be signed in to change notification settings - Fork 0
/
irc.go
41 lines (35 loc) · 969 Bytes
/
irc.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
package irc
import (
"fmt"
"github.com/agaffney/gwebirc/core"
"github.com/agaffney/gwebirc/types"
)
type IrcManager struct {
Conf *core.Config
Conns []*Connection
Events chan *types.Event
}
func (im *IrcManager) Start() {
// Initialize some things
im.Events = make(chan *types.Event, 100)
// Start the configured IRC connections
for _, conn := range im.Conf.Connections {
i := &Connection{Name: conn.Name, Host: conn.Host, Port: conn.Port, Tls: conn.Tls, manager: im}
im.Conns = append(im.Conns, i)
i.Init()
// Add our handlers
i.Add_handler("PRIVMSG", handle_msg)
i.Add_handler("NOTICE", handle_msg)
i.Add_handler("366", handle_366) // 366 means end of NAMES list
go i.Start()
}
}
func handle_366(c *Connection, cmd *types.Event) {
channel := cmd.Args[1]
fmt.Printf("Names list for %s:\n", channel)
for _, name := range c.Get_channel(channel).Names {
fmt.Println(name)
}
}
func handle_msg(c *Connection, cmd *types.Event) {
}