-
Notifications
You must be signed in to change notification settings - Fork 0
/
vropsbot.go
79 lines (62 loc) · 1.85 KB
/
vropsbot.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
75
76
77
78
79
package main
import (
"fmt"
"log"
"os"
"time"
"github.com/nlopes/slack"
"github.com/bruceadowns/vropsbot/bot"
"github.com/bruceadowns/vropsbot/comm"
"github.com/bruceadowns/vropsbot/common"
_ "github.com/bruceadowns/vropsbot/plugins/admin"
_ "github.com/bruceadowns/vropsbot/plugins/cat"
_ "github.com/bruceadowns/vropsbot/plugins/vro"
)
func die(err error) {
log.Fatal(err)
os.Exit(-1)
}
func initCaches(client *slack.Client) {
comm.InitUserCache(client)
comm.InitChannelCache(client)
comm.InitGroupCache(client)
}
func main() {
config, err := common.NewConfig()
if err != nil {
die(fmt.Errorf("error reading configuration file: %v", err))
}
db, err := common.InitDatabase()
if err != nil {
die(fmt.Errorf("error initializing the database: %v", err))
}
defer db.Close()
client := slack.New(config.SlackbotAuthToken)
client.SetDebug(config.Debug)
authRes, err := client.AuthTest()
if err != nil {
die(fmt.Errorf("error calling AuthTest: %s", err))
}
log.Printf("URL: %s", authRes.URL)
log.Printf("Team: %s:%s", authRes.TeamID, authRes.Team)
log.Printf("User: %s:%s", authRes.UserID, authRes.User)
userID := authRes.UserID
botIDs := []string{
fmt.Sprintf("<@%s>:", userID),
fmt.Sprintf("<@%s>", userID)}
log.Printf("vropsbot identifiers: %s", botIDs)
rtm := client.NewRTM()
go rtm.ManageConnection()
go initCaches(client)
comm.SB.ChanResponse = comm.RespChan(client, config.SwitchBoard.ResponseChannelSize)
comm.SB.ChanPersist = comm.SaveChan(config.SwitchBoard.SaveChannelSize, db)
comm.SB.ChanHeartbeat = comm.HeartbeatChan(config.SwitchBoard.HeartbeatChannelSize, db)
if err := bot.PM.Prepare(); err != nil {
die(fmt.Errorf("error calling Plugin Manager Prepare: %s", err))
}
go bot.PM.Start()
comm.SB.ChanPersist <- &common.KVStore{
Key: "start",
Value: time.Now().String()}
os.Exit(bot.Pump(rtm, botIDs))
}