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 <PKMember> > PostMember([FromBody] PKMember newMember) { var system = _auth.CurrentSystem; if (newMember.Name == null) { return(BadRequest("Member name cannot be null.")); } // Enforce per-system member limit var memberCount = await _members.MemberCount(system); if (memberCount >= Limits.MaxMemberCount) { return(BadRequest($"Member limit reached ({memberCount} / {Limits.MaxMemberCount}).")); } // Explicit bounds checks if (newMember.Name != null && newMember.Name.Length > Limits.MaxMemberNameLength) { return(BadRequest($"Member name too long ({newMember.Name.Length} > {Limits.MaxMemberNameLength}.")); } if (newMember.DisplayName != null && newMember.DisplayName.Length > Limits.MaxMemberNameLength) { return(BadRequest($"Member display name too long ({newMember.DisplayName.Length} > {Limits.MaxMemberNameLength}.")); } if (newMember.Pronouns != null && newMember.Pronouns.Length > Limits.MaxPronounsLength) { return(BadRequest($"Member pronouns too long ({newMember.Pronouns.Length} > {Limits.MaxPronounsLength}.")); } if (newMember.Description != null && newMember.Description.Length > Limits.MaxDescriptionLength) { return(BadRequest($"Member descriptions too long ({newMember.Description.Length} > {Limits.MaxDescriptionLength}.")); } // Sanity bounds checks if (newMember.AvatarUrl != null && newMember.AvatarUrl.Length > 1000) { return(BadRequest()); } if (newMember.Prefix != null && newMember.Prefix.Length > 1000) { return(BadRequest()); } if (newMember.Suffix != null && newMember.Suffix.Length > 1000) { return(BadRequest()); } var member = await _members.Create(system, newMember.Name); member.Name = newMember.Name; member.DisplayName = newMember.DisplayName; member.Color = newMember.Color; member.AvatarUrl = newMember.AvatarUrl; member.Birthday = newMember.Birthday; member.Pronouns = newMember.Pronouns; member.Description = newMember.Description; member.Prefix = newMember.Prefix; member.Suffix = newMember.Suffix; await _members.Save(member); return(Ok(member)); }
public async Task NewMember(Context ctx) { if (ctx.System == null) { throw Errors.NoSystemError; } var memberName = ctx.RemainderOrNull() ?? throw new PKSyntaxError("You must pass a member name."); // Hard name length cap if (memberName.Length > Limits.MaxMemberNameLength) { throw Errors.MemberNameTooLongError(memberName.Length); } // Warn if member name will be unproxyable (with/without tag) if (memberName.Length > ctx.System.MaxMemberNameLength) { var msg = await ctx.Reply($"{Emojis.Warn} Member name too long ({memberName.Length} > {ctx.System.MaxMemberNameLength} characters), this member will be unproxyable. Do you want to create it anyway? (You can change the name later, or set a member display name)"); if (!await ctx.PromptYesNo(msg)) { throw new PKError("Member creation cancelled."); } } // Warn if there's already a member by this name var existingMember = await _members.GetByName(ctx.System, memberName); if (existingMember != null) { var msg = await ctx.Reply($"{Emojis.Warn} You already have a member in your system with the name \"{existingMember.Name.SanitizeMentions()}\" (with ID `{existingMember.Hid}`). Do you want to create another member with the same name?"); if (!await ctx.PromptYesNo(msg)) { throw new PKError("Member creation cancelled."); } } // Enforce per-system member limit var memberCount = await _members.MemberCount(ctx.System); if (memberCount >= Limits.MaxMemberCount) { throw Errors.MemberLimitReachedError; } // Create the member var member = await _members.Create(ctx.System, memberName); memberCount++; // Send confirmation and space hint await ctx.Reply($"{Emojis.Success} Member \"{memberName.SanitizeMentions()}\" (`{member.Hid}`) registered! See the user guide for commands for editing this member: https://pluralkit.me/guide#member-management"); if (memberName.Contains(" ")) { await ctx.Reply($"{Emojis.Note} Note that this member's name contains spaces. You will need to surround it with \"double quotes\" when using commands referring to it, or just use the member's 5-character ID (which is `{member.Hid}`)."); } if (memberCount >= Limits.MaxMemberCount) { await ctx.Reply($"{Emojis.Warn} You have reached the per-system member limit ({Limits.MaxMemberCount}). You will be unable to create additional members until existing members are deleted."); } else if (memberCount >= Limits.MaxMembersWarnThreshold) { await ctx.Reply($"{Emojis.Warn} You are approaching the per-system member limit ({memberCount} / {Limits.MaxMemberCount} members). Please review your member list for unused or duplicate members."); } await _proxyCache.InvalidateResultsForSystem(ctx.System); }