-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (51 loc) · 1.38 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"crypto/tls"
"fmt"
"os"
"time"
irc "github.com/thoj/go-ircevent"
)
func main() {
channels := os.Getenv("IRC_CHANNELS")
hostname := os.Getenv("IRC_HOST") + ":" + os.Getenv("IRC_PORT")
ircnick1 := os.Getenv("IRC_NICK")
irccon := irc.IRC(ircnick1, ircnick1)
irccon.VerboseCallbackHandler = true
irccon.Debug = true
irccon.UseTLS = true
irccon.TLSConfig = &tls.Config{InsecureSkipVerify: false, ServerName: os.Getenv("IRC_HOST")}
irccon.AddCallback("001", func(e *irc.Event) {
irccon.Privmsgf("NickServ", "ID %s", os.Getenv("IRC_PASS"))
})
irccon.AddCallback("366", func(e *irc.Event) {})
irccon.AddCallback("396", func(e *irc.Event) { irccon.Join(channels) })
exported(irccon)
go heartBeat(irccon)
err := irccon.Connect(hostname)
if err != nil {
fmt.Printf("Err %s", err)
return
}
irccon.Loop()
}
type binFunc func(irccon *irc.Connection)
func exported(irccon *irc.Connection) {
available := []binFunc{addInvite, addJoin, addNotice, addPrivmsg}
for a := 0; a < len(available); a++ {
handle(available[a], irccon)
}
}
func handle(function binFunc, irccon *irc.Connection) {
function(irccon)
}
func heartBeat(irccon *irc.Connection) {
handleHeartBeat(irccon)
for range time.Tick(time.Second * 60) {
handleHeartBeat(irccon)
}
}
func handleHeartBeat(irccon *irc.Connection) {
fmt.Println(time.Now(), "Heartbeat")
go cronHandler(irccon)
}