mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
Enforce group count limit on creation
This commit is contained in:
parent
f47d366c8d
commit
47d5ad0004
2 changed files with 8 additions and 1 deletions
|
|
@ -3,6 +3,8 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Dapper;
|
||||
|
||||
using DSharpPlus.Entities;
|
||||
|
||||
using NodaTime;
|
||||
|
|
@ -29,8 +31,12 @@ namespace PluralKit.Bot
|
|||
throw new PKError($"Group name too long ({groupName.Length}/{Limits.MaxMemberNameLength} characters).");
|
||||
|
||||
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...`**");
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue