From 5b0d9e4dd3b4744c75bbca337e5ec89e5ac4d063 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Mon, 17 Jun 2024 14:33:15 +0200 Subject: chore(discord): prevent spaming discord API if a guild has more than 50 users --- xp/level.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'xp/level.go') 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)) } -- cgit v1.2.3