-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgogsm.go
59 lines (44 loc) · 1.09 KB
/
gogsm.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 (
"GoGSM/config"
"GoGSM/discord"
"fmt"
"github.com/patrickmn/go-cache"
"log"
"os"
"os/signal"
"syscall"
"time"
_ "embed"
)
//go:embed config/default.toml
var defaultConfig string
func main() {
config.DefaultConfig = defaultConfig
config.GlobalCache = cache.New(5*time.Minute, 10*time.Minute)
conf := config.ReadConfig()
// Download names from gamedig repo
// TODO: this should be cached
go config.GetGameNames()
// Start discord bot
s, err := discord.CreateBot(conf.Bot.Token)
if err != nil {
log.Fatalf("Error creating bot: %s", err)
}
// Sets the timer to do status updates
ticker := time.NewTicker(time.Second * time.Duration(conf.Bot.UpdateTime))
// Does the updates every tick
go func() {
for range ticker.C {
discord.RefreshServerStatus(s)
}
}()
discord.RefreshServerStatus(s)
// Clean exit on ctrl+c
fmt.Println("Bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
// TODO: write cache to disk here
fmt.Println("\nShutting down...")
}