Merge pull request #317 from spiralw/feat/fronters-only

Add flag to remove 'no fronter' item on frontpercent card
This commit is contained in:
Astrid 2021-04-22 18:35:24 +02:00 committed by GitHub
commit 752cd5dbfd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 6 deletions

View File

@ -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<PKSystem> GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn)

View File

@ -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));
}
}
}

View File

@ -321,9 +321,12 @@ namespace PluralKit.Bot {
return eb.Build();
}
public Task<Embed> CreateFrontPercentEmbed(FrontBreakdown breakdown, PKSystem system, PKGroup group, DateTimeZone tz, LookupContext ctx, string embedTitle)
public Task<Embed> 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<PKMember, Duration>(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()})"));
}

View File

@ -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|
|-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 \<group> frontpercent|fronters-only|fo|Same as above, but for groups|