Small pagination bugfix

This commit is contained in:
Master Kwoth 2017-10-17 16:10:51 +02:00
parent 88f92cbec6
commit e54ceba0ab
14 changed files with 28 additions and 30 deletions

View File

@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Administration
.WithTitle(GetText("self_assign_list", roleCnt)) .WithTitle(GetText("self_assign_list", roleCnt))
.WithDescription(string.Join("\n", roles.Skip(curPage * 10).Take(10))) .WithDescription(string.Join("\n", roles.Skip(curPage * 10).Take(10)))
.WithOkColor(); .WithOkColor();
}, roles.Count / 10); }, roles.Count, 10);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -259,7 +259,7 @@ namespace NadekoBot.Modules.Administration
.WithTitle(status) .WithTitle(status)
.WithOkColor() .WithOkColor()
.WithDescription(str); .WithDescription(str);
}, allShardStrings.Length / 25); }, allShardStrings.Length, 25);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -34,7 +34,7 @@ namespace NadekoBot.Modules.Administration
.WithOkColor() .WithOkColor()
.WithTitle(GetText("timezones_available")) .WithTitle(GetText("timezones_available"))
.WithDescription(string.Join("\n", timezones.Skip(curPage * 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); timezones.Length, timezonesPerPage);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -154,7 +154,7 @@ namespace NadekoBot.Modules.Administration
.WithTitle(GetText("warnings_list")) .WithTitle(GetText("warnings_list"))
.WithDescription(string.Join("\n", ws)); .WithDescription(string.Join("\n", ws));
}, warnings.Length / 15); }, warnings.Length, 15);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -152,7 +152,6 @@ namespace NadekoBot.Modules.CustomReactions
return; return;
} }
var lastPage = customReactions.Length / 20;
await Context.Channel.SendPaginatedConfirmAsync(_client, page, curPage => await Context.Channel.SendPaginatedConfirmAsync(_client, page, curPage =>
new EmbedBuilder().WithOkColor() new EmbedBuilder().WithOkColor()
.WithTitle(GetText("name")) .WithTitle(GetText("name"))
@ -171,7 +170,7 @@ namespace NadekoBot.Modules.CustomReactions
str = "📪" + str; str = "📪" + str;
} }
return str; return str;
}))), lastPage) }))), customReactions.Length, 20)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
@ -230,16 +229,15 @@ namespace NadekoBot.Modules.CustomReactions
.GroupBy(cr => cr.Trigger) .GroupBy(cr => cr.Trigger)
.OrderBy(cr => cr.Key) .OrderBy(cr => cr.Key)
.ToList(); .ToList();
var lastPage = ordered.Count / 20;
await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) => await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) =>
new EmbedBuilder().WithOkColor() new EmbedBuilder().WithOkColor()
.WithTitle(GetText("name")) .WithTitle(GetText("name"))
.WithDescription(string.Join("\r\n", ordered .WithDescription(string.Join("\r\n", ordered
.Skip(curPage * 20) .Skip(curPage * 20)
.Take(20) .Take(20)
.Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))), lastPage) .Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))),
.ConfigureAwait(false); ordered.Count, 20).ConfigureAwait(false);
} }
} }
@ -492,12 +490,12 @@ namespace NadekoBot.Modules.CustomReactions
var ordered = _service.ReactionStats.OrderByDescending(x => x.Value).ToArray(); var ordered = _service.ReactionStats.OrderByDescending(x => x.Value).ToArray();
if (!ordered.Any()) if (!ordered.Any())
return; return;
var lastPage = ordered.Length / 9;
await Context.Channel.SendPaginatedConfirmAsync(_client, page, await Context.Channel.SendPaginatedConfirmAsync(_client, page,
(curPage) => ordered.Skip(curPage * 9) (curPage) => ordered.Skip(curPage * 9)
.Take(9) .Take(9)
.Aggregate(new EmbedBuilder().WithOkColor().WithTitle(GetText("stats")), .Aggregate(new EmbedBuilder().WithOkColor().WithTitle(GetText("stats")),
(agg, cur) => agg.AddField(efb => efb.WithName(cur.Key).WithValue(cur.Value.ToString()).WithIsInline(true))), lastPage) (agg, cur) => agg.AddField(efb => efb.WithName(cur.Key).WithValue(cur.Value.ToString()).WithIsInline(true))),
ordered.Length, 9)
.ConfigureAwait(false); .ConfigureAwait(false);
} }
} }

View File

@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Gambling
embed.AddField(efb => efb.WithName($"#{curPage * 9 + i + 1} - {entry.Price}{_bc.BotConfig.CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true)); embed.AddField(efb => efb.WithName($"#{curPage * 9 + i + 1} - {entry.Price}{_bc.BotConfig.CurrencySign}").WithValue(EntryToString(entry)).WithIsInline(true));
} }
return embed; return embed;
}, entries.Count / 9, true); }, entries.Count, 9, true);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -258,7 +258,6 @@ namespace NadekoBot.Modules.Music
total.Minutes, total.Minutes,
total.Seconds); total.Seconds);
var maxPlaytime = mp.MaxPlaytimeSeconds; var maxPlaytime = mp.MaxPlaytimeSeconds;
var lastPage = songs.Length / itemsPerPage;
Func<int, EmbedBuilder> printAction = curPage => Func<int, EmbedBuilder> printAction = curPage =>
{ {
var startAt = itemsPerPage * curPage; var startAt = itemsPerPage * curPage;
@ -300,7 +299,7 @@ namespace NadekoBot.Modules.Music
desc = add + "\n" + desc; desc = add + "\n" + desc;
var embed = new EmbedBuilder() var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName(GetText("player_queue", curPage + 1, lastPage + 1)) .WithAuthor(eab => eab.WithName(GetText("player_queue", curPage + 1, (songs.Length / itemsPerPage) + 1))
.WithMusicIcon()) .WithMusicIcon())
.WithDescription(desc) .WithDescription(desc)
.WithFooter(ef => ef.WithText($"{mp.PrettyVolume} | {songs.Length} " + .WithFooter(ef => ef.WithText($"{mp.PrettyVolume} | {songs.Length} " +
@ -309,7 +308,8 @@ namespace NadekoBot.Modules.Music
return embed; return embed;
}; };
await Context.Channel.SendPaginatedConfirmAsync(_client, page, printAction, lastPage, false).ConfigureAwait(false); await Context.Channel.SendPaginatedConfirmAsync(_client,
page, printAction, songs.Length, itemsPerPage, false).ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Permissions
new EmbedBuilder() new EmbedBuilder()
.WithTitle(GetText("filter_word_list")) .WithTitle(GetText("filter_word_list"))
.WithDescription(string.Join("\n", fws.Skip(curPage * 10).Take(10))) .WithDescription(string.Join("\n", fws.Skip(curPage * 10).Take(10)))
, fws.Length / 10).ConfigureAwait(false); , fws.Length, 10).ConfigureAwait(false);
} }
} }
} }

View File

@ -103,7 +103,7 @@ namespace NadekoBot.Modules.Searches
return embed.WithDescription(fs); return embed.WithDescription(fs);
}, feeds.Count / 10); }, feeds.Count, 10);
} }
} }
} }

View File

@ -126,7 +126,7 @@ namespace NadekoBot.Modules.Utility
.WithDescription(string.Join("\n", .WithDescription(string.Join("\n",
arr.Skip(curPage * 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); }, arr.Length, 10).ConfigureAwait(false);
} }
} }
} }

View File

@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Linq;
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
@ -7,7 +6,6 @@ using NadekoBot.Common.Collections;
using NadekoBot.Extensions; using NadekoBot.Extensions;
using NadekoBot.Modules.Help.Services; using NadekoBot.Modules.Help.Services;
using NadekoBot.Core.Services; using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
namespace NadekoBot.Modules.Utility.Services namespace NadekoBot.Modules.Utility.Services
{ {

View File

@ -139,7 +139,7 @@ namespace NadekoBot.Modules.Xp
return embed.WithThumbnailUrl(club.ImageUrl); return embed.WithThumbnailUrl(club.ImageUrl);
return embed; return embed;
}, club.Users.Count / 10); }, club.Users.Count, 10);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
@ -170,7 +170,7 @@ namespace NadekoBot.Modules.Xp
.WithDescription(toShow) .WithDescription(toShow)
.WithOkColor(); .WithOkColor();
}, bans.Length / 10); }, bans.Length, 10);
} }
@ -202,7 +202,7 @@ namespace NadekoBot.Modules.Xp
.WithDescription(toShow) .WithDescription(toShow)
.WithOkColor(); .WithOkColor();
}, apps.Length / 10); }, apps.Length, 10);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -236,7 +236,7 @@ namespace NadekoBot.Modules.Xp
} }
return embed; return embed;
} }
}, addPaginatedFooter: false); }, 1000, 10, addPaginatedFooter: false);
} }
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]

View File

@ -55,15 +55,17 @@ namespace NadekoBot.Extensions
private static readonly IEmote arrow_left = new Emoji("⬅"); private static readonly IEmote arrow_left = new Emoji("⬅");
private static readonly IEmote arrow_right = new Emoji("➡"); private static readonly IEmote arrow_right = new Emoji("➡");
public static Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func<int, EmbedBuilder> pageFunc, int? lastPage = null, bool addPaginatedFooter = true) => public static Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func<int, EmbedBuilder> pageFunc, int totalElements, int itemsPerPage, bool addPaginatedFooter = true) =>
channel.SendPaginatedConfirmAsync(client, currentPage, (x) => Task.FromResult(pageFunc(x)), lastPage, addPaginatedFooter); channel.SendPaginatedConfirmAsync(client, currentPage, (x) => Task.FromResult(pageFunc(x)), totalElements, itemsPerPage, addPaginatedFooter);
/// <summary> /// <summary>
/// danny kamisama /// danny kamisama
/// </summary> /// </summary>
public static async Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func<int, Task<EmbedBuilder>> pageFunc, int? lastPage = null, bool addPaginatedFooter = true) public static async Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func<int, Task<EmbedBuilder>> pageFunc, int totalElements, int itemsPerPage, bool addPaginatedFooter = true)
{ {
var embed = await pageFunc(currentPage).ConfigureAwait(false); var embed = await pageFunc(currentPage).ConfigureAwait(false);
var lastPage = (totalElements - 1) / itemsPerPage;
if (addPaginatedFooter) if (addPaginatedFooter)
embed.AddPaginatedFooter(currentPage, lastPage); embed.AddPaginatedFooter(currentPage, lastPage);
@ -93,7 +95,7 @@ namespace NadekoBot.Extensions
} }
else if (r.Emote.Name == arrow_right.Name) else if (r.Emote.Name == arrow_right.Name)
{ {
if (lastPage == null || lastPage > currentPage) if (lastPage > currentPage)
{ {
var toSend = await pageFunc(++currentPage).ConfigureAwait(false); var toSend = await pageFunc(++currentPage).ConfigureAwait(false);
if (addPaginatedFooter) if (addPaginatedFooter)