-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
59 lines (52 loc) · 1.15 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
package main
import (
"fmt"
"os"
"os/signal"
"strings"
log "github.com/Sirupsen/logrus"
"github.com/radeklos/holly/bot"
"github.com/spf13/viper"
)
func EnvToCronMessages(data []string) []bot.CronMessage {
var s []bot.CronMessage
for _, item := range data {
splits := strings.Split(item, "=")
key := splits[0]
message := splits[1]
if strings.HasPrefix(key, "MSG") {
parts := strings.SplitN(key, "_", 4)
if len(parts) < 4 {
log.WithFields(log.Fields{
"name": key,
"value": message,
}).Warn("Cannot understand cron message")
continue
}
s = append(s, bot.CronMessage{
CronLine: fmt.Sprintf("%s %s * * MON-FRI *", parts[2], parts[1]),
Channel: parts[3],
Message: message,
})
}
}
return s
}
func main() {
viper.AutomaticEnv()
viper.SetDefault("SLACK_TOKEN", "")
bot := bot.NewBot(
bot.Config{
SlackToken: viper.GetString("SLACK_TOKEN"),
CronMessages: EnvToCronMessages(os.Environ()),
},
)
bot.Run()
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt, os.Kill)
// Run forever unless we get a signal
for sig := range signals {
log.Println(sig)
os.Exit(1)
}
}