From e7cfd85bd5f6b86887239a3af6acd2a63c6057f3 Mon Sep 17 00:00:00 2001 From: Spectralitree Date: Sun, 28 Mar 2021 12:15:21 +0200 Subject: [PATCH] I messed up the branches oops --- PluralKit.Bot/Commands/CommandTree.cs | 2 -- PluralKit.Bot/Commands/Groups.cs | 25 ------------------- PluralKit.Bot/Commands/SystemFront.cs | 2 +- .../Repository/ModelRepository.Switch.cs | 15 +++-------- PluralKit.Core/Services/DataFileService.cs | 2 +- 5 files changed, 6 insertions(+), 40 deletions(-) diff --git a/PluralKit.Bot/Commands/CommandTree.cs b/PluralKit.Bot/Commands/CommandTree.cs index a36f9090..08c56ba6 100644 --- a/PluralKit.Bot/Commands/CommandTree.cs +++ b/PluralKit.Bot/Commands/CommandTree.cs @@ -404,8 +404,6 @@ namespace PluralKit.Bot await ctx.Execute(GroupIcon, g => g.GroupIcon(ctx, target)); else if (ctx.Match("color", "colour")) await ctx.Execute(GroupColor, g => g.GroupColor(ctx, target)); - else if (ctx.Match("fp", "frontpercent", "front%", "frontbreakdown")) - await ctx.Execute(GroupFrontPercent, g => g.GroupFrontPercent(ctx, target)); else if (!ctx.HasNext()) await ctx.Execute(GroupInfo, g => g.ShowGroupCard(ctx, target)); else diff --git a/PluralKit.Bot/Commands/Groups.cs b/PluralKit.Bot/Commands/Groups.cs index 6c68bb24..f9b7b73e 100644 --- a/PluralKit.Bot/Commands/Groups.cs +++ b/PluralKit.Bot/Commands/Groups.cs @@ -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 GetGroupSystem(Context ctx, PKGroup target, IPKConnection conn) { var system = ctx.System; diff --git a/PluralKit.Bot/Commands/SystemFront.cs b/PluralKit.Bot/Commands/SystemFront.cs index d9531216..9121be04 100644 --- a/PluralKit.Bot/Commands/SystemFront.cs +++ b/PluralKit.Bot/Commands/SystemFront.cs @@ -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())); } } diff --git a/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs b/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs index d8633acf..f313f00a 100644 --- a/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs +++ b/PluralKit.Core/Database/Repository/ModelRepository.Switch.cs @@ -122,7 +122,7 @@ namespace PluralKit.Core await GetSwitches(conn, system).FirstOrDefaultAsync(); public async Task> 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( - "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 GetFrontBreakdown(IPKConnection conn, SystemId system, GroupId? group, Instant periodStart, + public async Task 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) diff --git a/PluralKit.Core/Services/DataFileService.cs b/PluralKit.Core/Services/DataFileService.cs index cc259d3b..05dd3b37 100644 --- a/PluralKit.Core/Services/DataFileService.cs +++ b/PluralKit.Core/Services/DataFileService.cs @@ -51,7 +51,7 @@ namespace PluralKit.Core // Export switches var switches = new List(); - 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(),