From c0b2b9793bb86e7a4d66618f5e294a66c1434740 Mon Sep 17 00:00:00 2001 From: Noi Date: Wed, 23 Mar 2022 11:13:55 -0700 Subject: [PATCH] Add role removal limit per run --- BackgroundServices/BirthdayRoleUpdate.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/BackgroundServices/BirthdayRoleUpdate.cs b/BackgroundServices/BirthdayRoleUpdate.cs index 1b605a8..cf847ea 100644 --- a/BackgroundServices/BirthdayRoleUpdate.cs +++ b/BackgroundServices/BirthdayRoleUpdate.cs @@ -132,9 +132,10 @@ class BirthdayRoleUpdate : BackgroundService { if (!toApply.Contains(user.Id)) removals.Add(user); else no_ops.Add(user.Id); } + int removalAllowance = 15; // Limit removals per run, to not get continuously stuck on rate limits in misconfigured servers foreach (var user in removals) { - // TODO this gets hit with rate limits sometimes. figure something out. await user.RemoveRoleAsync(r); + if (--removalAllowance == 0) break; } foreach (var target in toApply) { @@ -146,7 +147,7 @@ class BirthdayRoleUpdate : BackgroundService { } } catch (Discord.Net.HttpException ex) when (ex.DiscordCode is DiscordErrorCode.MissingPermissions or DiscordErrorCode.InsufficientPermissions) { - // Encountered access and/or permission issues despite earlier checks. Quit the loop here. + // Encountered access and/or permission issues despite earlier checks. Quit the loop here, don't report error. } return additions; }