mirror of
https://codeberg.org/yeentown/barkey
synced 2024-11-23 00:15:13 +00:00
Refactor
This commit is contained in:
parent
68ea377759
commit
d1f5d62251
2 changed files with 22 additions and 8 deletions
|
@ -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 '投稿しましたよ!';
|
||||
}
|
||||
|
||||
|
|
12
src/common/get-user-summary.ts
Normal file
12
src/common/get-user-summary.ts
Normal 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}」`;
|
||||
}
|
Loading…
Reference in a new issue