-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (48 loc) · 1.11 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 (
"os"
"os/signal"
"syscall"
"github.com/FM1337/ASB/internal/bot"
"github.com/FM1337/ASB/internal/ent"
"github.com/FM1337/ASB/internal/models"
"github.com/apex/log"
"github.com/lrstanley/clix"
)
var (
cli = &clix.CLI[models.Flags]{
Links: clix.GithubLinks("github.com/FM1337/ASB", "main", "https://github.com/FM1337/ASB"),
}
logger log.Interface
db *ent.Client
asb *bot.Bot
)
func init() {
cli.Parse()
logger = cli.Logger
if !cli.Flags.Configured {
logger.Fatal("Bot not configured")
}
}
func main() {
// Run the required setup tasks
setup()
err := asb.Start()
if err != nil {
logger.WithError(err).Fatal("Failed to start bot")
}
// Wait here until CTRL-C or other term signal is received.
done := make(chan struct{})
signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
select {
case <-signals:
logger.Info("received SIGINT/SIGTERM/SIGQUIT, closing connections...")
// Shut down the bot followed by the databases
asb.Stop()
db.Close()
logger.Info("done cleaning up; exiting")
os.Exit(0)
case <-done:
}
}