From 2898b3989af1899dc3b10b9d94e7aeedcb40f585 Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 19:22:31 +0200 Subject: [PATCH] Add color to all lists --- PluralKit.Bot/Commands/Groups.cs | 4 ++-- PluralKit.Bot/Commands/Lists/ContextListExt.cs | 4 ++-- PluralKit.Bot/Commands/ServerConfig.cs | 1 + PluralKit.Bot/Commands/SystemFront.cs | 1 + PluralKit.Bot/Commands/SystemList.cs | 2 +- PluralKit.Bot/Utils/ContextUtils.cs | 4 +++- 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index ac4d4425..eb23c685 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -311,7 +311,7 @@ namespace PluralKit.Bot } 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 page) { @@ -390,7 +390,7 @@ namespace PluralKit.Bot if (opts.Search != null) 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 diff --git a/PluralKit.Bot/Commands/Lists/ContextListExt.cs b/PluralKit.Bot/Commands/Lists/ContextListExt.cs index acca3b5f..fa990c4b 100644 --- a/PluralKit.Bot/Commands/Lists/ContextListExt.cs +++ b/PluralKit.Bot/Commands/Lists/ContextListExt.cs @@ -78,7 +78,7 @@ namespace PluralKit.Bot 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 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(); 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 Task Renderer(EmbedBuilder eb, IEnumerable page) diff --git a/PluralKit.Bot/Commands/ServerConfig.cs b/PluralKit.Bot/Commands/ServerConfig.cs index e29db8d4..12641288 100644 --- a/PluralKit.Bot/Commands/ServerConfig.cs +++ b/PluralKit.Bot/Commands/ServerConfig.cs @@ -107,6 +107,7 @@ namespace PluralKit.Bot await ctx.Paginate(channels.ToAsyncEnumerable(), channels.Count, 25, $"Blacklisted channels for {ctx.Guild.Name}", + null, (eb, l) => { string CategoryName(ulong? id) => diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index 3f8cbc0b..cde6359d 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -69,6 +69,7 @@ namespace PluralKit.Bot totalSwitches, 10, embedTitle, + system.Color, async (builder, switches) => { var sb = new StringBuilder(); diff --git a/PluralKit.Bot/Commands/SystemList.cs b/PluralKit.Bot/Commands/SystemList.cs index 493e5bda..8a33e552 100644 --- a/PluralKit.Bot/Commands/SystemList.cs +++ b/PluralKit.Bot/Commands/SystemList.cs @@ -20,7 +20,7 @@ namespace PluralKit.Bot ctx.CheckSystemPrivacy(target, target.MemberListPrivacy); 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) diff --git a/PluralKit.Bot/Utils/ContextUtils.cs b/PluralKit.Bot/Utils/ContextUtils.cs index 2472c098..9f24d176 100644 --- a/PluralKit.Bot/Utils/ContextUtils.cs +++ b/PluralKit.Bot/Utils/ContextUtils.cs @@ -96,7 +96,7 @@ namespace PluralKit.Bot { return string.Equals(msg.Content, expectedReply, StringComparison.InvariantCultureIgnoreCase); } - public static async Task Paginate(this Context ctx, IAsyncEnumerable items, int totalCount, int itemsPerPage, string title, Func, Task> renderer) { + public static async Task Paginate(this Context ctx, IAsyncEnumerable items, int totalCount, int itemsPerPage, string title, string color, Func, Task> renderer) { // TODO: make this generic enough we can use it in Choose below var buffer = new List(); @@ -111,6 +111,8 @@ namespace PluralKit.Bot { var eb = new EmbedBuilder(); 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)); return eb.Build(); }