From d80d3c5f04d1473b94bf0e6a7f486bcc4dec1486 Mon Sep 17 00:00:00 2001 From: dev-kittens Date: Fri, 9 Oct 2020 14:23:31 +0000 Subject: [PATCH 1/3] Fix limit message on creating new members --- PluralKit.Bot/Commands/Member.cs | 8 ++++---- PluralKit.Core/Utils/Limits.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/PluralKit.Bot/Commands/Member.cs b/PluralKit.Bot/Commands/Member.cs index 6b2c2bf9..9e236892 100644 --- a/PluralKit.Bot/Commands/Member.cs +++ b/PluralKit.Bot/Commands/Member.cs @@ -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"); 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."); + if (memberCount >= memberLimit) + 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(memberLimit)) + 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) diff --git a/PluralKit.Core/Utils/Limits.cs b/PluralKit.Core/Utils/Limits.cs index 1d2246ef..00f09075 100644 --- a/PluralKit.Core/Utils/Limits.cs +++ b/PluralKit.Core/Utils/Limits.cs @@ -6,7 +6,7 @@ namespace PluralKit.Core { public static readonly int MaxSystemNameLength = 100; public static readonly int MaxSystemTagLength = MaxProxyNameLength - 1; 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 MaxDescriptionLength = 1000; public static readonly int MaxMemberNameLength = 100; // Fair bit larger than MaxProxyNameLength for bookkeeping From 019800f39663305841d76d3cf0770e9e7d880600 Mon Sep 17 00:00:00 2001 From: dev-kittens Date: Fri, 9 Oct 2020 14:24:15 +0000 Subject: [PATCH 2/3] Fix per-system member limit being ignored on import --- PluralKit.Core/Services/DataFileService.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PluralKit.Core/Services/DataFileService.cs b/PluralKit.Core/Services/DataFileService.cs index a2422be0..87f3684c 100644 --- a/PluralKit.Core/Services/DataFileService.cs +++ b/PluralKit.Core/Services/DataFileService.cs @@ -119,7 +119,9 @@ namespace PluralKit.Core system = result.System = await _repo.CreateSystem(conn, data.Name); await _repo.AddAccount(conn, system.Id, accountId); } - + + var memberLimit = system.MemberLimitOverride ?? Limits.MaxMemberCount; + // Apply system info var patch = new SystemPatch {Name = data.Name}; 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 var memberCountBefore = await _repo.GetSystemMemberCount(conn, system.Id); 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.Message = $"Import would exceed the maximum number of members ({Limits.MaxMemberCount})."; + result.Message = $"Import would exceed the maximum number of members ({memberLimit})."; return result; } From 2eade8cb8a4c648258e6440d4275b092ca2bd14e Mon Sep 17 00:00:00 2001 From: spiral Date: Thu, 22 Oct 2020 15:50:56 -0500 Subject: [PATCH 3/3] Fix error message when importing >1k members --- PluralKit.Core/Services/DataFileService.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/PluralKit.Core/Services/DataFileService.cs b/PluralKit.Core/Services/DataFileService.cs index 87f3684c..c694a156 100644 --- a/PluralKit.Core/Services/DataFileService.cs +++ b/PluralKit.Core/Services/DataFileService.cs @@ -206,7 +206,8 @@ namespace PluralKit.Core [JsonIgnore] public bool Valid => TimeZoneValid && 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) && Switches != null && Switches.Count < 10000 && @@ -363,4 +364,4 @@ namespace PluralKit.Core [JsonIgnore] public bool Valid => true; } -} \ No newline at end of file +}