From b1c7fbd2dfe50153937818d83c5893c738c7e6a5 Mon Sep 17 00:00:00 2001 From: Spectralitree <72747870+Spectralitree@users.noreply.github.com> Date: Fri, 7 May 2021 10:40:57 +0200 Subject: [PATCH] Add color to frontpercent embed (#307) * Add color to frontpercent embed * don't pass color as a separate argument Co-authored-by: Astrid --- PluralKit.Bot/Services/EmbedService.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index 0ffc89fc..2e88a81e 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -323,13 +323,29 @@ namespace PluralKit.Bot { public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle, bool ignoreNoFronters) { + string color = system.Color; + if (group != null) + { + color = group.Color; + } + + uint embedColor; + try + { + embedColor = color?.ToDiscordColor() ?? DiscordUtils.Gray; + } + catch (ArgumentException) + { + embedColor = DiscordUtils.Gray; + } + var actualPeriod = breakdown.RangeEnd - breakdown.RangeStart; // this is kinda messy? var hasFrontersPeriod = Duration.FromTicks(breakdown.MemberSwitchDurations.Values.ToList().Sum(i => i.TotalTicks)); var eb = new EmbedBuilder() .Title(embedTitle) - .Color(DiscordUtils.Gray) + .Color(embedColor) .Footer(new($"Since {breakdown.RangeStart.FormatZoned(tz)} ({actualPeriod.FormatDuration()} ago)")); var maxEntriesToDisplay = 24; // max 25 fields allowed in embed - reserve 1 for "others"