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.")
.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.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<UserXpStats>()
.Where(x => !tempTable.Select(x => x.GuildId)
.Contains(x.GuildId))
.DeleteAsync();
// delete expressions
await ctx.GetTable<EllieExpression>()
.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<Quote>()
.Where(x => !tempTable.Select(x => x.GuildId)
.Contains(x.GuildId))
.DeleteAsync();
// delete planted currencies
await ctx.GetTable<PlantedCurrency>()
.Where(x => !tempTable.Select(x => x.GuildId)
.Contains(x.GuildId))
.DeleteAsync();
// delete image only channels
await ctx.GetTable<ImageOnlyChannel>()
.Where(x => !tempTable.Select(x => x.GuildId)
.Contains(x.GuildId))
.DeleteAsync();
// delete reaction roles
await ctx.GetTable<ReactionRoleV2>()
.Where(x => !tempTable.Select(x => x.GuildId)
.Contains(x.GuildId))
.DeleteAsync();
// delete ignored users
await ctx.GetTable<DiscordPermOverride>()
.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<DiscordPermOverride>()
.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<Repeater>()
.Where(x => !tempTable.Select(x => x.GuildId)
.Contains(x.GuildId))
.DeleteAsync();
return new()
{
GuildCount = guildIds.Keys.Count,
};
}
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)
{
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; }
}

View file

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

View file

@ -1416,4 +1416,6 @@ coins:
- crypto
- cryptos
afk:
- afk
- afk
keep:
- keep

View file

@ -4598,4 +4598,11 @@ afk:
- ''
params:
- 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:
- {}