private async Task DoSwitchCommand(Context ctx, ICollection <PKMember> members) { // Make sure there are no dupes in the list // We do this by checking if removing duplicate member IDs results in a list of different length if (members.Select(m => m.Id).Distinct().Count() != members.Count) { throw Errors.DuplicateSwitchMembers; } // Find the last switch and its members if applicable var lastSwitch = await _switches.GetLatestSwitch(ctx.System); if (lastSwitch != null) { var lastSwitchMembers = await _switches.GetSwitchMembers(lastSwitch); // Make sure the requested switch isn't identical to the last one if (lastSwitchMembers.Select(m => m.Id).SequenceEqual(members.Select(m => m.Id))) { throw Errors.SameSwitch(members); } } await _switches.RegisterSwitch(ctx.System, members); if (members.Count == 0) { await ctx.Reply($"{Emojis.Success} Switch-out registered."); } else { await ctx.Reply($"{Emojis.Success} Switch registered. Current fronter is now {string.Join(", ", members.Select(m => m.Name)).SanitizeMentions()}."); } }
public async Task <Embed> CreateSystemEmbed(PKSystem system) { var accounts = await _systems.GetLinkedAccountIds(system); // Fetch/render info for all accounts simultaneously var users = await Task.WhenAll(accounts.Select(async uid => (await _client.GetUserAsync(uid))?.NameAndMention() ?? $"(deleted account {uid})")); var memberCount = await _members.MemberCount(system); var eb = new EmbedBuilder() .WithColor(Color.Blue) .WithTitle(system.Name ?? null) .WithThumbnailUrl(system.AvatarUrl ?? null) .WithFooter($"System ID: {system.Hid}"); var latestSwitch = await _switches.GetLatestSwitch(system); if (latestSwitch != null) { var switchMembers = (await _switches.GetSwitchMembers(latestSwitch)).ToList(); if (switchMembers.Count > 0) { eb.AddField("Fronter".ToQuantity(switchMembers.Count(), ShowQuantityAs.None), string.Join(", ", switchMembers.Select(m => m.Name))); } } if (system.Tag != null) { eb.AddField("Tag", system.Tag); } eb.AddField("Linked accounts", string.Join(", ", users), true); eb.AddField($"Members ({memberCount})", $"(see `pk;system {system.Hid} list` or `pk;system {system.Hid} list full`)", true); if (system.Description != null) { eb.AddField("Description", system.Description.Truncate(1024), false); } return(eb.Build()); }
public async Task <ActionResult <FrontersReturn> > GetFronters(string hid) { var system = await _systems.GetByHid(hid); if (system == null) { return(NotFound("System not found.")); } var sw = await _switches.GetLatestSwitch(system); if (sw == null) { return(NotFound("System has no registered switches.")); } var members = await _switches.GetSwitchMembers(sw); return(Ok(new FrontersReturn { Timestamp = sw.Timestamp, Members = members })); }
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) };