This commit is contained in:
syuilo 2017-10-07 17:20:47 +09:00
parent 68ea377759
commit d1f5d62251
2 changed files with 22 additions and 8 deletions

View File

@ -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 '投稿しましたよ!';
}

View File

@ -0,0 +1,12 @@
import { IUser } from '../api/models/user';
/**
*
* @param user
*/
export default function(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}`;
}