diff --git a/packages/core/src/command/index.ts b/packages/core/src/command/index.ts index e6b6a857a..f44aeb25f 100644 --- a/packages/core/src/command/index.ts +++ b/packages/core/src/command/index.ts @@ -44,6 +44,7 @@ interface DeclarationList extends Array { export namespace Commander { export interface Config { prefix?: Computed + prefixMode?: 'auto' | 'strict' } } @@ -282,7 +283,8 @@ export class Commander { const { stripped, isDirect } = argv.session // guild message should have prefix or appel to be interpreted as a command call - if (argv.root && !isDirect && stripped.prefix === null && !stripped.appel) return + const isStrict = this.config.prefixMode === 'strict' || !isDirect && !stripped.appel + if (argv.root && stripped.prefix === null && isStrict) return const segments: string[] = [] while (argv.tokens.length) { const { content } = argv.tokens[0] diff --git a/packages/core/src/context.ts b/packages/core/src/context.ts index 9df3270d2..8cda405b2 100644 --- a/packages/core/src/context.ts +++ b/packages/core/src/context.ts @@ -158,6 +158,10 @@ export namespace Context { defineProperty(Context.Config, 'Basic', Schema.object({ prefix: Schema.array(Schema.string().default('')).default(['']).role('table').computed().description('指令前缀字符构成的数组。将被用于指令的匹配。'), + prefixMode: Schema.union([ + Schema.const('auto').description('默认:当存在称呼时允许无前缀触发。'), + Schema.const('strict').description('严格:只有在指令前缀匹配时才允许触发。'), + ]).experimental().role('radio').default('auto').description('指令前缀匹配模式。'), nickname: Schema.array(String).role('table').computed().description('机器人昵称构成的数组。将被用于指令的匹配。'), autoAssign: Schema.boolean().default(true).computed().description('当获取不到频道数据时,是否使用接受者作为受理人。'), autoAuthorize: Schema.natural().default(1).computed().description('当获取不到用户数据时默认使用的权限等级。'),