Skip to content

Commit

Permalink
fix(teach): empty content should not trigger answer, fix #457
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 3, 2022
1 parent e9da7b4 commit f6e348b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
10 changes: 6 additions & 4 deletions plugins/teach/src/receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ const fullWidth = ',、。~?!()【】'
const fullWidthRegExp = new RegExp(`[${fullWidth}]`)

export async function triggerDialogue(ctx: Context, session: Session, next: Next = noop) {
if (!session.content) return

const state = ctx.getSessionState(session)
state.next = next
state.test = {}
Expand Down Expand Up @@ -246,7 +248,7 @@ export async function triggerDialogue(ctx: Context, session: Session, next: Next
await ctx.app.parallel(session, 'dialogue/send', state)
}

export default function apply(ctx: Context, config: Dialogue.Config) {
export default function receiver(ctx: Context, config: Dialogue.Config) {
const { nickname = ctx.app.options.nickname, maxRedirections = 3 } = config
const nicknames = makeArray(nickname).map(escapeRegExp)
const nicknameRE = new RegExp(`^((${nicknames.join('|')})[,,]?\\s*)+`)
Expand Down Expand Up @@ -336,9 +338,9 @@ export default function apply(ctx: Context, config: Dialogue.Config) {
})

ctx2.command('dialogue <message:text>', '触发教学对话')
.action(async ({ session, next }, message = '') => {
if (session._redirected > maxRedirections) return next()
.action(async ({ session }, message = '') => {
if (session._redirected > maxRedirections) return
session.content = message
return triggerDialogue(ctx, session, next)
return triggerDialogue(ctx, session)
})
}
1 change: 0 additions & 1 deletion plugins/teach/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ function isIntegerOrInterval(source: string) {
}

function review(dialogues: Dialogue[], argv: Dialogue.Argv) {
const { session } = argv
const output = dialogues.map((d) => {
const details = getDetails(argv, d)
const { questionType = '问题', answerType = '回答' } = details
Expand Down

0 comments on commit f6e348b

Please sign in to comment.