diff --git a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs index de22a10b..6ac3c41f 100644 --- a/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs +++ b/src/NadekoBot/Modules/Administration/Commands/SelfAssignedRolesCommand.cs @@ -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(); var removeMsg = new StringBuilder(); var roles = new List(); @@ -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] diff --git a/src/NadekoBot/Modules/Administration/Commands/TimeZoneCommands.cs b/src/NadekoBot/Modules/Administration/Commands/TimeZoneCommands.cs index 65dfa1de..e054288c 100644 --- a/src/NadekoBot/Modules/Administration/Commands/TimeZoneCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/TimeZoneCommands.cs @@ -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); } diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index aacefe8d..5dac3b9c 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -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) diff --git a/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs b/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs index c755cc2c..dfc8d648 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs @@ -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 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() diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 2210dd9b..afb34192 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -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 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} " + diff --git a/src/NadekoBot/Modules/Utility/Commands/CommandMapCommands.cs b/src/NadekoBot/Modules/Utility/Commands/CommandMapCommands.cs index e5294fc6..d38cfb90 100644 --- a/src/NadekoBot/Modules/Utility/Commands/CommandMapCommands.cs +++ b/src/NadekoBot/Modules/Utility/Commands/CommandMapCommands.cs @@ -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); } diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 78bc03bd..4774a266 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -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"); diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 7ed4f270..362a1184 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -54,7 +54,6 @@ namespace NadekoBot.Extensions /// public static async Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordShardedClient client, int currentPage, Func 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())); }