From 8b2ed0dbdcb96d56f36d0bb28297e87c27e66725 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 27 Aug 2024 00:39:42 +0000 Subject: [PATCH] fix: fix for .leaveunkeptservers --- .../DangerousCommands/CleanupService.cs | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupService.cs b/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupService.cs index c7d9a54f9..7a6af8ef0 100644 --- a/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupService.cs +++ b/src/NadekoBot/Modules/Administration/DangerousCommands/CleanupService.cs @@ -59,14 +59,19 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, INService var allGuildIds = _client.Guilds.Select(x => x.Id); - var table = await GetKeptGuildsTable(); + HashSet dontDelete; + await using (var db = _db.GetDbContext()) + { + await using var ctx = db.CreateLinqToDBContext(); + var table = ctx.CreateTable(tableOptions: TableOptions.CheckExistence); - var dontDeleteList = await table - .Where(x => allGuildIds.Contains(x.GuildId)) - .Select(x => x.GuildId) - .ToListAsyncLinqToDB(); + var dontDeleteList = await table + .Where(x => allGuildIds.Contains(x.GuildId)) + .Select(x => x.GuildId) + .ToListAsyncLinqToDB(); - var dontDelete = dontDeleteList.ToHashSet(); + dontDelete = dontDeleteList.ToHashSet(); + } guildIds = new(); foreach (var guildId in allGuildIds) @@ -209,8 +214,9 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, INService public async Task KeepGuild(ulong guildId) { - var table = await GetKeptGuildsTable(); - + await using var db = _db.GetDbContext(); + await using var ctx = db.CreateLinqToDBContext(); + var table = ctx.CreateTable(tableOptions: TableOptions.CheckExistence); if (await table.AnyAsyncLinqToDB(x => x.GuildId == guildId)) return false; @@ -223,17 +229,11 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, INService } public async Task GetKeptGuildCount() - { - var table = await GetKeptGuildsTable(); - return await table.CountAsync(); - } - - private async Task> GetKeptGuildsTable() { await using var db = _db.GetDbContext(); await using var ctx = db.CreateLinqToDBContext(); var table = ctx.CreateTable(tableOptions: TableOptions.CheckExistence); - return table; + return await table.CountAsync(); } public async Task LeaveUnkeptServers()