-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
48 lines (38 loc) · 911 Bytes
/
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
package main
import (
"context"
"egg/bot"
"egg/config"
"egg/datastore"
"os"
"os/signal"
"github.com/sirupsen/logrus"
)
func main() {
ctx := context.Background()
db, err := datastore.ConnectDatabase("sqlite-file", true)
if err != nil {
panic(err)
}
if err = db.AutoMigrate(datastore.User{}); err != nil {
panic(err)
}
dStore := datastore.Database{DB: db}
if err = config.LoadConfigFromFile("./config.json"); err != nil {
panic(err)
}
commands, session := bot.Start(ctx, dStore)
defer func() {
_ = session.Close()
}()
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
<-stop
logrus.Info("--> removing bot commands from server ...")
for _, command := range commands {
if err = session.ApplicationCommandDelete(session.State.User.ID, config.Config.GuildID, command.ID); err != nil {
panic(err)
}
}
logrus.Info("--> gracefully shutting down ...")
}