aboutsummaryrefslogtreecommitdiff
path: root/xp
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-06-17 14:33:15 +0200
committerAnhgelus Morhtuuzh <anhgelus.morhtuuzh@proton.me>2024-06-17 14:33:15 +0200
commit5b0d9e4dd3b4744c75bbca337e5ec89e5ac4d063 (patch)
treeef0201476b33acd5fd3e4992ab9fa83d9f76dad9 /xp
parentd485b0de1ce170aa18b09b6654a607a7f04f0315 (diff)
chore(discord): prevent spaming discord API if a guild has more than 50 users
Diffstat (limited to 'xp')
-rw-r--r--xp/level.go7
1 files changed, 5 insertions, 2 deletions
diff --git a/xp/level.go b/xp/level.go
index 328a287..e577920 100644
--- a/xp/level.go
+++ b/xp/level.go
@@ -165,7 +165,10 @@ func XPUpdate(s *discordgo.Session, c *Copaing) {
func PeriodicReducer(s *discordgo.Session) {
var wg sync.WaitGroup
for _, g := range s.State.Guilds {
- for _, m := range utils.FetchGuildUser(s, g.ID) {
+ for i, m := range utils.FetchGuildUser(s, g.ID) {
+ if i%50 == 49 {
+ time.Sleep(15 * time.Second) // sleep prevents from spamming the Discord API and the database
+ }
if m.User.Bot {
continue
}
@@ -178,7 +181,7 @@ func PeriodicReducer(s *discordgo.Session) {
}
wg.Wait() // finish the entire guild before starting another
utils.SendDebug("Periodic reduce, guild finished", "guild", g.Name)
- time.Sleep(10 * time.Second) // sleep prevents from spamming the Discord API and the database
+ time.Sleep(15 * time.Second) // sleep prevents from spamming the Discord API and the database
}
utils.SendDebug("Periodic reduce finished", "len(guilds)", len(s.State.Guilds))
}