diff --git a/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupCommands.cs b/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupCommands.cs index 724983a91..f3f1f66ba 100644 --- a/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupCommands.cs +++ b/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupCommands.cs @@ -8,9 +8,13 @@ public partial class Administration public partial class CleanupCommands : CleanupModuleBase { private readonly ICleanupService _svc; + private readonly IBotCredsProvider _creds; - public CleanupCommands(ICleanupService svc) - => _svc = svc; + public CleanupCommands(ICleanupService svc, IBotCredsProvider creds) + { + _svc = svc; + _creds = creds; + } [Cmd] [OwnerOnly] @@ -42,7 +46,7 @@ public partial class Administration [Cmd] [OwnerOnly] - public async Task LeaveUnkeptServers(int shardId, int delay = 1000) + public async Task LeaveUnkeptServers(int startShardId) { var keptGuildCount = await _svc.GetKeptGuildCount(); @@ -58,7 +62,12 @@ public partial class Administration if (!response) return; - await _svc.LeaveUnkeptServers(shardId, delay); + for (var i = startShardId; i < _creds.GetCreds().TotalShards; i++) + { + await _svc.LeaveUnkeptServers(startShardId); + await Task.Delay(2250 * 1000); + } + await ctx.OkAsync(); } } diff --git a/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupService.cs b/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupService.cs index b6eede256..4b537712a 100644 --- a/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupService.cs +++ b/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupService.cs @@ -12,7 +12,7 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, INService private TypedKey _cleanupReportKey = new("cleanup:report"); private TypedKey _cleanupTriggerKey = new("cleanup:trigger"); - private TypedKey<(int, int)> _keepTriggerKey = new("keep:trigger"); + private TypedKey _keepTriggerKey = new("keep:trigger"); private readonly IPubSub _pubSub; private readonly DiscordSocketClient _client; @@ -45,10 +45,8 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, INService private bool keepTriggered = false; - private async ValueTask InternalTriggerKeep((int, int) data) + private async ValueTask InternalTriggerKeep(int shardId) { - var (shardId, delay) = data; - if (_client.ShardId != shardId) return; @@ -74,13 +72,16 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, INService dontDelete = dontDeleteList.ToHashSet(); } - Log.Information("Leaving {RemainingCount} guilds every {Delay} seconds, {DontDeleteCount} will remain", allGuildIds.Length - dontDelete.Count, delay, dontDelete.Count); + Log.Information("Leaving {RemainingCount} guilds every {Delay} seconds, {DontDeleteCount} will remain", + allGuildIds.Length - dontDelete.Count, + shardId, + dontDelete.Count); foreach (var guildId in allGuildIds) { if (dontDelete.Contains(guildId)) continue; - await Task.Delay(delay); + await Task.Delay(1016); SocketGuild? guild = null; try @@ -236,8 +237,8 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, INService return await table.CountAsync(); } - public async Task LeaveUnkeptServers(int shardId, int delay) - => await _pubSub.Pub(_keepTriggerKey, (shardId, delay)); + public async Task LeaveUnkeptServers(int shardId) + => await _pubSub.Pub(_keepTriggerKey, shardId); private ValueTask OnKeepReport(KeepReport report) { diff --git a/src/NadekoBot/Modules/Administration/DangerousCommands/_common/ICleanupService.cs b/src/NadekoBot/Modules/Administration/DangerousCommands/_common/ICleanupService.cs index 055d73179..43dd70c59 100644 --- a/src/NadekoBot/Modules/Administration/DangerousCommands/_common/ICleanupService.cs +++ b/src/NadekoBot/Modules/Administration/DangerousCommands/_common/ICleanupService.cs @@ -5,5 +5,5 @@ public interface ICleanupService Task DeleteMissingGuildDataAsync(); Task KeepGuild(ulong guildId); Task GetKeptGuildCount(); - Task LeaveUnkeptServers(int shardId, int delay); + Task LeaveUnkeptServers(int shardId); } \ No newline at end of file