@@ -11,8 +11,8 @@ const selectCommand = (req) => req.request.command
1111
1212export default class Scene extends Alice {
1313 public name : string
14- public enterCommand : Command
15- public leaveCommand : Command
14+ public enterCommand : Commands
15+ public leaveCommand : Commands
1616 public anyCallback : ( ctx : Ctx ) => void
1717 public commands : Commands
1818 public config : configInterface
@@ -41,17 +41,17 @@ export default class Scene extends Alice {
4141 */
4242 public enter ( name , callback ) {
4343 if ( ! name ) { throw new Error ( 'Enter command name is not specified' ) }
44- this . enterCommand = new Command ( name , callback )
45- this . commands . add ( name , callback )
44+ this . enterCommand = new Commands ( this . config . fuseOptions || null )
45+ this . enterCommand . add ( name , callback )
4646 }
4747
4848 /*
4949 * Trigger to leave the scene
5050 */
5151 public leave ( name , callback ) {
5252 if ( ! name ) { throw new Error ( 'Leave command name is not specified' ) }
53- this . leaveCommand = new Command ( name , callback )
54- this . commands . add ( name , callback )
53+ this . leaveCommand = new Commands ( this . config . fuseOptions || null )
54+ this . leaveCommand . add ( name , callback )
5555 }
5656
5757 public command ( name , callback ) {
@@ -62,30 +62,37 @@ export default class Scene extends Alice {
6262 this . anyCallback = callback
6363 }
6464
65- public isEnterCommand ( commandName ) {
65+ public async isEnterCommand ( ctx ) {
6666 if ( ! this . enterCommand ) { return false }
67- return this . enterCommand . name . toLowerCase ( ) === commandName . toLowerCase ( )
67+ const matched = await this . enterCommand . search ( ctx )
68+ return matched . length !== 0
6869 }
6970
70- public isLeaveCommand ( commandName ) {
71+ public async isLeaveCommand ( ctx ) {
7172 if ( ! this . leaveCommand ) { return false }
72- return this . leaveCommand . name . toLowerCase ( ) === commandName . toLowerCase ( )
73+ const matched = await this . leaveCommand . search ( ctx )
74+ return matched . length !== 0
7375 }
7476
7577 public async handleRequest (
7678 req : WebhookRequest ,
7779 sendResponse : ( res : WebhookResponse ) => void ,
7880 ctx : CtxInterface ,
81+ type : string = null ,
7982 ) : Promise < any > {
8083
8184 ctx . sendResponse = sendResponse
8285 ctx . leaveScene = super . _handleLeaveScene
8386 ctx . enterScene = super . _handleEnterScene
8487
85- const requestedCommands = await this . commands . search ( ctx )
88+ let requestedCommands = [ ]
8689
87- if ( this . isLeaveCommand ( ctx . message ) ) {
88- this . _handleLeaveScene ( )
90+ if ( type === 'enter' ) {
91+ requestedCommands = [ this . enterCommand . get ( ) [ 0 ] ]
92+ } else if ( type === 'leave' ) {
93+ requestedCommands = [ this . leaveCommand . get ( ) [ 0 ] ]
94+ } else {
95+ requestedCommands = await this . commands . search ( ctx )
8996 }
9097
9198 if ( requestedCommands . length !== 0 ) {
0 commit comments