diff --git a/packages/core/src/command/command.ts b/packages/core/src/command/command.ts index bb88641ef..2aa39d1c5 100644 --- a/packages/core/src/command/command.ts +++ b/packages/core/src/command/command.ts @@ -360,6 +360,7 @@ function toStringType(type: Argv.Type) { export namespace Command { export interface Config extends Argv.CommandBase.Config, Permissions.Config { + captureQuote?: boolean /** disallow unknown options */ checkUnknown?: boolean /** check argument count */ @@ -376,6 +377,7 @@ export namespace Command { permissions: Schema.array(String).role('perms').default(['authority:1']).description('权限继承。'), dependencies: Schema.array(String).role('perms').description('权限依赖。'), slash: Schema.boolean().description('启用斜线指令功能。').default(true), + captureQuote: Schema.boolean().description('是否捕获引用文本。').default(true).hidden(), checkUnknown: Schema.boolean().description('是否检查未知选项。').default(false).hidden(), checkArgCount: Schema.boolean().description('是否检查参数数量。').default(false).hidden(), showWarning: Schema.boolean().description('是否显示警告。').default(true).hidden(), diff --git a/packages/core/src/command/index.ts b/packages/core/src/command/index.ts index 1208548ec..5d3b8bcf9 100644 --- a/packages/core/src/command/index.ts +++ b/packages/core/src/command/index.ts @@ -57,18 +57,9 @@ export class Commander { ctx.before('parse', (content, session) => { // we need to make sure that the user truly has the intension to call a command - const { quote, isDirect, stripped: { prefix, appel } } = session + const { isDirect, stripped: { prefix, appel } } = session if (!isDirect && typeof prefix !== 'string' && !appel) return - const argv = Argv.parse(content) - if (quote?.content) { - argv.tokens.push({ - content: quote.content, - quoted: true, - inters: [], - terminator: '', - }) - } - return argv + return Argv.parse(content) }) ctx.on('interaction/command', (session) => { @@ -173,26 +164,26 @@ export class Commander { }, { numeric: true }) this.domain('integer', (source, session) => { - const value = +source + const value = +source.replace(/[,_]/g, '') if (value * 0 === 0 && Math.floor(value) === value) return value throw new Error('internal.invalid-integer') }, { numeric: true }) this.domain('posint', (source, session) => { - const value = +source + const value = +source.replace(/[,_]/g, '') if (value * 0 === 0 && Math.floor(value) === value && value > 0) return value throw new Error('internal.invalid-posint') }, { numeric: true }) this.domain('natural', (source, session) => { - const value = +source + const value = +source.replace(/[,_]/g, '') if (value * 0 === 0 && Math.floor(value) === value && value >= 0) return value throw new Error('internal.invalid-natural') }, { numeric: true }) this.domain('bigint', (source, session) => { try { - return BigInt(source) + return BigInt(source.replace(/[,_]/g, '')) } catch { throw new Error('internal.invalid-integer') } @@ -291,7 +282,7 @@ export class Commander { if (argv.command) return argv.command if (argv.name) return argv.command = this.resolve(argv.name) - const { stripped, isDirect } = argv.session + const { stripped, isDirect, quote } = argv.session // guild message should have prefix or appel to be interpreted as a command call const isStrict = this.config.prefixMode === 'strict' || !isDirect && !stripped.appel if (argv.root && stripped.prefix === null && isStrict) return @@ -307,6 +298,14 @@ export class Commander { argv.options = command._aliases[name].options if (command._arguments.length) break } + if (argv.command?.config.captureQuote !== false && quote?.content) { + argv.tokens.push({ + content: quote.content, + quoted: true, + inters: [], + terminator: '', + }) + } return argv.command } diff --git a/plugins/common/inspect/src/index.ts b/plugins/common/inspect/src/index.ts index efd5186aa..81e0d5f85 100644 --- a/plugins/common/inspect/src/index.ts +++ b/plugins/common/inspect/src/index.ts @@ -10,7 +10,7 @@ export const Config: Schema = Schema.object({}) export function apply(ctx: Context) { ctx.i18n.define('zh-CN', zhCN) - ctx.command('inspect') + ctx.command('inspect', { captureQuote: false }) .action(({ session }, target) => { if (session.quote) { return session.text('.message', {