fix: merge system/group frontpercent code, fix flags
This commit is contained in:
parent
bf122f1046
commit
c7851f6f5a
@ -219,14 +219,14 @@ public partial class CommandTree
|
|||||||
if (ctx.Match("h", "history"))
|
if (ctx.Match("h", "history"))
|
||||||
await ctx.Execute<SystemFront>(SystemFrontHistory, m => m.SystemFrontHistory(ctx, target));
|
await ctx.Execute<SystemFront>(SystemFrontHistory, m => m.SystemFrontHistory(ctx, target));
|
||||||
else if (ctx.Match("p", "percent", "%"))
|
else if (ctx.Match("p", "percent", "%"))
|
||||||
await ctx.Execute<SystemFront>(SystemFrontPercent, m => m.SystemFrontPercent(ctx, target));
|
await ctx.Execute<SystemFront>(SystemFrontPercent, m => m.FrontPercent(ctx, system: target));
|
||||||
else
|
else
|
||||||
await ctx.Execute<SystemFront>(SystemFronter, m => m.SystemFronter(ctx, target));
|
await ctx.Execute<SystemFront>(SystemFronter, m => m.SystemFronter(ctx, target));
|
||||||
}
|
}
|
||||||
else if (ctx.Match("fh", "fronthistory", "history", "switches"))
|
else if (ctx.Match("fh", "fronthistory", "history", "switches"))
|
||||||
await ctx.Execute<SystemFront>(SystemFrontHistory, m => m.SystemFrontHistory(ctx, target));
|
await ctx.Execute<SystemFront>(SystemFrontHistory, m => m.SystemFrontHistory(ctx, target));
|
||||||
else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown"))
|
else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown"))
|
||||||
await ctx.Execute<SystemFront>(SystemFrontPercent, m => m.SystemFrontPercent(ctx, target));
|
await ctx.Execute<SystemFront>(SystemFrontPercent, m => m.FrontPercent(ctx, system: target));
|
||||||
else if (ctx.Match("info", "view", "show"))
|
else if (ctx.Match("info", "view", "show"))
|
||||||
await ctx.Execute<System>(SystemInfo, m => m.Query(ctx, target));
|
await ctx.Execute<System>(SystemInfo, m => m.Query(ctx, target));
|
||||||
else if (ctx.Match("groups", "gs"))
|
else if (ctx.Match("groups", "gs"))
|
||||||
@ -354,7 +354,7 @@ public partial class CommandTree
|
|||||||
else if (ctx.Match("banner", "splash", "cover"))
|
else if (ctx.Match("banner", "splash", "cover"))
|
||||||
await ctx.Execute<Groups>(GroupBannerImage, g => g.GroupBannerImage(ctx, target));
|
await ctx.Execute<Groups>(GroupBannerImage, g => g.GroupBannerImage(ctx, target));
|
||||||
else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown"))
|
else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown"))
|
||||||
await ctx.Execute<Groups>(GroupFrontPercent, g => g.GroupFrontPercent(ctx, target));
|
await ctx.Execute<SystemFront>(GroupFrontPercent, g => g.FrontPercent(ctx, group: target));
|
||||||
else if (ctx.Match("color", "colour"))
|
else if (ctx.Match("color", "colour"))
|
||||||
await ctx.Execute<Groups>(GroupColor, g => g.GroupColor(ctx, target));
|
await ctx.Execute<Groups>(GroupColor, g => g.GroupColor(ctx, target));
|
||||||
else if (!ctx.HasNext())
|
else if (!ctx.HasNext())
|
||||||
|
@ -575,36 +575,6 @@ public class Groups
|
|||||||
await ctx.Reply($"{Emojis.Success} Group deleted.");
|
await ctx.Reply($"{Emojis.Success} Group deleted.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task GroupFrontPercent(Context ctx, PKGroup target)
|
|
||||||
{
|
|
||||||
var targetSystem = await GetGroupSystem(ctx, target);
|
|
||||||
ctx.CheckSystemPrivacy(targetSystem.Id, targetSystem.FrontHistoryPrivacy);
|
|
||||||
|
|
||||||
var totalSwitches = await _repo.GetSwitchCount(targetSystem.Id);
|
|
||||||
if (totalSwitches == 0) throw Errors.NoRegisteredSwitches;
|
|
||||||
|
|
||||||
var durationStr = ctx.RemainderOrNull() ?? "30d";
|
|
||||||
|
|
||||||
var now = SystemClock.Instance.GetCurrentInstant();
|
|
||||||
|
|
||||||
var rangeStart = DateUtils.ParseDateTime(durationStr, true, ctx.Zone);
|
|
||||||
if (rangeStart == null) throw Errors.InvalidDateTime(durationStr);
|
|
||||||
if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture;
|
|
||||||
|
|
||||||
var title = new StringBuilder($"Frontpercent of {target.DisplayName ?? target.Name} (`{target.Hid}`) in ");
|
|
||||||
if (targetSystem.Name != null)
|
|
||||||
title.Append($"{targetSystem.Name} (`{targetSystem.Hid}`)");
|
|
||||||
else
|
|
||||||
title.Append($"`{targetSystem.Hid}`");
|
|
||||||
|
|
||||||
var ignoreNoFronters = ctx.MatchFlag("fo", "fronters-only");
|
|
||||||
var showFlat = ctx.MatchFlag("flat");
|
|
||||||
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,
|
|
||||||
ctx.Zone, ctx.LookupContextFor(targetSystem.Id), title.ToString(), ignoreNoFronters, showFlat));
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<PKSystem> GetGroupSystem(Context ctx, PKGroup target)
|
private async Task<PKSystem> GetGroupSystem(Context ctx, PKGroup target)
|
||||||
{
|
{
|
||||||
var system = ctx.System;
|
var system = ctx.System;
|
||||||
|
@ -95,14 +95,19 @@ public class SystemFront
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SystemFrontPercent(Context ctx, PKSystem system)
|
public async Task FrontPercent(Context ctx, PKSystem? system = null, PKGroup? group = null)
|
||||||
{
|
{
|
||||||
if (system == null) throw Errors.NoSystemError;
|
if (system == null && group == null) throw Errors.NoSystemError;
|
||||||
|
if (system == null) system = await GetGroupSystem(ctx, group);
|
||||||
|
|
||||||
ctx.CheckSystemPrivacy(system.Id, system.FrontHistoryPrivacy);
|
ctx.CheckSystemPrivacy(system.Id, system.FrontHistoryPrivacy);
|
||||||
|
|
||||||
var totalSwitches = await _repo.GetSwitchCount(system.Id);
|
var totalSwitches = await _repo.GetSwitchCount(system.Id);
|
||||||
if (totalSwitches == 0) throw Errors.NoRegisteredSwitches;
|
if (totalSwitches == 0) throw Errors.NoRegisteredSwitches;
|
||||||
|
|
||||||
|
var ignoreNoFronters = ctx.MatchFlag("fo", "fronters-only");
|
||||||
|
var showFlat = ctx.MatchFlag("flat");
|
||||||
|
|
||||||
var durationStr = ctx.RemainderOrNull() ?? "30d";
|
var durationStr = ctx.RemainderOrNull() ?? "30d";
|
||||||
|
|
||||||
// Picked the UNIX epoch as a random date
|
// Picked the UNIX epoch as a random date
|
||||||
@ -118,19 +123,26 @@ public class SystemFront
|
|||||||
if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture;
|
if (rangeStart.Value.ToInstant() > now) throw Errors.FrontPercentTimeInFuture;
|
||||||
|
|
||||||
var title = new StringBuilder("Frontpercent of ");
|
var title = new StringBuilder("Frontpercent of ");
|
||||||
if (system.Name != null)
|
if (group != null)
|
||||||
|
title.Append($"{group.NameFor(ctx)} (`{group.Hid}`)");
|
||||||
|
else if (system.Name != null)
|
||||||
title.Append($"{system.Name} (`{system.Hid}`)");
|
title.Append($"{system.Name} (`{system.Hid}`)");
|
||||||
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, group?.Id, rangeStart.Value.ToInstant(), now));
|
||||||
var showFlat = ctx.MatchFlag("flat");
|
await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, group, ctx.Zone,
|
||||||
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, ctx.Zone,
|
|
||||||
ctx.LookupContextFor(system.Id), title.ToString(), ignoreNoFronters, showFlat));
|
ctx.LookupContextFor(system.Id), title.ToString(), ignoreNoFronters, showFlat));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<PKSystem> GetGroupSystem(Context ctx, PKGroup target)
|
||||||
|
{
|
||||||
|
var system = ctx.System;
|
||||||
|
if (system?.Id == target.System)
|
||||||
|
return system;
|
||||||
|
return await _repo.GetSystem(target.System)!;
|
||||||
|
}
|
||||||
|
|
||||||
private struct FrontHistoryEntry
|
private struct FrontHistoryEntry
|
||||||
{
|
{
|
||||||
public readonly Instant? LastTime;
|
public readonly Instant? LastTime;
|
||||||
|
Loading…
Reference in New Issue
Block a user