From dfa25b77c79ce2d25eab92dd84431c59ad573a53 Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 22 Apr 2021 01:18:41 +0100 Subject: [PATCH] Add flag to remove 'no fronter' item on frontpercent card --- PluralKit.Bot/Commands/Groups.cs | 3 ++- PluralKit.Bot/Commands/SystemFront.cs | 3 ++- PluralKit.Bot/Services/EmbedService.cs | 9 ++++++--- docs/content/tips-and-tricks.md | 8 +++++++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index 7cbc5200..6be11216 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -499,8 +499,9 @@ namespace PluralKit.Bot else title.Append($"`{targetSystem.Hid}`"); + var ignoreNoFronters = ctx.MatchFlag("fo", "fronters-only"); var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, targetSystem.Id, target.Id, rangeStart.Value.ToInstant(), now)); - await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, targetSystem, target, targetSystem.Zone, ctx.LookupContextFor(targetSystem), title.ToString())); + await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, targetSystem, target, targetSystem.Zone, ctx.LookupContextFor(targetSystem), title.ToString(), ignoreNoFronters)); } private async Task GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn) diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index 0be2429a..2129dcae 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -131,8 +131,9 @@ namespace PluralKit.Bot else title.Append($"`{system.Hid}`"); + var ignoreNoFronters = ctx.MatchFlag("fo", "fronters-only"); var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, null, rangeStart.Value.ToInstant(), now)); - await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, null, system.Zone, ctx.LookupContextFor(system), title.ToString())); + await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, null, system.Zone, ctx.LookupContextFor(system), title.ToString(), ignoreNoFronters)); } } } \ No newline at end of file diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index 56f197b3..0ffc89fc 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -321,9 +321,12 @@ namespace PluralKit.Bot { return eb.Build(); } - public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle) + public Task CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle, bool ignoreNoFronters) { 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) @@ -333,13 +336,13 @@ namespace PluralKit.Bot { // We convert to a list of pairs so we can add the no-fronter value // Dictionary doesn't allow for null keys so we instead have a pair with a null key ;) var pairs = breakdown.MemberSwitchDurations.ToList(); - if (breakdown.NoFronterDuration != Duration.Zero) + if (breakdown.NoFronterDuration != Duration.Zero && !ignoreNoFronters) pairs.Add(new KeyValuePair(null, breakdown.NoFronterDuration)); var membersOrdered = pairs.OrderByDescending(pair => pair.Value).Take(maxEntriesToDisplay).ToList(); foreach (var pair in membersOrdered) { - var frac = pair.Value / actualPeriod; + var frac = pair.Value / (ignoreNoFronters ? hasFrontersPeriod : actualPeriod); eb.Field(new(pair.Key?.NameFor(ctx) ?? "*(no fronter)*", $"{frac*100:F0}% ({pair.Value.FormatDuration()})")); } diff --git a/docs/content/tips-and-tricks.md b/docs/content/tips-and-tricks.md index 3bea60eb..2d7b19ea 100644 --- a/docs/content/tips-and-tricks.md +++ b/docs/content/tips-and-tricks.md @@ -61,4 +61,10 @@ You cannot look up private members of another system. |-with-last-message|-with-last-proxy, -wlm, -wlp|Show each member's last message date| |-with-message-count|-wmc|Show each member's message count| |-with-created|-wc|Show each member's creation date| -|-with-avatar|-wa, -wi, -ia, -ii, -img|Show each member's avatar URL| \ No newline at end of file +|-with-avatar|-wa, -wi, -ia, -ii, -img|Show each member's avatar URL| + +## Miscellaneous flags +|Command|Flag|Aliases|Description| +|---|---|---|---| +|pk;system frontpercent|fronters-only|fo|Hides the "no fronters" list item| +|pk;group \ frontpercent|fronters-only|fo|Same as above, but for groups| \ No newline at end of file