-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (42 loc) · 1.29 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
package main
import (
"github.com/charmbracelet/log"
"github.com/kaplan-michael/slack-kudos/pkg/config"
"github.com/kaplan-michael/slack-kudos/pkg/database"
"github.com/kaplan-michael/slack-kudos/pkg/dispatcher"
"github.com/slack-go/slack"
"github.com/slack-go/slack/socketmode"
l "log"
"os"
)
func main() {
config.Init()
err := database.InitDB()
if err != nil {
log.Fatalf("Error initializing database: %s\n", err)
}
// Initialize the central dispatcher
disp := dispatcher.NewDispatcher()
token := config.AppConfig.SlackToken
appToken := config.AppConfig.SlackAppToken
api := slack.New(token, slack.OptionDebug(true), slack.OptionDebug(false), slack.OptionAppLevelToken(appToken))
client := socketmode.New(
api,
socketmode.OptionDebug(false),
socketmode.OptionLog(l.New(os.Stdout, "socketmode: ", l.Lshortfile|l.LstdFlags)),
)
// Start listening for Slack events
go func() {
for evt := range client.Events {
// Dispatch all events to the central dispatcher
if err := disp.Dispatch(&evt, client); err != nil {
log.Warnf("Error processing event: %s\n", err)
}
}
}()
log.Info("Bot is running...")
// Run the Socket Mode client, which listens and responds to events from Slack
if err := client.Run(); err != nil {
log.Fatalf("Error running client: %v", err)
}
}