-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdiscordBots.go
36 lines (31 loc) · 862 Bytes
/
discordBots.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
package main
import (
"github.com/bwmarrin/discordgo"
"github.com/kubastick/dblgo"
"log"
"time"
)
func postServerCountToDiscordBotAPI(s *discordgo.Session) {
if config.DiscordStatsSecret != "" && config.DiscordAppID != "" {
dblAPI := dblgo.NewDBLApi(config.DiscordStatsSecret)
postStatsLoop(s, dblAPI)
} else {
log.Println("Discord Bot List Api is deactivated")
}
}
func postStats(s *discordgo.Session, api *dblgo.DBLApi) {
log.Println("Posting stats to Discord Bot List")
guildsNum := len(s.State.Guilds)
log.Printf("Number of guilds %d", guildsNum)
err := api.PostStatsSimple(guildsNum)
if err != nil {
log.Println("Failed to post stats to Discord Bot List", err)
}
log.Printf("Stats successfully posted")
}
func postStatsLoop(s *discordgo.Session, api dblgo.DBLApi) {
for {
postStats(s, &api)
time.Sleep(30 * time.Minute)
}
}