feat: add confirm yes flag to clear handlers for system edit

This commit is contained in:
dusk 2025-04-01 16:50:43 +09:00
parent ae2703f5d9
commit 293570c91c
No known key found for this signature in database
3 changed files with 52 additions and 51 deletions

View file

@ -31,35 +31,35 @@ public partial class CommandTree
Commands.SystemShowNameSelf(_, var flags) => ctx.Execute<SystemEdit>(SystemRename, m => m.ShowName(ctx, ctx.System, flags.GetReplyFormat())),
Commands.SystemShowName(var param, var flags) => ctx.Execute<SystemEdit>(SystemRename, m => m.ShowName(ctx, param.target, flags.GetReplyFormat())),
Commands.SystemRename(var param, _) => ctx.Execute<SystemEdit>(SystemRename, m => m.Rename(ctx, ctx.System, param.name)),
Commands.SystemClearName(var param, _) => ctx.Execute<SystemEdit>(SystemRename, m => m.ClearName(ctx, ctx.System)),
Commands.SystemClearName(var param, var flags) => ctx.Execute<SystemEdit>(SystemRename, m => m.ClearName(ctx, ctx.System, flags.yes)),
Commands.SystemShowServerNameSelf(_, var flags) => ctx.Execute<SystemEdit>(SystemServerName, m => m.ShowServerName(ctx, ctx.System, flags.GetReplyFormat())),
Commands.SystemShowServerName(var param, var flags) => ctx.Execute<SystemEdit>(SystemServerName, m => m.ShowServerName(ctx, param.target, flags.GetReplyFormat())),
Commands.SystemClearServerName(var param, _) => ctx.Execute<SystemEdit>(SystemServerName, m => m.ClearServerName(ctx, ctx.System)),
Commands.SystemClearServerName(var param, var flags) => ctx.Execute<SystemEdit>(SystemServerName, m => m.ClearServerName(ctx, ctx.System, flags.yes)),
Commands.SystemRenameServerName(var param, _) => ctx.Execute<SystemEdit>(SystemServerName, m => m.RenameServerName(ctx, ctx.System, param.name)),
Commands.SystemShowDescriptionSelf(_, var flags) => ctx.Execute<SystemEdit>(SystemDesc, m => m.ShowDescription(ctx, ctx.System, flags.GetReplyFormat())),
Commands.SystemShowDescription(var param, var flags) => ctx.Execute<SystemEdit>(SystemDesc, m => m.ShowDescription(ctx, param.target, flags.GetReplyFormat())),
Commands.SystemClearDescription(var param, _) => ctx.Execute<SystemEdit>(SystemDesc, m => m.ClearDescription(ctx, ctx.System)),
Commands.SystemClearDescription(var param, var flags) => ctx.Execute<SystemEdit>(SystemDesc, m => m.ClearDescription(ctx, ctx.System, flags.yes)),
Commands.SystemChangeDescription(var param, _) => ctx.Execute<SystemEdit>(SystemDesc, m => m.ChangeDescription(ctx, ctx.System, param.description)),
Commands.SystemShowColorSelf(_, var flags) => ctx.Execute<SystemEdit>(SystemColor, m => m.ShowColor(ctx, ctx.System, flags.GetReplyFormat())),
Commands.SystemShowColor(var param, var flags) => ctx.Execute<SystemEdit>(SystemColor, m => m.ShowColor(ctx, param.target, flags.GetReplyFormat())),
Commands.SystemClearColor(var param, _) => ctx.Execute<SystemEdit>(SystemColor, m => m.ClearColor(ctx, ctx.System)),
Commands.SystemClearColor(var param, var flags) => ctx.Execute<SystemEdit>(SystemColor, m => m.ClearColor(ctx, ctx.System, flags.yes)),
Commands.SystemChangeColor(var param, _) => ctx.Execute<SystemEdit>(SystemColor, m => m.ChangeColor(ctx, ctx.System, param.color)),
Commands.SystemShowTagSelf(_, var flags) => ctx.Execute<SystemEdit>(SystemTag, m => m.ShowTag(ctx, ctx.System, flags.GetReplyFormat())),
Commands.SystemShowTag(var param, var flags) => ctx.Execute<SystemEdit>(SystemTag, m => m.ShowTag(ctx, param.target, flags.GetReplyFormat())),
Commands.SystemClearTag(var param, _) => ctx.Execute<SystemEdit>(SystemTag, m => m.ClearTag(ctx, ctx.System)),
Commands.SystemClearTag(var param, var flags) => ctx.Execute<SystemEdit>(SystemTag, m => m.ClearTag(ctx, ctx.System, flags.yes)),
Commands.SystemChangeTag(var param, _) => ctx.Execute<SystemEdit>(SystemTag, m => m.ChangeTag(ctx, ctx.System, param.tag)),
Commands.SystemShowServerTagSelf(_, var flags) => ctx.Execute<SystemEdit>(SystemServerTag, m => m.ShowServerTag(ctx, ctx.System, flags.GetReplyFormat())),
Commands.SystemShowServerTag(var param, var flags) => ctx.Execute<SystemEdit>(SystemServerTag, m => m.ShowServerTag(ctx, param.target, flags.GetReplyFormat())),
Commands.SystemClearServerTag(var param, _) => ctx.Execute<SystemEdit>(SystemServerTag, m => m.ClearServerTag(ctx, ctx.System)),
Commands.SystemClearServerTag(var param, var flags) => ctx.Execute<SystemEdit>(SystemServerTag, m => m.ClearServerTag(ctx, ctx.System, flags.yes)),
Commands.SystemChangeServerTag(var param, _) => ctx.Execute<SystemEdit>(SystemServerTag, m => m.ChangeServerTag(ctx, ctx.System, param.tag)),
Commands.SystemShowPronounsSelf(_, var flags) => ctx.Execute<SystemEdit>(SystemPronouns, m => m.ShowPronouns(ctx, ctx.System, flags.GetReplyFormat())),
Commands.SystemShowPronouns(var param, var flags) => ctx.Execute<SystemEdit>(SystemPronouns, m => m.ShowPronouns(ctx, param.target, flags.GetReplyFormat())),
Commands.SystemClearPronouns(var param, var flags) => ctx.Execute<SystemEdit>(SystemPronouns, m => m.ClearPronouns(ctx, ctx.System, flags.yes)),
Commands.SystemChangePronouns(var param, _) => ctx.Execute<SystemEdit>(SystemPronouns, m => m.ChangePronouns(ctx, ctx.System, param.pronouns)),
_ =>
// this should only ever occur when deving if commands are not implemented...
ctx.Reply(
$"{Emojis.Error} Parsed command {ctx.Parameters.Callback().AsCode()} not implemented in PluralKit.Bot!"),
// this should only ever occur when deving if commands are not implemented...
ctx.Reply(
$"{Emojis.Error} Parsed command {ctx.Parameters.Callback().AsCode()} not implemented in PluralKit.Bot!"),
};
if (ctx.Match("system", "s"))
return HandleSystemCommand(ctx);

View file

@ -64,12 +64,12 @@ public class SystemEdit
return;
}
public async Task ClearName(Context ctx, PKSystem target)
public async Task ClearName(Context ctx, PKSystem target, bool flagConfirmYes)
{
ctx.CheckSystemPrivacy(target.Id, target.NamePrivacy);
ctx.CheckSystem().CheckOwnSystem(target);
if (await ctx.ConfirmClear("your system's name"))
if (await ctx.ConfirmClear("your system's name", flagConfirmYes))
{
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Name = null });
@ -128,12 +128,12 @@ public class SystemEdit
return;
}
public async Task ClearServerName(Context ctx, PKSystem target)
public async Task ClearServerName(Context ctx, PKSystem target, bool flagConfirmYes)
{
ctx.CheckGuildContext();
ctx.CheckSystem().CheckOwnSystem(target);
if (await ctx.ConfirmClear("your system's name for this server"))
if (await ctx.ConfirmClear("your system's name for this server", flagConfirmYes))
{
await ctx.Repository.UpdateSystemGuild(target.Id, ctx.Guild.Id, new SystemGuildPatch { DisplayName = null });
@ -154,12 +154,12 @@ public class SystemEdit
await ctx.Reply($"{Emojis.Success} System name for this server changed (using {newSystemGuildName.Length}/{Limits.MaxSystemNameLength} characters).");
}
public async Task ClearDescription(Context ctx, PKSystem target)
public async Task ClearDescription(Context ctx, PKSystem target, bool flagConfirmYes)
{
ctx.CheckSystemPrivacy(target.Id, target.DescriptionPrivacy);
ctx.CheckSystem().CheckOwnSystem(target);
if (await ctx.ConfirmClear("your system's description"))
if (await ctx.ConfirmClear("your system's description", flagConfirmYes))
{
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Description = null });
@ -237,12 +237,15 @@ public class SystemEdit
.Build());
}
public async Task ClearColor(Context ctx, PKSystem target)
public async Task ClearColor(Context ctx, PKSystem target, bool flagConfirmYes)
{
ctx.CheckSystem().CheckOwnSystem(target);
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Color = Partial<string>.Null() });
await ctx.Reply($"{Emojis.Success} System color cleared.");
if (await ctx.ConfirmClear("your system's color", flagConfirmYes))
{
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Color = Partial<string>.Null() });
await ctx.Reply($"{Emojis.Success} System color cleared.");
}
}
public async Task ShowColor(Context ctx, PKSystem target, ReplyFormat format)
@ -277,11 +280,11 @@ public class SystemEdit
.Build());
}
public async Task ClearTag(Context ctx, PKSystem target)
public async Task ClearTag(Context ctx, PKSystem target, bool flagConfirmYes)
{
ctx.CheckSystem().CheckOwnSystem(target);
if (await ctx.ConfirmClear("your system's tag"))
if (await ctx.ConfirmClear("your system's tag", flagConfirmYes))
{
await ctx.Repository.UpdateSystem(target.Id, new SystemPatch { Tag = null });
@ -402,11 +405,11 @@ public class SystemEdit
$"You currently have no system tag specific to the server '{ctx.Guild.Name}'. To set one, type `{ctx.DefaultPrefix}s servertag <tag>`. To disable the system tag in the current server, type `{ctx.DefaultPrefix}s servertag -disable`.");
}
public async Task ClearServerTag(Context ctx, PKSystem target)
public async Task ClearServerTag(Context ctx, PKSystem target, bool flagConfirmYes)
{
ctx.CheckSystem().CheckOwnSystem(target).CheckGuildContext();
if (!await ctx.ConfirmClear("your system's server tag"))
if (!await ctx.ConfirmClear("your system's server tag", flagConfirmYes))
return;
var settings = await ctx.Repository.GetSystemGuild(ctx.Guild.Id, target.Id);