From cc35412cb5f7f2726ca754dc312638c7bbb0560b Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 11 Aug 2018 18:43:50 +0900 Subject: [PATCH] =?UTF-8?q?=E5=8D=A0=E3=81=84=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 10 +++++++++ package.json | 2 ++ src/index.ts | 2 ++ src/message-like.ts | 5 +++-- src/modules/fortune/index.ts | 43 ++++++++++++++++++++++++++++++++++++ src/serifs.ts | 1 + 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/modules/fortune/index.ts diff --git a/package-lock.json b/package-lock.json index bf38284..eb6a8ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,6 +26,11 @@ "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.10.2.tgz", "integrity": "sha512-LqJkY4VQ7S09XhI7kA3ON71AxauROhSv74639VsNXC9ish4IWHnIi98if+nP1MxQV3RMPqXSCYgpPsDHjlg9UQ==" }, + "@types/seedrandom": { + "version": "2.4.27", + "resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-2.4.27.tgz", + "integrity": "sha1-nbVjk33YaRX2kJK8QyWdL0hXjkE=" + }, "@types/ws": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/@types/ws/-/ws-5.1.2.tgz", @@ -461,6 +466,11 @@ "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" }, + "seedrandom": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-2.4.3.tgz", + "integrity": "sha1-JDhQTa0zkXMUv/GKxNeU8W1qrsw=" + }, "source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", diff --git a/package.json b/package.json index 02d2954..1529cdc 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,14 @@ "dependencies": { "@types/node": "10.0.5", "@types/promise-retry": "1.1.2", + "@types/seedrandom": "2.4.27", "@types/ws": "5.1.2", "misskey-reversi": "0.0.5", "promise-retry": "1.1.1", "reconnecting-websocket": "4.0.0-rc5", "request": "2.87.0", "request-promise-native": "1.0.5", + "seedrandom": "2.4.3", "ts-node": "6.0.3", "typescript": "2.8.3", "ws": "6.0.0" diff --git a/src/index.ts b/src/index.ts index 825b057..7676bc1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import ReversiModule from './modules/reversi'; import ServerModule from './modules/server'; import PingModule from './modules/ping'; import EmojiModule from './modules/emoji'; +import FortuneModule from './modules/fortune'; import * as request from 'request-promise-native'; const promiseRetry = require('promise-retry'); @@ -18,6 +19,7 @@ promiseRetry(retry => { ai.install(new PingModule()); ai.install(new EmojiModule()); + ai.install(new FortuneModule()); ai.install(new ServerModule()); ai.install(new ReversiModule()); }); diff --git a/src/message-like.ts b/src/message-like.ts index 413e90e..6b2947c 100644 --- a/src/message-like.ts +++ b/src/message-like.ts @@ -23,7 +23,7 @@ export default class MessageLike { this.isMessage = isMessage; } - public reply = (text: string) => { + public reply = (text: string, cw?: string) => { console.log(`sending reply of ${this.id} ...`); setTimeout(() => { @@ -34,7 +34,8 @@ export default class MessageLike { } else { this.ai.post({ replyId: this.messageOrNote.id, - text: text + text: text, + cw: cw }); } }, 2000); diff --git a/src/modules/fortune/index.ts b/src/modules/fortune/index.ts new file mode 100644 index 0000000..cf1e705 --- /dev/null +++ b/src/modules/fortune/index.ts @@ -0,0 +1,43 @@ +import 藍 from '../../ai'; +import IModule from '../../module'; +import MessageLike from '../../message-like'; +import serifs from '../../serifs'; +import * as seedrandom from 'seedrandom'; + +const omikujis = [ + '大大吉', + '大吉', + '吉', + '中吉', + '小吉', + '凶', + '大凶' +]; + +const items = [ + 'ナス', + 'トマト', + 'きゅうり', + 'じゃがいも', + '焼きビーフン', + '腰', + '寿司' +]; + +export default class EmojiModule implements IModule { + public install = (ai: 藍) => { } + + public onMention = (msg: MessageLike) => { + if (msg.text && msg.text.indexOf('占') > -1) { + const date = new Date(); + const seed = `${date.getFullYear()}/${date.getMonth()}/${date.getDay()}@${msg.userId}`; + const rng = seedrandom(seed); + const omikuji = omikujis[Math.floor(rng() * omikujis.length)]; + const item = items[Math.floor(rng() * items.length)]; + msg.reply(`**${omikuji}🎉**\nラッキーアイテム: ${item}`, serifs.FORTUNE_CW); + return true; + } else { + return false; + } + } +} diff --git a/src/serifs.ts b/src/serifs.ts index bfb127e..ae23a2b 100644 --- a/src/serifs.ts +++ b/src/serifs.ts @@ -25,4 +25,5 @@ export default { */ EMOJI_SUGGEST: 'こんなのはどうですか?→$', + FORTUNE_CW: '私が今日のあなたの運勢を占いました...' };