Add groups to pk;admin
This commit is contained in:
@@ -77,6 +77,36 @@ namespace PluralKit.Bot
|
||||
await ctx.Reply($"{Emojis.Success} Member ID updated (`{target.Hid}` -> `{newHid}`).");
|
||||
}
|
||||
|
||||
public async Task UpdateGroupId(Context ctx)
|
||||
{
|
||||
AssertBotAdmin(ctx);
|
||||
|
||||
var target = await ctx.MatchGroup();
|
||||
if (target == null)
|
||||
throw new PKError("Unknown group.");
|
||||
|
||||
var newHid = ctx.PopArgument();
|
||||
if (!Regex.IsMatch(newHid, "^[a-z]{5}$"))
|
||||
throw new PKError($"Invalid new group ID `{newHid}`.");
|
||||
|
||||
var existingGroup = await _db.Execute(c => _repo.GetGroupByHid(c, newHid));
|
||||
if (existingGroup != null)
|
||||
throw new PKError($"Another group already exists with ID `{newHid}`.");
|
||||
|
||||
var prompt = new YesNoPrompt(ctx)
|
||||
{
|
||||
Message = $"Change group ID of **{target.Name}** (`{target.Hid}`) to `{newHid}`?",
|
||||
AcceptLabel = "Change"
|
||||
};
|
||||
await prompt.Run();
|
||||
|
||||
if (prompt.Result != true)
|
||||
throw new PKError("ID change cancelled.");
|
||||
|
||||
await _db.Execute(c => _repo.UpdateGroup(c, target.Id, new GroupPatch {Hid = newHid}));
|
||||
await ctx.Reply($"{Emojis.Success} Group ID updated (`{target.Hid}` -> `{newHid}`).");
|
||||
}
|
||||
|
||||
public async Task SystemMemberLimit(Context ctx)
|
||||
{
|
||||
AssertBotAdmin(ctx);
|
||||
@@ -114,6 +144,43 @@ namespace PluralKit.Bot
|
||||
await ctx.Reply($"{Emojis.Success} Member limit updated.");
|
||||
}
|
||||
|
||||
public async Task SystemGroupLimit(Context ctx)
|
||||
{
|
||||
AssertBotAdmin(ctx);
|
||||
|
||||
var target = await ctx.MatchSystem();
|
||||
if (target == null)
|
||||
throw new PKError("Unknown system.");
|
||||
|
||||
var currentLimit = target.GroupLimitOverride ?? Limits.MaxGroupCount;
|
||||
if (!ctx.HasNext())
|
||||
{
|
||||
await ctx.Reply($"Current group limit is **{currentLimit}** groups.");
|
||||
return;
|
||||
}
|
||||
|
||||
var newLimitStr = ctx.PopArgument();
|
||||
if (!int.TryParse(newLimitStr, out var newLimit))
|
||||
throw new PKError($"Couldn't parse `{newLimitStr}` as number.");
|
||||
|
||||
var prompt = new YesNoPrompt(ctx)
|
||||
{
|
||||
Message = $"Update group limit from **{currentLimit}** to **{newLimit}**?",
|
||||
AcceptLabel = "Update"
|
||||
};
|
||||
await prompt.Run();
|
||||
|
||||
if (prompt.Result != true)
|
||||
throw new PKError("Group limit change cancelled.");
|
||||
|
||||
await using var conn = await _db.Obtain();
|
||||
await _repo.UpdateSystem(conn, target.Id, new SystemPatch
|
||||
{
|
||||
GroupLimitOverride = newLimit
|
||||
});
|
||||
await ctx.Reply($"{Emojis.Success} Group limit updated.");
|
||||
}
|
||||
|
||||
private void AssertBotAdmin(Context ctx)
|
||||
{
|
||||
if (!IsBotAdmin(ctx))
|
||||
|
@@ -217,8 +217,12 @@ namespace PluralKit.Bot
|
||||
await ctx.Execute<Admin>(Admin, a => a.UpdateSystemId(ctx));
|
||||
else if (ctx.Match("umid", "updatememberid"))
|
||||
await ctx.Execute<Admin>(Admin, a => a.UpdateMemberId(ctx));
|
||||
else if (ctx.Match("ugid", "updategroupid"))
|
||||
await ctx.Execute<Admin>(Admin, a => a.UpdateGroupId(ctx));
|
||||
else if (ctx.Match("uml", "updatememberlimit"))
|
||||
await ctx.Execute<Admin>(Admin, a => a.SystemMemberLimit(ctx));
|
||||
else if (ctx.Match("ugl", "updategrouplimit"))
|
||||
await ctx.Execute<Admin>(Admin, a => a.SystemGroupLimit(ctx));
|
||||
else
|
||||
await ctx.Reply($"{Emojis.Error} Unknown command.");
|
||||
}
|
||||
|
Reference in New Issue
Block a user