forked from EllieBotDevs/elliebot
Changed .leaveunkeptservers again to only accept startShardId, it will loop through the shards and execute clean on them every 2250 seconds (assuming shards are almost full). Delay is fixed at 1 second as that is the discord ratelimit
This commit is contained in:
parent
45d9fa08db
commit
b752633e83
4 changed files with 24 additions and 16 deletions
|
@ -8,9 +8,13 @@ public partial class Administration
|
||||||
public partial class CleanupCommands : CleanupModuleBase
|
public partial class CleanupCommands : CleanupModuleBase
|
||||||
{
|
{
|
||||||
private readonly ICleanupService _svc;
|
private readonly ICleanupService _svc;
|
||||||
|
private readonly IBotCredsProvider _creds;
|
||||||
|
|
||||||
public CleanupCommands(ICleanupService svc)
|
public CleanupCommands(ICleanupService svc, IBotCredsProvider creds)
|
||||||
=> _svc = svc;
|
{
|
||||||
|
_svc = svc;
|
||||||
|
_creds = creds;
|
||||||
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
|
@ -42,7 +46,7 @@ public partial class Administration
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
public async Task LeaveUnkeptServers(int shardId, int delay = 1000)
|
public async Task LeaveUnkeptServers(int startShardId)
|
||||||
{
|
{
|
||||||
var keptGuildCount = await _svc.GetKeptGuildCount();
|
var keptGuildCount = await _svc.GetKeptGuildCount();
|
||||||
|
|
||||||
|
@ -58,7 +62,12 @@ public partial class Administration
|
||||||
if (!response)
|
if (!response)
|
||||||
return;
|
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();
|
await ctx.OkAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
||||||
private TypedKey<KeepReport> _cleanupReportKey = new("cleanup:report");
|
private TypedKey<KeepReport> _cleanupReportKey = new("cleanup:report");
|
||||||
private TypedKey<bool> _cleanupTriggerKey = new("cleanup:trigger");
|
private TypedKey<bool> _cleanupTriggerKey = new("cleanup:trigger");
|
||||||
|
|
||||||
private TypedKey<(int, int)> _keepTriggerKey = new("keep:trigger");
|
private TypedKey<int> _keepTriggerKey = new("keep:trigger");
|
||||||
|
|
||||||
private readonly IPubSub _pubSub;
|
private readonly IPubSub _pubSub;
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
|
@ -45,10 +45,8 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
||||||
|
|
||||||
private bool keepTriggered = false;
|
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)
|
if (_client.ShardId != shardId)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -74,13 +72,16 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
||||||
dontDelete = dontDeleteList.ToHashSet();
|
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)
|
foreach (var guildId in allGuildIds)
|
||||||
{
|
{
|
||||||
if (dontDelete.Contains(guildId))
|
if (dontDelete.Contains(guildId))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
await Task.Delay(delay);
|
await Task.Delay(1016);
|
||||||
|
|
||||||
SocketGuild? guild = null;
|
SocketGuild? guild = null;
|
||||||
try
|
try
|
||||||
|
@ -236,8 +237,8 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
||||||
return await table.CountAsync();
|
return await table.CountAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task LeaveUnkeptServers(int shardId, int delay)
|
public async Task LeaveUnkeptServers(int shardId)
|
||||||
=> await _pubSub.Pub(_keepTriggerKey, (shardId, delay));
|
=> await _pubSub.Pub(_keepTriggerKey, shardId);
|
||||||
|
|
||||||
private ValueTask OnKeepReport(KeepReport report)
|
private ValueTask OnKeepReport(KeepReport report)
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,5 +5,5 @@ public interface ICleanupService
|
||||||
Task<KeepResult?> DeleteMissingGuildDataAsync();
|
Task<KeepResult?> DeleteMissingGuildDataAsync();
|
||||||
Task<bool> KeepGuild(ulong guildId);
|
Task<bool> KeepGuild(ulong guildId);
|
||||||
Task<int> GetKeptGuildCount();
|
Task<int> GetKeptGuildCount();
|
||||||
Task LeaveUnkeptServers(int shardId, int delay);
|
Task LeaveUnkeptServers(int shardId);
|
||||||
}
|
}
|
|
@ -4564,5 +4564,3 @@ leaveunkeptservers:
|
||||||
params:
|
params:
|
||||||
- shardId:
|
- shardId:
|
||||||
desc: "Shard id from which to start leaving unkept servers."
|
desc: "Shard id from which to start leaving unkept servers."
|
||||||
- delay:
|
|
||||||
desc: "Delay in miliseconds between leaves"
|
|
Reference in a new issue