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.")
|
||||
.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.Data;
|
||||
using LinqToDB.EntityFrameworkCore;
|
||||
using LinqToDB.Mapping;
|
||||
using EllieBot.Common.ModuleBehaviors;
|
||||
using EllieBot.Db.Models;
|
||||
|
||||
|
@ -75,7 +76,8 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
|||
|
||||
// delete expressions
|
||||
await ctx.GetTable<EllieExpression>()
|
||||
.Where(x => x.GuildId != null && !tempTable.Select(x => x.GuildId)
|
||||
.Where(x => x.GuildId != null
|
||||
&& !tempTable.Select(x => x.GuildId)
|
||||
.Contains(x.GuildId.Value))
|
||||
.DeleteAsync();
|
||||
|
||||
|
@ -105,13 +107,15 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
|||
|
||||
// delete ignored users
|
||||
await ctx.GetTable<DiscordPermOverride>()
|
||||
.Where(x => x.GuildId != null && !tempTable.Select(x => x.GuildId)
|
||||
.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)
|
||||
.Where(x => x.GuildId != null
|
||||
&& !tempTable.Select(x => x.GuildId)
|
||||
.Contains(x.GuildId.Value))
|
||||
.DeleteAsync();
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
guildIds[report.ShardId] = report.GuildIds;
|
||||
|
@ -153,3 +175,9 @@ public sealed class CleanupService : ICleanupService, IReadyExecutor, IEService
|
|||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
public class KeptGuilds
|
||||
{
|
||||
[PrimaryKey]
|
||||
public ulong GuildId { get; set; }
|
||||
}
|
|
@ -3,4 +3,5 @@
|
|||
public interface ICleanupService
|
||||
{
|
||||
Task<KeepResult?> DeleteMissingGuildDataAsync();
|
||||
Task<bool> KeepGuild(ulong guildId);
|
||||
}
|
|
@ -1417,3 +1417,5 @@ coins:
|
|||
- cryptos
|
||||
afk:
|
||||
- afk
|
||||
keep:
|
||||
- keep
|
|
@ -4599,3 +4599,10 @@ afk:
|
|||
params:
|
||||
- msg:
|
||||
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