From 9b7f3ebbb1bfbea4e154f408e29243f38c1b1ea3 Mon Sep 17 00:00:00 2001 From: Shigma <1700011071@pku.edu.cn> Date: Wed, 14 Oct 2020 02:30:27 +0800 Subject: [PATCH] fix(teach): braces should not be stripped for regexp questions --- packages/plugin-teach/src/internal.ts | 6 ++++-- packages/plugin-teach/src/receiver.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/plugin-teach/src/internal.ts b/packages/plugin-teach/src/internal.ts index 3dabeac6bc..16710a6759 100644 --- a/packages/plugin-teach/src/internal.ts +++ b/packages/plugin-teach/src/internal.ts @@ -59,11 +59,13 @@ export default function apply(ctx: Context, config: Dialogue.Config) { return Message.Teach.ProhibitedCQCode } - const { unprefixed, prefixed, appellative } = config._stripQuestion(options.question) + const { unprefixed, prefixed, appellative } = options.regexp + ? { unprefixed: question, prefixed: question, appellative: false } + : config._stripQuestion(question) argv.appellative = appellative Object.defineProperty(options, '_original', { value: prefixed }) if (unprefixed) { - options.original = options.question + options.original = question options.question = unprefixed } else { delete options.question diff --git a/packages/plugin-teach/src/receiver.ts b/packages/plugin-teach/src/receiver.ts index 64f588c73f..5df7463f63 100644 --- a/packages/plugin-teach/src/receiver.ts +++ b/packages/plugin-teach/src/receiver.ts @@ -307,7 +307,7 @@ export default function (ctx: Context, config: Dialogue.Config) { } function prepareSource(source: string) { - return CQCode.stringifyAll(CQCode.parseAll(source || '').map((code, index, arr) => { + return CQCode.stringifyAll(CQCode.parseAll(source).map((code, index, arr) => { if (typeof code !== 'string') return code let message = simplify(CQCode.unescape('' + code)) .toLowerCase()