ai/src/modules/valentine/index.ts

52 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-01-14 15:14:22 +00:00
import autobind from 'autobind-decorator';
import Module from '../../module';
2019-01-12 04:14:16 +00:00
import Friend from '../../friend';
import serifs from '../../serifs';
2019-01-14 15:14:22 +00:00
export default class ValentineModule extends Module {
2019-01-12 04:14:16 +00:00
public readonly name = 'valentine';
2019-01-14 15:14:22 +00:00
@autobind
public install() {
2019-01-12 04:14:16 +00:00
this.crawleValentine();
setInterval(this.crawleValentine, 1000 * 60 * 3);
2019-01-14 15:14:22 +00:00
return {};
2019-01-12 04:14:16 +00:00
}
/**
*
*/
2019-01-14 15:14:22 +00:00
@autobind
private crawleValentine() {
2019-01-12 04:14:16 +00:00
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
});
});
}
}