Changed how leaving unkept servers work. It only works per-shard now
This commit is contained in:
parent
7f935a72c1
commit
7874008da2
3 changed files with 11 additions and 8 deletions
|
@ -42,7 +42,7 @@ public partial class Administration
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
public async Task LeaveUnkeptServers()
|
public async Task LeaveUnkeptServers(int shardId = 0)
|
||||||
{
|
{
|
||||||
var keptGuildCount = await _svc.GetKeptGuildCount();
|
var keptGuildCount = await _svc.GetKeptGuildCount();
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ public partial class Administration
|
||||||
if (!response)
|
if (!response)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
await _svc.LeaveUnkeptServers();
|
await _svc.LeaveUnkeptServers(shardId);
|
||||||
await ctx.OkAsync();
|
await ctx.OkAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,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<bool> _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;
|
||||||
|
@ -47,8 +47,11 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
||||||
|
|
||||||
private bool keepTriggered = false;
|
private bool keepTriggered = false;
|
||||||
|
|
||||||
private async ValueTask InternalTriggerKeep(bool arg)
|
private async ValueTask InternalTriggerKeep(int shardId)
|
||||||
{
|
{
|
||||||
|
if (_client.ShardId != shardId)
|
||||||
|
return;
|
||||||
|
|
||||||
if (keepTriggered)
|
if (keepTriggered)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -80,7 +83,7 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// 1 leave per 20 seconds per shard
|
// 1 leave per 20 seconds per shard
|
||||||
await Task.Delay(RandomNumberGenerator.GetInt32(18_000, 22_000));
|
await Task.Delay(500);
|
||||||
|
|
||||||
SocketGuild? guild = null;
|
SocketGuild? guild = null;
|
||||||
try
|
try
|
||||||
|
@ -236,8 +239,8 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
||||||
return await table.CountAsync();
|
return await table.CountAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task LeaveUnkeptServers()
|
public async Task LeaveUnkeptServers(int shardId)
|
||||||
=> await _pubSub.Pub(_keepTriggerKey, true);
|
=> 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();
|
Task LeaveUnkeptServers(int shardId);
|
||||||
}
|
}
|
Loading…
Reference in a new issue