From da9bfbb46d9eb93cb65b86ae86b522da57b2cbad Mon Sep 17 00:00:00 2001 From: Ske Date: Sun, 5 Jul 2020 13:08:18 +0200 Subject: [PATCH] Redo blacklist list fetching/rendering --- PluralKit.Bot/Commands/ServerConfig.cs | 33 +++++++++++++++----------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/PluralKit.Bot/Commands/ServerConfig.cs b/PluralKit.Bot/Commands/ServerConfig.cs index fd6c7298..504bd06c 100644 --- a/PluralKit.Bot/Commands/ServerConfig.cs +++ b/PluralKit.Bot/Commands/ServerConfig.cs @@ -77,22 +77,27 @@ namespace PluralKit.Bot { 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)); + + // Resolve all channels from the cache and order by position + var channels = blacklist.Blacklist + .Select(id => ctx.Guild.GetChannel(id)) + .OrderBy(c => c.Position) + .ToList(); + + if (channels.Count == 0) { - var guild = await conn.QueryOrInsertGuildConfig(ctx.Guild.Id); - List blacklist = new List(); - - foreach (ulong item in guild.Blacklist.ToHashSet()) { - blacklist.Add($"<#{item}>"); - } - - await ctx.Paginate(blacklist.ToAsyncEnumerable(), blacklist.Count, 25, $"Blacklisted channels for {ctx.Guild.Name}", - (eb, l) => { - eb.Description += string.Join("\n", l); - return Task.CompletedTask; - }); - + await ctx.Reply($"This server has no blacklisted channels."); + return; } + + await ctx.Paginate(channels.ToAsyncEnumerable(), channels.Count, 25, + $"Blacklisted channels for {ctx.Guild.Name}", + (eb, l) => + { + eb.Description = string.Join("\n", l.Select(c => c.Mention)); + return Task.CompletedTask; + }); } public async Task SetBlacklisted(Context ctx, bool shouldAdd)