Redo blacklist list fetching/rendering

This commit is contained in:
Ske 2020-07-05 13:08:18 +02:00
parent 01d25ca391
commit da9bfbb46d

View File

@ -77,22 +77,27 @@ namespace PluralKit.Bot
{ {
ctx.CheckGuildContext().CheckAuthorPermission(Permissions.ManageGuild, "Manage Server"); ctx.CheckGuildContext().CheckAuthorPermission(Permissions.ManageGuild, "Manage Server");
await using (var conn = await _db.Obtain()) var blacklist = await _db.Execute(c => c.QueryOrInsertGuildConfig(ctx.Guild.Id));
{
var guild = await conn.QueryOrInsertGuildConfig(ctx.Guild.Id);
List<string> blacklist = new List<string>();
foreach (ulong item in guild.Blacklist.ToHashSet()) { // Resolve all channels from the cache and order by position
blacklist.Add($"<#{item}>"); var channels = blacklist.Blacklist
.Select(id => ctx.Guild.GetChannel(id))
.OrderBy(c => c.Position)
.ToList();
if (channels.Count == 0)
{
await ctx.Reply($"This server has no blacklisted channels.");
return;
} }
await ctx.Paginate(blacklist.ToAsyncEnumerable(), blacklist.Count, 25, $"Blacklisted channels for {ctx.Guild.Name}", await ctx.Paginate(channels.ToAsyncEnumerable(), channels.Count, 25,
(eb, l) => { $"Blacklisted channels for {ctx.Guild.Name}",
eb.Description += string.Join("\n", l); (eb, l) =>
{
eb.Description = string.Join("\n", l.Select(c => c.Mention));
return Task.CompletedTask; return Task.CompletedTask;
}); });
}
} }
public async Task SetBlacklisted(Context ctx, bool shouldAdd) public async Task SetBlacklisted(Context ctx, bool shouldAdd)