Example #1
0
        public async Task SystemFrontPercent(Context ctx, PKSystem system)
        {
            if (system == null)
            {
                throw Errors.NoSystemError;
            }
            ctx.CheckSystemPrivacy(system, system.FrontHistoryPrivacy);

            string durationStr = ctx.RemainderOrNull() ?? "30d";

            var now = SystemClock.Instance.GetCurrentInstant();

            var rangeStart = DateUtils.ParseDateTime(durationStr, true, system.Zone);

            if (rangeStart == null)
            {
                throw Errors.InvalidDateTime(durationStr);
            }
            if (rangeStart.Value.ToInstant() > now)
            {
                throw Errors.FrontPercentTimeInFuture;
            }

            var frontpercent = await _db.Execute(c => _repo.GetFrontBreakdown(c, system.Id, rangeStart.Value.ToInstant(), now));

            await ctx.Reply(embed : await _embeds.CreateFrontPercentEmbed(frontpercent, system.Zone, ctx.LookupContextFor(system)));
        }
Example #2
0
        public async Task SystemFrontPercent(Context ctx, PKSystem system)
        {
            if (system == null)
            {
                throw Errors.NoSystemError;
            }
            ctx.CheckSystemPrivacy(system, system.FrontHistoryPrivacy);

            var totalSwitches = await _db.Execute(conn => _repo.GetSwitchCount(conn, system.Id));

            if (totalSwitches == 0)
            {
                throw Errors.NoRegisteredSwitches;
            }

            string durationStr = ctx.RemainderOrNull() ?? "30d";

            var now = SystemClock.Instance.GetCurrentInstant();

            var rangeStart = DateUtils.ParseDateTime(durationStr, true, system.Zone);

            if (rangeStart == null)
            {
                throw Errors.InvalidDateTime(durationStr);
            }
            if (rangeStart.Value.ToInstant() > now)
            {
                throw Errors.FrontPercentTimeInFuture;
            }

            var title = new StringBuilder($"Frontpercent of ");

            if (system.Name != null)
            {
                title.Append($"{system.Name} (`{system.Hid}`)");
            }
            else
            {
                title.Append($"`{system.Hid}`");
            }

            var ignoreNoFronters = ctx.MatchFlag("fo", "fronters-only");
            var showFlat         = ctx.MatchFlag("flat");
            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(), ignoreNoFronters, showFlat));
        }