add missing confirms to command handlers and -yes flags to the definitions

This commit is contained in:
dawn 2026-01-26 02:38:53 +03:00
parent 12655fb539
commit 498d657cd4
No known key found for this signature in database
3 changed files with 19 additions and 6 deletions

View file

@ -237,10 +237,10 @@ public partial class CommandTree
Commands.GroupClearName(var param, var flags) => ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, param.target, null)), Commands.GroupClearName(var param, var flags) => ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, param.target, null)),
Commands.GroupRename(var param, var flags) => ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, param.target, param.name, flags.yes)), Commands.GroupRename(var param, var flags) => ctx.Execute<Groups>(GroupRename, g => g.RenameGroup(ctx, param.target, param.name, flags.yes)),
Commands.GroupShowDisplayName(var param, var flags) => ctx.Execute<Groups>(GroupDisplayName, g => g.ShowGroupDisplayName(ctx, param.target, flags.GetReplyFormat())), Commands.GroupShowDisplayName(var param, var flags) => ctx.Execute<Groups>(GroupDisplayName, g => g.ShowGroupDisplayName(ctx, param.target, flags.GetReplyFormat())),
Commands.GroupClearDisplayName(var param, var flags) => ctx.Execute<Groups>(GroupDisplayName, g => g.ClearGroupDisplayName(ctx, param.target)), Commands.GroupClearDisplayName(var param, var flags) => ctx.Execute<Groups>(GroupDisplayName, g => g.ClearGroupDisplayName(ctx, param.target, flags.yes)),
Commands.GroupChangeDisplayName(var param, _) => ctx.Execute<Groups>(GroupDisplayName, g => g.ChangeGroupDisplayName(ctx, param.target, param.name)), Commands.GroupChangeDisplayName(var param, _) => ctx.Execute<Groups>(GroupDisplayName, g => g.ChangeGroupDisplayName(ctx, param.target, param.name)),
Commands.GroupShowDescription(var param, var flags) => ctx.Execute<Groups>(GroupDesc, g => g.ShowGroupDescription(ctx, param.target, flags.GetReplyFormat())), Commands.GroupShowDescription(var param, var flags) => ctx.Execute<Groups>(GroupDesc, g => g.ShowGroupDescription(ctx, param.target, flags.GetReplyFormat())),
Commands.GroupClearDescription(var param, var flags) => ctx.Execute<Groups>(GroupDesc, g => g.ClearGroupDescription(ctx, param.target)), Commands.GroupClearDescription(var param, var flags) => ctx.Execute<Groups>(GroupDesc, g => g.ClearGroupDescription(ctx, param.target, flags.yes)),
Commands.GroupChangeDescription(var param, _) => ctx.Execute<Groups>(GroupDesc, g => g.ChangeGroupDescription(ctx, param.target, param.description)), Commands.GroupChangeDescription(var param, _) => ctx.Execute<Groups>(GroupDesc, g => g.ChangeGroupDescription(ctx, param.target, param.description)),
Commands.GroupShowIcon(var param, var flags) => ctx.Execute<Groups>(GroupIcon, g => g.ShowGroupIcon(ctx, param.target, flags.GetReplyFormat())), Commands.GroupShowIcon(var param, var flags) => ctx.Execute<Groups>(GroupIcon, g => g.ShowGroupIcon(ctx, param.target, flags.GetReplyFormat())),
Commands.GroupClearIcon(var param, var flags) => ctx.Execute<Groups>(GroupIcon, g => g.ClearGroupIcon(ctx, param.target, flags.yes)), Commands.GroupClearIcon(var param, var flags) => ctx.Execute<Groups>(GroupIcon, g => g.ClearGroupIcon(ctx, param.target, flags.yes)),
@ -249,7 +249,7 @@ public partial class CommandTree
Commands.GroupClearBanner(var param, var flags) => ctx.Execute<Groups>(GroupBannerImage, g => g.ClearGroupBanner(ctx, param.target, flags.yes)), Commands.GroupClearBanner(var param, var flags) => ctx.Execute<Groups>(GroupBannerImage, g => g.ClearGroupBanner(ctx, param.target, flags.yes)),
Commands.GroupChangeBanner(var param, _) => ctx.Execute<Groups>(GroupBannerImage, g => g.ChangeGroupBanner(ctx, param.target, param.banner)), Commands.GroupChangeBanner(var param, _) => ctx.Execute<Groups>(GroupBannerImage, g => g.ChangeGroupBanner(ctx, param.target, param.banner)),
Commands.GroupShowColor(var param, var flags) => ctx.Execute<Groups>(GroupColor, g => g.ShowGroupColor(ctx, param.target, flags.GetReplyFormat())), Commands.GroupShowColor(var param, var flags) => ctx.Execute<Groups>(GroupColor, g => g.ShowGroupColor(ctx, param.target, flags.GetReplyFormat())),
Commands.GroupClearColor(var param, var flags) => ctx.Execute<Groups>(GroupColor, g => g.ClearGroupColor(ctx, param.target)), Commands.GroupClearColor(var param, var flags) => ctx.Execute<Groups>(GroupColor, g => g.ClearGroupColor(ctx, param.target, flags.yes)),
Commands.GroupChangeColor(var param, _) => ctx.Execute<Groups>(GroupColor, g => g.ChangeGroupColor(ctx, param.target, param.color)), Commands.GroupChangeColor(var param, _) => ctx.Execute<Groups>(GroupColor, g => g.ChangeGroupColor(ctx, param.target, param.color)),
Commands.GroupAddMember(var param, var flags) => ctx.Execute<GroupMember>(GroupAdd, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Add, flags.all)), Commands.GroupAddMember(var param, var flags) => ctx.Execute<GroupMember>(GroupAdd, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Add, flags.all)),
Commands.GroupRemoveMember(var param, var flags) => ctx.Execute<GroupMember>(GroupRemove, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Remove, flags.all, flags.yes)), Commands.GroupRemoveMember(var param, var flags) => ctx.Execute<GroupMember>(GroupRemove, g => g.AddRemoveMembers(ctx, param.target, param.targets, Groups.AddRemoveOperation.Remove, flags.all, flags.yes)),

View file

@ -174,10 +174,13 @@ public class Groups
await ctx.Reply(embed: eb2.Build()); await ctx.Reply(embed: eb2.Build());
} }
public async Task ClearGroupDisplayName(Context ctx, PKGroup target) public async Task ClearGroupDisplayName(Context ctx, PKGroup target, bool confirmYes = false)
{ {
ctx.CheckOwnGroup(target); ctx.CheckOwnGroup(target);
if (!await ctx.ConfirmClear("this group's display name", confirmYes))
return;
var patch = new GroupPatch { DisplayName = Partial<string>.Null() }; var patch = new GroupPatch { DisplayName = Partial<string>.Null() };
await ctx.Repository.UpdateGroup(target.Id, patch); await ctx.Repository.UpdateGroup(target.Id, patch);
@ -253,10 +256,13 @@ public class Groups
await ctx.Reply(embed: eb2.Build()); await ctx.Reply(embed: eb2.Build());
} }
public async Task ClearGroupDescription(Context ctx, PKGroup target) public async Task ClearGroupDescription(Context ctx, PKGroup target, bool confirmYes = false)
{ {
ctx.CheckOwnGroup(target); ctx.CheckOwnGroup(target);
if (!await ctx.ConfirmClear("this group's description", confirmYes))
return;
var patch = new GroupPatch { Description = Partial<string>.Null() }; var patch = new GroupPatch { Description = Partial<string>.Null() };
await ctx.Repository.UpdateGroup(target.Id, patch); await ctx.Repository.UpdateGroup(target.Id, patch);
@ -479,10 +485,13 @@ public class Groups
await ctx.Reply(embed: eb.Build(), files: [MiscUtils.GenerateColorPreview(target.Color)]); await ctx.Reply(embed: eb.Build(), files: [MiscUtils.GenerateColorPreview(target.Color)]);
} }
public async Task ClearGroupColor(Context ctx, PKGroup target) public async Task ClearGroupColor(Context ctx, PKGroup target, bool confirmYes = false)
{ {
ctx.CheckOwnGroup(target); ctx.CheckOwnGroup(target);
if (!await ctx.ConfirmClear("this group's color", confirmYes))
return;
await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { Color = Partial<string>.Null() }); await ctx.Repository.UpdateGroup(target.Id, new GroupPatch { Color = Partial<string>.Null() });
await ctx.Reply($"{Emojis.Success} Group color cleared."); await ctx.Reply($"{Emojis.Success} Group color cleared.");

View file

@ -38,6 +38,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
let group_name_cmd = [ let group_name_cmd = [
command!(group_name => "group_show_name").help("Shows the group's name"), command!(group_name => "group_show_name").help("Shows the group's name"),
command!(group_name, CLEAR => "group_clear_name") command!(group_name, CLEAR => "group_clear_name")
.flag(YES)
.help("Clears the group's name"), .help("Clears the group's name"),
command!(group_name, Remainder(("name", OpaqueString)) => "group_rename") command!(group_name, Remainder(("name", OpaqueString)) => "group_rename")
.flag(YES) .flag(YES)
@ -49,6 +50,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
command!(group_display_name => "group_show_display_name") command!(group_display_name => "group_show_display_name")
.help("Shows the group's display name"), .help("Shows the group's display name"),
command!(group_display_name, CLEAR => "group_clear_display_name") command!(group_display_name, CLEAR => "group_clear_display_name")
.flag(YES)
.help("Clears the group's display name"), .help("Clears the group's display name"),
command!(group_display_name, Remainder(("name", OpaqueString)) => "group_change_display_name") command!(group_display_name, Remainder(("name", OpaqueString)) => "group_change_display_name")
.help("Changes the group's display name"), .help("Changes the group's display name"),
@ -65,6 +67,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
command!(group_description => "group_show_description") command!(group_description => "group_show_description")
.help("Shows the group's description"), .help("Shows the group's description"),
command!(group_description, CLEAR => "group_clear_description") command!(group_description, CLEAR => "group_clear_description")
.flag(YES)
.help("Clears the group's description"), .help("Clears the group's description"),
command!(group_description, Remainder(("description", OpaqueString)) => "group_change_description") command!(group_description, Remainder(("description", OpaqueString)) => "group_change_description")
.help("Changes the group's description"), .help("Changes the group's description"),
@ -97,6 +100,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
let group_color_cmd = [ let group_color_cmd = [
command!(group_color => "group_show_color").help("Shows the group's color"), command!(group_color => "group_show_color").help("Shows the group's color"),
command!(group_color, CLEAR => "group_clear_color") command!(group_color, CLEAR => "group_clear_color")
.flag(YES)
.help("Clears the group's color"), .help("Clears the group's color"),
command!(group_color, ("color", OpaqueString) => "group_change_color") command!(group_color, ("color", OpaqueString) => "group_change_color")
.help("Changes a group's color"), .help("Changes a group's color"),