From c064ab9e72d7019c094f3e432763f3bcb2d750fb Mon Sep 17 00:00:00 2001 From: Shigma Date: Sat, 30 Dec 2023 23:22:00 +0800 Subject: [PATCH] fix(commands): fix mutable option snapshot, fix #281 --- plugins/commands/src/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugins/commands/src/index.ts b/plugins/commands/src/index.ts index 18f6613b..77771c34 100644 --- a/plugins/commands/src/index.ts +++ b/plugins/commands/src/index.ts @@ -1,4 +1,4 @@ -import { Argv, Command, Context, Dict, remove, Schema } from 'koishi' +import { Argv, clone, Command, Context, Dict, remove, Schema } from 'koishi' import ConsoleExtension from './console' import CommandExtension from './command' @@ -112,8 +112,8 @@ export class CommandManager { parent: command.parent, initial: { aliases: command._aliases, - options: command._options, - config: command.config, + options: clone(command._options), + config: clone(command.config), }, override: { aliases: command._aliases, @@ -240,6 +240,11 @@ export class CommandManager { if (override.config && !Object.keys(override.config).length) { delete override.config } + for (const key in override.options) { + if (override.options[key] && !Object.keys(override.options[key]).length) { + delete override.options[key] + } + } if (override.options && !Object.keys(override.options).length) { delete override.options }