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