-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (42 loc) · 899 Bytes
/
main.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
50
// Load Balancer backend discovery over IRC
package main
import (
"fmt"
"github.com/lrstanley/girc"
"log"
"os"
"strings"
"time"
)
func main() {
client := girc.New(girc.Config{
Server: "localhost",
Port: 6667,
Nick: "test",
User: "user",
Name: "Example bot",
Debug: os.Stdout,
})
client.Handlers.Add(girc.CONNECTED, func(c *girc.Client, e girc.Event) {
c.Cmd.Join("#dev")
})
client.Handlers.Add(girc.PRIVMSG, func(c *girc.Client, e girc.Event) {
if strings.Contains(e.Last(), "add") {
c.Cmd.ReplyTo(e, fmt.Sprintf("%s", e.Last()))
return
}
if strings.Contains(e.Last(), "quit") {
c.Close()
}
})
// An example of how you would add reconnect logic.
for {
if err := client.Connect(); err != nil {
log.Printf("error: %s", err)
log.Println("reconnecting in 30 seconds...")
time.Sleep(30 * time.Second)
} else {
return
}
}
}