diff --git a/packages/koishi-core/src/app.ts b/packages/koishi-core/src/app.ts index a8a281baf9..f3eabb4b22 100644 --- a/packages/koishi-core/src/app.ts +++ b/packages/koishi-core/src/app.ts @@ -262,18 +262,18 @@ export class App extends Context { private _preprocess = async (meta: MessageMeta, next: NextFunction) => { // strip prefix let capture: RegExpMatchArray - let atMe = false, nickname = false, prefix: string = null + let atMe = false, nickname = '', prefix: string = null let message = simplify(meta.message.trim()) let parsedArgv: ParsedCommandLine if (meta.messageType !== 'private' && (capture = message.match(this.atMeRE))) { atMe = true - nickname = true + nickname = capture[0] message = message.slice(capture[0].length) } if ((capture = message.match(this.nicknameRE))?.[0].length) { - nickname = true + nickname = capture[0] message = message.slice(capture[0].length) } @@ -283,6 +283,9 @@ export class App extends Context { message = message.slice(capture[0].length) } + // store parsed message + meta.$stripped = { atMe, nickname, prefix, message } + // parse as command if (prefix !== null || nickname || meta.messageType === 'private') { parsedArgv = this.parseCommandLine(message, meta) diff --git a/packages/koishi-core/src/meta.ts b/packages/koishi-core/src/meta.ts index 9d548913e4..11e0bd3a6d 100644 --- a/packages/koishi-core/src/meta.ts +++ b/packages/koishi-core/src/meta.ts @@ -42,6 +42,13 @@ export interface ResponsePayload { reason?: string } +export interface StrippedMessage { + atMe?: boolean + nickname?: string + prefix?: string + message?: string +} + /** CQHTTP Meta Information */ export interface Meta { // database bindings @@ -52,6 +59,9 @@ export interface Meta { $ctxId?: number $ctxType?: ContextType + // other properties + $stripped?: StrippedMessage + // quick operations $response?: (payload: ResponsePayload) => void $delete?: () => Promise