.lsar is now paginated
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
using Discord;
 | 
			
		||||
using Discord.Commands;
 | 
			
		||||
using Discord.WebSocket;
 | 
			
		||||
using NadekoBot.Attributes;
 | 
			
		||||
using NadekoBot.Extensions;
 | 
			
		||||
using NadekoBot.Services;
 | 
			
		||||
@@ -105,8 +106,11 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
 | 
			
		||||
            [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
            [RequireContext(ContextType.Guild)]
 | 
			
		||||
            public async Task Lsar()
 | 
			
		||||
            public async Task Lsar(int page = 1)
 | 
			
		||||
            {
 | 
			
		||||
                if (--page < 0)
 | 
			
		||||
                    return;
 | 
			
		||||
 | 
			
		||||
                var toRemove = new ConcurrentHashSet<SelfAssignedRole>();
 | 
			
		||||
                var removeMsg = new StringBuilder();
 | 
			
		||||
                var roles = new List<string>();
 | 
			
		||||
@@ -131,11 +135,18 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                    }
 | 
			
		||||
                    foreach (var role in toRemove)
 | 
			
		||||
                    {
 | 
			
		||||
                        removeMsg.AppendLine(GetText("role_clean", role.RoleId));
 | 
			
		||||
                        roles.Add(GetText("role_clean", role.RoleId));
 | 
			
		||||
                    }
 | 
			
		||||
                    await uow.CompleteAsync();
 | 
			
		||||
                }
 | 
			
		||||
                await Context.Channel.SendConfirmAsync(GetText("self_assign_list", roleCnt), "\n" + string.Join(", ", roles) + "\n\n" + removeMsg).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
                await Context.Channel.SendPaginatedConfirmAsync((DiscordShardedClient)Context.Client, page, (curPage) =>
 | 
			
		||||
                {
 | 
			
		||||
                    return new EmbedBuilder()
 | 
			
		||||
                        .WithTitle(GetText("self_assign_list", roleCnt))
 | 
			
		||||
                        .WithDescription(string.Join("\n", roles.Skip(curPage * 10).Take(10)))
 | 
			
		||||
                        .WithOkColor();
 | 
			
		||||
                }, roles.Count / 10);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
            [RequireContext(ContextType.Guild)]
 | 
			
		||||
            public async Task Timezones(int page = 1)
 | 
			
		||||
            {
 | 
			
		||||
                page -= 1;
 | 
			
		||||
                page--;
 | 
			
		||||
 | 
			
		||||
                if (page < 0 || page > 20)
 | 
			
		||||
                    return;
 | 
			
		||||
@@ -36,11 +36,11 @@ namespace NadekoBot.Modules.Administration
 | 
			
		||||
                    .ToArray();
 | 
			
		||||
                var timezonesPerPage = 20;
 | 
			
		||||
 | 
			
		||||
                await Context.Channel.SendPaginatedConfirmAsync((DiscordShardedClient)Context.Client, page + 1, 
 | 
			
		||||
                await Context.Channel.SendPaginatedConfirmAsync((DiscordShardedClient)Context.Client, page, 
 | 
			
		||||
                    (curPage) => new EmbedBuilder()
 | 
			
		||||
                        .WithOkColor()
 | 
			
		||||
                        .WithTitle(GetText("timezones_available"))
 | 
			
		||||
                        .WithDescription(string.Join("\n", timezones.Skip((curPage - 1) * timezonesPerPage).Take(timezonesPerPage).Select(x => $"`{x.Id,-25}` {(x.BaseUtcOffset < TimeSpan.Zero? "-" : "+")}{x.BaseUtcOffset:hhmm}"))),
 | 
			
		||||
                        .WithDescription(string.Join("\n", timezones.Skip(curPage * timezonesPerPage).Take(timezonesPerPage).Select(x => $"`{x.Id,-25}` {(x.BaseUtcOffset < TimeSpan.Zero? "-" : "+")}{x.BaseUtcOffset:hhmm}"))),
 | 
			
		||||
                    timezones.Length / timezonesPerPage);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -87,7 +87,7 @@ namespace NadekoBot.Modules.CustomReactions
 | 
			
		||||
        [Priority(0)]
 | 
			
		||||
        public async Task ListCustReact(int page = 1)
 | 
			
		||||
        {
 | 
			
		||||
            if (page < 1 || page > 1000)
 | 
			
		||||
            if (--page < 0 || page > 999)
 | 
			
		||||
                return;
 | 
			
		||||
            CustomReaction[] customReactions;
 | 
			
		||||
            if (Context.Guild == null)
 | 
			
		||||
@@ -106,7 +106,7 @@ namespace NadekoBot.Modules.CustomReactions
 | 
			
		||||
                new EmbedBuilder().WithOkColor()
 | 
			
		||||
                    .WithTitle(GetText("name"))
 | 
			
		||||
                    .WithDescription(string.Join("\n", customReactions.OrderBy(cr => cr.Trigger)
 | 
			
		||||
                                                    .Skip((curPage - 1) * 20)
 | 
			
		||||
                                                    .Skip(curPage * 20)
 | 
			
		||||
                                                    .Take(20)
 | 
			
		||||
                                                    .Select(cr =>
 | 
			
		||||
                                                    {
 | 
			
		||||
@@ -161,7 +161,7 @@ namespace NadekoBot.Modules.CustomReactions
 | 
			
		||||
        [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
        public async Task ListCustReactG(int page = 1)
 | 
			
		||||
        {
 | 
			
		||||
            if (page < 1 || page > 10000)
 | 
			
		||||
            if (--page < 0 || page > 9999)
 | 
			
		||||
                return;
 | 
			
		||||
            CustomReaction[] customReactions;
 | 
			
		||||
            if (Context.Guild == null)
 | 
			
		||||
@@ -185,7 +185,7 @@ namespace NadekoBot.Modules.CustomReactions
 | 
			
		||||
                    new EmbedBuilder().WithOkColor()
 | 
			
		||||
                        .WithTitle(GetText("name"))
 | 
			
		||||
                        .WithDescription(string.Join("\r\n", ordered
 | 
			
		||||
                                                         .Skip((curPage - 1) * 20)
 | 
			
		||||
                                                         .Skip(curPage * 20)
 | 
			
		||||
                                                         .Take(20)
 | 
			
		||||
                                                         .Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))), lastPage)
 | 
			
		||||
                             .ConfigureAwait(false);
 | 
			
		||||
@@ -399,14 +399,14 @@ namespace NadekoBot.Modules.CustomReactions
 | 
			
		||||
        [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
        public async Task CrStats(int page = 1)
 | 
			
		||||
        {
 | 
			
		||||
            if (page < 1)
 | 
			
		||||
            if (--page < 0)
 | 
			
		||||
                return;
 | 
			
		||||
            var ordered = _crs.ReactionStats.OrderByDescending(x => x.Value).ToArray();
 | 
			
		||||
            if (!ordered.Any())
 | 
			
		||||
                return;
 | 
			
		||||
            var lastPage = ordered.Length / 9;
 | 
			
		||||
            await Context.Channel.SendPaginatedConfirmAsync(_client, page,
 | 
			
		||||
                (curPage) => ordered.Skip((curPage - 1) * 9)
 | 
			
		||||
                (curPage) => ordered.Skip(curPage * 9)
 | 
			
		||||
                                    .Take(9)
 | 
			
		||||
                                    .Aggregate(new EmbedBuilder().WithOkColor().WithTitle(GetText("stats")),
 | 
			
		||||
                                            (agg, cur) => agg.AddField(efb => efb.WithName(cur.Key).WithValue(cur.Value.ToString()).WithIsInline(true))), lastPage)
 | 
			
		||||
 
 | 
			
		||||
@@ -46,9 +46,8 @@ namespace NadekoBot.Modules.Gambling
 | 
			
		||||
            [RequireContext(ContextType.Guild)]
 | 
			
		||||
            public async Task Shop(int page = 1)
 | 
			
		||||
            {
 | 
			
		||||
                if (page <= 0)
 | 
			
		||||
                if (--page < 0)
 | 
			
		||||
                    return;
 | 
			
		||||
                page -= 1;
 | 
			
		||||
                List<ShopEntry> entries;
 | 
			
		||||
                using (var uow = _db.UnitOfWork)
 | 
			
		||||
                {
 | 
			
		||||
@@ -57,9 +56,9 @@ namespace NadekoBot.Modules.Gambling
 | 
			
		||||
                                  .ThenInclude(x => x.Items)).ShopEntries);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                await Context.Channel.SendPaginatedConfirmAsync(_client, page + 1, (curPage) =>
 | 
			
		||||
                await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) =>
 | 
			
		||||
                {
 | 
			
		||||
                    var theseEntries = entries.Skip((curPage - 1) * 9).Take(9);
 | 
			
		||||
                    var theseEntries = entries.Skip(curPage * 9).Take(9);
 | 
			
		||||
 | 
			
		||||
                    if (!theseEntries.Any())
 | 
			
		||||
                        return new EmbedBuilder().WithErrorColor()
 | 
			
		||||
 
 | 
			
		||||
@@ -244,7 +244,8 @@ namespace NadekoBot.Modules.Music
 | 
			
		||||
                await ReplyErrorLocalized("no_player").ConfigureAwait(false);
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
            if (page <= 0)
 | 
			
		||||
 | 
			
		||||
            if (--page < 0)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            try { await musicPlayer.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { }
 | 
			
		||||
@@ -260,7 +261,7 @@ namespace NadekoBot.Modules.Music
 | 
			
		||||
            var lastPage = musicPlayer.Playlist.Count / itemsPerPage;
 | 
			
		||||
            Func<int, EmbedBuilder> printAction = curPage =>
 | 
			
		||||
            {
 | 
			
		||||
                var startAt = itemsPerPage * (curPage - 1);
 | 
			
		||||
                var startAt = itemsPerPage * curPage;
 | 
			
		||||
                var number = 0 + startAt;
 | 
			
		||||
                var desc = string.Join("\n", musicPlayer.Playlist
 | 
			
		||||
                        .Skip(startAt)
 | 
			
		||||
@@ -277,7 +278,7 @@ namespace NadekoBot.Modules.Music
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                var embed = new EmbedBuilder()
 | 
			
		||||
                    .WithAuthor(eab => eab.WithName(GetText("player_queue", curPage, lastPage + 1))
 | 
			
		||||
                    .WithAuthor(eab => eab.WithName(GetText("player_queue", curPage + 1, lastPage + 1))
 | 
			
		||||
                        .WithMusicIcon())
 | 
			
		||||
                    .WithDescription(desc)
 | 
			
		||||
                    .WithFooter(ef => ef.WithText($"{musicPlayer.PrettyVolume} | {musicPlayer.Playlist.Count} " +
 | 
			
		||||
 
 | 
			
		||||
@@ -124,12 +124,12 @@ namespace NadekoBot.Modules.Utility
 | 
			
		||||
 | 
			
		||||
                var arr = maps.ToArray();
 | 
			
		||||
 | 
			
		||||
                await Context.Channel.SendPaginatedConfirmAsync(_client, page + 1, (curPage) =>
 | 
			
		||||
                await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) =>
 | 
			
		||||
                {
 | 
			
		||||
                    return new EmbedBuilder().WithOkColor()
 | 
			
		||||
                    .WithTitle(GetText("alias_list"))
 | 
			
		||||
                    .WithDescription(string.Join("\n",
 | 
			
		||||
                        arr.Skip((curPage - 1) * 10).Take(10).Select(x => $"`{x.Key}` => `{x.Value}`")));
 | 
			
		||||
                        arr.Skip(curPage * 10).Take(10).Select(x => $"`{x.Key}` => `{x.Value}`")));
 | 
			
		||||
 | 
			
		||||
                }, arr.Length / 10).ConfigureAwait(false);
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -356,7 +356,7 @@ namespace NadekoBot.Modules.Utility
 | 
			
		||||
        [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
        public async Task ShardStats(int page = 1)
 | 
			
		||||
        {
 | 
			
		||||
            if (page < 1)
 | 
			
		||||
            if (--page < 0)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            var status = string.Join(", ", _client.Shards.GroupBy(x => x.ConnectionState)
 | 
			
		||||
@@ -374,7 +374,7 @@ namespace NadekoBot.Modules.Utility
 | 
			
		||||
            await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) =>
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
                var str = string.Join("\n", allShardStrings.Skip(25 * (curPage - 1)).Take(25));
 | 
			
		||||
                var str = string.Join("\n", allShardStrings.Skip(25 * curPage).Take(25));
 | 
			
		||||
 | 
			
		||||
                if (string.IsNullOrWhiteSpace(str))
 | 
			
		||||
                    str = GetText("no_shards_on_page");
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,6 @@ namespace NadekoBot.Extensions
 | 
			
		||||
        /// </summary>
 | 
			
		||||
        public static async Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordShardedClient client, int currentPage, Func<int, EmbedBuilder> pageFunc, int? lastPage = null, bool addPaginatedFooter = true)
 | 
			
		||||
        {
 | 
			
		||||
            lastPage += 1;
 | 
			
		||||
            var embed = pageFunc(currentPage);
 | 
			
		||||
 | 
			
		||||
            if(addPaginatedFooter)
 | 
			
		||||
@@ -62,7 +61,7 @@ namespace NadekoBot.Extensions
 | 
			
		||||
 | 
			
		||||
            var msg = await channel.EmbedAsync(embed) as IUserMessage;
 | 
			
		||||
 | 
			
		||||
            if (currentPage >= lastPage && lastPage == 1)
 | 
			
		||||
            if (lastPage == 0)
 | 
			
		||||
                return;
 | 
			
		||||
 | 
			
		||||
            
 | 
			
		||||
@@ -77,7 +76,7 @@ namespace NadekoBot.Extensions
 | 
			
		||||
                {
 | 
			
		||||
                    if (r.Emote.Name == arrow_left.Name)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (currentPage == 1)
 | 
			
		||||
                        if (currentPage == 0)
 | 
			
		||||
                            return;
 | 
			
		||||
                        var toSend = pageFunc(--currentPage);
 | 
			
		||||
                        if (addPaginatedFooter)
 | 
			
		||||
@@ -109,7 +108,7 @@ namespace NadekoBot.Extensions
 | 
			
		||||
        private static EmbedBuilder AddPaginatedFooter(this EmbedBuilder embed, int curPage, int? lastPage)
 | 
			
		||||
        {
 | 
			
		||||
            if (lastPage != null)
 | 
			
		||||
                return embed.WithFooter(efb => efb.WithText($"{curPage} / {lastPage}"));
 | 
			
		||||
                return embed.WithFooter(efb => efb.WithText($"{curPage + 1} / {lastPage + 1}"));
 | 
			
		||||
            else
 | 
			
		||||
                return embed.WithFooter(efb => efb.WithText(curPage.ToString()));
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user