Added pagination to .reroli

This commit is contained in:
Kwoth
2022-09-14 02:44:31 +02:00
parent 75f8254a8e
commit 62ec2241e4

View File

@@ -67,42 +67,52 @@ public partial class Administration
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
[UserPerm(GuildPerm.ManageRoles)] [UserPerm(GuildPerm.ManageRoles)]
[BotPerm(GuildPerm.ManageRoles)] [BotPerm(GuildPerm.ManageRoles)]
public async Task ReactionRolesList() public async Task ReactionRolesList(int page = 1)
{ {
if (--page < 0)
return;
var reros = await _rero.GetReactionRolesAsync(ctx.Guild.Id); var reros = await _rero.GetReactionRolesAsync(ctx.Guild.Id);
var embed = _eb.Create(ctx) await ctx.SendPaginatedConfirmAsync(page, curPage =>
.WithOkColor();
var content = string.Empty;
foreach (var g in reros.GroupBy(x => x.MessageId).OrderBy(x => x.Key))
{ {
var messageId = g.Key; var embed = _eb.Create(ctx)
content += .WithOkColor();
$"[{messageId}](https://discord.com/channels/{ctx.Guild.Id}/{g.First().ChannelId}/{g.Key})\n";
var groupGroups = g.GroupBy(x => x.Group); var content = string.Empty;
foreach (var g in reros.OrderBy(x => x.Group)
foreach (var ggs in groupGroups) .Skip(curPage * 10)
.GroupBy(x => x.MessageId)
.OrderBy(x => x.Key))
{ {
content += $"`< {(g.Key == 0 ? ("Not Exclusive (Group 0)") : ($"Group {ggs.Key}"))} >`\n"; var messageId = g.Key;
content +=
$"[{messageId}](https://discord.com/channels/{ctx.Guild.Id}/{g.First().ChannelId}/{g.Key})\n";
foreach (var rero in ggs) var groupGroups = g.GroupBy(x => x.Group);
foreach (var ggs in groupGroups)
{ {
content += $"\t{rero.Emote} -> {(ctx.Guild.GetRole(rero.RoleId)?.Mention ?? "<missing role>")}"; content += $"`< {(g.Key == 0 ? ("Not Exclusive (Group 0)") : ($"Group {ggs.Key}"))} >`\n";
if (rero.LevelReq > 0)
content += $" (lvl {rero.LevelReq}+)"; foreach (var rero in ggs)
content += '\n'; {
content +=
$"\t{rero.Emote} -> {(ctx.Guild.GetRole(rero.RoleId)?.Mention ?? "<missing role>")}";
if (rero.LevelReq > 0)
content += $" (lvl {rero.LevelReq}+)";
content += '\n';
}
} }
} }
} embed.WithDescription(string.IsNullOrWhiteSpace(content)
? "There are no reaction roles on this server"
: content);
embed.WithDescription(string.IsNullOrWhiteSpace(content) return embed;
? "There are no reaction roles on this server" }, reros.Count, 10);
: content);
await ctx.Channel.EmbedAsync(embed);
} }
[Cmd] [Cmd]