-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
61 lines (54 loc) · 1.33 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
package main
import (
"os"
"github.com/eleboucher/coalibot/utils"
"github.com/joho/godotenv"
log "github.com/sirupsen/logrus"
"github.com/slack-go/slack"
"gitlab.com/clafoutis/api42"
)
func init() {
log.SetFormatter(&log.JSONFormatter{})
log.SetOutput(os.Stdout)
log.SetLevel(log.InfoLevel)
}
func main() {
err := godotenv.Load()
if err != nil {
log.Fatal(err)
}
api := slack.New(os.Getenv("SLACK_API_TOKEN"))
rtm := api.NewRTM()
reactions := InitReaction()
// api.SetDebug(true)
client, err := api42.NewAPI(os.Getenv("INTRA_CLIENT_ID"), os.Getenv("INTRA_SECRET"))
if err != nil {
log.Errorf("Error with the api, %s %#v", err, client)
}
go rtm.ManageConnection()
for msg := range rtm.IncomingEvents {
switch ev := msg.Data.(type) {
case *slack.ConnectedEvent:
log.Info("Ready")
case *slack.MessageEvent:
var message = utils.Message{
Message: ev.Msg.Text,
Channel: ev.Msg.Channel,
User: ev.Msg.User,
Timestamp: ev.Msg.Timestamp,
ThreadTimestamp: ev.Msg.ThreadTimestamp,
API: api,
FortyTwo: client,
}
go React(message, reactions)
if message.User != "" {
go handleCommand(&message)
}
case *slack.RTMError:
log.Fatal(ev.Error())
case *slack.InvalidAuthEvent:
log.Fatal("Invalid credentials")
return
}
}
}