diff --git a/src/EllieBot/Modules/Administration/DangerousCommands/CleanupCommands.cs b/src/EllieBot/Modules/Administration/DangerousCommands/CleanupCommands.cs index 8fee8a3..e4e8e76 100644 --- a/src/EllieBot/Modules/Administration/DangerousCommands/CleanupCommands.cs +++ b/src/EllieBot/Modules/Administration/DangerousCommands/CleanupCommands.cs @@ -27,5 +27,15 @@ public partial class Administration .Confirm($"{result.GuildCount} guilds' data remain in the database.") .SendAsync(); } + + [Cmd] + [RequireContext(ContextType.Guild)] + [UserPerm(GuildPerm.Administrator)] + public async Task Keep() + { + var result = await _svc.KeepGuild(Context.Guild.Id); + + await Response().Text("This guild's bot data will be saved.").SendAsync(); + } } } \ No newline at end of file diff --git a/src/EllieBot/Modules/Administration/DangerousCommands/CleanupService.cs b/src/EllieBot/Modules/Administration/DangerousCommands/CleanupService.cs index b2dbf46..92feac4 100644 --- a/src/EllieBot/Modules/Administration/DangerousCommands/CleanupService.cs +++ b/src/EllieBot/Modules/Administration/DangerousCommands/CleanupService.cs @@ -1,6 +1,7 @@ using LinqToDB; using LinqToDB.Data; using LinqToDB.EntityFrameworkCore; +using LinqToDB.Mapping; using EllieBot.Common.ModuleBehaviors; using EllieBot.Db.Models; @@ -66,67 +67,88 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService .Where(x => !tempTable.Select(x => x.GuildId) .Contains(x.GuildId)) .DeleteAsync(); - + // delete guild xp await ctx.GetTable() .Where(x => !tempTable.Select(x => x.GuildId) .Contains(x.GuildId)) .DeleteAsync(); - + // delete expressions await ctx.GetTable() - .Where(x => x.GuildId != null && !tempTable.Select(x => x.GuildId) - .Contains(x.GuildId.Value)) + .Where(x => x.GuildId != null + && !tempTable.Select(x => x.GuildId) + .Contains(x.GuildId.Value)) .DeleteAsync(); - + // delete quotes await ctx.GetTable() .Where(x => !tempTable.Select(x => x.GuildId) .Contains(x.GuildId)) .DeleteAsync(); - + // delete planted currencies await ctx.GetTable() .Where(x => !tempTable.Select(x => x.GuildId) .Contains(x.GuildId)) .DeleteAsync(); - + // delete image only channels await ctx.GetTable() .Where(x => !tempTable.Select(x => x.GuildId) .Contains(x.GuildId)) .DeleteAsync(); - + // delete reaction roles await ctx.GetTable() .Where(x => !tempTable.Select(x => x.GuildId) .Contains(x.GuildId)) .DeleteAsync(); - + // delete ignored users await ctx.GetTable() - .Where(x => x.GuildId != null && !tempTable.Select(x => x.GuildId) - .Contains(x.GuildId.Value)) + .Where(x => x.GuildId != null + && !tempTable.Select(x => x.GuildId) + .Contains(x.GuildId.Value)) .DeleteAsync(); - + // delete perm overrides await ctx.GetTable() - .Where(x => x.GuildId != null && !tempTable.Select(x => x.GuildId) - .Contains(x.GuildId.Value)) + .Where(x => x.GuildId != null + && !tempTable.Select(x => x.GuildId) + .Contains(x.GuildId.Value)) .DeleteAsync(); - + // delete repeaters await ctx.GetTable() .Where(x => !tempTable.Select(x => x.GuildId) .Contains(x.GuildId)) .DeleteAsync(); - + return new() { GuildCount = guildIds.Keys.Count, }; } - + + public async Task KeepGuild(ulong guildId) + { + 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; + + await table.InsertAsync(() => new() + { + GuildId = guildId + }); + + return true; + } + private ValueTask OnKeepReport(KeepReport report) { guildIds[report.ShardId] = report.GuildIds; @@ -152,4 +174,10 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService return default; } +} + +public class KeptGuilds +{ + [PrimaryKey] + public ulong GuildId { get; set; } } \ No newline at end of file diff --git a/src/EllieBot/Modules/Administration/DangerousCommands/_common/ICleanupService.cs b/src/EllieBot/Modules/Administration/DangerousCommands/_common/ICleanupService.cs index a396082..5d4a720 100644 --- a/src/EllieBot/Modules/Administration/DangerousCommands/_common/ICleanupService.cs +++ b/src/EllieBot/Modules/Administration/DangerousCommands/_common/ICleanupService.cs @@ -3,4 +3,5 @@ public interface ICleanupService { Task DeleteMissingGuildDataAsync(); + Task KeepGuild(ulong guildId); } \ No newline at end of file diff --git a/src/EllieBot/data/aliases.yml b/src/EllieBot/data/aliases.yml index 8e9ff14..a6b5e16 100644 --- a/src/EllieBot/data/aliases.yml +++ b/src/EllieBot/data/aliases.yml @@ -1416,4 +1416,6 @@ coins: - crypto - cryptos afk: - - afk \ No newline at end of file + - afk +keep: + - keep \ No newline at end of file diff --git a/src/EllieBot/data/strings/commands/commands.en-US.yml b/src/EllieBot/data/strings/commands/commands.en-US.yml index f5d5a6d..2ba8bc7 100644 --- a/src/EllieBot/data/strings/commands/commands.en-US.yml +++ b/src/EllieBot/data/strings/commands/commands.en-US.yml @@ -4598,4 +4598,11 @@ afk: - '' params: - msg: - desc: "The message to send when someone pings you." \ No newline at end of file + desc: "The message to send when someone pings you." +keep: + desc: |- + The current serve, won't be deleted from Ellie's database during the purge. + ex: + - '' + params: + - {} \ No newline at end of file