mirror of
https://github.com/syuilo/ai.git
synced 2024-11-22 05:08:00 +00:00
占い実装
This commit is contained in:
parent
e9a4ceec09
commit
cc35412cb5
10
package-lock.json
generated
10
package-lock.json
generated
|
@ -26,6 +26,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.10.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.10.2.tgz",
|
||||||
"integrity": "sha512-LqJkY4VQ7S09XhI7kA3ON71AxauROhSv74639VsNXC9ish4IWHnIi98if+nP1MxQV3RMPqXSCYgpPsDHjlg9UQ=="
|
"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": {
|
"@types/ws": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-5.1.2.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
|
"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": {
|
"source-map": {
|
||||||
"version": "0.6.1",
|
"version": "0.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
|
||||||
|
|
|
@ -7,12 +7,14 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/node": "10.0.5",
|
"@types/node": "10.0.5",
|
||||||
"@types/promise-retry": "1.1.2",
|
"@types/promise-retry": "1.1.2",
|
||||||
|
"@types/seedrandom": "2.4.27",
|
||||||
"@types/ws": "5.1.2",
|
"@types/ws": "5.1.2",
|
||||||
"misskey-reversi": "0.0.5",
|
"misskey-reversi": "0.0.5",
|
||||||
"promise-retry": "1.1.1",
|
"promise-retry": "1.1.1",
|
||||||
"reconnecting-websocket": "4.0.0-rc5",
|
"reconnecting-websocket": "4.0.0-rc5",
|
||||||
"request": "2.87.0",
|
"request": "2.87.0",
|
||||||
"request-promise-native": "1.0.5",
|
"request-promise-native": "1.0.5",
|
||||||
|
"seedrandom": "2.4.3",
|
||||||
"ts-node": "6.0.3",
|
"ts-node": "6.0.3",
|
||||||
"typescript": "2.8.3",
|
"typescript": "2.8.3",
|
||||||
"ws": "6.0.0"
|
"ws": "6.0.0"
|
||||||
|
|
|
@ -4,6 +4,7 @@ import ReversiModule from './modules/reversi';
|
||||||
import ServerModule from './modules/server';
|
import ServerModule from './modules/server';
|
||||||
import PingModule from './modules/ping';
|
import PingModule from './modules/ping';
|
||||||
import EmojiModule from './modules/emoji';
|
import EmojiModule from './modules/emoji';
|
||||||
|
import FortuneModule from './modules/fortune';
|
||||||
import * as request from 'request-promise-native';
|
import * as request from 'request-promise-native';
|
||||||
const promiseRetry = require('promise-retry');
|
const promiseRetry = require('promise-retry');
|
||||||
|
|
||||||
|
@ -18,6 +19,7 @@ promiseRetry(retry => {
|
||||||
|
|
||||||
ai.install(new PingModule());
|
ai.install(new PingModule());
|
||||||
ai.install(new EmojiModule());
|
ai.install(new EmojiModule());
|
||||||
|
ai.install(new FortuneModule());
|
||||||
ai.install(new ServerModule());
|
ai.install(new ServerModule());
|
||||||
ai.install(new ReversiModule());
|
ai.install(new ReversiModule());
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,7 +23,7 @@ export default class MessageLike {
|
||||||
this.isMessage = isMessage;
|
this.isMessage = isMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public reply = (text: string) => {
|
public reply = (text: string, cw?: string) => {
|
||||||
console.log(`sending reply of ${this.id} ...`);
|
console.log(`sending reply of ${this.id} ...`);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
@ -34,7 +34,8 @@ export default class MessageLike {
|
||||||
} else {
|
} else {
|
||||||
this.ai.post({
|
this.ai.post({
|
||||||
replyId: this.messageOrNote.id,
|
replyId: this.messageOrNote.id,
|
||||||
text: text
|
text: text,
|
||||||
|
cw: cw
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
|
43
src/modules/fortune/index.ts
Normal file
43
src/modules/fortune/index.ts
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,4 +25,5 @@ export default {
|
||||||
*/
|
*/
|
||||||
EMOJI_SUGGEST: 'こんなのはどうですか?→$',
|
EMOJI_SUGGEST: 'こんなのはどうですか?→$',
|
||||||
|
|
||||||
|
FORTUNE_CW: '私が今日のあなたの運勢を占いました...'
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue