-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (50 loc) · 1.35 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 (
"encoding/json"
"fmt"
"os"
"log"
"github.com/hreeder/slyrc/config"
"github.com/hreeder/slyrc/irc"
"github.com/nlopes/slack"
thojirc "github.com/thoj/go-ircevent"
)
var cfg config.Configuration
var ircConnections map[string]*irc.SlyrcIRCClient
var ready bool
var slackAPI *slack.Client
var ircClient *thojirc.Connection
func main() {
file, _ := os.Open("config.json")
decoder := json.NewDecoder(file)
cfg = config.Configuration{}
cfgErr := decoder.Decode(&cfg)
if cfgErr != nil {
fmt.Println(cfgErr)
panic("Could not load config.json")
}
ircConnections = make(map[string]*irc.SlyrcIRCClient)
ready = false
slackAPI = slack.New(cfg.Slack.BotKey)
slackLogger := log.New(os.Stdout, "slack: ", log.Lshortfile|log.LstdFlags)
slack.SetLogger(slackLogger)
slackAPI.SetDebug(false)
ircClient = thojirc.IRC(cfg.IRC.Nickname, cfg.IRC.Username)
if cfg.IRC.Password != "" {
ircClient.Password = cfg.IRC.Password
}
if cfg.IRC.TLS {
ircClient.UseTLS = true
}
ircErr := ircClient.Connect(cfg.IRC.Server)
if ircErr != nil {
fmt.Println(ircErr)
panic("Failed to connect to IRC")
}
fmt.Println("Connected to IRC")
ircClient.AddCallback("001", onConnect)
ircClient.AddCallback("PRIVMSG", onPrivmsg)
fmt.Println("Added IRC Callbacks")
fmt.Println("Starting Slack connection")
HandleAndRunSlack(slackAPI, ircClient)
}