-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgopherbot.go
More file actions
72 lines (58 loc) · 1.55 KB
/
Copy pathgopherbot.go
File metadata and controls
72 lines (58 loc) · 1.55 KB
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
package main
import (
"io/ioutil"
"log"
"github.com/ameske/gopherbot/core"
"github.com/ameske/gopherbot/extensions/coreext"
"github.com/ameske/gopherbot/extensions/wordnikext"
"github.com/thoj/go-ircevent"
"gopkg.in/yaml.v2"
)
type gopherbotConfig struct {
StartingRoom string `yaml:"STARTING_ROOM"`
Server string `yaml:"SERVER"`
}
var (
config gopherbotConfig
startingRoom = "#gopherbot"
)
func main() {
bytes, err := ioutil.ReadFile("gopherbot.yaml")
if err != nil {
log.Fatalf(err.Error())
}
err = yaml.Unmarshal(bytes, &config)
if err != nil {
log.Fatalf(err.Error())
}
con := irc.IRC("gopherbot", "gopherbot")
err = con.Connect(config.Server)
if err != nil {
log.Fatalf("Could not connect to IRC server: %s", err.Error())
}
registry := core.NewExtensions(con)
coreext.Register(registry)
wordnikext.Register(registry)
// Join the starting room for gopherbot
con.AddCallback("001", func(e *irc.Event) {
con.Join(config.StartingRoom)
})
// Announce the arrival of gopherbot. Gophers have manners!
con.AddCallback("JOIN", func(e *irc.Event) {
for _, room := range e.Arguments {
con.Privmsg(room, "Oh hey guys, this is Gopherbot")
}
})
// Join the room(s) that gopherbot was invited to. Gopher are friendly creatures!
con.AddCallback("INVITE", func(e *irc.Event) {
if len(e.Arguments) != 2 {
return
}
if e.Arguments[0] == "gopherbot" {
con.Join(e.Arguments[1])
}
})
// Gophers can to many things. Select the trick that a user requested.
con.AddCallback("PRIVMSG", registry.Select)
con.Loop()
}