Skip to content

Commit

Permalink
Update events.ts
Browse files Browse the repository at this point in the history
core: fix command execute by string
  • Loading branch information
ahdg6 committed Jul 2, 2024
1 parent 1297634 commit a29918d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/core/src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ export interface ServiceContext {

get commands(): CommandInstance[];

executeString(bot: Bot, session: MessageSession): void;
executeString(
bot: Bot,
session: MessageSession,
input?: string,
): Promise<CommandInstance[] | undefined>;

addCommandHelp(message: IHelpMessage): IHelpMessage;
}
9 changes: 5 additions & 4 deletions packages/core/src/services/commander/commander.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ export class Commander {
}

executeString(bot: Bot, session: MessageSession, input?: string) {
input = input ?? session.data.content;
if (!input.startsWith(this.prefix)) return;
return this.parseStringAndExecuteFound(bot, session);
return this.parseStringAndExecuteFound(bot, session, input);
}

command<T extends Flags, P extends string>(
Expand Down Expand Up @@ -187,8 +185,11 @@ export class Commander {
private async parseStringAndExecuteFound(
bot: Bot,
session: MessageSession,
input?: string,
): Promise<CommandInstance[] | undefined> {
let input = session.data.content.substring(this.prefix.length);
if (input == undefined) {
input = session.data.content.substring(this.prefix.length);
}

const response = await this.ctx.bail('command/before-parse', input, bot, session);
// 如果 response 没被返回任何内容,则正常解析,如果返回了一个字符串则覆盖要解析的内容,如果返回了 false 则取消该指令解析
Expand Down

0 comments on commit a29918d

Please sign in to comment.