From b6c5258b0fafc289b7f71f47737f96f4c3f124f0 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Fri, 11 Feb 2022 00:16:44 +0900 Subject: [PATCH 01/42] =?UTF-8?q?=E8=89=B2=E6=B1=BA=E3=82=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/color/index.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/modules/color/index.ts diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts new file mode 100644 index 0000000..ecd8904 --- /dev/null +++ b/src/modules/color/index.ts @@ -0,0 +1,33 @@ +import autobind from 'autobind-decorator'; +import Module from '@/module'; +import Message from '@/message'; + +export default class extends Module { + public readonly name = 'color'; + + @autobind + public install() { + return { + mentionHook: this.mentionHook + }; + } + + @autobind + private async mentionHook(msg: Message) { + if (msg.text && msg.text.includes('色決めて')) { + // rgbをそれぞれ乱数で生成する + const r = Math.floor(Math.random() * 256); + const g = Math.floor(Math.random() * 256); + const b = Math.floor(Math.random() * 256); + // rgbをhexに変換する + const hex = `${r.toString(16)}${g.toString(16)}${b.toString(16)}`; + const message = `RGB: ${r}, ${g}, ${b} (#${hex})とかどう? [参考](https://www.colorhexa.com/${hex})` + msg.reply(message, { + immediate: true + }); + return true; + } else { + return false; + } + } +} From 83068eb8ffdedbf4e7c93156a4369f9891dc69d2 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Fri, 11 Feb 2022 00:16:53 +0900 Subject: [PATCH 02/42] =?UTF-8?q?=E8=A8=80=E8=91=89=E3=81=AE=E6=84=8F?= =?UTF-8?q?=E5=91=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/dic/index.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/modules/dic/index.ts diff --git a/src/modules/dic/index.ts b/src/modules/dic/index.ts new file mode 100644 index 0000000..29d2dce --- /dev/null +++ b/src/modules/dic/index.ts @@ -0,0 +1,32 @@ +import autobind from 'autobind-decorator'; +import Module from '@/module'; +import Message from '@/message'; + +export default class extends Module { + public readonly name = 'dic'; + + @autobind + public install() { + return { + mentionHook: this.mentionHook + }; + } + + @autobind + private async mentionHook(msg: Message) { + if (msg.text && msg.text.includes('って何')) { + // msg.textのうち、「の意味は」の直前で、「@ai」よりも後の物を抽出 + const dic_prefix = "https://www.weblio.jp/content/"; + const raw_word = msg.text.split('って何')[0].split('@ai_dev')[1].trim(); + // スペースがある場合は、半角スペースを除去 + const word = raw_word.replace(/\s/g, ''); + const url = dic_prefix + encodeURIComponent(word); + msg.reply(`こんな意味っぽい?> [${word}](${url})`, { + immediate: true + }); + return true; + } else { + return false; + } + } +} From 9faff19b2aa010294f11bb8d90816b157663139b Mon Sep 17 00:00:00 2001 From: na2na-p Date: Fri, 11 Feb 2022 00:17:01 +0900 Subject: [PATCH 03/42] =?UTF-8?q?=E3=83=A2=E3=82=B8=E3=83=A5=E3=83=BC?= =?UTF-8?q?=E3=83=AB=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.ts b/src/index.ts index dca5703..96c5c8b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,6 +34,8 @@ import SleepReportModule from './modules/sleep-report'; import NotingModule from './modules/noting'; import PollModule from './modules/poll'; import ReminderModule from './modules/reminder'; +import DicModule from './modules/dic'; +import GetColorModule from './modules/color'; console.log(' __ ____ _____ ___ '); console.log(' /__\\ (_ _)( _ )/ __)'); @@ -88,6 +90,8 @@ promiseRetry(retry => { new NotingModule(), new PollModule(), new ReminderModule(), + new DicModule(), + new GetColorModule(), ]); }).catch(e => { log(chalk.red('Failed to fetch the account')); From 9030b376de3e37742ed6078b7e55c921ab96c47a Mon Sep 17 00:00:00 2001 From: na2na-p Date: Fri, 11 Feb 2022 00:27:41 +0900 Subject: [PATCH 04/42] =?UTF-8?q?=E3=83=87=E3=83=90=E3=83=83=E3=82=B0?= =?UTF-8?q?=E7=94=A8=E3=82=B3=E3=83=BC=E3=83=89=E5=85=A5=E3=81=A3=E3=81=A6?= =?UTF-8?q?=E3=81=9F=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/dic/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/dic/index.ts b/src/modules/dic/index.ts index 29d2dce..0220f68 100644 --- a/src/modules/dic/index.ts +++ b/src/modules/dic/index.ts @@ -17,7 +17,7 @@ export default class extends Module { if (msg.text && msg.text.includes('って何')) { // msg.textのうち、「の意味は」の直前で、「@ai」よりも後の物を抽出 const dic_prefix = "https://www.weblio.jp/content/"; - const raw_word = msg.text.split('って何')[0].split('@ai_dev')[1].trim(); + const raw_word = msg.text.split('って何')[0].split('@ai')[1].trim(); // スペースがある場合は、半角スペースを除去 const word = raw_word.replace(/\s/g, ''); const url = dic_prefix + encodeURIComponent(word); From 9d7f82d117a55a2128cc247574dc67f265324a77 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Sat, 12 Feb 2022 13:23:38 +0900 Subject: [PATCH 05/42] =?UTF-8?q?=E3=81=94=E3=81=AF=E3=82=93=E3=81=95?= =?UTF-8?q?=E3=83=BC=E3=81=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 +++ src/index.ts | 2 ++ src/modules/menu/index.ts | 62 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 src/modules/menu/index.ts diff --git a/package.json b/package.json index 84db823..49d11c9 100644 --- a/package.json +++ b/package.json @@ -20,10 +20,12 @@ "autobind-decorator": "2.4.0", "canvas": "2.8.0", "chalk": "4.1.1", + "jsdom": "19.0.0", "lokijs": "1.5.12", "memory-streams": "0.1.3", "misskey-reversi": "0.0.5", "module-alias": "2.2.2", + "node-fetch": "2.6.7", "promise-retry": "2.0.1", "random-seed": "0.3.0", "reconnecting-websocket": "4.4.0", @@ -40,8 +42,10 @@ "devDependencies": { "@koa/router": "9.4.0", "@types/jest": "26.0.23", + "@types/jsdom": "16.2.14", "@types/koa": "2.13.1", "@types/koa__router": "8.0.4", + "@types/node-fetch": "3.0.3", "@types/websocket": "1.0.2", "jest": "26.6.3", "koa": "2.13.1", diff --git a/src/index.ts b/src/index.ts index 96c5c8b..5ecb258 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,7 @@ import NotingModule from './modules/noting'; import PollModule from './modules/poll'; import ReminderModule from './modules/reminder'; import DicModule from './modules/dic'; +import menuModule from './modules/menu'; import GetColorModule from './modules/color'; console.log(' __ ____ _____ ___ '); @@ -91,6 +92,7 @@ promiseRetry(retry => { new PollModule(), new ReminderModule(), new DicModule(), + new menuModule(), new GetColorModule(), ]); }).catch(e => { diff --git a/src/modules/menu/index.ts b/src/modules/menu/index.ts new file mode 100644 index 0000000..42b950f --- /dev/null +++ b/src/modules/menu/index.ts @@ -0,0 +1,62 @@ +import autobind from 'autobind-decorator'; +import Module from '@/module'; +import Message from '@/message'; +import fetch from 'node-fetch'; +import { JSDOM } from 'jsdom'; +import { title } from 'process'; + +export default class extends Module { + public readonly name = 'menu'; + + @autobind + public install() { + return { + mentionHook: this.mentionHook + }; + } + + @autobind + private async mentionHook(msg: Message) { + if (msg.text && msg.text.includes('ごはん')) { + // 1~2535111の適当な数字を取得 + const random_number = Math.floor(Math.random() * 2535111) + 1; + const url = `https://cookpad.com/recipe/${random_number}`; + //testUrlして、200以外なら再取得 + const res = await fetch(url); + if (res.status !== 200) { + return this.mentionHook(msg); + } else { + //jsdomを利用してレシピのタイトルを取得 + const dom = new JSDOM(await res.text()); + //@ts-ignore + let title = dom.window.document.querySelector('h1.recipe-title').textContent; + // titleから改行を除去 + title = title!.replace(/\n/g, ''); + msg.reply(`こんなのどう?> [${title}](${url})`, { + immediate: true + }); + return true; + } + } else { + return false; + } + } +} + +function testUrl(url: string) { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest() + xhr.open('GET', url) + xhr.onload = () => { + if (xhr.status === 200) { + resolve(true) + } else { + reject(false) + } + } + xhr.onerror = () => { + reject(false) + } + xhr.send() + }) +} \ No newline at end of file From cb01d8602993eb3f929cb746c395970e9b58ce01 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Sat, 12 Feb 2022 13:26:39 +0900 Subject: [PATCH 06/42] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AA=E3=83=96?= =?UTF-8?q?=E3=83=84=E3=81=AE=E9=99=A4=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/menu/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/menu/index.ts b/src/modules/menu/index.ts index 42b950f..57f5390 100644 --- a/src/modules/menu/index.ts +++ b/src/modules/menu/index.ts @@ -3,7 +3,6 @@ import Module from '@/module'; import Message from '@/message'; import fetch from 'node-fetch'; import { JSDOM } from 'jsdom'; -import { title } from 'process'; export default class extends Module { public readonly name = 'menu'; From e5e9d0076ecf0960e8d28efba19ddd11e72b05fa Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Thu, 17 Feb 2022 00:46:40 +0900 Subject: [PATCH 07/42] =?UTF-8?q?=F0=9F=98=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/ping/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/modules/ping/index.ts b/src/modules/ping/index.ts index 147a7d5..c3bf81c 100644 --- a/src/modules/ping/index.ts +++ b/src/modules/ping/index.ts @@ -14,10 +14,16 @@ export default class extends Module { @autobind private async mentionHook(msg: Message) { - if (msg.text && msg.text.includes('ping')) { - msg.reply('PONG!', { - immediate: true - }); + if (msg.text && (msg.text.includes('ping') || msg.text.includes('おい'))) { + if (msg.text.includes('おい')) { + msg.reply('はい。。。', { + immediate: true + }); + } else { + msg.reply('PONG!', { + immediate: true + }); + } return true; } else { return false; From d23ffe197c3d49e06d97df28ae78c18660fe8fe0 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Thu, 17 Feb 2022 01:03:16 +0900 Subject: [PATCH 08/42] =?UTF-8?q?=E5=8D=98=E8=89=B2=E3=81=AE=E7=94=BB?= =?UTF-8?q?=E5=83=8F=E3=82=92=E7=94=9F=E6=88=90=E3=81=97=E3=81=A6=E3=83=AA?= =?UTF-8?q?=E3=83=97=E3=83=A9=E3=82=A4=E3=81=A7=E8=BF=94=E3=81=99=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/color/index.ts | 29 ++++++++++++++++++++++++----- src/modules/color/render.ts | 17 +++++++++++++++++ 2 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/modules/color/render.ts diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index ecd8904..a7e13be 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -1,6 +1,7 @@ import autobind from 'autobind-decorator'; import Module from '@/module'; import Message from '@/message'; +import { generateColorSample } from './render'; export default class extends Module { public readonly name = 'color'; @@ -21,13 +22,31 @@ export default class extends Module { const b = Math.floor(Math.random() * 256); // rgbをhexに変換する const hex = `${r.toString(16)}${g.toString(16)}${b.toString(16)}`; - const message = `RGB: ${r}, ${g}, ${b} (#${hex})とかどう? [参考](https://www.colorhexa.com/${hex})` - msg.reply(message, { - immediate: true - }); - return true; + const message = `RGB: ${r}, ${g}, ${b} (# ${hex})とかどう?` + + setTimeout(async () => { + const file = await this.getColorSampleFile(r,g,b); + this.log('Replying...'); + msg.reply(message, { file }); + }, 500); + return { + reaction: 'like' + }; } else { return false; } } + + @autobind + private async getColorSampleFile(r,g,b): Promise { + const colorSample = generateColorSample(r,g,b); + + this.log('Image uploading...'); + const file = await this.ai.upload(colorSample, { + filename: 'color.png', + contentType: 'image/png' + }); + + return file; + } } diff --git a/src/modules/color/render.ts b/src/modules/color/render.ts new file mode 100644 index 0000000..05aa6ca --- /dev/null +++ b/src/modules/color/render.ts @@ -0,0 +1,17 @@ +import { createCanvas } from 'canvas'; + +const imageSize = 512; //px + +export function generateColorSample(r: string, g: string, b: string) { + const canvas = createCanvas(imageSize, imageSize); + const ctx = canvas.getContext('2d'); + ctx.antialias = 'none'; + + // 引数で渡されたrgb値を基準に、色を塗りつぶす + ctx.fillStyle = `rgb(${r},${g},${b})`; + ctx.beginPath(); + ctx.fillRect(0, 0, imageSize, imageSize); + + // canvas.toBuffer()をreturn + return canvas.toBuffer(); +} \ No newline at end of file From 4099fa30b601edb4e03e75ebaf6670df0ff5e871 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Thu, 17 Feb 2022 01:06:33 +0900 Subject: [PATCH 09/42] =?UTF-8?q?=E3=83=AA=E3=82=A2=E3=82=AF=E3=82=B7?= =?UTF-8?q?=E3=83=A7=E3=83=B3=E3=81=AE=E7=B5=B5=E6=96=87=E5=AD=97=E3=82=92?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/color/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index a7e13be..dbb4a72 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -30,7 +30,7 @@ export default class extends Module { msg.reply(message, { file }); }, 500); return { - reaction: 'like' + reaction: '🎨' }; } else { return false; From cb0878fab10b7487281fbdca2c9d8e5e572e13a7 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Thu, 17 Feb 2022 01:13:26 +0900 Subject: [PATCH 10/42] =?UTF-8?q?=E7=94=9F=E6=88=90=E3=81=99=E3=82=8B?= =?UTF-8?q?=E7=94=BB=E5=83=8F=E3=81=AE=E3=82=B5=E3=82=A4=E3=82=BA=E3=82=92?= =?UTF-8?q?1px=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/color/render.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/color/render.ts b/src/modules/color/render.ts index 05aa6ca..e4449d0 100644 --- a/src/modules/color/render.ts +++ b/src/modules/color/render.ts @@ -1,6 +1,6 @@ import { createCanvas } from 'canvas'; -const imageSize = 512; //px +const imageSize = 1; //px export function generateColorSample(r: string, g: string, b: string) { const canvas = createCanvas(imageSize, imageSize); From c63341d8a63dc0554f13c56391587381070396b9 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Thu, 17 Feb 2022 01:13:49 +0900 Subject: [PATCH 11/42] =?UTF-8?q?=E3=82=AB=E3=83=A9=E3=83=BC=E3=82=B3?= =?UTF-8?q?=E3=83=BC=E3=83=89=E3=81=AE=E8=A1=A8=E7=A4=BA=E3=81=8C=E3=82=BF?= =?UTF-8?q?=E3=82=B0=E5=8C=96=E3=81=97=E3=81=AA=E3=81=84=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/color/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index dbb4a72..140e36e 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -22,7 +22,7 @@ export default class extends Module { const b = Math.floor(Math.random() * 256); // rgbをhexに変換する const hex = `${r.toString(16)}${g.toString(16)}${b.toString(16)}`; - const message = `RGB: ${r}, ${g}, ${b} (# ${hex})とかどう?` + const message = `RGB: ${r}, ${g}, ${b} (\`#${hex})\`とかどう?` setTimeout(async () => { const file = await this.getColorSampleFile(r,g,b); From 1a68e6970fcb0bbbef612d760fd20a8a19fdd447 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Thu, 17 Feb 2022 15:33:25 +0900 Subject: [PATCH 12/42] =?UTF-8?q?=E3=81=84=E3=81=84=EF=BC=9F=E3=81=A8?= =?UTF-8?q?=E8=81=9E=E3=81=8F=E3=81=A8=E3=82=84=E3=81=A3=E3=81=A6=E3=81=84?= =?UTF-8?q?=E3=81=84=E3=81=8B=E3=81=A9=E3=81=86=E3=81=8B=E3=82=92=E3=83=AA?= =?UTF-8?q?=E3=82=A2=E3=82=AF=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=99=E3=82=8B?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 ++ src/modules/okng/index.ts | 48 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/modules/okng/index.ts diff --git a/src/index.ts b/src/index.ts index 5ecb258..b61f300 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,6 +16,7 @@ import TalkModule from './modules/talk'; import BirthdayModule from './modules/birthday'; import ReversiModule from './modules/reversi'; import PingModule from './modules/ping'; +import okngModule from './modules/okng'; import EmojiModule from './modules/emoji'; import EmojiReactModule from './modules/emoji-react'; import FortuneModule from './modules/fortune'; @@ -69,6 +70,7 @@ promiseRetry(retry => { // 藍起動 new 藍(account, [ new CoreModule(), + new okngModule(), new EmojiModule(), new EmojiReactModule(), new FortuneModule(), diff --git a/src/modules/okng/index.ts b/src/modules/okng/index.ts new file mode 100644 index 0000000..ac07655 --- /dev/null +++ b/src/modules/okng/index.ts @@ -0,0 +1,48 @@ +import autobind from 'autobind-decorator'; +import { parse } from 'twemoji-parser'; +const delay = require('timeout-as-promise'); + +import { Note } from '@/misskey/note'; +import Module from '@/module'; +import Stream from '@/stream'; +import includes from '@/utils/includes'; + +export default class extends Module { + public readonly name = 'okng'; + + private htl: ReturnType; + + @autobind + public install() { + this.htl = this.ai.connection.useSharedConnection('homeTimeline'); + this.htl.on('note', this.onNote); + + return {}; + } + + @autobind + private async onNote(note: Note) { + if (note.reply != null) return; + if (note.text == null) return; + if (note.text.includes('@')) return; // (自分または他人問わず)メンションっぽかったらreject + + const react = async (reaction: string, immediate = false) => { + if (!immediate) { + await delay(1500); + } + this.ai.api('notes/reactions/create', { + noteId: note.id, + reaction: reaction + }); + }; + + if (includes(note.text, ['いい']) && (includes(note.text, ["?"]) || includes(note.text, ["?"]))) { + // 50%の確率で":dame:"または":yattare:"を返す + if (Math.random() < 0.5) { + return react(':dame:'); + } else { + return react(':yattare:'); + } + } + } +} From 80a8b68d8c02c51fee20abc8f9c265c0daeb6140 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Thu, 17 Feb 2022 15:44:16 +0900 Subject: [PATCH 13/42] =?UTF-8?q?=E5=88=86=E3=81=91=E3=82=8B=E6=84=8F?= =?UTF-8?q?=E5=91=B3=E3=81=8C=E3=81=AA=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE?= =?UTF-8?q?=E3=81=A7=E5=90=88=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 -- src/modules/emoji-react/index.ts | 9 ++++++ src/modules/okng/index.ts | 48 -------------------------------- 3 files changed, 9 insertions(+), 50 deletions(-) delete mode 100644 src/modules/okng/index.ts diff --git a/src/index.ts b/src/index.ts index b61f300..5ecb258 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,6 @@ import TalkModule from './modules/talk'; import BirthdayModule from './modules/birthday'; import ReversiModule from './modules/reversi'; import PingModule from './modules/ping'; -import okngModule from './modules/okng'; import EmojiModule from './modules/emoji'; import EmojiReactModule from './modules/emoji-react'; import FortuneModule from './modules/fortune'; @@ -70,7 +69,6 @@ promiseRetry(retry => { // 藍起動 new 藍(account, [ new CoreModule(), - new okngModule(), new EmojiModule(), new EmojiReactModule(), new FortuneModule(), diff --git a/src/modules/emoji-react/index.ts b/src/modules/emoji-react/index.ts index e671b4d..e716493 100644 --- a/src/modules/emoji-react/index.ts +++ b/src/modules/emoji-react/index.ts @@ -36,6 +36,15 @@ export default class extends Module { }); }; + if (includes(note.text, ['いい']) && (includes(note.text, ["?"]) || includes(note.text, ["?"]))) { + // 50%の確率で":dame:"または":yattare:"を返す + if (Math.random() < 0.5) { + return react(':dame:', true); + } else { + return react(':yattare:', true); + } + } + const customEmojis = note.text.match(/:([^\n:]+?):/g); if (customEmojis) { // カスタム絵文字が複数種類ある場合はキャンセル diff --git a/src/modules/okng/index.ts b/src/modules/okng/index.ts deleted file mode 100644 index ac07655..0000000 --- a/src/modules/okng/index.ts +++ /dev/null @@ -1,48 +0,0 @@ -import autobind from 'autobind-decorator'; -import { parse } from 'twemoji-parser'; -const delay = require('timeout-as-promise'); - -import { Note } from '@/misskey/note'; -import Module from '@/module'; -import Stream from '@/stream'; -import includes from '@/utils/includes'; - -export default class extends Module { - public readonly name = 'okng'; - - private htl: ReturnType; - - @autobind - public install() { - this.htl = this.ai.connection.useSharedConnection('homeTimeline'); - this.htl.on('note', this.onNote); - - return {}; - } - - @autobind - private async onNote(note: Note) { - if (note.reply != null) return; - if (note.text == null) return; - if (note.text.includes('@')) return; // (自分または他人問わず)メンションっぽかったらreject - - const react = async (reaction: string, immediate = false) => { - if (!immediate) { - await delay(1500); - } - this.ai.api('notes/reactions/create', { - noteId: note.id, - reaction: reaction - }); - }; - - if (includes(note.text, ['いい']) && (includes(note.text, ["?"]) || includes(note.text, ["?"]))) { - // 50%の確率で":dame:"または":yattare:"を返す - if (Math.random() < 0.5) { - return react(':dame:'); - } else { - return react(':yattare:'); - } - } - } -} From e6894bc723ae18a5a2a3fa319631f25b5bb54b17 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Thu, 17 Feb 2022 16:03:23 +0900 Subject: [PATCH 14/42] =?UTF-8?q?=E3=81=86=E3=82=93=E3=81=93=E6=92=B2?= =?UTF-8?q?=E6=BB=85=E3=81=86=E3=82=93=E3=81=A1=E3=81=88=E3=82=89=E3=81=84?= =?UTF-8?q?=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/emoji-react/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/modules/emoji-react/index.ts b/src/modules/emoji-react/index.ts index e716493..046d6c1 100644 --- a/src/modules/emoji-react/index.ts +++ b/src/modules/emoji-react/index.ts @@ -36,6 +36,15 @@ export default class extends Module { }); }; + // /う[〜|ー]*んこ/g]にマッチしたときの処理 + if (note.text.match(/う[〜|ー]*んこ/g)) { + await react(':anataima_unkotte_iimashitane:', true); + } + + if (note.text.match(/う[〜|ー]*んち/g)) { + await react(':erait:', true); + } + if (includes(note.text, ['いい']) && (includes(note.text, ["?"]) || includes(note.text, ["?"]))) { // 50%の確率で":dame:"または":yattare:"を返す if (Math.random() < 0.5) { From d4c9a1147261964347c7dd75c1ad9b96c94ecd83 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Thu, 17 Feb 2022 16:20:42 +0900 Subject: [PATCH 15/42] unko --- src/modules/emoji-react/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/emoji-react/index.ts b/src/modules/emoji-react/index.ts index 046d6c1..f15e503 100644 --- a/src/modules/emoji-react/index.ts +++ b/src/modules/emoji-react/index.ts @@ -37,7 +37,7 @@ export default class extends Module { }; // /う[〜|ー]*んこ/g]にマッチしたときの処理 - if (note.text.match(/う[〜|ー]*んこ/g)) { + if (note.text.match(/う[〜|ー]*んこ/g) || includes(note.text, ['unko'])) { await react(':anataima_unkotte_iimashitane:', true); } From 359c2272696a38b7f6e43f5674e19b382374e513 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Sat, 19 Feb 2022 15:34:53 +0900 Subject: [PATCH 16/42] =?UTF-8?q?=E9=96=89=E3=81=98=E3=81=8B=E3=81=A3?= =?UTF-8?q?=E3=81=93=E3=81=AE=E4=BD=8D=E7=BD=AE=E3=81=8C=E3=81=8A=E3=81=8B?= =?UTF-8?q?=E3=81=97=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE=E3=82=92=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/color/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/color/index.ts b/src/modules/color/index.ts index 140e36e..3cd0f2b 100644 --- a/src/modules/color/index.ts +++ b/src/modules/color/index.ts @@ -22,7 +22,7 @@ export default class extends Module { const b = Math.floor(Math.random() * 256); // rgbをhexに変換する const hex = `${r.toString(16)}${g.toString(16)}${b.toString(16)}`; - const message = `RGB: ${r}, ${g}, ${b} (\`#${hex})\`とかどう?` + const message = `RGB: ${r}, ${g}, ${b} \`(#${hex})\`とかどう?` setTimeout(async () => { const file = await this.getColorSampleFile(r,g,b); From 2f58ad8fa9e5909b928ca7c8334e66cbdfdc38bd Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Mon, 21 Feb 2022 09:52:45 +0900 Subject: [PATCH 17/42] =?UTF-8?q?=E6=8A=95=E7=A5=A8=E7=94=9F=E6=88=90?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=82=92=E4=BD=BF=E3=81=88=E3=81=AA=E3=81=8F?= =?UTF-8?q?=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5ecb258..3a5f0de 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,7 +32,7 @@ import MazeModule from './modules/maze'; import ChartModule from './modules/chart'; import SleepReportModule from './modules/sleep-report'; import NotingModule from './modules/noting'; -import PollModule from './modules/poll'; +// import PollModule from './modules/poll'; import ReminderModule from './modules/reminder'; import DicModule from './modules/dic'; import menuModule from './modules/menu'; @@ -89,7 +89,7 @@ promiseRetry(retry => { new ChartModule(), new SleepReportModule(), new NotingModule(), - new PollModule(), + // new PollModule(), new ReminderModule(), new DicModule(), new menuModule(), From 9358a91f507dc5a3e35348d9e6f0ab7cd18453fd Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Mon, 21 Feb 2022 09:55:58 +0900 Subject: [PATCH 18/42] =?UTF-8?q?Update[emoji-react]=E5=8F=8D=E5=BF=9C?= =?UTF-8?q?=E3=83=AF=E3=83=BC=E3=83=89=E3=81=AE=E4=B8=80=E9=83=A8=E5=85=A5?= =?UTF-8?q?=E3=82=8C=E6=9B=BF=E3=81=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/emoji-react/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/emoji-react/index.ts b/src/modules/emoji-react/index.ts index f15e503..7e037a8 100644 --- a/src/modules/emoji-react/index.ts +++ b/src/modules/emoji-react/index.ts @@ -86,6 +86,7 @@ export default class extends Module { if (includes(note.text, ['ぷりん'])) return react('🍮'); if (includes(note.text, ['寿司', 'sushi']) || note.text === 'すし') return react('🍣'); - if (includes(note.text, ['藍'])) return react('🙌'); + if (includes(note.text, ['ずなず']) || includes(note.text, ['ずにゃず'])) return react('🙌'); + if (includes(note.text, ['なず']) || includes(note.text, ['にゃず'])) return react(':google_hart:'); } } From c6a47b7854e7d8989adc7099e3a2cf527ac907c5 Mon Sep 17 00:00:00 2001 From: na2na-p Date: Mon, 21 Feb 2022 13:41:57 +0900 Subject: [PATCH 19/42] =?UTF-8?q?Update[emoji-react]=E3=81=8A=E3=82=B2?= =?UTF-8?q?=E3=83=BC=E3=83=A0=E3=81=97=E3=81=BE=E3=81=97=E3=82=87=E3=81=86?= =?UTF-8?q?=E3=81=AD=E3=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/emoji-react/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/modules/emoji-react/index.ts b/src/modules/emoji-react/index.ts index 7e037a8..4b5e5d5 100644 --- a/src/modules/emoji-react/index.ts +++ b/src/modules/emoji-react/index.ts @@ -88,5 +88,15 @@ export default class extends Module { if (includes(note.text, ['ずなず']) || includes(note.text, ['ずにゃず'])) return react('🙌'); if (includes(note.text, ['なず']) || includes(note.text, ['にゃず'])) return react(':google_hart:'); + + const gameReact = [ + ':ysvi:', + ':ysf:', + ':yso:' + ] + if (includes(note.text, ['おゲームするかしら'])){ + // gameReactの中からランダムに選択 + return react(gameReact[Math.floor(Math.random() * gameReact.length)]); + } } } From c74c709ae9cb83fd797fa2ed2492290cce497cb4 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Fri, 25 Feb 2022 14:13:10 +0900 Subject: [PATCH 20/42] =?UTF-8?q?=E3=81=AD=E3=81=93=E5=8F=AC=E5=96=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.ts | 2 ++ src/modules/emoji-react/index.ts | 8 ++--- src/modules/summonCat/index.ts | 58 ++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 src/modules/summonCat/index.ts diff --git a/src/index.ts b/src/index.ts index 3a5f0de..353db8b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,6 +15,7 @@ import CoreModule from './modules/core'; import TalkModule from './modules/talk'; import BirthdayModule from './modules/birthday'; import ReversiModule from './modules/reversi'; +import summonCat from './modules/summonCat'; import PingModule from './modules/ping'; import EmojiModule from './modules/emoji'; import EmojiReactModule from './modules/emoji-react'; @@ -69,6 +70,7 @@ promiseRetry(retry => { // 藍起動 new 藍(account, [ new CoreModule(), + new summonCat(), new EmojiModule(), new EmojiReactModule(), new FortuneModule(), diff --git a/src/modules/emoji-react/index.ts b/src/modules/emoji-react/index.ts index 7e037a8..9a21677 100644 --- a/src/modules/emoji-react/index.ts +++ b/src/modules/emoji-react/index.ts @@ -38,19 +38,19 @@ export default class extends Module { // /う[〜|ー]*んこ/g]にマッチしたときの処理 if (note.text.match(/う[〜|ー]*んこ/g) || includes(note.text, ['unko'])) { - await react(':anataima_unkotte_iimashitane:', true); + await react(':anataima_unkotte_iimashitane:'); } if (note.text.match(/う[〜|ー]*んち/g)) { - await react(':erait:', true); + await react(':erait:'); } if (includes(note.text, ['いい']) && (includes(note.text, ["?"]) || includes(note.text, ["?"]))) { // 50%の確率で":dame:"または":yattare:"を返す if (Math.random() < 0.5) { - return react(':dame:', true); + return react(':dame:'); } else { - return react(':yattare:', true); + return react(':yattare:'); } } diff --git a/src/modules/summonCat/index.ts b/src/modules/summonCat/index.ts new file mode 100644 index 0000000..9ffce4d --- /dev/null +++ b/src/modules/summonCat/index.ts @@ -0,0 +1,58 @@ +import autobind from 'autobind-decorator'; +import Module from '@/module'; +import Message from '@/message'; +import fetch from 'node-fetch'; +import { ReadStream } from 'fs'; + +export default class extends Module { + public readonly name = 'summonCat'; + + @autobind + public install() { + return { + mentionHook: this.mentionHook + }; + } + + @autobind + private async mentionHook(msg: Message) { + // cat/Cat/ねこ/ネコ/にゃん + console.log(msg.text) + if (msg.text && (msg.text.match(/(cat|Cat|ねこ|ネコ|にゃ[〜|ー]*ん)/g))) { + const message = "にゃ~ん!"; + + setTimeout(async () => { + const file = await this.getCatImage(); + this.log(file); + this.log('Replying...'); + msg.reply(message, { file }); + }, 500); + + return { + reaction: ':blobcatmeltnomblobcatmelt:' + }; + } else { + return false; + } + } + + @autobind + private async getCatImage(): Promise { + // https://aws.random.cat/meowにGETリクエストを送る + // fileに画像URLが返ってくる + const res = await fetch('https://aws.random.cat/meow'); + const json = await res.json(); + console.table(json); + const fileUri = json.file; + // 拡張子を取り除く + const fileName = fileUri.split('/').pop().split('.')[0]; + const rawFile = await fetch(fileUri); + const imgBuffer = await rawFile.buffer(); + // 拡張子とcontentTypeを判断する + const ext = fileUri.split('.').pop(); + const file = await this.ai.upload(imgBuffer, { + filename: `${fileName}.${ext}`, + }); + return file; + } +} From 87a291c2076a6187175457d2501bcf3a4c6a6007 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 8 Mar 2022 00:48:24 +0900 Subject: [PATCH 21/42] =?UTF-8?q?=E3=81=A9=E3=81=93-=E3=81=8A=E3=81=B5?= =?UTF-8?q?=E3=81=A8=E3=82=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/emoji-react/index.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/emoji-react/index.ts b/src/modules/emoji-react/index.ts index 62c3877..4f2b74b 100644 --- a/src/modules/emoji-react/index.ts +++ b/src/modules/emoji-react/index.ts @@ -28,7 +28,7 @@ export default class extends Module { const react = async (reaction: string, immediate = false) => { if (!immediate) { - await delay(1500); + await delay(2500); } this.ai.api('notes/reactions/create', { noteId: note.id, @@ -38,11 +38,11 @@ export default class extends Module { // /う[〜|ー]*んこ/g]にマッチしたときの処理 if (note.text.match(/う[〜|ー]*んこ/g) || includes(note.text, ['unko'])) { - await react(':anataima_unkotte_iimashitane:'); + return await react(':anataima_unkotte_iimashitane:'); } if (note.text.match(/う[〜|ー]*んち/g)) { - await react(':erait:'); + return await react(':erait:'); } if (includes(note.text, ['いい']) && (includes(note.text, ["?"]) || includes(note.text, ["?"]))) { @@ -54,6 +54,10 @@ export default class extends Module { } } + if (includes(note.text, ['どこ'])) { + return await react(':t_ofuton:'); + } + const customEmojis = note.text.match(/:([^\n:]+?):/g); if (customEmojis) { // カスタム絵文字が複数種類ある場合はキャンセル From 587a3852386d5f06c8c647d374281a4d9c96e219 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 01:40:19 +0900 Subject: [PATCH 22/42] wip --- src/index.ts | 2 + src/modules/earthquake/index.ts | 116 +++++++++++++++++++++++++++++ src/modules/earthquake/typeMemo.cs | 38 ++++++++++ 3 files changed, 156 insertions(+) create mode 100644 src/modules/earthquake/index.ts create mode 100644 src/modules/earthquake/typeMemo.cs diff --git a/src/index.ts b/src/index.ts index 353db8b..5f5b4c0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -35,6 +35,7 @@ import SleepReportModule from './modules/sleep-report'; import NotingModule from './modules/noting'; // import PollModule from './modules/poll'; import ReminderModule from './modules/reminder'; +import earthquake from './modules/earthquake'; import DicModule from './modules/dic'; import menuModule from './modules/menu'; import GetColorModule from './modules/color'; @@ -96,6 +97,7 @@ promiseRetry(retry => { new DicModule(), new menuModule(), new GetColorModule(), + new earthquake(), ]); }).catch(e => { log(chalk.red('Failed to fetch the account')); diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts new file mode 100644 index 0000000..0ee8742 --- /dev/null +++ b/src/modules/earthquake/index.ts @@ -0,0 +1,116 @@ +import autobind from "autobind-decorator"; +import Module from "@/module"; +import Message from "@/message"; +import * as http from "http"; + +// 基本的に生データはstringばっかり。都合のいい形に加工済みの状態の型定義を書いています。 +// ここでいくらか言及されてる(https://bultar.bbs.fc2.com/?act=reply&tid=5645851); +interface 緊急地震速報 { + type: 'eew'; + time: Date; + report: string; // 第n報 最終報はstringで'final'となるので、とりあえずstring型 + epicenter: string; // 震源地 + depth: string; // 震源の深さ + magnitude: string; // 地震の規模を示すマグニチュード + latitude: string; // 緯度らしいが謎 + longitude: string; // 経度らしいが謎 + intensity: string; // 地震の強さ + index: number; // 謎 +} + +interface 緊急地震速報キャンセル { + type: 'pga_alert_cancel'; + time: Date; +} + +interface 震度レポート { + type: 'intensity_report'; + time: Date; + max_index: number; + intensity_list: { + intensity: string; + index: number; + region_list: string[]; + }[]; +} + +interface 地震検知 { + type: 'pga_alert'; + time: Date; + max_pga: number; + new: boolean; + estimated_intensity: number; + region_list: string[]; +} + +export default class extends Module { + public readonly name = "earthquake"; + private message: string = ""; + + @autobind + public install() { + this.createListenServer(); + return {}; + } + + @autobind + private async createListenServer() { + http.createServer(async (req, res) => { + const buffers: Buffer[] = []; + for await (const chunk of req) { + buffers.push(chunk); + } + + const rawDataString = Buffer.concat(buffers).toString(); + // rawDataString について、Unicodeエスケープシーケンスが含まれていたら通常の文字列に変換する + // JSONでなければreturn falseする + if (rawDataString.match(/\\u[0-9a-f]{4}/)) { + const rawDataJSON = JSON.parse( + rawDataString.replace(/\\u([\d\w]{4})/g, (match, p1) => { + return String.fromCharCode(parseInt(p1, 16)); + }), + ); + + if (rawDataJSON.type == "pga_alert") { + const data: 地震検知 = { + type: rawDataJSON.type, + time: new Date(parseInt(rawDataJSON.time)), + max_pga: rawDataJSON.max_pga, + new: rawDataJSON.new, + estimated_intensity: rawDataJSON.estimated_intensity, + region_list: rawDataJSON.region_list, + }; + this.message = + // region_listはオブジェクトなので、2行改行してから列挙する + `PGA Alert\n${data.time.toLocaleString()}\n${data.max_pga}\n${data.estimated_intensity}\n\n${data.region_list.join("\n")}`; + }else if (rawDataJSON.type == 'intensity_report'){ + const data: 震度レポート = { + type: rawDataJSON.type, + time: new Date(parseInt(rawDataJSON.time)), + max_index: rawDataJSON.max_index, + intensity_list: rawDataJSON.intensity_list, + } + this.message = + `Intensity Report\n${data.time.toLocaleString()}\n\n${data.intensity_list.map(intensity => `震度${intensity.intensity} ${intensity.region_list.join(" ")}`).join("\n")}`; + } + this.returnResponse(res, "ok"); + if (this.message) { + this.ai.post({ + visibility: "home", + text: this.message, + }); + } + } else { + this.returnResponse(res, "debobigego"); + } + }).listen(process.env.EARTHQUAKE_PORT || 9999); + } + + @autobind + private returnResponse(res: http.ServerResponse, text: string) { + res.writeHead(200, { + "Content-Type": "text/plain", + }); + res.end(text); + } +} diff --git a/src/modules/earthquake/typeMemo.cs b/src/modules/earthquake/typeMemo.cs new file mode 100644 index 0000000..e8c6b52 --- /dev/null +++ b/src/modules/earthquake/typeMemo.cs @@ -0,0 +1,38 @@ +# 緊急地震速報 +{"type":"eew", +"time":long, +"report":int, +"epicenter":String, +"depth":String, +"magnitude":String, +"latitude":String, +"longitude":String, +"intensity":String, +"index":int +} + +# 地震検知 +{"type":"pga_alert", +"time":long, +"max_pga":float, +"new":boolean, +"estimated_intensity":int, +"region_list":[String,String,,,] +} + +# 地震検知キャンセル +{"type":"pga_alert_cancel", "time":long } + +# 震度レポート +{"type":"intensity_report", +"time":long, +"max_index":int, +"intensity_list":[ +{"intensity":String, +"index":int, +"region_list":[String,String,,,,]}, +{"intensity":String, +"index":int, +"region_list":[String,String,,,,]}, +,,] +} From fb4ed538c6f07e9c33c8049f3a0dcefc309a5289 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 01:50:23 +0900 Subject: [PATCH 23/42] wip --- src/config.ts | 1 + src/modules/earthquake/index.ts | 69 +++++++++++++++------------------ 2 files changed, 32 insertions(+), 38 deletions(-) diff --git a/src/config.ts b/src/config.ts index 1918b4f..81892a6 100644 --- a/src/config.ts +++ b/src/config.ts @@ -12,6 +12,7 @@ type Config = { mecab?: string; mecabDic?: string; memoryDir?: string; + earthQuakeMonitorPort?: number; }; const config = require('../config.json'); diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index 0ee8742..55eaca7 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -1,41 +1,42 @@ import autobind from "autobind-decorator"; import Module from "@/module"; +import config from "@/config"; import Message from "@/message"; import * as http from "http"; // 基本的に生データはstringばっかり。都合のいい形に加工済みの状態の型定義を書いています。 // ここでいくらか言及されてる(https://bultar.bbs.fc2.com/?act=reply&tid=5645851); interface 緊急地震速報 { - type: 'eew'; - time: Date; - report: string; // 第n報 最終報はstringで'final'となるので、とりあえずstring型 - epicenter: string; // 震源地 - depth: string; // 震源の深さ - magnitude: string; // 地震の規模を示すマグニチュード - latitude: string; // 緯度らしいが謎 - longitude: string; // 経度らしいが謎 - intensity: string; // 地震の強さ - index: number; // 謎 + type: "eew"; + time: Date; + report: string; // 第n報 最終報はstringで'final'となるので、とりあえずstring型 + epicenter: string; // 震源地 + depth: string; // 震源の深さ + magnitude: string; // 地震の規模を示すマグニチュード + latitude: string; // 緯度らしいが謎 + longitude: string; // 経度らしいが謎 + intensity: string; // 地震の強さ + index: number; // 謎 } interface 緊急地震速報キャンセル { - type: 'pga_alert_cancel'; - time: Date; + type: "pga_alert_cancel"; + time: Date; } interface 震度レポート { - type: 'intensity_report'; + type: "intensity_report"; time: Date; max_index: number; intensity_list: { - intensity: string; - index: number; - region_list: string[]; - }[]; + intensity: string; + index: number; + region_list: string[]; + }[]; } interface 地震検知 { - type: 'pga_alert'; + type: "pga_alert"; time: Date; max_pga: number; new: boolean; @@ -71,28 +72,20 @@ export default class extends Module { }), ); - if (rawDataJSON.type == "pga_alert") { - const data: 地震検知 = { + if (rawDataJSON.type == "intensity_report") { + const data: 震度レポート = { type: rawDataJSON.type, time: new Date(parseInt(rawDataJSON.time)), - max_pga: rawDataJSON.max_pga, - new: rawDataJSON.new, - estimated_intensity: rawDataJSON.estimated_intensity, - region_list: rawDataJSON.region_list, + max_index: rawDataJSON.max_index, + intensity_list: rawDataJSON.intensity_list, }; - this.message = - // region_listはオブジェクトなので、2行改行してから列挙する - `PGA Alert\n${data.time.toLocaleString()}\n${data.max_pga}\n${data.estimated_intensity}\n\n${data.region_list.join("\n")}`; - }else if (rawDataJSON.type == 'intensity_report'){ - const data: 震度レポート = { - type: rawDataJSON.type, - time: new Date(parseInt(rawDataJSON.time)), - max_index: rawDataJSON.max_index, - intensity_list: rawDataJSON.intensity_list, - } - this.message = - `Intensity Report\n${data.time.toLocaleString()}\n\n${data.intensity_list.map(intensity => `震度${intensity.intensity} ${intensity.region_list.join(" ")}`).join("\n")}`; - } + this.message = `震度レポート\n${data.time.toLocaleString()}\n\n${ + data.intensity_list.map((intensity) => + `震度${intensity.intensity}: ${intensity.region_list.join(" ")}` + ).join("\n") + }`; + } + console.log(rawDataJSON); // デバッグ用 this.returnResponse(res, "ok"); if (this.message) { this.ai.post({ @@ -103,7 +96,7 @@ export default class extends Module { } else { this.returnResponse(res, "debobigego"); } - }).listen(process.env.EARTHQUAKE_PORT || 9999); + }).listen(config.earthQuakeMonitorPort || 9999); } @autobind From 4133d9aeb30fd3df76728dd4de1bfc6abcd2f3d1 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 02:40:31 +0900 Subject: [PATCH 24/42] =?UTF-8?q?=F0=9F=98=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 5 ++-- src/modules/earthquake/index.ts | 28 ++++++++++++++++--- .../earthquake/{typeMemo.cs => typeMemo.c} | 0 3 files changed, 27 insertions(+), 6 deletions(-) rename src/modules/earthquake/{typeMemo.cs => typeMemo.c} (100%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 68ecdba..9397f56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "typescript.tsdk": "node_modules\\typescript\\lib" -} \ No newline at end of file + "typescript.tsdk": "node_modules\\typescript\\lib", + "C_Cpp.errorSquiggles": "Disabled" +} diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index 55eaca7..16d9313 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -48,6 +48,8 @@ export default class extends Module { public readonly name = "earthquake"; private message: string = ""; + private earthQuakeIndex: string[] = ["0未満", "0", "1", "2", "3", "4", "5弱", "5強", "6弱", "7"] + @autobind public install() { this.createListenServer(); @@ -65,7 +67,7 @@ export default class extends Module { const rawDataString = Buffer.concat(buffers).toString(); // rawDataString について、Unicodeエスケープシーケンスが含まれていたら通常の文字列に変換する // JSONでなければreturn falseする - if (rawDataString.match(/\\u[0-9a-f]{4}/)) { + if (rawDataString.match(/\\u[0-9a-f]{4}/) || true) { const rawDataJSON = JSON.parse( rawDataString.replace(/\\u([\d\w]{4})/g, (match, p1) => { return String.fromCharCode(parseInt(p1, 16)); @@ -79,16 +81,34 @@ export default class extends Module { max_index: rawDataJSON.max_index, intensity_list: rawDataJSON.intensity_list, }; - this.message = `震度レポート\n${data.time.toLocaleString()}\n\n${ + this.message = `地震かも?\n\n震度レポート\n${data.time.toLocaleString()}\n最大震度:${this.earthQuakeIndex[data.max_index + 1]}\n\n${ data.intensity_list.map((intensity) => - `震度${intensity.intensity}: ${intensity.region_list.join(" ")}` + `震度${this.earthQuakeIndex[intensity.index + 1]}: ${intensity.region_list.join(" ")}` ).join("\n") }`; - } + } if (rawDataJSON.type == 'eew' && false) { + const data: 緊急地震速報 = { + type: rawDataJSON.type, + time: new Date(parseInt(rawDataJSON.time)), + report: rawDataJSON.report, + epicenter: rawDataJSON.epicenter, + depth: rawDataJSON.depth, + magnitude: rawDataJSON.magnitude, + latitude: rawDataJSON.latitude, + longitude: rawDataJSON.longitude, + intensity: rawDataJSON.intensity, + index: rawDataJSON.index, + } + + if (data.report == '1') { + this.message = `**TEST TEST TEST TEST**\n地震かも?\n\n緊急地震速報\n${data.time.toLocaleString()}\n\n第${data.report}報\n震源地: ${data.epicenter}\n震源の深さ: ${data.depth}\n地震の規模(M): ${data.magnitude}\n緯度: ${data.latitude}\n経度: ${data.longitude}\n予想される最大震度(?): ${data.intensity}\n`; + } + } console.log(rawDataJSON); // デバッグ用 this.returnResponse(res, "ok"); if (this.message) { this.ai.post({ + cw: "試験運用中!!!!!", visibility: "home", text: this.message, }); diff --git a/src/modules/earthquake/typeMemo.cs b/src/modules/earthquake/typeMemo.c similarity index 100% rename from src/modules/earthquake/typeMemo.cs rename to src/modules/earthquake/typeMemo.c From a6ccecc155c4f8fe96cf77996683826a7d9d444f Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 02:44:21 +0900 Subject: [PATCH 25/42] =?UTF-8?q?CO=E7=B7=A8=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index 16d9313..b872f82 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -86,7 +86,7 @@ export default class extends Module { `震度${this.earthQuakeIndex[intensity.index + 1]}: ${intensity.region_list.join(" ")}` ).join("\n") }`; - } if (rawDataJSON.type == 'eew' && false) { + } if (rawDataJSON.type == 'eew' && false) { // これ使わなさそうだしとりあえず入らないようにした const data: 緊急地震速報 = { type: rawDataJSON.type, time: new Date(parseInt(rawDataJSON.time)), From 23391583df0496b8f413fb5c9f812cc031f3736a Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 02:51:18 +0900 Subject: [PATCH 26/42] =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=87=E3=83=B3?= =?UTF-8?q?=E3=83=88=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 68 +++++++++++++-------- src/modules/earthquake/テスト用生データ.txt | 4 ++ 2 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 src/modules/earthquake/テスト用生データ.txt diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index b872f82..152fde5 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -48,7 +48,18 @@ export default class extends Module { public readonly name = "earthquake"; private message: string = ""; - private earthQuakeIndex: string[] = ["0未満", "0", "1", "2", "3", "4", "5弱", "5強", "6弱", "7"] + private earthQuakeIndex: string[] = [ + "0未満", + "0", + "1", + "2", + "3", + "4", + "5弱", + "5強", + "6弱", + "7", + ]; @autobind public install() { @@ -81,34 +92,41 @@ export default class extends Module { max_index: rawDataJSON.max_index, intensity_list: rawDataJSON.intensity_list, }; - this.message = `地震かも?\n\n震度レポート\n${data.time.toLocaleString()}\n最大震度:${this.earthQuakeIndex[data.max_index + 1]}\n\n${ - data.intensity_list.map((intensity) => - `震度${this.earthQuakeIndex[intensity.index + 1]}: ${intensity.region_list.join(" ")}` - ).join("\n") - }`; - } if (rawDataJSON.type == 'eew' && false) { // これ使わなさそうだしとりあえず入らないようにした - const data: 緊急地震速報 = { - type: rawDataJSON.type, - time: new Date(parseInt(rawDataJSON.time)), - report: rawDataJSON.report, - epicenter: rawDataJSON.epicenter, - depth: rawDataJSON.depth, - magnitude: rawDataJSON.magnitude, - latitude: rawDataJSON.latitude, - longitude: rawDataJSON.longitude, - intensity: rawDataJSON.intensity, - index: rawDataJSON.index, - } + this.message = + `地震かも?\n\n震度レポート\n${data.time.toLocaleString()}\n最大震度:${ + this.earthQuakeIndex[data.max_index + 1] + }\n\n${ + data.intensity_list.map((intensity) => + `震度${this.earthQuakeIndex[intensity.index + 1]}: ${ + intensity.region_list.join(" ") + }` + ).join("\n") + }`; + } + if (rawDataJSON.type == "eew" && false) { // これ使わなさそうだしとりあえず入らないようにした + const data: 緊急地震速報 = { + type: rawDataJSON.type, + time: new Date(parseInt(rawDataJSON.time)), + report: rawDataJSON.report, + epicenter: rawDataJSON.epicenter, + depth: rawDataJSON.depth, + magnitude: rawDataJSON.magnitude, + latitude: rawDataJSON.latitude, + longitude: rawDataJSON.longitude, + intensity: rawDataJSON.intensity, + index: rawDataJSON.index, + }; - if (data.report == '1') { - this.message = `**TEST TEST TEST TEST**\n地震かも?\n\n緊急地震速報\n${data.time.toLocaleString()}\n\n第${data.report}報\n震源地: ${data.epicenter}\n震源の深さ: ${data.depth}\n地震の規模(M): ${data.magnitude}\n緯度: ${data.latitude}\n経度: ${data.longitude}\n予想される最大震度(?): ${data.intensity}\n`; - } - } - console.log(rawDataJSON); // デバッグ用 + if (data.report == "1") { + this.message = + `**TEST TEST TEST TEST**\n地震かも?\n\n緊急地震速報\n${data.time.toLocaleString()}\n\n第${data.report}報\n震源地: ${data.epicenter}\n震源の深さ: ${data.depth}\n地震の規模(M): ${data.magnitude}\n緯度: ${data.latitude}\n経度: ${data.longitude}\n予想される最大震度(?): ${data.intensity}\n`; + } + } + console.log(rawDataJSON); // デバッグ用 this.returnResponse(res, "ok"); if (this.message) { this.ai.post({ - cw: "試験運用中!!!!!", + cw: "試験運用中!!!!!", visibility: "home", text: this.message, }); diff --git a/src/modules/earthquake/テスト用生データ.txt b/src/modules/earthquake/テスト用生データ.txt new file mode 100644 index 0000000..9d4696d --- /dev/null +++ b/src/modules/earthquake/テスト用生データ.txt @@ -0,0 +1,4 @@ +# テスト用生データ +{"type":"pga_alert","time":"1649085285968","max_pga":-0.531,"new":true,"estimated_intensity":0,"region_list":["\u8328\u57ce"]} +{"type":"intensity_report","time":"1649085285968","max_index":-1,"intensity_list":[{"intensity":"0\u672a\u6e80","index":-1,"region_list":["\u8328\u57ce"]}]} +{"type": "eew","report": "1","epicenter": "伊予灘","depth": "60km","magnitude": 3.5,"latitude": 33.8,"longitude": 132.1,"intensity": "2","index": 2} From 59cdd5849f02e132aa86ceea2fca2a71c6af9a83 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 09:50:08 +0900 Subject: [PATCH 27/42] =?UTF-8?q?=E3=81=A1=E3=82=87=E3=81=A3=E3=81=A8?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index 152fde5..fe6ce5d 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -48,7 +48,7 @@ export default class extends Module { public readonly name = "earthquake"; private message: string = ""; - private earthQuakeIndex: string[] = [ + private earthquakeIntensityIndex: string[] = [ "0未満", "0", "1", @@ -58,6 +58,7 @@ export default class extends Module { "5弱", "5強", "6弱", + "6強", "7", ]; @@ -94,10 +95,10 @@ export default class extends Module { }; this.message = `地震かも?\n\n震度レポート\n${data.time.toLocaleString()}\n最大震度:${ - this.earthQuakeIndex[data.max_index + 1] + this.earthquakeIntensityIndex[data.max_index + 1] }\n\n${ data.intensity_list.map((intensity) => - `震度${this.earthQuakeIndex[intensity.index + 1]}: ${ + `震度${this.earthquakeIntensityIndex[intensity.index + 1]}: ${ intensity.region_list.join(" ") }` ).join("\n") @@ -122,7 +123,12 @@ export default class extends Module { `**TEST TEST TEST TEST**\n地震かも?\n\n緊急地震速報\n${data.time.toLocaleString()}\n\n第${data.report}報\n震源地: ${data.epicenter}\n震源の深さ: ${data.depth}\n地震の規模(M): ${data.magnitude}\n緯度: ${data.latitude}\n経度: ${data.longitude}\n予想される最大震度(?): ${data.intensity}\n`; } } - console.log(rawDataJSON); // デバッグ用 + + console.table(rawDataJSON); // デバッグ用 + if (rawDataJSON.type == 'intensity_report') { + console.table(rawDataJSON.region_list); // デバッグ用 + } + this.returnResponse(res, "ok"); if (this.message) { this.ai.post({ From dc3b7dd954c0258344826c77675af8c873f72200 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 09:57:23 +0900 Subject: [PATCH 28/42] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=87=BA=E3=81=99?= =?UTF-8?q?=E3=81=A8=E3=81=8D=E3=81=AE=E6=9C=80=E5=A4=A7=E9=9C=87=E5=BA=A6?= =?UTF-8?q?=E3=81=97=E3=81=8D=E3=81=84=E5=80=A4=E3=81=BE=E3=82=8F=E3=82=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 37 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index fe6ce5d..d95b590 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -48,6 +48,7 @@ export default class extends Module { public readonly name = "earthquake"; private message: string = ""; + private thresholdVal = 0; // 下の配列の添え字に相当する値。しきい値以上のものについて通知を出す。 private earthquakeIntensityIndex: string[] = [ "0未満", "0", @@ -87,22 +88,24 @@ export default class extends Module { ); if (rawDataJSON.type == "intensity_report") { - const data: 震度レポート = { - type: rawDataJSON.type, - time: new Date(parseInt(rawDataJSON.time)), - max_index: rawDataJSON.max_index, - intensity_list: rawDataJSON.intensity_list, - }; - this.message = - `地震かも?\n\n震度レポート\n${data.time.toLocaleString()}\n最大震度:${ - this.earthquakeIntensityIndex[data.max_index + 1] - }\n\n${ - data.intensity_list.map((intensity) => - `震度${this.earthquakeIntensityIndex[intensity.index + 1]}: ${ - intensity.region_list.join(" ") - }` - ).join("\n") - }`; + if (rawDataJSON.max_index >= this.thresholdVal) { + const data: 震度レポート = { + type: rawDataJSON.type, + time: new Date(parseInt(rawDataJSON.time)), + max_index: rawDataJSON.max_index, + intensity_list: rawDataJSON.intensity_list, + }; + this.message = + `地震かも?\n\n震度レポート\n${data.time.toLocaleString()}\n最大震度:${ + this.earthquakeIntensityIndex[data.max_index + 1] + }\n\n${ + data.intensity_list.map((intensity) => + `震度${this.earthquakeIntensityIndex[intensity.index + 1]}: ${ + intensity.region_list.join(" ") + }` + ).join("\n") + }`; + } } if (rawDataJSON.type == "eew" && false) { // これ使わなさそうだしとりあえず入らないようにした const data: 緊急地震速報 = { @@ -123,7 +126,7 @@ export default class extends Module { `**TEST TEST TEST TEST**\n地震かも?\n\n緊急地震速報\n${data.time.toLocaleString()}\n\n第${data.report}報\n震源地: ${data.epicenter}\n震源の深さ: ${data.depth}\n地震の規模(M): ${data.magnitude}\n緯度: ${data.latitude}\n経度: ${data.longitude}\n予想される最大震度(?): ${data.intensity}\n`; } } - + console.table(rawDataJSON); // デバッグ用 if (rawDataJSON.type == 'intensity_report') { console.table(rawDataJSON.region_list); // デバッグ用 From 5f8c7d957228e2f2de5ea28257871d16daa4b86d Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 16:52:44 +0900 Subject: [PATCH 29/42] =?UTF-8?q?=E3=81=A8=E3=82=8A=E3=81=82=E3=81=88?= =?UTF-8?q?=E3=81=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index d95b590..3237657 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -48,7 +48,7 @@ export default class extends Module { public readonly name = "earthquake"; private message: string = ""; - private thresholdVal = 0; // 下の配列の添え字に相当する値。しきい値以上のものについて通知を出す。 + private thresholdVal = 5; // 下の配列の添え字に相当する値。しきい値以上のものについて通知を出す。 private earthquakeIntensityIndex: string[] = [ "0未満", "0", @@ -88,7 +88,7 @@ export default class extends Module { ); if (rawDataJSON.type == "intensity_report") { - if (rawDataJSON.max_index >= this.thresholdVal) { + if (rawDataJSON.max_index >= this.thresholdVal - 1) { const data: 震度レポート = { type: rawDataJSON.type, time: new Date(parseInt(rawDataJSON.time)), @@ -96,7 +96,7 @@ export default class extends Module { intensity_list: rawDataJSON.intensity_list, }; this.message = - `地震かも?\n\n震度レポート\n${data.time.toLocaleString()}\n最大震度:${ + `地震かも?\n\n震度レポート\n${data.time.toLocaleString()}\n最大震度: ${ this.earthquakeIntensityIndex[data.max_index + 1] }\n\n${ data.intensity_list.map((intensity) => @@ -129,7 +129,7 @@ export default class extends Module { console.table(rawDataJSON); // デバッグ用 if (rawDataJSON.type == 'intensity_report') { - console.table(rawDataJSON.region_list); // デバッグ用 + console.table(rawDataJSON.intensity_list); // デバッグ用 } this.returnResponse(res, "ok"); From 5d49778cbc3420f898cf279eb06991ade4ce1a97 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 17:05:01 +0900 Subject: [PATCH 30/42] =?UTF-8?q?=E3=83=87=E3=83=90=E3=83=83=E3=82=B0?= =?UTF-8?q?=E7=94=A8=E5=88=86=E5=B2=90=E3=81=AE=E9=99=A4=E5=8E=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index 3237657..f21e17b 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -80,7 +80,7 @@ export default class extends Module { const rawDataString = Buffer.concat(buffers).toString(); // rawDataString について、Unicodeエスケープシーケンスが含まれていたら通常の文字列に変換する // JSONでなければreturn falseする - if (rawDataString.match(/\\u[0-9a-f]{4}/) || true) { + if (rawDataString.match(/\\u[0-9a-f]{4}/)) { const rawDataJSON = JSON.parse( rawDataString.replace(/\\u([\d\w]{4})/g, (match, p1) => { return String.fromCharCode(parseInt(p1, 16)); From 6840398ba70de14f17eeafdfb9c4bafce58cc9f5 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 17:10:28 +0900 Subject: [PATCH 31/42] =?UTF-8?q?=E3=81=84=E3=81=A3=E3=81=9F=E3=82=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index f21e17b..a934973 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -48,7 +48,7 @@ export default class extends Module { public readonly name = "earthquake"; private message: string = ""; - private thresholdVal = 5; // 下の配列の添え字に相当する値。しきい値以上のものについて通知を出す。 + private thresholdVal = 0; // 下の配列の添え字に相当する値。しきい値以上のものについて通知を出す。 普段は5(震度3) private earthquakeIntensityIndex: string[] = [ "0未満", "0", From 067af920ad92183cf3d9c71e3e428136242b8ad4 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 20:32:38 +0900 Subject: [PATCH 32/42] wip --- src/modules/earthquake/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index a934973..8a3250d 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -91,6 +91,7 @@ export default class extends Module { if (rawDataJSON.max_index >= this.thresholdVal - 1) { const data: 震度レポート = { type: rawDataJSON.type, + // 日付時刻は、yyyy-mm-dd hh:mm:ss time: new Date(parseInt(rawDataJSON.time)), max_index: rawDataJSON.max_index, intensity_list: rawDataJSON.intensity_list, From 20e006cb1846bba7ecb5025a026009bf785d7d3d Mon Sep 17 00:00:00 2001 From: na2na-p Date: Tue, 5 Apr 2022 20:51:47 +0900 Subject: [PATCH 33/42] =?UTF-8?q?=E6=97=A5=E4=BB=98=E8=A1=A8=E7=A4=BA?= =?UTF-8?q?=E3=82=92=E5=A4=89=E6=9B=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index 8a3250d..2347ecf 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -26,7 +26,7 @@ interface 緊急地震速報キャンセル { interface 震度レポート { type: "intensity_report"; - time: Date; + time: string; max_index: number; intensity_list: { intensity: string; @@ -89,21 +89,24 @@ export default class extends Module { if (rawDataJSON.type == "intensity_report") { if (rawDataJSON.max_index >= this.thresholdVal - 1) { + // 日付時刻は、yyyy-mm-dd hh:mm:ss + const time = new Date(parseInt(rawDataJSON.time)); + const timeString = `${time.getFullYear()}-${(time.getMonth() + + 1).toString().padStart(2, '0')}-${time.getDate().toString().padStart(2, '0')} ${time.getHours().toString().padStart(2, '0')}:${time.getMinutes().toString().padStart(2, '0')}:${time.getSeconds().toString().padStart(2, '0')}`; const data: 震度レポート = { type: rawDataJSON.type, - // 日付時刻は、yyyy-mm-dd hh:mm:ss - time: new Date(parseInt(rawDataJSON.time)), + time: timeString, max_index: rawDataJSON.max_index, intensity_list: rawDataJSON.intensity_list, }; this.message = - `地震かも?\n\n震度レポート\n${data.time.toLocaleString()}\n最大震度: ${ + `地震かも?\n\`\`\`\n震度レポート\n${data.time}\n最大震度: ${ this.earthquakeIntensityIndex[data.max_index + 1] }\n\n${ data.intensity_list.map((intensity) => `震度${this.earthquakeIntensityIndex[intensity.index + 1]}: ${ intensity.region_list.join(" ") - }` + }\n\`\`\`` ).join("\n") }`; } From a5365eab6fbb5508a1dc7f14639713dc4d93f47d Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 5 Apr 2022 21:02:10 +0900 Subject: [PATCH 34/42] =?UTF-8?q?=E3=83=89=E3=82=AD=E3=83=A5=E3=83=A1?= =?UTF-8?q?=E3=83=B3=E3=83=88=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 68 +++++++++++-------------------------------------------- 1 file changed, 13 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 87dcf11..629d5a2 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,19 @@ -

藍

-

An Ai for Misskey. About Ai

+# フォーク元と違うところ -## これなに -Misskey用の日本語Botです。 +- 一部の絵文字リアクション機能 +- ねこ召喚(summonCat) +- ランダムカラーピッカー(color) +- ランダムにクックパッドからレシピを引っ張ってくる(menu) +- 強震モニター Extension と連携して震度レポートのノート(earthquake) -## インストール -> Node.js と npm と MeCab (オプション) がインストールされている必要があります。 +# メモ -まず適当なディレクトリに `git clone` します。 -次にそのディレクトリに `config.json` を作成します。中身は次のようにします: -``` json -{ - "host": "https:// + あなたのインスタンスのURL (末尾の / は除く)", - "i": "藍として動かしたいアカウントのアクセストークン", - "master": "管理者のユーザー名(オプション)", - "notingEnabled": "ランダムにノートを投稿する機能を無効にする場合は false を入れる", - "keywordEnabled": "キーワードを覚える機能 (MeCab が必要) を有効にする場合は true を入れる (無効にする場合は false)", - "chartEnabled": "チャート機能を無効化する場合は false を入れてください", - "reversiEnabled": "藍とリバーシで対局できる機能を有効にする場合は true を入れる (無効にする場合は false)", - "serverMonitoring": "サーバー監視の機能を有効にする場合は true を入れる (無効にする場合は false)", - "mecab": "MeCab のインストールパス (ソースからインストールした場合、大体は /usr/local/bin/mecab)", - "mecabDic": "MeCab の辞書ファイルパス (オプション)", - "memoryDir": "memory.jsonの保存先(オプション、デフォルトは'.'(レポジトリのルートです))" -} -``` -`npm install` して `npm run build` して `npm start` すれば起動できます +## 強震モニターについて -## Dockerで動かす -まず適当なディレクトリに `git clone` します。 -次にそのディレクトリに `config.json` を作成します。中身は次のようにします: -(MeCabの設定、memoryDirについては触らないでください) -``` json -{ - "host": "https:// + あなたのインスタンスのURL (末尾の / は除く)", - "i": "藍として動かしたいアカウントのアクセストークン", - "master": "管理者のユーザー名(オプション)", - "notingEnabled": "ランダムにノートを投稿する機能を無効にする場合は false を入れる", - "keywordEnabled": "キーワードを覚える機能 (MeCab が必要) を有効にする場合は true を入れる (無効にする場合は false)", - "chartEnabled": "チャート機能を無効化する場合は false を入れてください", - "reversiEnabled": "藍とリバーシで対局できる機能を有効にする場合は true を入れる (無効にする場合は false)", - "serverMonitoring": "サーバー監視の機能を有効にする場合は true を入れる (無効にする場合は false)", - "mecab": "/usr/bin/mecab", - "mecabDic": "/usr/lib/x86_64-linux-gnu/mecab/dic/mecab-ipadic-neologd/", - "memoryDir": "data" -} -``` -`docker-compose build` して `docker-compose up` すれば起動できます。 -`docker-compose.yml` の `enable_mecab` を `0` にすると、MeCabをインストールしないようにもできます。(メモリが少ない環境など) +http サーバーを起動させて、震度レポートを受け取るような仕組み。 +config.json にポート番号を指定、そのポート番号に対して、震度レポートを受け取るようにする。 +リバースプロキシなんかを使ってたりします。 -## フォント -一部の機能にはフォントが必要です。藍にはフォントは同梱されていないので、ご自身でフォントをインストールディレクトリに`font.ttf`という名前で設置してください。 +## ランダムカラーピッカー -## 記憶 -藍は記憶の保持にインメモリデータベースを使用しており、藍のインストールディレクトリに `memory.json` という名前で永続化されます。 - -## ライセンス -MIT - -## Awards -Works on my machine +ランダムに決定した色の 1px \* 1px の画像をアップロードしてます。 From 35db08f4e6f54732eab3e49e01324d1db401533e Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Wed, 6 Apr 2022 00:12:53 +0900 Subject: [PATCH 35/42] =?UTF-8?q?=E3=83=87=E3=83=90=E3=83=83=E3=82=B0?= =?UTF-8?q?=E7=94=A8=E3=82=B3=E3=83=BC=E3=83=89=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index 2347ecf..acd859a 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -145,6 +145,11 @@ export default class extends Module { }); } } else { + this.ai.post({ + cw: "試験運用中!!!!!", + visibility: "home", + text: 'eq:デボビゲゴ', + }); this.returnResponse(res, "debobigego"); } }).listen(config.earthQuakeMonitorPort || 9999); From d42b549585dbdbc7386659c474debc22c8dee7a6 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Mon, 11 Apr 2022 09:49:47 +0900 Subject: [PATCH 36/42] =?UTF-8?q?[reminder]visibility=E3=81=8Cfollowers?= =?UTF-8?q?=E3=81=AE=E3=81=A8=E3=81=8D=E3=81=ABtodo=E3=82=92=E5=8F=97?= =?UTF-8?q?=E3=81=91=E4=BB=98=E3=81=91=E3=81=AA=E3=81=84=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/message.ts | 4 ++++ src/modules/reminder/index.ts | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/message.ts b/src/message.ts index 05c7f86..1c81439 100644 --- a/src/message.ts +++ b/src/message.ts @@ -34,6 +34,10 @@ export default class Message { return this.messageOrNote.renoteId; } + public get visibility(): string { + return this.messageOrNote.visibility; + } + /** * メンション部分を除いたテキスト本文 */ diff --git a/src/modules/reminder/index.ts b/src/modules/reminder/index.ts index 434e943..bfebb31 100644 --- a/src/modules/reminder/index.ts +++ b/src/modules/reminder/index.ts @@ -59,9 +59,12 @@ export default class extends Module { const separatorIndex = text.indexOf(' ') > -1 ? text.indexOf(' ') : text.indexOf('\n'); const thing = text.substr(separatorIndex + 1).trim(); - if (thing === '' && msg.quoteId == null) { + if (thing === '' && msg.quoteId == null || msg.visibility === 'followers') { msg.reply(serifs.reminder.invalid); - return true; + return { + reaction: '🆖', + immediate: true, + }; } const remind = this.reminds.insertOne({ From 82bc350345e848016cd83c88cc084afb1f93bbbf Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Mon, 11 Apr 2022 09:52:48 +0900 Subject: [PATCH 37/42] =?UTF-8?q?=E5=85=AC=E9=96=8B=E7=AF=84=E5=9B=B2?= =?UTF-8?q?=E3=82=92=E7=90=86=E7=94=B1=E3=81=AB=E6=8B=92=E5=90=A6=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=9F=E9=9A=9B=E3=81=AE=E3=82=BB=E3=83=AA=E3=83=95?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/reminder/index.ts | 7 ++++++- src/serifs.ts | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/modules/reminder/index.ts b/src/modules/reminder/index.ts index bfebb31..f104037 100644 --- a/src/modules/reminder/index.ts +++ b/src/modules/reminder/index.ts @@ -59,8 +59,13 @@ export default class extends Module { const separatorIndex = text.indexOf(' ') > -1 ? text.indexOf(' ') : text.indexOf('\n'); const thing = text.substr(separatorIndex + 1).trim(); - if (thing === '' && msg.quoteId == null || msg.visibility === 'followers') { + if (thing === '' && msg.quoteId == null) { msg.reply(serifs.reminder.invalid); + return true; + } + + if (msg.visibility === 'followers') { + msg.reply(serifs.reminder.invalidVisibility); return { reaction: '🆖', immediate: true, diff --git a/src/serifs.ts b/src/serifs.ts index 7d61ba3..d349cd9 100644 --- a/src/serifs.ts +++ b/src/serifs.ts @@ -339,6 +339,8 @@ export default { reminder: { invalid: 'うーん...?', + invalidVisibility: "公開範囲の指定を変えてみて", + reminds: 'やること一覧です!', notify: (name) => name ? `${name}、これやりましたか?` : `これやりましたか?`, From 8082d9719655f4628991eb9f217d3eb153f06cff Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Mon, 11 Apr 2022 10:58:56 +0900 Subject: [PATCH 38/42] wip --- .vscode/settings.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 9397f56..823bc61 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,8 @@ { "typescript.tsdk": "node_modules\\typescript\\lib", - "C_Cpp.errorSquiggles": "Disabled" + "C_Cpp.errorSquiggles": "Disabled", + "cSpell.words": [ + "lokijs", + "todos" + ] } From 2fb90c94139b7b0e6d1b003a59e93b45eb8fd6ec Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Tue, 12 Apr 2022 09:29:41 +0900 Subject: [PATCH 39/42] =?UTF-8?q?[earthquake]=E3=81=97=E3=81=8D=E3=81=84?= =?UTF-8?q?=E5=80=A4=E8=A8=AD=E5=AE=9A=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index acd859a..2f746f9 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -48,7 +48,7 @@ export default class extends Module { public readonly name = "earthquake"; private message: string = ""; - private thresholdVal = 0; // 下の配列の添え字に相当する値。しきい値以上のものについて通知を出す。 普段は5(震度3) + private thresholdVal = 5; // 下の配列の添え字に相当する値。しきい値以上のものについて通知を出す。 普段は5(震度3) private earthquakeIntensityIndex: string[] = [ "0未満", "0", From 4314bef2d79548a7beee81b6bcd8a15b2aa4fafd Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Wed, 13 Apr 2022 11:17:27 +0900 Subject: [PATCH 40/42] =?UTF-8?q?=E3=81=97=E3=81=8D=E3=81=84=E5=80=A4?= =?UTF-8?q?=E3=81=AE=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index 2f746f9..86c1d83 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -48,7 +48,7 @@ export default class extends Module { public readonly name = "earthquake"; private message: string = ""; - private thresholdVal = 5; // 下の配列の添え字に相当する値。しきい値以上のものについて通知を出す。 普段は5(震度3) + private thresholdVal = 3; // 下の配列の添え字に相当する値。しきい値以上のものについて通知を出す。 普段は3(震度2) private earthquakeIntensityIndex: string[] = [ "0未満", "0", From c0ca00222c6cc54adf60259961f574196b15d3d0 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Thu, 14 Apr 2022 13:10:33 +0900 Subject: [PATCH 41/42] =?UTF-8?q?=E4=BA=8B=E6=95=85=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/earthquake/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/earthquake/index.ts b/src/modules/earthquake/index.ts index 86c1d83..f48eba0 100644 --- a/src/modules/earthquake/index.ts +++ b/src/modules/earthquake/index.ts @@ -106,9 +106,9 @@ export default class extends Module { data.intensity_list.map((intensity) => `震度${this.earthquakeIntensityIndex[intensity.index + 1]}: ${ intensity.region_list.join(" ") - }\n\`\`\`` + }` ).join("\n") - }`; + }\n\`\`\``; } } if (rawDataJSON.type == "eew" && false) { // これ使わなさそうだしとりあえず入らないようにした From 4ec8fc78572813e0bc85eded57a33829c8bea931 Mon Sep 17 00:00:00 2001 From: na2na <49822810+na2na-p@users.noreply.github.com> Date: Thu, 14 Apr 2022 22:01:08 +0900 Subject: [PATCH 42/42] =?UTF-8?q?#70(=E4=BB=96=E4=BA=BA=E3=81=AE=E3=83=AA?= =?UTF-8?q?=E3=83=9E=E3=82=A4=E3=83=B3=E3=83=80=E3=83=BC=E3=82=92=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E3=81=A7=E3=81=8D=E3=82=8B)=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/reminder/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/reminder/index.ts b/src/modules/reminder/index.ts index 9b53f36..29e2ead 100644 --- a/src/modules/reminder/index.ts +++ b/src/modules/reminder/index.ts @@ -123,12 +123,16 @@ export default class extends Module { const done = msg.includes(['done', 'やった', 'やりました', 'はい']); const cancel = msg.includes(['やめる', 'やめた', 'キャンセル']); + const isOneself = msg.userId === remind.userId; - if (done || cancel) { + if ((done || cancel) && isOneself) { this.unsubscribeReply(key); this.reminds.remove(remind); msg.reply(done ? getSerif(serifs.reminder.done(msg.friend.name)) : serifs.reminder.cancel); return; + } else if (isOneself === false) { + msg.reply("イタズラはめっですよ!"); + return; } else { if (msg.isDm) this.unsubscribeReply(key); return false;