Add color to all lists
This commit is contained in:
parent
8da5c94b1c
commit
2898b3989a
@ -311,7 +311,7 @@ namespace PluralKit.Bot
|
|||||||
}
|
}
|
||||||
|
|
||||||
var title = system.Name != null ? $"Groups of {system.Name} (`{system.Hid}`)" : $"Groups of `{system.Hid}`";
|
var title = system.Name != null ? $"Groups of {system.Name} (`{system.Hid}`)" : $"Groups of `{system.Hid}`";
|
||||||
await ctx.Paginate(groups.ToAsyncEnumerable(), groups.Count, 25, title, Renderer);
|
await ctx.Paginate(groups.ToAsyncEnumerable(), groups.Count, 25, title, ctx.System.Color, Renderer);
|
||||||
|
|
||||||
Task Renderer(EmbedBuilder eb, IEnumerable<ListedGroup> page)
|
Task Renderer(EmbedBuilder eb, IEnumerable<ListedGroup> page)
|
||||||
{
|
{
|
||||||
@ -390,7 +390,7 @@ namespace PluralKit.Bot
|
|||||||
if (opts.Search != null)
|
if (opts.Search != null)
|
||||||
title.Append($" matching **{opts.Search}**");
|
title.Append($" matching **{opts.Search}**");
|
||||||
|
|
||||||
await ctx.RenderMemberList(ctx.LookupContextFor(target.System), _db, target.System, title.ToString(), opts);
|
await ctx.RenderMemberList(ctx.LookupContextFor(target.System), _db, target.System, title.ToString(), target.Color, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum AddRemoveOperation
|
public enum AddRemoveOperation
|
||||||
|
@ -78,7 +78,7 @@ namespace PluralKit.Bot
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task RenderMemberList(this Context ctx, LookupContext lookupCtx, IDatabase db, SystemId system, string embedTitle, MemberListOptions opts)
|
public static async Task RenderMemberList(this Context ctx, LookupContext lookupCtx, IDatabase db, SystemId system, string embedTitle, string color, MemberListOptions opts)
|
||||||
{
|
{
|
||||||
// We take an IDatabase instead of a IPKConnection so we don't keep the handle open for the entire runtime
|
// We take an IDatabase instead of a IPKConnection so we don't keep the handle open for the entire runtime
|
||||||
// We wanna release it as soon as the member list is actually *fetched*, instead of potentially minutes later (paginate timeout)
|
// We wanna release it as soon as the member list is actually *fetched*, instead of potentially minutes later (paginate timeout)
|
||||||
@ -87,7 +87,7 @@ namespace PluralKit.Bot
|
|||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var itemsPerPage = opts.Type == ListType.Short ? 25 : 5;
|
var itemsPerPage = opts.Type == ListType.Short ? 25 : 5;
|
||||||
await ctx.Paginate(members.ToAsyncEnumerable(), members.Count, itemsPerPage, embedTitle, Renderer);
|
await ctx.Paginate(members.ToAsyncEnumerable(), members.Count, itemsPerPage, embedTitle, color, Renderer);
|
||||||
|
|
||||||
// Base renderer, dispatches based on type
|
// Base renderer, dispatches based on type
|
||||||
Task Renderer(EmbedBuilder eb, IEnumerable<ListedMember> page)
|
Task Renderer(EmbedBuilder eb, IEnumerable<ListedMember> page)
|
||||||
|
@ -107,6 +107,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
await ctx.Paginate(channels.ToAsyncEnumerable(), channels.Count, 25,
|
await ctx.Paginate(channels.ToAsyncEnumerable(), channels.Count, 25,
|
||||||
$"Blacklisted channels for {ctx.Guild.Name}",
|
$"Blacklisted channels for {ctx.Guild.Name}",
|
||||||
|
null,
|
||||||
(eb, l) =>
|
(eb, l) =>
|
||||||
{
|
{
|
||||||
string CategoryName(ulong? id) =>
|
string CategoryName(ulong? id) =>
|
||||||
|
@ -69,6 +69,7 @@ namespace PluralKit.Bot
|
|||||||
totalSwitches,
|
totalSwitches,
|
||||||
10,
|
10,
|
||||||
embedTitle,
|
embedTitle,
|
||||||
|
system.Color,
|
||||||
async (builder, switches) =>
|
async (builder, switches) =>
|
||||||
{
|
{
|
||||||
var sb = new StringBuilder();
|
var sb = new StringBuilder();
|
||||||
|
@ -20,7 +20,7 @@ namespace PluralKit.Bot
|
|||||||
ctx.CheckSystemPrivacy(target, target.MemberListPrivacy);
|
ctx.CheckSystemPrivacy(target, target.MemberListPrivacy);
|
||||||
|
|
||||||
var opts = ctx.ParseMemberListOptions(ctx.LookupContextFor(target));
|
var opts = ctx.ParseMemberListOptions(ctx.LookupContextFor(target));
|
||||||
await ctx.RenderMemberList(ctx.LookupContextFor(target), _db, target.Id, GetEmbedTitle(target, opts), opts);
|
await ctx.RenderMemberList(ctx.LookupContextFor(target), _db, target.Id, GetEmbedTitle(target, opts), target.Color, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetEmbedTitle(PKSystem target, MemberListOptions opts)
|
private string GetEmbedTitle(PKSystem target, MemberListOptions opts)
|
||||||
|
@ -96,7 +96,7 @@ namespace PluralKit.Bot {
|
|||||||
return string.Equals(msg.Content, expectedReply, StringComparison.InvariantCultureIgnoreCase);
|
return string.Equals(msg.Content, expectedReply, StringComparison.InvariantCultureIgnoreCase);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task Paginate<T>(this Context ctx, IAsyncEnumerable<T> items, int totalCount, int itemsPerPage, string title, Func<EmbedBuilder, IEnumerable<T>, Task> renderer) {
|
public static async Task Paginate<T>(this Context ctx, IAsyncEnumerable<T> items, int totalCount, int itemsPerPage, string title, string color, Func<EmbedBuilder, IEnumerable<T>, Task> renderer) {
|
||||||
// TODO: make this generic enough we can use it in Choose<T> below
|
// TODO: make this generic enough we can use it in Choose<T> below
|
||||||
|
|
||||||
var buffer = new List<T>();
|
var buffer = new List<T>();
|
||||||
@ -111,6 +111,8 @@ namespace PluralKit.Bot {
|
|||||||
|
|
||||||
var eb = new EmbedBuilder();
|
var eb = new EmbedBuilder();
|
||||||
eb.Title(pageCount > 1 ? $"[{page+1}/{pageCount}] {title}" : title);
|
eb.Title(pageCount > 1 ? $"[{page+1}/{pageCount}] {title}" : title);
|
||||||
|
if (color != null)
|
||||||
|
eb.Color(color.ToDiscordColor());
|
||||||
await renderer(eb, buffer.Skip(page*itemsPerPage).Take(itemsPerPage));
|
await renderer(eb, buffer.Skip(page*itemsPerPage).Take(itemsPerPage));
|
||||||
return eb.Build();
|
return eb.Build();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user