Skip to content

Commit

Permalink
feat(teach): trigger dialogue command in middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Sep 13, 2020
1 parent 1605d2e commit a056933
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/plugin-teach/src/receiver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ declare module './utils' {
}
}

// TODO change name
export interface SessionState {
userId: number
groupId: number
Expand Down Expand Up @@ -163,7 +162,7 @@ export class MessageBuffer {
}
}

export async function triggerDialogue(ctx: Context, session: Session, config: Dialogue.Config, next: NextFunction = noop) {
export async function triggerDialogue(ctx: Context, session: Session, next: NextFunction = noop) {
const state = ctx.getSessionState(session)
state.next = next
state.test = {}
Expand Down Expand Up @@ -269,7 +268,11 @@ export default function (ctx: Context, config: Dialogue.Config) {
}

ctx.group().middleware(async (session, next) => {
return triggerDialogue(ctx, session, config, next)
return session.$execute({
command: 'dialogue',
args: [session.message],
next,
})
})

ctx.on('dialogue/receive', ({ session, test }) => {
Expand All @@ -295,11 +298,11 @@ export default function (ctx: Context, config: Dialogue.Config) {
}
})

ctx.group().command('teach/dialogue <message...>', '触发教学对话')
ctx.group().command('dialogue <message...>', '触发教学对话')
.action(async ({ session, next }, message = '') => {
if (session._redirected > maxRedirections) return next()
session.message = message
return triggerDialogue(ctx, session, config, next)
return triggerDialogue(ctx, session, next)
})
}

Expand Down

0 comments on commit a056933

Please sign in to comment.