I messed up the branches oops

This commit is contained in:
Spectralitree 2021-03-28 12:15:21 +02:00
parent ba30a96c7c
commit e7cfd85bd5
5 changed files with 6 additions and 40 deletions

View File

@ -404,8 +404,6 @@ namespace PluralKit.Bot
await ctx.Execute<Groups>(GroupIcon, g => g.GroupIcon(ctx, target));
else if (ctx.Match("color", "colour"))
await ctx.Execute<Groups>(GroupColor, g => g.GroupColor(ctx, target));
else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown"))
await ctx.Execute<Groups>(GroupFrontPercent, g => g.GroupFrontPercent(ctx, target));
else if (!ctx.HasNext())
await ctx.Execute<Groups>(GroupInfo, g => g.ShowGroupCard(ctx, target));
else

View File

@ -478,31 +478,6 @@ namespace PluralKit.Bot
await ctx.Reply($"{Emojis.Success} Group deleted.");
}
public async Task GroupFrontPercent(Context ctx, PKGroup target)
{
await using var conn = await _db.Obtain();
var targetSystem = await GetGroupSystem(ctx, target, conn);
ctx.CheckSystemPrivacy(targetSystem, targetSystem.FrontHistoryPrivacy);
string durationStr = ctx.RemainderOrNull() ?? "30d";
var now = SystemClock.Instance.GetCurrentInstant();
var rangeStart = DateUtils.ParseDateTime(durationStr, true, targetSystem.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 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()));
}
private async Task<PKSystem> GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn)
{
var system = ctx.System;

View File

@ -130,7 +130,7 @@ namespace PluralKit.Bot
else
title.Append($"`{system.Hid}`");
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, rangeStart.Value.ToInstant(), now));
await ctx.Reply(embed: await _embeds.CreateFrontPercentEmbed(frontpercent, system, null, system.Zone, ctx.LookupContextFor(system), title.ToString()));
}
}

View File

@ -122,7 +122,7 @@ namespace PluralKit.Core
await GetSwitches(conn, system).FirstOrDefaultAsync();
public async Task<IEnumerable<SwitchListEntry>> GetPeriodFronters(IPKConnection conn,
SystemId system, GroupId? group, Instant periodStart,
SystemId system, Instant periodStart,
Instant periodEnd)
{
// TODO: IAsyncEnumerable-ify this one
@ -139,14 +139,7 @@ namespace PluralKit.Core
new {Switches = switchMembers.Select(m => m.Member.Value).Distinct().ToList()});
var memberObjects = membersList.ToDictionary(m => m.Id);
// check if a group ID is provided. if so, query DB for all members of said group, otherwise use membersList
var groupMembersList = group != null ? await conn.QueryAsync<PKMember>(
"select * from members inner join group_members on members.id = group_members.member_id where group_id = @id",
new {id = group}) : membersList;
var groupMemberObjects = groupMembersList.ToDictionary(m => m.Id);
// Initialize entries - still need to loop to determine the TimespanEnd below
// use groupMemberObjects to make sure no members outside of the specified group (if present) are selected
var entries =
from item in switchMembers
group item by item.Timestamp
@ -154,7 +147,7 @@ namespace PluralKit.Core
select new SwitchListEntry
{
TimespanStart = g.Key,
Members = g.Where(x => x.Member != default(MemberId) && groupMemberObjects.Any(m => x.Member == m.Key) ).Select(x => memberObjects[x.Member])
Members = g.Where(x => x.Member != default(MemberId)).Select(x => memberObjects[x.Member])
.ToList()
};
@ -181,7 +174,7 @@ namespace PluralKit.Core
return outList;
}
public async Task<FrontBreakdown> GetFrontBreakdown(IPKConnection conn, SystemId system, GroupId? group, Instant periodStart,
public async Task<FrontBreakdown> GetFrontBreakdown(IPKConnection conn, SystemId system, Instant periodStart,
Instant periodEnd)
{
// TODO: this doesn't belong in the repo
@ -195,7 +188,7 @@ namespace PluralKit.Core
var actualStart = periodEnd; // will be "pulled" down
var actualEnd = periodStart; // will be "pulled" up
foreach (var sw in await GetPeriodFronters(conn, system, group, periodStart, periodEnd))
foreach (var sw in await GetPeriodFronters(conn, system, periodStart, periodEnd))
{
var span = sw.TimespanEnd - sw.TimespanStart;
foreach (var member in sw.Members)

View File

@ -51,7 +51,7 @@ namespace PluralKit.Core
// Export switches
var switches = new List<DataFileSwitch>();
var switchList = await _repo.GetPeriodFronters(conn, system.Id, null, Instant.FromDateTimeUtc(DateTime.MinValue.ToUniversalTime()), SystemClock.Instance.GetCurrentInstant());
var switchList = await _repo.GetPeriodFronters(conn, system.Id, Instant.FromDateTimeUtc(DateTime.MinValue.ToUniversalTime()), SystemClock.Instance.GetCurrentInstant());
switches.AddRange(switchList.Select(x => new DataFileSwitch
{
Timestamp = x.TimespanStart.FormatExport(),