Skip to content

Commit

Permalink
feat(koishi): add config.prefixMode, fix #1364
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 16, 2024
1 parent 781125e commit ff53b75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/core/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface DeclarationList extends Array<Argv.Declaration> {
export namespace Commander {
export interface Config {
prefix?: Computed<string | string[]>
prefixMode?: 'auto' | 'strict'
}
}

Expand Down Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('当获取不到用户数据时默认使用的权限等级。'),
Expand Down

0 comments on commit ff53b75

Please sign in to comment.