Enforce group count limit on creation
This commit is contained in:
parent
f47d366c8d
commit
47d5ad0004
@ -3,6 +3,8 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Dapper;
|
||||||
|
|
||||||
using DSharpPlus.Entities;
|
using DSharpPlus.Entities;
|
||||||
|
|
||||||
using NodaTime;
|
using NodaTime;
|
||||||
@ -29,8 +31,12 @@ namespace PluralKit.Bot
|
|||||||
throw new PKError($"Group name too long ({groupName.Length}/{Limits.MaxMemberNameLength} characters).");
|
throw new PKError($"Group name too long ({groupName.Length}/{Limits.MaxMemberNameLength} characters).");
|
||||||
|
|
||||||
await using var conn = await _db.Obtain();
|
await using var conn = await _db.Obtain();
|
||||||
var newGroup = await conn.CreateGroup(ctx.System.Id, groupName);
|
|
||||||
|
|
||||||
|
var existingGroupCount = await conn.QuerySingleAsync<int>("select count(*) from groups where system = @System", ctx.System.Id);
|
||||||
|
if (existingGroupCount >= Limits.MaxGroupCount)
|
||||||
|
throw new PKError($"System has reached the maximum number of groups ({Limits.MaxGroupCount}). Please delete unused groups first in order to create new ones.");
|
||||||
|
|
||||||
|
var newGroup = await conn.CreateGroup(ctx.System.Id, groupName);
|
||||||
await ctx.Reply($"{Emojis.Success} Group \"**{groupName}**\" (`{newGroup.Hid}`) registered!\nYou can now start adding members to the group like this:\n> **pk;group `{newGroup.Hid}` add `member1` `member2...`**");
|
await ctx.Reply($"{Emojis.Success} Group \"**{groupName}**\" (`{newGroup.Hid}`) registered!\nYou can now start adding members to the group like this:\n> **pk;group `{newGroup.Hid}` add `member1` `member2...`**");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ namespace PluralKit.Core {
|
|||||||
public static readonly int MaxSystemTagLength = MaxProxyNameLength - 1;
|
public static readonly int MaxSystemTagLength = MaxProxyNameLength - 1;
|
||||||
public static readonly int MaxMemberCount = 1500;
|
public static readonly int MaxMemberCount = 1500;
|
||||||
public static readonly int MaxMembersWarnThreshold = MaxMemberCount - 50;
|
public static readonly int MaxMembersWarnThreshold = MaxMemberCount - 50;
|
||||||
|
public static readonly int MaxGroupCount = 50; // TODO: up to 100+?
|
||||||
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
|
||||||
public static readonly int MaxGroupNameLength = 100;
|
public static readonly int MaxGroupNameLength = 100;
|
||||||
|
Loading…
Reference in New Issue
Block a user