コード例 #1
0
        public async Task ShowBlacklisted(Context ctx)
        {
            ctx.CheckGuildContext().CheckAuthorPermission(PermissionSet.ManageGuild, "Manage Server");

            var blacklist = await _db.Execute(c => _repo.GetGuild(c, ctx.Guild.Id));

            // Resolve all channels from the cache and order by position
            var channels = blacklist.Blacklist
                           .Select(id => _cache.GetChannelOrNull(id))
                           .Where(c => c != null)
                           .OrderBy(c => c.Position)
                           .ToList();

            if (channels.Count == 0)
            {
                await ctx.Reply($"This server has no blacklisted channels.");

                return;
            }

            await ctx.Paginate(channels.ToAsyncEnumerable(), channels.Count, 25,
                               $"Blacklisted channels for {ctx.Guild.Name}",
                               null,
                               (eb, l) =>
            {
                string CategoryName(ulong?id) =>
                id != null ? _cache.GetChannel(id.Value).Name : "(no category)";

                ulong?lastCategory = null;

                var fieldValue = new StringBuilder();
                foreach (var channel in l)
                {
                    if (lastCategory != channel !.ParentId && fieldValue.Length > 0)
                    {
                        eb.Field(new(CategoryName(lastCategory), fieldValue.ToString()));
                        fieldValue.Clear();
                    }