Add groups to pk;admin
This commit is contained in:
parent
889e1a8331
commit
c2b6e0eeed
@ -77,6 +77,36 @@ namespace PluralKit.Bot
|
|||||||
await ctx.Reply($"{Emojis.Success} Member ID updated (`{target.Hid}` -> `{newHid}`).");
|
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)
|
public async Task SystemMemberLimit(Context ctx)
|
||||||
{
|
{
|
||||||
AssertBotAdmin(ctx);
|
AssertBotAdmin(ctx);
|
||||||
@ -114,6 +144,43 @@ namespace PluralKit.Bot
|
|||||||
await ctx.Reply($"{Emojis.Success} Member limit updated.");
|
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)
|
private void AssertBotAdmin(Context ctx)
|
||||||
{
|
{
|
||||||
if (!IsBotAdmin(ctx))
|
if (!IsBotAdmin(ctx))
|
||||||
|
@ -217,8 +217,12 @@ namespace PluralKit.Bot
|
|||||||
await ctx.Execute<Admin>(Admin, a => a.UpdateSystemId(ctx));
|
await ctx.Execute<Admin>(Admin, a => a.UpdateSystemId(ctx));
|
||||||
else if (ctx.Match("umid", "updatememberid"))
|
else if (ctx.Match("umid", "updatememberid"))
|
||||||
await ctx.Execute<Admin>(Admin, a => a.UpdateMemberId(ctx));
|
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"))
|
else if (ctx.Match("uml", "updatememberlimit"))
|
||||||
await ctx.Execute<Admin>(Admin, a => a.SystemMemberLimit(ctx));
|
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
|
else
|
||||||
await ctx.Reply($"{Emojis.Error} Unknown command.");
|
await ctx.Reply($"{Emojis.Error} Unknown command.");
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ namespace PluralKit.Core
|
|||||||
public class GroupPatch: PatchObject
|
public class GroupPatch: PatchObject
|
||||||
{
|
{
|
||||||
public Partial<string> Name { get; set; }
|
public Partial<string> Name { get; set; }
|
||||||
|
public Partial<string> Hid { get; set; }
|
||||||
public Partial<string?> DisplayName { get; set; }
|
public Partial<string?> DisplayName { get; set; }
|
||||||
public Partial<string?> Description { get; set; }
|
public Partial<string?> Description { get; set; }
|
||||||
public Partial<string?> Icon { get; set; }
|
public Partial<string?> Icon { get; set; }
|
||||||
@ -18,6 +19,7 @@ namespace PluralKit.Core
|
|||||||
|
|
||||||
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
|
public override UpdateQueryBuilder Apply(UpdateQueryBuilder b) => b
|
||||||
.With("name", Name)
|
.With("name", Name)
|
||||||
|
.With("hid", Hid)
|
||||||
.With("display_name", DisplayName)
|
.With("display_name", DisplayName)
|
||||||
.With("description", Description)
|
.With("description", Description)
|
||||||
.With("icon", Icon)
|
.With("icon", Icon)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user