unkept leave now has a configurable delay

This commit is contained in:
Toastie (DCS Team) 2024-08-28 19:57:33 +12:00
parent 7874008da2
commit 1c53371598
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
4 changed files with 15 additions and 15 deletions

View file

@ -42,7 +42,7 @@ public partial class Administration
[Cmd] [Cmd]
[OwnerOnly] [OwnerOnly]
public async Task LeaveUnkeptServers(int shardId = 0) public async Task LeaveUnkeptServers(int shardId = 0, int delay = 1000)
{ {
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(shardId); await _svc.LeaveUnkeptServers(shardId, delay);
await ctx.OkAsync(); await ctx.OkAsync();
} }
} }

View file

@ -2,10 +2,8 @@
using LinqToDB.Data; using LinqToDB.Data;
using LinqToDB.EntityFrameworkCore; using LinqToDB.EntityFrameworkCore;
using LinqToDB.Mapping; using LinqToDB.Mapping;
using LinqToDB.Tools;
using EllieBot.Common.ModuleBehaviors; using EllieBot.Common.ModuleBehaviors;
using EllieBot.Db.Models; using EllieBot.Db.Models;
using System.Security.Cryptography;
namespace EllieBot.Modules.Administration.DangerousCommands; namespace EllieBot.Modules.Administration.DangerousCommands;
@ -14,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> _keepTriggerKey = new("keep:trigger"); private TypedKey<(int, int)> _keepTriggerKey = new("keep:trigger");
private readonly IPubSub _pubSub; private readonly IPubSub _pubSub;
private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;
@ -47,8 +45,10 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
private bool keepTriggered = false; private bool keepTriggered = false;
private async ValueTask InternalTriggerKeep(int shardId) private async ValueTask InternalTriggerKeep((int shardId, int delay) data)
{ {
var (shardId, delay) = data;
if (_client.ShardId != shardId) if (_client.ShardId != shardId)
return; return;
@ -58,8 +58,6 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
keepTriggered = true; keepTriggered = true;
try try
{ {
await Task.Delay(10 + (10 * _client.ShardId));
var allGuildIds = _client.Guilds.Select(x => x.Id); var allGuildIds = _client.Guilds.Select(x => x.Id);
HashSet<ulong> dontDelete; HashSet<ulong> dontDelete;
@ -82,8 +80,7 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
if (dontDelete.Contains(guildId)) if (dontDelete.Contains(guildId))
continue; continue;
// 1 leave per 20 seconds per shard await Task.Delay(delay);
await Task.Delay(500);
SocketGuild? guild = null; SocketGuild? guild = null;
try try
@ -239,8 +236,8 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
return await table.CountAsync(); return await table.CountAsync();
} }
public async Task LeaveUnkeptServers(int shardId) public async Task LeaveUnkeptServers(int shardId, int delay)
=> await _pubSub.Pub(_keepTriggerKey, shardId); => await _pubSub.Pub(_keepTriggerKey, (shardId, delay));
private ValueTask OnKeepReport(KeepReport report) private ValueTask OnKeepReport(KeepReport report)
{ {

View file

@ -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); Task LeaveUnkeptServers(int shardId, int delay);
} }

View file

@ -4562,4 +4562,7 @@ leaveunkeptservers:
ex: ex:
- '' - ''
params: params:
- { } - shardId:
desc: "Shard id from which to start leaving unkept servers."
- delay:
desc: "Delay in miliseconds between leaves"