-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (60 loc) · 1.86 KB
/
main.go
File metadata and controls
74 lines (60 loc) · 1.86 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/SoundBoardBot/server-counter/config"
"github.com/SoundBoardBot/server-counter/db"
"github.com/SoundBoardBot/server-counter/http"
"github.com/SoundBoardBot/server-counter/tasks"
"github.com/SoundBoardBot/server-counter/utils"
"github.com/go-co-op/gocron/v2"
)
func main() {
config.Parse()
lerr := utils.Configure(nil, config.Conf.JsonLogs, config.Conf.LogLevel)
if lerr != nil {
panic(fmt.Errorf("failed to create zap logger: %w", lerr))
}
db.Init()
s, s_err := gocron.NewScheduler()
if s_err != nil {
panic(fmt.Errorf("failed to create cron scheduler: %w", s_err))
}
utils.Logger.Sugar().Infof("top.gg Enabled: %s", IsEnabled(config.Conf.Auth.TopGG))
utils.Logger.Sugar().Infof("discordbotlist.com Enabled: %s", IsEnabled(config.Conf.Auth.DiscordBotList))
utils.Logger.Sugar().Infof("botlist.me Enabled: %s", IsEnabled(config.Conf.Auth.BotListMe))
utils.Logger.Sugar().Infof("voidbots.net Enabled: %s", IsEnabled(config.Conf.Auth.VoidBots))
if config.Conf.OneShot {
utils.Logger.Info("Running Job - Bot Stats")
tasks.UpdateBotStats()
return
}
// add hourly fresh bot data
s.NewJob(gocron.CronJob("*/5 * * * *", false), gocron.NewTask(func() {
utils.Logger.Debug("Running Job - Bot Stats")
tasks.UpdateBotStats()
}))
// start the scheduler
utils.Logger.Info("Starting cron jobs")
s.Start()
// Start HTTP server...
if config.Conf.Http.Enabled {
utils.Logger.Info("Starting HTTP server...")
server := http.NewServer(utils.Logger, config.Conf)
server.RegisterRoutes()
server.Start()
}
// keep alive until shutdown signal
shutdownCh := make(chan os.Signal, 1)
signal.Notify(shutdownCh, syscall.SIGINT, syscall.SIGTERM)
<-shutdownCh
utils.Logger.Info("Received shutdown signal")
}
func IsEnabled(value string) string {
if value == "" {
return "No"
}
return "Yes"
}