This commit is contained in:
syuilo 2019-01-14 18:17:30 +09:00
parent 8b52efea4c
commit 69bf95e6bf
No known key found for this signature in database
GPG key ID: BDC4C49D06AB9D69
4 changed files with 62 additions and 45 deletions

View file

@ -2,6 +2,7 @@ import 藍 from './ai';
import config from './config'; import config from './config';
import CoreModule from './modules/core'; import CoreModule from './modules/core';
import BirthdayModule from './modules/birthday';
import ReversiModule from './modules/reversi'; import ReversiModule from './modules/reversi';
import PingModule from './modules/ping'; import PingModule from './modules/ping';
import EmojiModule from './modules/emoji'; import EmojiModule from './modules/emoji';
@ -42,6 +43,7 @@ promiseRetry(retry => {
new WelcomeModule(), new WelcomeModule(),
new ServerModule(), new ServerModule(),
new FollowModule(), new FollowModule(),
new BirthdayModule(),
new ValentineModule(), new ValentineModule(),
]; ];

View file

@ -0,0 +1,56 @@
import from '../../ai';
import IModule from '../../module';
import Friend from '../../friend';
import serifs from '../../serifs';
function zeroPadding(num: number, length: number): string {
return ('0000000000' + num).slice(-length);
}
export default class BirthdayModule implements IModule {
public readonly name = 'birthday';
private ai: ;
public install = (ai: ) => {
this.ai = ai;
this.crawleBirthday();
setInterval(this.crawleBirthday, 1000 * 60 * 3);
}
/**
* ()
*/
private crawleBirthday = () => {
const now = new Date();
const m = now.getMonth();
const d = now.getDate();
// Misskeyの誕生日は 2018-06-16 のような形式
const today = `${zeroPadding(m + 1, 2)}-${zeroPadding(d, 2)}`;
const birthFriends = this.ai.friends.find({
'user.profile.birthday': { '$regex': new RegExp('-' + today + '$') }
} as any);
birthFriends.forEach(f => {
const friend = new Friend(this.ai, { doc: f });
// 親愛度が3以上必要
if (friend.love < 3) return;
const data = friend.getPerModulesData(this);
if (data.lastBirthdayChecked == today) return;
data.lastBirthdayChecked = today;
friend.setPerModulesData(this, data);
const text = serifs.birthday.happyBirthday(friend.name);
this.ai.sendMessage(friend.userId, {
text: text
});
});
}
}

View file

@ -2,13 +2,8 @@ import 藍 from '../../ai';
import IModule, { Result } from '../../module'; import IModule, { Result } from '../../module';
import MessageLike from '../../message-like'; import MessageLike from '../../message-like';
import serifs, { getSerif } from '../../serifs'; import serifs, { getSerif } from '../../serifs';
import Friend from '../../friend';
import getDate from '../../utils/get-date'; import getDate from '../../utils/get-date';
function zeroPadding(num: number, length: number): string {
return ('0000000000' + num).slice(-length);
}
const titles = ['さん', 'くん', '君', 'ちゃん', '様', '先生']; const titles = ['さん', 'くん', '君', 'ちゃん', '様', '先生'];
const invalidChars = ['@', '#', '*', ':', '(', '[', ' ', ' ']; const invalidChars = ['@', '#', '*', ':', '(', '[', ' ', ' '];
@ -19,9 +14,6 @@ export default class CoreModule implements IModule {
public install = (ai: ) => { public install = (ai: ) => {
this.ai = ai; this.ai = ai;
this.crawleBirthday();
setInterval(this.crawleBirthday, 1000 * 60 * 3);
} }
public onMention = (msg: MessageLike) => { public onMention = (msg: MessageLike) => {
@ -42,41 +34,6 @@ export default class CoreModule implements IModule {
); );
} }
/**
* ()
*/
private crawleBirthday = () => {
const now = new Date();
const m = now.getMonth();
const d = now.getDate();
// Misskeyの誕生日は 2018-06-16 のような形式
const today = `${zeroPadding(m + 1, 2)}-${zeroPadding(d, 2)}`;
const birthFriends = this.ai.friends.find({
'user.profile.birthday': { '$regex': new RegExp('-' + today + '$') }
} as any);
birthFriends.forEach(f => {
const friend = new Friend(this.ai, { doc: f });
// 親愛度が3以上必要
if (friend.love < 3) return;
const data = friend.getPerModulesData(this);
if (data.lastBirthdayChecked == today) return;
data.lastBirthdayChecked = today;
friend.setPerModulesData(this, data);
const text = serifs.core.happyBirthday(friend.name);
this.ai.sendMessage(friend.userId, {
text: text
});
});
}
private setName = (msg: MessageLike): boolean => { private setName = (msg: MessageLike): boolean => {
if (!msg.text) return false; if (!msg.text) return false;
if (!msg.text.includes('って呼んで')) return false; if (!msg.text.includes('って呼んで')) return false;

View file

@ -42,8 +42,6 @@ export default {
requireMoreLove: 'もっと仲良くなったら考えてあげてもいいですよ?', requireMoreLove: 'もっと仲良くなったら考えてあげてもいいですよ?',
happyBirthday: name => name ? `お誕生日おめでとうございます、${name}🎉` : 'お誕生日おめでとうございます🎉',
nadenade: { nadenade: {
normal: 'ひゃっ…! びっくりしました', normal: 'ひゃっ…! びっくりしました',
@ -113,6 +111,10 @@ export default {
done: res => `${res} です!` done: res => `${res} です!`
}, },
birthday: {
happyBirthday: name => name ? `お誕生日おめでとうございます、${name}🎉` : 'お誕生日おめでとうございます🎉',
},
/** /**
* *
*/ */