From 5c3408714bb9a347b26e33b8ae71ea78ed68f451 Mon Sep 17 00:00:00 2001 From: Xeltica <7106976+Xeltica@users.noreply.github.com> Date: Mon, 3 Dec 2018 16:48:00 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AD=E3=83=90=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=8F=E3=82=8C=E3=82=8B=E6=A9=9F=E8=83=BD=20(#20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Implement Follow Back * Require more love * モジュール読むの忘れてたw * 条件式ミスった * 完全なユーザー情報を取れるように * バグったのでやり方かえた * 毎度取得することに * 型がおかしいのなおした * fix bugs * 藍ちゃが好感度に関わらずフォロバするように --- src/index.ts | 4 +++- src/modules/follow/index.ts | 35 +++++++++++++++++++++++++++++++++++ src/serifs.ts | 10 ++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/modules/follow/index.ts diff --git a/src/index.ts b/src/index.ts index 4a17ed3..966c5c3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ import ServerModule from './modules/server'; import * as request from 'request-promise-native'; import IModule from './module'; +import FollowModule from './modules/follow'; const promiseRetry = require('promise-retry'); console.log('--- starting ai... ---'); @@ -38,7 +39,8 @@ promiseRetry(retry => { new CoreModule(), new PingModule(), new WelcomeModule(), - new ServerModule() + new ServerModule(), + new FollowModule(), ]; if (config.keywordEnabled) modules.push(new KeywordModule()); diff --git a/src/modules/follow/index.ts b/src/modules/follow/index.ts new file mode 100644 index 0000000..ad501bf --- /dev/null +++ b/src/modules/follow/index.ts @@ -0,0 +1,35 @@ +import 藍 from '../../ai'; +import IModule from '../../module'; +import MessageLike from '../../message-like'; +import serifs from '../../serifs'; + +export default class FollowModule implements IModule { + public readonly name = 'follow'; + private ai: 藍; + + public install = (ai: 藍) => { + this.ai = ai; + } + + public onMention = (msg: MessageLike) => { + if (msg.text && msg.text.includes('フォロー')) { + let user: any; + this.ai.api("users/show", { + userId: msg.userId, + }).then(u => { + user = u; + if (user.isFollowing) { + msg.reply(serifs.follow.alreadyFollowed); + } else { + this.ai.api("following/create", { + userId: msg.userId, + }); + msg.reply(serifs.follow.ok); + } + }); + return true; + } else { + return false; + } + } +} diff --git a/src/serifs.ts b/src/serifs.ts index 55a52ba..bb6e336 100644 --- a/src/serifs.ts +++ b/src/serifs.ts @@ -260,6 +260,16 @@ export default { server: { cpu: 'サーバーの負荷が高そうです。大丈夫でしょうか...?' + }, + + follow: { + ok: 'フォローしました!', + + requireMoreLove: 'もう少し仲良くなったらお願いできますか?', + + alreadyFollowed: 'えっ?既にあなたのことはフォローしていますよ!', + + ng: '嫌です...', } };