From 7cebf762839e39d13fe6ae5bbff5d30b98e587a7 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 7 Oct 2017 06:03:16 +0900 Subject: [PATCH] :v: --- src/api/bot/core.ts | 5 +++-- src/api/bot/interfaces/line.ts | 20 ++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/api/bot/core.ts b/src/api/bot/core.ts index 1f624c5f0..4109519ca 100644 --- a/src/api/bot/core.ts +++ b/src/api/bot/core.ts @@ -34,7 +34,7 @@ export default class BotCore extends EventEmitter { public static import(data) { const core = new BotCore(); - core.user = data.user; + core.user = data.user ? data.user : null; core.setContect(data.context ? Context.import(core, data.context) : null); return core; } @@ -84,7 +84,7 @@ abstract class Context extends EventEmitter { } class SigninContext extends Context { - private temporaryUser: IUser; + private temporaryUser: IUser = null; public async greet(): Promise { return 'まずユーザー名を教えてください:'; @@ -124,6 +124,7 @@ class SigninContext extends Context { public export() { return { + type: 'signin', temporaryUser: this.temporaryUser }; } diff --git a/src/api/bot/interfaces/line.ts b/src/api/bot/interfaces/line.ts index 61aa72812..52559eaef 100644 --- a/src/api/bot/interfaces/line.ts +++ b/src/api/bot/interfaces/line.ts @@ -32,20 +32,16 @@ module.exports = async (app: express.Application) => { } }); - if (user) { - session = new BotCore(user); - } else { - session = new BotCore(); - session.on('set-user', user => { - User.update(user._id, { - $set: { - line: { - user_id: sourceId - } + session = new BotCore(user); + session.on('set-user', user => { + User.update(user._id, { + $set: { + line: { + user_id: sourceId } - }); + } }); - } + }); redis.set(sessionId, JSON.stringify(session.export())); } else {