mirror of
https://github.com/syuilo/ai.git
synced 2024-11-14 17:57:59 +00:00
52 lines
1.1 KiB
TypeScript
52 lines
1.1 KiB
TypeScript
|
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
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
}
|