-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
74 lines (65 loc) · 1.53 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
66
67
68
69
70
71
72
73
74
package main
import "io/ioutil"
import "log"
import "encoding/json"
import "os"
import "os/user"
import "path"
type configuration struct {
Server string
Port int
SSL bool
SSLInsecureSkipVerify bool
Pass string
ChannelName string
}
var (
config configuration
configpath string
)
func configload() error {
b, err := ioutil.ReadFile(configpath)
if err == nil {
return json.Unmarshal(b, &config)
}
return err
}
func configsave() error {
j, err := json.MarshalIndent(config, "", "\t")
if err == nil {
return ioutil.WriteFile(configpath, j, 0600)
}
return err
}
func init() {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
configpath = path.Join(usr.HomeDir, ".friendbotsrc")
config.Server = "irc.freenode.net"
config.Port = 7000
config.SSL = true
config.SSLInsecureSkipVerify = true
config.Pass = "secret"
config.ChannelName = "#chan"
errConfigLoad := configload()
if _, ok := errConfigLoad.(*os.PathError); ok {
log.Printf("No config file found. Creating %s ...", configpath)
if errConfigSave := configsave(); errConfigSave != nil {
log.Fatal(errConfigSave)
}
} else if errConfigLoad != nil {
log.Fatalf("could not parse %v: %v", configpath, errConfigLoad)
}
}
func main() {
// Yves
go connect(config, "Ygbot", handleMessageYgbot)
// Caro
go connect(config, "Carot", handleMessageCarot)
// Vincent
go connect(config, "VBAbot", handleMessageVBAbot)
// Guilhem
connect(config, "GuilhemBot", handleMessageGuilhem)
}