-
Notifications
You must be signed in to change notification settings - Fork 6
/
client.go
47 lines (38 loc) · 1015 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
package main
import "crypto/tls"
import "log"
import irc "github.com/fluffle/goirc/client"
var channelName string
func connect(
config configuration,
channelNick string,
callback func(conn *irc.Conn, line *irc.Line),
) {
cfg := irc.NewConfig(channelNick)
cfg.SSL = config.SSL
cfg.SSLConfig = &tls.Config{InsecureSkipVerify: config.SSLInsecureSkipVerify}
cfg.Server = config.Server
cfg.Pass = config.Pass
cfg.NewNick = func(n string) string { return n + "^" }
c := irc.Client(cfg)
channelName = config.ChannelName
c.HandleFunc("connected", joinChannel)
c.HandleFunc("privmsg", callback)
// And a signal on disconnect
quit := make(chan bool)
c.HandleFunc(
"disconnected",
func(conn *irc.Conn, line *irc.Line) { quit <- true },
)
// Tell client to connect.
if err := c.Connect(); err != nil {
log.Fatalf("Connection error: %s\n", err)
} else {
log.Print("Connected")
}
// Wait for disconnect
<-quit
}
func joinChannel(conn *irc.Conn, line *irc.Line) {
conn.Join(channelName)
}