summaryrefslogtreecommitdiff
path: root/src/api/bot/core.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-10-07 17:20:47 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-10-07 17:20:47 +0900
commitd1f5d62251526c01b23e741ec363152cc21cc58c (patch)
tree62b8009b1891217f59522c32d0f846fcd67f3a0f /src/api/bot/core.ts
parentMerge pull request #819 from syuilo/greenkeeper/monk-6.0.5 (diff)
downloadsharkey-d1f5d62251526c01b23e741ec363152cc21cc58c.tar.gz
sharkey-d1f5d62251526c01b23e741ec363152cc21cc58c.tar.bz2
sharkey-d1f5d62251526c01b23e741ec363152cc21cc58c.zip
Refactor
Diffstat (limited to 'src/api/bot/core.ts')
-rw-r--r--src/api/bot/core.ts18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/api/bot/core.ts b/src/api/bot/core.ts
index 5038665573..4970f24469 100644
--- a/src/api/bot/core.ts
+++ b/src/api/bot/core.ts
@@ -4,14 +4,12 @@ import * as bcrypt from 'bcryptjs';
import User, { IUser, init as initUser } from '../models/user';
import getPostSummary from '../../common/get-post-summary';
+import getUserSummary from '../../common/get-user-summary';
-function getUserSummary(user: IUser): string {
- return `${user.name} (@${user.username})\n` +
- `${user.posts_count}投稿、${user.following_count}フォロー、${user.followers_count}フォロワー\n` +
- `場所: ${user.profile.location}、誕生日: ${user.profile.birthday}\n` +
- `「${user.description}」`;
-}
+/**
+ * Botの頭脳
+ */
export default class BotCore extends EventEmitter {
public user: IUser = null;
@@ -23,6 +21,10 @@ export default class BotCore extends EventEmitter {
this.user = user;
}
+ public clearContext() {
+ this.setContext(null);
+ }
+
public setContext(context: Context) {
this.context = context;
this.emit('updated');
@@ -178,7 +180,7 @@ class SigninContext extends Context {
if (same) {
this.core.signin(this.temporaryUser);
- this.core.setContext(null);
+ this.core.clearContext();
return `${this.temporaryUser.name}さん、おかえりなさい!`;
} else {
return `パスワードが違います... もう一度教えてください:`;
@@ -211,7 +213,7 @@ class PostContext extends Context {
await require('../endpoints/posts/create')({
text: query
}, this.core.user);
- this.core.setContext(null);
+ this.core.clearContext();
return '投稿しましたよ!';
}