1
Fork 0
mirror of https://gitlab.com/Kwoth/nadekobot.git synced 2024-10-02 12:09:07 +00:00

change: unkept leave now has a configurable delay

This commit is contained in:
Kwoth 2024-08-28 02:22:58 +00:00
parent 52b87c7776
commit c9ed2cf4b5
4 changed files with 15 additions and 15 deletions

View file

@ -42,7 +42,7 @@ public partial class Administration
[Cmd]
[OwnerOnly]
public async Task LeaveUnkeptServers(int shardId = 0)
public async Task LeaveUnkeptServers(int shardId = 0, int delay = 1000)
{
var keptGuildCount = await _svc.GetKeptGuildCount();
@ -58,7 +58,7 @@ public partial class Administration
if (!response)
return;
await _svc.LeaveUnkeptServers(shardId);
await _svc.LeaveUnkeptServers(shardId, delay);
await ctx.OkAsync();
}
}

View file

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

View file

@ -5,5 +5,5 @@ public interface ICleanupService
Task<KeepResult?> DeleteMissingGuildDataAsync();
Task<bool> KeepGuild(ulong guildId);
Task<int> GetKeptGuildCount();
Task LeaveUnkeptServers(int shardId);
Task LeaveUnkeptServers(int shardId, int delay);
}

View file

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