feat(bot): add admin commands for hid rerolls

This commit is contained in:
Iris System 2022-11-23 23:53:21 +13:00
parent 4f0236d766
commit 0d27e669c8
2 changed files with 77 additions and 0 deletions

View File

@ -117,6 +117,12 @@ public partial class CommandTree
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("rsid", "rerollsystemid"))
await ctx.Execute<Admin>(Admin, a => a.RerollSystemId(ctx));
else if (ctx.Match("rmid", "rerollmemberid"))
await ctx.Execute<Admin>(Admin, a => a.RerollMemberId(ctx));
else if (ctx.Match("rgid", "rerollgroupid"))
await ctx.Execute<Admin>(Admin, a => a.RerollGroupId(ctx));
else if (ctx.Match("uml", "updatememberlimit"))
await ctx.Execute<Admin>(Admin, a => a.SystemMemberLimit(ctx));
else if (ctx.Match("ugl", "updategrouplimit"))

View File

@ -1,5 +1,8 @@
using System.Text.RegularExpressions;
using Dapper;
using SqlKata;
using PluralKit.Core;
namespace PluralKit.Bot;
@ -87,6 +90,74 @@ public class Admin
await ctx.Reply($"{Emojis.Success} Group ID updated (`{target.Hid}` -> `{newHid}`).");
}
public async Task RerollSystemId(Context ctx)
{
ctx.AssertBotAdmin();
var target = await ctx.MatchSystem();
if (target == null)
throw new PKError("Unknown system.");
if (!await ctx.PromptYesNo($"Reroll system ID `{target.Hid}`?", "Reroll"))
throw new PKError("ID change cancelled.");
var query = new Query("systems").AsUpdate(new
{
hid = new UnsafeLiteral("find_free_system_hid()"),
})
.Where("id", target.Id);
var newHid = await ctx.Database.QueryFirst<string>(query, "returning hid");
await ctx.Reply($"{Emojis.Success} System ID updated (`{target.Hid}` -> `{newHid}`).");
}
public async Task RerollMemberId(Context ctx)
{
ctx.AssertBotAdmin();
var target = await ctx.MatchMember();
if (target == null)
throw new PKError("Unknown member.");
if (!await ctx.PromptYesNo(
$"Reroll member ID for **{target.NameFor(LookupContext.ByNonOwner)}** (`{target.Hid}`)?",
"Reroll"
))
throw new PKError("ID change cancelled.");
var query = new Query("members").AsUpdate(new
{
hid = new UnsafeLiteral("find_free_member_hid()"),
})
.Where("id", target.Id);
var newHid = await ctx.Database.QueryFirst<string>(query, "returning hid");
await ctx.Reply($"{Emojis.Success} Member ID updated (`{target.Hid}` -> `{newHid}`).");
}
public async Task RerollGroupId(Context ctx)
{
ctx.AssertBotAdmin();
var target = await ctx.MatchGroup();
if (target == null)
throw new PKError("Unknown group.");
if (!await ctx.PromptYesNo($"Reroll group ID for **{target.Name}** (`{target.Hid}`)?",
"Change"
))
throw new PKError("ID change cancelled.");
var query = new Query("groups").AsUpdate(new
{
hid = new UnsafeLiteral("find_free_group_hid()"),
})
.Where("id", target.Id);
var newHid = await ctx.Database.QueryFirst<string>(query, "returning hid");
await ctx.Reply($"{Emojis.Success} Group ID updated (`{target.Hid}` -> `{newHid}`).");
}
public async Task SystemMemberLimit(Context ctx)
{
ctx.AssertBotAdmin();