summaryrefslogtreecommitdiff
path: root/src/api/bot
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-11-11 00:27:02 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-11-11 00:27:02 +0900
commit3f0f307104300e148b02f05fd51ac833f9b75b01 (patch)
tree131ad6c84bcbad684d0fac285915953045e30627 /src/api/bot
parentv2996 (diff)
downloadsharkey-3f0f307104300e148b02f05fd51ac833f9b75b01.tar.gz
sharkey-3f0f307104300e148b02f05fd51ac833f9b75b01.tar.bz2
sharkey-3f0f307104300e148b02f05fd51ac833f9b75b01.zip
[LINE] 通知の表示に対応
Diffstat (limited to 'src/api/bot')
-rw-r--r--src/api/bot/core.ts24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/api/bot/core.ts b/src/api/bot/core.ts
index 8324390880..ff3f681804 100644
--- a/src/api/bot/core.ts
+++ b/src/api/bot/core.ts
@@ -5,6 +5,7 @@ import User, { IUser, init as initUser } from '../models/user';
import getPostSummary from '../../common/get-post-summary';
import getUserSummary from '../../common/get-user-summary';
+import getNotificationSummary from '../../common/get-notification-summary';
import Othello, { ai as othelloAi } from '../../common/othello';
@@ -84,6 +85,7 @@ export default class BotCore extends EventEmitter {
'logout, signout: サインアウトします\n' +
'post: 投稿します\n' +
'tl: タイムラインを見ます\n' +
+ 'no: 通知を見ます\n' +
'@<ユーザー名>: ユーザーを表示します';
case 'me':
@@ -115,6 +117,11 @@ export default class BotCore extends EventEmitter {
case 'タイムライン':
return await this.tlCommand();
+ case 'no':
+ case 'notifications':
+ case '通知':
+ return await this.notificationsCommand();
+
case 'guessing-game':
case '数当てゲーム':
this.setContext(new GuessingGameContext(this));
@@ -155,6 +162,7 @@ export default class BotCore extends EventEmitter {
this.emit('updated');
}
+ // TODO: if (this.user == null) return 'まずサインインしてください。'; を @signinRequired みたいなデコレータでいい感じにする
public async tlCommand(): Promise<string | void> {
if (this.user == null) return 'まずサインインしてください。';
@@ -163,7 +171,21 @@ export default class BotCore extends EventEmitter {
}, this.user);
const text = tl
- .map(post => getPostSummary(post))
+ .map(post => post.user.name + ': ' + getPostSummary(post))
+ .join('\n-----\n');
+
+ return text;
+ }
+
+ public async notificationsCommand(): Promise<string | void> {
+ if (this.user == null) return 'まずサインインしてください。';
+
+ const notifications = await require('../endpoints/i/notifications')({
+ limit: 5
+ }, this.user);
+
+ const text = notifications
+ .map(notification => getNotificationSummary(notification))
.join('\n-----\n');
return text;