forked from Gentux/friend-bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
46 lines (38 loc) · 1013 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
package main
//import "crypto/tls"
import "fmt"
import irc "github.com/fluffle/goirc/client"
func connect(
channelName string,
channelNick string,
callback func(conn *irc.Conn, line *irc.Line),
) {
cfg := irc.NewConfig(channelNick)
cfg.SSL = true
//cfg.SSLConfig = &tls.Config{InsecureSkipVerify: true}
cfg.Server = "irc.freenode.net:7000"
//cfg.Pass = "secret"
cfg.NewNick = func(n string) string { return n + "^" }
c := irc.Client(cfg)
// Add handlers to do things here!
// e.g. join a channel on connect.
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 {
fmt.Println("Connection error: %s\n", err)
} else {
fmt.Println("Connected")
}
// Wait for disconnect
<-quit
}
func joinChannel(conn *irc.Conn, line *irc.Line) {
conn.Join(channelName)
}