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

fix: fix for .leaveunkeptservers

This commit is contained in:
Kwoth 2024-08-27 00:39:42 +00:00
parent 9424d4d5f9
commit 8b2ed0dbdc

View file

@ -59,14 +59,19 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, INService
var allGuildIds = _client.Guilds.Select(x => x.Id);
var table = await GetKeptGuildsTable();
HashSet<ulong> dontDelete;
await using (var db = _db.GetDbContext())
{
await using var ctx = db.CreateLinqToDBContext();
var table = ctx.CreateTable<KeptGuilds>(tableOptions: TableOptions.CheckExistence);
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<bool> KeepGuild(ulong guildId)
{
var table = await GetKeptGuildsTable();
await using var db = _db.GetDbContext();
await using var ctx = db.CreateLinqToDBContext();
var table = ctx.CreateTable<KeptGuilds>(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<int> GetKeptGuildCount()
{
var table = await GetKeptGuildsTable();
return await table.CountAsync();
}
private async Task<ITable<KeptGuilds>> GetKeptGuildsTable()
{
await using var db = _db.GetDbContext();
await using var ctx = db.CreateLinqToDBContext();
var table = ctx.CreateTable<KeptGuilds>(tableOptions: TableOptions.CheckExistence);
return table;
return await table.CountAsync();
}
public async Task LeaveUnkeptServers()