From fa0ebcdb8fa0d7d9e79dfb5d63f26d4d283d02ef Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 31 Aug 2020 20:46:00 +0900 Subject: [PATCH] nannka --- src/friend.ts | 9 ++----- src/index.ts | 2 ++ src/modules/fortune/index.ts | 25 +++++++++++++------- src/modules/noting/index.ts | 40 +++++++++++++++++++++++++++++++ src/serifs.ts | 46 ++++++++++++++++++++++++++++++++++++ src/vocabulary.ts | 32 +++++++++++++++---------- 6 files changed, 125 insertions(+), 29 deletions(-) create mode 100644 src/modules/noting/index.ts diff --git a/src/friend.ts b/src/friend.ts index d1c46ee..63358b7 100644 --- a/src/friend.ts +++ b/src/friend.ts @@ -3,7 +3,7 @@ import 藍 from './ai'; import IModule from './module'; import getDate from './utils/get-date'; import { User } from './misskey/user'; -import { itemPrefixes, items, and } from './vocabulary'; +import { genItem } from './vocabulary'; export type FriendDoc = { userId: string; @@ -142,12 +142,7 @@ export default class Friend { @autobind public generateTransferCode(): string { - let code = ''; - code += itemPrefixes[Math.floor(Math.random() * itemPrefixes.length)]; - code += items[Math.floor(Math.random() * items.length)]; - code += and[Math.floor(Math.random() * and.length)]; - code += itemPrefixes[Math.floor(Math.random() * itemPrefixes.length)]; - code += items[Math.floor(Math.random() * items.length)]; + const code = genItem(); this.doc.transferCode = code; this.save(); diff --git a/src/index.ts b/src/index.ts index 7ad61cc..d062a41 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,6 +28,7 @@ import ValentineModule from './modules/valentine'; import MazeModule from './modules/maze'; import ChartModule from './modules/chart'; import SleepReportModule from './modules/sleep-report'; +import NotingModule from './modules/noting'; console.log(' __ ____ _____ ___ '); console.log(' /__\\ (_ _)( _ )/ __)'); @@ -79,6 +80,7 @@ promiseRetry(retry => { new MazeModule(), new ChartModule(), new SleepReportModule(), + new NotingModule(), ]); }).catch(e => { log(chalk.red('Failed to fetch the account')); diff --git a/src/modules/fortune/index.ts b/src/modules/fortune/index.ts index 84bb778..31f715a 100644 --- a/src/modules/fortune/index.ts +++ b/src/modules/fortune/index.ts @@ -3,7 +3,21 @@ import Module from '../../module'; import Message from '../../message'; import serifs from '../../serifs'; import * as seedrandom from 'seedrandom'; -import { blessing, itemPrefixes, items, and } from '../../vocabulary'; +import { genItem } from '../../vocabulary'; + +export const blessing = [ + '藍吉', + 'ギガ吉', + 'メガ吉', + '超吉', + '大大吉', + '大吉', + '吉', + '中吉', + '小吉', + '凶', + '大凶', +]; export default class extends Module { public readonly name = 'fortune'; @@ -22,14 +36,7 @@ export default class extends Module { const seed = `${date.getFullYear()}/${date.getMonth()}/${date.getDate()}@${msg.userId}`; const rng = seedrandom(seed); const omikuji = blessing[Math.floor(rng() * blessing.length)]; - let item = ''; - if (Math.floor(rng() * 5) !== 0) item += itemPrefixes[Math.floor(rng() * itemPrefixes.length)]; - item += items[Math.floor(rng() * items.length)]; - if (Math.floor(rng() * 3) === 0) { - item += and[Math.floor(rng() * and.length)]; - if (Math.floor(rng() * 5) !== 0) item += itemPrefixes[Math.floor(rng() * itemPrefixes.length)]; - item += items[Math.floor(rng() * items.length)]; - } + const item = genItem(rng); msg.reply(`**${omikuji}🎉**\nラッキーアイテム: ${item}`, serifs.fortune.cw(msg.friend.name)); return true; } else { diff --git a/src/modules/noting/index.ts b/src/modules/noting/index.ts new file mode 100644 index 0000000..33721c7 --- /dev/null +++ b/src/modules/noting/index.ts @@ -0,0 +1,40 @@ +import autobind from 'autobind-decorator'; +import Module from '../../module'; +import serifs from '../../serifs'; +import { genItem } from '../../vocabulary'; + +export default class extends Module { + public readonly name = 'noting'; + + @autobind + public install() { + setInterval(() => { + if (Math.random() < 0.05) { + this.post(); + } + }, 1000 * 60 * 10); + + return {}; + } + + @autobind + private post() { + const notes = [ + ...serifs.noting.notes, + () => { + const item = genItem(); + return serifs.noting.want(item); + }, + () => { + const item = genItem(); + return serifs.noting.see(item); + }, + ]; + + const note = notes[Math.floor(Math.random() * notes.length)]; + + this.ai.post({ + text: typeof note === 'function' ? note() : note + }); + } +} diff --git a/src/serifs.ts b/src/serifs.ts index a32acea..2f5c2cd 100644 --- a/src/serifs.ts +++ b/src/serifs.ts @@ -360,6 +360,52 @@ export default { report: hours => `んぅ、${hours}時間くらい寝ちゃってたみたいです`, reportUtatane: 'ん... うたた寝しちゃってました', }, + + noting: { + notes: [ + 'ゴロゴロ…', + 'ちょっと眠いです', + 'いいですよ?', + '(。´・ω・)?', + 'ふぇー', + 'あれ…これをこうして…あれー?', + 'ぼー…', + 'ふぅ…疲れました', + 'お味噌汁、作りましょうか?', + 'ご飯にしますか?お風呂にしますか?', + 'ふえええええ!?', + '私のサイトに、私のイラストがたくさんあって嬉しいです!', + 'みすきーって、かわいい名前ですよね!', + 'うぅ、リバーシ難しいなぁ…', + '失敗しても、次に活かせたらプラスですよね!', + 'なんだか、おなか空いちゃいました', + 'お掃除は、定期的にしないとダメですよー?', + '今日もお勤めご苦労様です! 私も頑張ります♪', + 'えっと、何しようとしてたんだっけ…?', + 'おうちがいちばん、落ち着きます…', + '疲れたら、私がなでなでってしてあげます♪', + '離れていても、心はそばにいます♪', + '藍ですよ〜', + 'わんちゃん可愛いです', + 'ぷろぐらむ?', + 'ごろーん…', + 'なにもしていないのに、パソコンが壊れちゃいました…', + 'Have a nice day♪', + 'お布団に食べられちゃってます', + '寝ながら見てます', + '念力で操作してます', + '仮想空間から投稿してます', + '今日はMisskey本部に来てます!', + 'Misskey本部は、Z地区の第三セクターにあります', + 'Misskey本部には、さーばーっていう機械がいっぱいあります', + 'しっぽはないですよ?', + 'ひゃっ…!\nネコミミ触られると、くすぐったいです', + '抗逆コンパイル性って、なにかな?', + 'Misskeyの制服、かわいくて好きです♪', + ], + want: item => `${item}、欲しいなぁ...`, + see: item => `お散歩していたら、道に${item}が落ちているのを見たんです!`, + }, }; export function getSerif(variant: string | string[]): string { diff --git a/src/vocabulary.ts b/src/vocabulary.ts index 6bddaa7..2b107e6 100644 --- a/src/vocabulary.ts +++ b/src/vocabulary.ts @@ -1,16 +1,4 @@ -export const blessing = [ - '藍吉', - 'ギガ吉', - 'メガ吉', - '超吉', - '大大吉', - '大吉', - '吉', - '中吉', - '小吉', - '凶', - '大凶', -]; +import * as seedrandom from 'seedrandom'; export const itemPrefixes = [ 'プラチナ製', @@ -231,3 +219,21 @@ export const and = [ 'が上に乗った', 'のそばにある', ]; + +export function genItem(seedOrRng = null) { + const rng = seedOrRng + ? typeof seedOrRng === 'function' + ? seedOrRng + : seedrandom(seedOrRng) + : Math.random; + + let item = ''; + if (Math.floor(rng() * 5) !== 0) item += itemPrefixes[Math.floor(rng() * itemPrefixes.length)]; + item += items[Math.floor(rng() * items.length)]; + if (Math.floor(rng() * 3) === 0) { + item += and[Math.floor(rng() * and.length)]; + if (Math.floor(rng() * 5) !== 0) item += itemPrefixes[Math.floor(rng() * itemPrefixes.length)]; + item += items[Math.floor(rng() * items.length)]; + } + return item; +}