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:
parent
ddbf8fd3de
commit
13fa7bd17b
5 changed files with 67 additions and 19 deletions
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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;
|
||||||
|
|
||||||
|
@ -66,67 +67,88 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
||||||
.Where(x => !tempTable.Select(x => x.GuildId)
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
.Contains(x.GuildId))
|
.Contains(x.GuildId))
|
||||||
.DeleteAsync();
|
.DeleteAsync();
|
||||||
|
|
||||||
// delete guild xp
|
// delete guild xp
|
||||||
await ctx.GetTable<UserXpStats>()
|
await ctx.GetTable<UserXpStats>()
|
||||||
.Where(x => !tempTable.Select(x => x.GuildId)
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
.Contains(x.GuildId))
|
.Contains(x.GuildId))
|
||||||
.DeleteAsync();
|
.DeleteAsync();
|
||||||
|
|
||||||
// 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
|
||||||
await ctx.GetTable<Quote>()
|
await ctx.GetTable<Quote>()
|
||||||
.Where(x => !tempTable.Select(x => x.GuildId)
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
.Contains(x.GuildId))
|
.Contains(x.GuildId))
|
||||||
.DeleteAsync();
|
.DeleteAsync();
|
||||||
|
|
||||||
// delete planted currencies
|
// delete planted currencies
|
||||||
await ctx.GetTable<PlantedCurrency>()
|
await ctx.GetTable<PlantedCurrency>()
|
||||||
.Where(x => !tempTable.Select(x => x.GuildId)
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
.Contains(x.GuildId))
|
.Contains(x.GuildId))
|
||||||
.DeleteAsync();
|
.DeleteAsync();
|
||||||
|
|
||||||
// delete image only channels
|
// delete image only channels
|
||||||
await ctx.GetTable<ImageOnlyChannel>()
|
await ctx.GetTable<ImageOnlyChannel>()
|
||||||
.Where(x => !tempTable.Select(x => x.GuildId)
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
.Contains(x.GuildId))
|
.Contains(x.GuildId))
|
||||||
.DeleteAsync();
|
.DeleteAsync();
|
||||||
|
|
||||||
// delete reaction roles
|
// delete reaction roles
|
||||||
await ctx.GetTable<ReactionRoleV2>()
|
await ctx.GetTable<ReactionRoleV2>()
|
||||||
.Where(x => !tempTable.Select(x => x.GuildId)
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
.Contains(x.GuildId))
|
.Contains(x.GuildId))
|
||||||
.DeleteAsync();
|
.DeleteAsync();
|
||||||
|
|
||||||
// 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
|
||||||
await ctx.GetTable<Repeater>()
|
await ctx.GetTable<Repeater>()
|
||||||
.Where(x => !tempTable.Select(x => x.GuildId)
|
.Where(x => !tempTable.Select(x => x.GuildId)
|
||||||
.Contains(x.GuildId))
|
.Contains(x.GuildId))
|
||||||
.DeleteAsync();
|
.DeleteAsync();
|
||||||
|
|
||||||
return new()
|
return new()
|
||||||
{
|
{
|
||||||
GuildCount = guildIds.Keys.Count,
|
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)
|
private ValueTask OnKeepReport(KeepReport report)
|
||||||
{
|
{
|
||||||
guildIds[report.ShardId] = report.GuildIds;
|
guildIds[report.ShardId] = report.GuildIds;
|
||||||
|
@ -152,4 +174,10 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class KeptGuilds
|
||||||
|
{
|
||||||
|
[PrimaryKey]
|
||||||
|
public ulong GuildId { get; set; }
|
||||||
}
|
}
|
|
@ -3,4 +3,5 @@
|
||||||
public interface ICleanupService
|
public interface ICleanupService
|
||||||
{
|
{
|
||||||
Task<KeepResult?> DeleteMissingGuildDataAsync();
|
Task<KeepResult?> DeleteMissingGuildDataAsync();
|
||||||
|
Task<bool> KeepGuild(ulong guildId);
|
||||||
}
|
}
|
|
@ -1416,4 +1416,6 @@ coins:
|
||||||
- crypto
|
- crypto
|
||||||
- cryptos
|
- cryptos
|
||||||
afk:
|
afk:
|
||||||
- afk
|
- afk
|
||||||
|
keep:
|
||||||
|
- keep
|
|
@ -4598,4 +4598,11 @@ 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:
|
||||||
|
- {}
|
Loading…
Reference in a new issue