public async Task <Embed> CreateFrontHistoryEmbed(IEnumerable <PKSwitch> sws, DateTimeZone zone) { var outputStr = ""; PKSwitch lastSw = null; foreach (var sw in sws) { // Fetch member list and format var members = (await _switches.GetSwitchMembers(sw)).ToList(); var membersStr = members.Any() ? string.Join(", ", members.Select(m => m.Name)) : "no fronter"; var switchSince = SystemClock.Instance.GetCurrentInstant() - sw.Timestamp; // If this isn't the latest switch, we also show duration if (lastSw != null) { // Calculate the time between the last switch (that we iterated - ie. the next one on the timeline) and the current one var switchDuration = lastSw.Timestamp - sw.Timestamp; outputStr += $"**{membersStr}** ({Formats.ZonedDateTimeFormat.Format(sw.Timestamp.InZone(zone))}, {Formats.DurationFormat.Format(switchSince)} ago, for {Formats.DurationFormat.Format(switchDuration)})\n"; } else { outputStr += $"**{membersStr}** ({Formats.ZonedDateTimeFormat.Format(sw.Timestamp.InZone(zone))}, {Formats.DurationFormat.Format(switchSince)} ago)\n"; } lastSw = sw; } return(new EmbedBuilder() .WithTitle("Past switches") .WithDescription(outputStr) .Build()); }
public async Task <Embed> CreateFronterEmbed(PKSwitch sw, DateTimeZone zone) { var members = (await _data.GetSwitchMembers(sw)).ToList(); var timeSinceSwitch = SystemClock.Instance.GetCurrentInstant() - sw.Timestamp; return(new EmbedBuilder() .WithColor(members.FirstOrDefault()?.Color?.ToDiscordColor() ?? Color.Blue) .AddField($"Current {"fronter".ToQuantity(members.Count, ShowQuantityAs.None)}", members.Count > 0 ? string.Join(", ", members.Select(m => m.Name)) : "*(no fronter)*") .AddField("Since", $"{Formats.ZonedDateTimeFormat.Format(sw.Timestamp.InZone(zone))} ({Formats.DurationFormat.Format(timeSinceSwitch)} ago)") .Build()); }
public async Task <DiscordEmbed> CreateFronterEmbed(PKSwitch sw, DateTimeZone zone, LookupContext ctx) { var members = await _data.GetSwitchMembers(sw).ToListAsync(); var timeSinceSwitch = SystemClock.Instance.GetCurrentInstant() - sw.Timestamp; return(new DiscordEmbedBuilder() .WithColor(members.FirstOrDefault()?.Color?.ToDiscordColor() ?? DiscordUtils.Gray) .AddField($"Current {"fronter".ToQuantity(members.Count, ShowQuantityAs.None)}", members.Count > 0 ? string.Join(", ", members.Select(m => m.NameFor(ctx))) : "*(no fronter)*") .AddField("Since", $"{sw.Timestamp.FormatZoned(zone)} ({timeSinceSwitch.FormatDuration()} ago)") .Build()); }
private async Task <DataFileSwitch> ExportSwitch(PKSwitch sw) => new DataFileSwitch { Members = (await _switches.GetSwitchMembers(sw)).Select(m => m.Hid).ToList(), Timestamp = Formats.TimestampExportFormat.Format(sw.Timestamp) };
public FrontHistoryEntry(Instant?lastTime, PKSwitch thisSwitch) { LastTime = lastTime; ThisSwitch = thisSwitch; }