Added .keep command which will add the current guild to the list of keptguilds. This is needed for the future database purge.

This commit is contained in:
Toastie (DCS Team) 2024-07-29 00:51:04 +12:00
parent ddbf8fd3de
commit 13fa7bd17b
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
5 changed files with 67 additions and 19 deletions

View file

@ -27,5 +27,15 @@ public partial class Administration
.Confirm($"{result.GuildCount} guilds' data remain in the database.") .Confirm($"{result.GuildCount} guilds' data remain in the database.")
.SendAsync(); .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();
}
} }
} }

View file

@ -1,6 +1,7 @@
using LinqToDB; using LinqToDB;
using LinqToDB.Data; using LinqToDB.Data;
using LinqToDB.EntityFrameworkCore; using LinqToDB.EntityFrameworkCore;
using LinqToDB.Mapping;
using EllieBot.Common.ModuleBehaviors; using EllieBot.Common.ModuleBehaviors;
using EllieBot.Db.Models; using EllieBot.Db.Models;
@ -75,8 +76,9 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
// delete expressions // delete expressions
await ctx.GetTable<EllieExpression>() await ctx.GetTable<EllieExpression>()
.Where(x => x.GuildId != null && !tempTable.Select(x => x.GuildId) .Where(x => x.GuildId != null
.Contains(x.GuildId.Value)) && !tempTable.Select(x => x.GuildId)
.Contains(x.GuildId.Value))
.DeleteAsync(); .DeleteAsync();
// delete quotes // delete quotes
@ -105,14 +107,16 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
// delete ignored users // delete ignored users
await ctx.GetTable<DiscordPermOverride>() await ctx.GetTable<DiscordPermOverride>()
.Where(x => x.GuildId != null && !tempTable.Select(x => x.GuildId) .Where(x => x.GuildId != null
.Contains(x.GuildId.Value)) && !tempTable.Select(x => x.GuildId)
.Contains(x.GuildId.Value))
.DeleteAsync(); .DeleteAsync();
// delete perm overrides // delete perm overrides
await ctx.GetTable<DiscordPermOverride>() await ctx.GetTable<DiscordPermOverride>()
.Where(x => x.GuildId != null && !tempTable.Select(x => x.GuildId) .Where(x => x.GuildId != null
.Contains(x.GuildId.Value)) && !tempTable.Select(x => x.GuildId)
.Contains(x.GuildId.Value))
.DeleteAsync(); .DeleteAsync();
// delete repeaters // delete repeaters
@ -127,6 +131,24 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
}; };
} }
public async Task<bool> KeepGuild(ulong guildId)
{
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;
await table.InsertAsync(() => new()
{
GuildId = guildId
});
return true;
}
private ValueTask OnKeepReport(KeepReport report) private ValueTask OnKeepReport(KeepReport report)
{ {
guildIds[report.ShardId] = report.GuildIds; guildIds[report.ShardId] = report.GuildIds;
@ -153,3 +175,9 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
return default; return default;
} }
} }
public class KeptGuilds
{
[PrimaryKey]
public ulong GuildId { get; set; }
}

View file

@ -3,4 +3,5 @@
public interface ICleanupService public interface ICleanupService
{ {
Task<KeepResult?> DeleteMissingGuildDataAsync(); Task<KeepResult?> DeleteMissingGuildDataAsync();
Task<bool> KeepGuild(ulong guildId);
} }

View file

@ -1417,3 +1417,5 @@ coins:
- cryptos - cryptos
afk: afk:
- afk - afk
keep:
- keep

View file

@ -4599,3 +4599,10 @@ afk:
params: params:
- msg: - msg:
desc: "The message to send when someone pings you." 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:
- {}