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))
.WithDescription(string.Join("\n", roles.Skip(curPage * 10).Take(10)))
.WithOkColor();
}, roles.Count / 10);
}, roles.Count, 10);
}
[NadekoCommand, Usage, Description, Aliases]

View File

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

View File

@ -34,7 +34,7 @@ namespace NadekoBot.Modules.Administration
.WithOkColor()
.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}"))),
timezones.Length / timezonesPerPage);
timezones.Length, timezonesPerPage);
}
[NadekoCommand, Usage, Description, Aliases]

View File

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

View File

@ -152,7 +152,6 @@ namespace NadekoBot.Modules.CustomReactions
return;
}
var lastPage = customReactions.Length / 20;
await Context.Channel.SendPaginatedConfirmAsync(_client, page, curPage =>
new EmbedBuilder().WithOkColor()
.WithTitle(GetText("name"))
@ -171,7 +170,7 @@ namespace NadekoBot.Modules.CustomReactions
str = "📪" + str;
}
return str;
}))), lastPage)
}))), customReactions.Length, 20)
.ConfigureAwait(false);
}
@ -231,15 +230,14 @@ namespace NadekoBot.Modules.CustomReactions
.OrderBy(cr => cr.Key)
.ToList();
var lastPage = ordered.Count / 20;
await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) =>
new EmbedBuilder().WithOkColor()
.WithTitle(GetText("name"))
.WithDescription(string.Join("\r\n", ordered
.Skip(curPage * 20)
.Take(20)
.Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))), lastPage)
.ConfigureAwait(false);
.Select(cr => $"**{cr.Key.Trim().ToLowerInvariant()}** `x{cr.Count()}`"))),
ordered.Count, 20).ConfigureAwait(false);
}
}
@ -492,12 +490,12 @@ namespace NadekoBot.Modules.CustomReactions
var ordered = _service.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 * 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)
(agg, cur) => agg.AddField(efb => efb.WithName(cur.Key).WithValue(cur.Value.ToString()).WithIsInline(true))),
ordered.Length, 9)
.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));
}
return embed;
}, entries.Count / 9, true);
}, entries.Count, 9, true);
}
[NadekoCommand, Usage, Description, Aliases]

View File

@ -258,7 +258,6 @@ namespace NadekoBot.Modules.Music
total.Minutes,
total.Seconds);
var maxPlaytime = mp.MaxPlaytimeSeconds;
var lastPage = songs.Length / itemsPerPage;
Func<int, EmbedBuilder> printAction = curPage =>
{
var startAt = itemsPerPage * curPage;
@ -300,7 +299,7 @@ namespace NadekoBot.Modules.Music
desc = add + "\n" + desc;
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())
.WithDescription(desc)
.WithFooter(ef => ef.WithText($"{mp.PrettyVolume} | {songs.Length} " +
@ -309,7 +308,8 @@ namespace NadekoBot.Modules.Music
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]

View File

@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Permissions
new EmbedBuilder()
.WithTitle(GetText("filter_word_list"))
.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);
}, feeds.Count / 10);
}, feeds.Count, 10);
}
}
}

View File

@ -126,7 +126,7 @@ namespace NadekoBot.Modules.Utility
.WithDescription(string.Join("\n",
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 Discord;
using Discord.Commands;
@ -7,7 +6,6 @@ using NadekoBot.Common.Collections;
using NadekoBot.Extensions;
using NadekoBot.Modules.Help.Services;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
namespace NadekoBot.Modules.Utility.Services
{

View File

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

View File

@ -236,7 +236,7 @@ namespace NadekoBot.Modules.Xp
}
return embed;
}
}, addPaginatedFooter: false);
}, 1000, 10, addPaginatedFooter: false);
}
[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_right = new Emoji("➡");
public static Task SendPaginatedConfirmAsync(this IMessageChannel channel, DiscordSocketClient client, int currentPage, Func<int, EmbedBuilder> pageFunc, int? lastPage = null, bool addPaginatedFooter = true) =>
channel.SendPaginatedConfirmAsync(client, currentPage, (x) => Task.FromResult(pageFunc(x)), lastPage, addPaginatedFooter);
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)), totalElements, itemsPerPage, addPaginatedFooter);
/// <summary>
/// danny kamisama
/// </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 lastPage = (totalElements - 1) / itemsPerPage;
if (addPaginatedFooter)
embed.AddPaginatedFooter(currentPage, lastPage);
@ -93,7 +95,7 @@ namespace NadekoBot.Extensions
}
else if (r.Emote.Name == arrow_right.Name)
{
if (lastPage == null || lastPage > currentPage)
if (lastPage > currentPage)
{
var toSend = await pageFunc(++currentPage).ConfigureAwait(false);
if (addPaginatedFooter)