From fc4023791ef4728ce4b1cc7c33b328d867644db3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 12 Jan 2019 13:14:16 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=8D=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 ++ src/modules/valentine/index.ts | 51 ++++++++++++++++++++++++++++++++++ src/serifs.ts | 7 +++++ 3 files changed, 60 insertions(+) create mode 100644 src/modules/valentine/index.ts diff --git a/src/index.ts b/src/index.ts index 3de339f..4823a0c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,6 +13,7 @@ import TimerModule from './modules/timer'; import DiceModule from './modules/dice'; import ServerModule from './modules/server'; import FollowModule from './modules/follow'; +import ValentineModule from './modules/valentine'; import * as request from 'request-promise-native'; import IModule from './module'; @@ -41,6 +42,7 @@ promiseRetry(retry => { new WelcomeModule(), new ServerModule(), new FollowModule(), + new ValentineModule(), ]; if (config.keywordEnabled) modules.push(new KeywordModule()); diff --git a/src/modules/valentine/index.ts b/src/modules/valentine/index.ts new file mode 100644 index 0000000..ad7bed1 --- /dev/null +++ b/src/modules/valentine/index.ts @@ -0,0 +1,51 @@ +import 藍 from '../../ai'; +import IModule from '../../module'; +import Friend from '../../friend'; +import serifs from '../../serifs'; + +export default class ValentineModule implements IModule { + public readonly name = 'valentine'; + + private ai: 藍; + + public install = (ai: 藍) => { + this.ai = ai; + + this.crawleValentine(); + setInterval(this.crawleValentine, 1000 * 60 * 3); + } + + /** + * チョコ配り + */ + private crawleValentine = () => { + const now = new Date(); + + const isValentine = now.getMonth() == 1 && now.getDate() == 14; + if (!isValentine) return; + + const date = `${now.getFullYear()}-${now.getMonth()}-${now.getDate()}`; + + const friends = this.ai.friends.find({} as any); + + friends.forEach(f => { + const friend = new Friend(this.ai, { doc: f }); + + // 親愛度が7以上必要 + if (friend.love < 7) return; + + const data = friend.getPerModulesData(this); + + if (data.lastChocolated == date) return; + + data.lastChocolated = date; + friend.setPerModulesData(this, data); + + const text = serifs.valentine.chocolateForYou(friend.name); + + this.ai.sendMessage(friend.userId, { + text: text + }); + }); + } +} diff --git a/src/serifs.ts b/src/serifs.ts index 10501fb..f370dfc 100644 --- a/src/serifs.ts +++ b/src/serifs.ts @@ -258,6 +258,13 @@ export default { notify: (time, name) => name ? `${name}、${time}経ちましたよ!` : `${time}経ちましたよ!` }, + /** + * バレンタイン + */ + valentine: { + chocolateForYou: name => name ? `${name}、その... チョコレート作ったのでよかったらどうぞ!🍫` : 'チョコレート作ったのでよかったらどうぞ!🍫', + }, + server: { cpu: 'サーバーの負荷が高そうです。大丈夫でしょうか...?' },