ai/src/modules/fortune/index.ts
2019-01-15 18:47:22 +09:00

33 lines
1.1 KiB
TypeScript

import autobind from 'autobind-decorator';
import Module from '../../module';
import Message from '../../message';
import serifs from '../../serifs';
import * as seedrandom from 'seedrandom';
import { blessing, itemPrefixes, items } from './vocabulary';
export default class FortuneModule extends Module {
public readonly name = 'fortune';
@autobind
public install() {
return {
mentionHook: this.mentionHook
};
}
@autobind
private mentionHook(msg: Message) {
if (msg.includes(['占', 'うらな', '運勢', 'おみくじ'])) {
const date = new Date();
const seed = `${date.getFullYear()}/${date.getMonth()}/${date.getDate()}@${msg.userId}`;
const rng = seedrandom(seed);
const omikuji = blessing[Math.floor(rng() * blessing.length)];
const itemPrefix = Math.floor(rng() * 5) != 0 ? itemPrefixes[Math.floor(rng() * itemPrefixes.length)] : '';
const item = items[Math.floor(rng() * items.length)];
msg.reply(`**${omikuji}🎉**\nラッキーアイテム: ${itemPrefix}${item}`, serifs.fortune.cw(msg.friend.name));
return true;
} else {
return false;
}
}
}