Merge pull request #228 from dev-kittens/fix/memberlimits

Fix per-system member limits not being considered in certain conditionals
This commit is contained in:
Astrid 2020-10-23 11:11:11 +02:00 committed by GitHub
commit 025fbfe120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 10 deletions

View File

@ -49,10 +49,10 @@ namespace PluralKit.Bot
await ctx.Reply($"{Emojis.Success} Member \"{memberName}\" (`{member.Hid}`) registered! Check out the getting started page for how to get a member up and running: https://pluralkit.me/start#members"); await ctx.Reply($"{Emojis.Success} Member \"{memberName}\" (`{member.Hid}`) registered! Check out the getting started page for how to get a member up and running: https://pluralkit.me/start#members");
if (memberName.Contains(" ")) 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}`)."); 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) if (memberCount >= memberLimit)
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."); await ctx.Reply($"{Emojis.Warn} You have reached the per-system member limit ({memberLimit}). You will be unable to create additional members until existing members are deleted.");
else if (memberCount >= Limits.MaxMembersWarnThreshold) else if (memberCount >= Limits.MaxMembersWarnThreshold(memberLimit))
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 ctx.Reply($"{Emojis.Warn} You are approaching the per-system member limit ({memberCount} / {memberLimit} members). Please review your member list for unused or duplicate members.");
} }
public async Task MemberRandom(Context ctx) public async Task MemberRandom(Context ctx)

View File

@ -120,6 +120,8 @@ namespace PluralKit.Core
await _repo.AddAccount(conn, system.Id, accountId); await _repo.AddAccount(conn, system.Id, accountId);
} }
var memberLimit = system.MemberLimitOverride ?? Limits.MaxMemberCount;
// Apply system info // Apply system info
var patch = new SystemPatch {Name = data.Name}; var patch = new SystemPatch {Name = data.Name};
if (data.Description != null) patch.Description = data.Description; if (data.Description != null) patch.Description = data.Description;
@ -135,10 +137,10 @@ namespace PluralKit.Core
// If creating the unmatched members would put us over the member limit, abort before creating any members // If creating the unmatched members would put us over the member limit, abort before creating any members
var memberCountBefore = await _repo.GetSystemMemberCount(conn, system.Id); var memberCountBefore = await _repo.GetSystemMemberCount(conn, system.Id);
var membersToAdd = data.Members.Count(m => imp.IsNewMember(m.Id, m.Name)); var membersToAdd = data.Members.Count(m => imp.IsNewMember(m.Id, m.Name));
if (memberCountBefore + membersToAdd > Limits.MaxMemberCount) if (memberCountBefore + membersToAdd > memberLimit)
{ {
result.Success = false; result.Success = false;
result.Message = $"Import would exceed the maximum number of members ({Limits.MaxMemberCount})."; result.Message = $"Import would exceed the maximum number of members ({memberLimit}).";
return result; return result;
} }
@ -204,7 +206,8 @@ namespace PluralKit.Core
[JsonIgnore] public bool Valid => [JsonIgnore] public bool Valid =>
TimeZoneValid && TimeZoneValid &&
Members != null && Members != null &&
Members.Count <= Limits.MaxMemberCount && // no need to check this here, it is checked later as part of the import
// Members.Count <= Limits.MaxMemberCount &&
Members.All(m => m.Valid) && Members.All(m => m.Valid) &&
Switches != null && Switches != null &&
Switches.Count < 10000 && Switches.Count < 10000 &&

View File

@ -6,7 +6,7 @@ namespace PluralKit.Core {
public static readonly int MaxSystemNameLength = 100; public static readonly int MaxSystemNameLength = 100;
public static readonly int MaxSystemTagLength = MaxProxyNameLength - 1; public static readonly int MaxSystemTagLength = MaxProxyNameLength - 1;
public static readonly int MaxMemberCount = 1000; public static readonly int MaxMemberCount = 1000;
public static readonly int MaxMembersWarnThreshold = MaxMemberCount - 50; public static int MaxMembersWarnThreshold (int memberLimit) => memberLimit - 50;
public static readonly int MaxGroupCount = 250; public static readonly int MaxGroupCount = 250;
public static readonly int MaxDescriptionLength = 1000; public static readonly int MaxDescriptionLength = 1000;
public static readonly int MaxMemberNameLength = 100; // Fair bit larger than MaxProxyNameLength for bookkeeping public static readonly int MaxMemberNameLength = 100; // Fair bit larger than MaxProxyNameLength for bookkeeping