Add flag to remove 'no fronter' item on frontpercent card
This commit is contained in:
parent
a2d2036851
commit
dfa25b77c7
@ -499,8 +499,9 @@ namespace PluralKit.Bot
|
|||||||
else
|
else
|
||||||
title.Append($"`{targetSystem.Hid}`");
|
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));
|
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)
|
private async Task<PKSystem> GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn)
|
||||||
|
@ -131,8 +131,9 @@ namespace PluralKit.Bot
|
|||||||
else
|
else
|
||||||
title.Append($"`{system.Hid}`");
|
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));
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -321,9 +321,12 @@ namespace PluralKit.Bot {
|
|||||||
return eb.Build();
|
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;
|
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()
|
var eb = new EmbedBuilder()
|
||||||
.Title(embedTitle)
|
.Title(embedTitle)
|
||||||
.Color(DiscordUtils.Gray)
|
.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
|
// 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 ;)
|
// Dictionary doesn't allow for null keys so we instead have a pair with a null key ;)
|
||||||
var pairs = breakdown.MemberSwitchDurations.ToList();
|
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));
|
pairs.Add(new KeyValuePair<PKMember, Duration>(null, breakdown.NoFronterDuration));
|
||||||
|
|
||||||
var membersOrdered = pairs.OrderByDescending(pair => pair.Value).Take(maxEntriesToDisplay).ToList();
|
var membersOrdered = pairs.OrderByDescending(pair => pair.Value).Take(maxEntriesToDisplay).ToList();
|
||||||
foreach (var pair in membersOrdered)
|
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()})"));
|
eb.Field(new(pair.Key?.NameFor(ctx) ?? "*(no fronter)*", $"{frac*100:F0}% ({pair.Value.FormatDuration()})"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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-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-message-count|-wmc|Show each member's message count|
|
||||||
|-with-created|-wc|Show each member's creation date|
|
|-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|
|
Loading…
Reference in New Issue
Block a user