From c0df3d73441d66468bdb812b90a08327e4766780 Mon Sep 17 00:00:00 2001 From: Last2014 Date: Sat, 2 May 2026 20:07:37 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=E5=A4=A9=E6=B0=97=E4=BA=88=E5=A0=B1?= =?UTF-8?q?=E3=81=AE=E5=88=86=E5=89=B2=E6=95=B0=E3=82=92=E8=87=AA=E5=8B=95?= =?UTF-8?q?=E7=9A=84=E3=81=AB=E8=A8=88=E7=AE=97=E3=81=99=E3=82=8B=E6=A9=9F?= =?UTF-8?q?=E8=83=BD=20/=20Fix:=20=E9=9C=87=E5=BA=A60=E3=81=AE=E5=9C=B0?= =?UTF-8?q?=E9=9C=87=E6=83=85=E5=A0=B1=E3=81=AB=E5=AF=BE=E5=BF=9C=E3=81=97?= =?UTF-8?q?=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C=20/=20Fe?= =?UTF-8?q?at:=20=E6=9C=80=E5=A4=A7=E9=9C=87=E5=BA=A6=E3=81=AE=E8=A6=81?= =?UTF-8?q?=E6=B1=82=E3=82=92=E8=A8=AD=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=20/=20Feat:=20=E6=9C=80=E5=A4=A7=E9=9C=87?= =?UTF-8?q?=E5=BA=A6=E3=81=8C=E4=B8=8D=E6=98=8E=E3=81=AA=E5=A0=B4=E5=90=88?= =?UTF-8?q?=E3=81=AB=E6=8A=95=E7=A8=BF=E3=81=99=E3=82=8B=E3=81=8B=E3=81=A9?= =?UTF-8?q?=E3=81=86=E3=81=8B=E3=82=92=E8=A8=AD=E5=AE=9A=E3=81=A7=E3=81=8D?= =?UTF-8?q?=E3=82=8B=E6=A9=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/example.yaml | 16 ++++++++++++++-- src/feature/earthquakeNotice.ts | 18 ++++++++++++++++++ src/feature/weatherNotice.ts | 5 +++-- src/index.ts | 4 ++-- src/lib/config.ts | 17 +++++++++++++---- src/lib/memory.ts | 26 +++++++++++++++++++------- 6 files changed, 69 insertions(+), 17 deletions(-) diff --git a/config/example.yaml b/config/example.yaml index d33f0c6..cc794f6 100644 --- a/config/example.yaml +++ b/config/example.yaml @@ -1,10 +1,22 @@ command: + # コマンド処理の間隔(分) number + # 自然数のみが有効です。 interval: 10 -weather: - splits: 4 earthquake: + # 地震発生情報を投稿することに必要な最大震度 number + # 例: 30を指定すると、最大震度が震度3以上の地震発生情報のみを投稿します。 + # 10(震度1), 20(震度2), 30(震度3), 40(震度4), 45(震度5弱), 50(震度5強), 55(震度6弱), 60(震度6強), 70(震度7)が有効です。 + requireMaxScale: 30 + # 最大震度が不明な地震発生情報を投稿するかどうか boolean + canUnknownMaxScale: true + # 過去のデバッグ用データを使用して地震情報を配信するかどうか boolean + # デバッグ用途のみで使用してください。 useHistoryData: false uwuzu: + # APIトークン string + # とくに理由がない限り、全権限を与えてください。 token: API_TOKEN + # uwuzuサーバーのorigin string origin: https://uwuzu.example.com +# デバッグモードにするかどうか boolean debug: false \ No newline at end of file diff --git a/src/feature/earthquakeNotice.ts b/src/feature/earthquakeNotice.ts index 3e43130..a3a1954 100644 --- a/src/feature/earthquakeNotice.ts +++ b/src/feature/earthquakeNotice.ts @@ -64,6 +64,7 @@ const processMessage = async (message: any) => { try { const scaleMessages: Record = { "-1": "不明", + "0": "震度0", "10": "震度1", "20": "震度2", "30": "震度3", @@ -85,6 +86,23 @@ const processMessage = async (message: any) => { { console.log("地震発生情報を受信しました"); + if ( + (message.earthquake.maxScale === -1 || + message.earthquake.maxScale === undefined) && + !config.earthquake.canUnknownMaxScale + ) { + console.log("最大震度が不明であり、最大震度が不明な場合の投稿が許可されていないため、スキップします"); + break; + } + + if ( + message.earthquake.maxScale !== -1 && + message.earthquake.maxScale < config.earthquake.requireMaxScale + ) { + console.log("投稿に必要な最大震度に満たないため、スキップします"); + break; + } + const domesticTsunamiMessages: Record = { "None": "😌この地震による**国内**の津波の心配はありません。", "Unknown": "😕この地震による**国内**の***津波情報は***不明です。", diff --git a/src/feature/weatherNotice.ts b/src/feature/weatherNotice.ts index ef55938..79412d0 100644 --- a/src/feature/weatherNotice.ts +++ b/src/feature/weatherNotice.ts @@ -1,6 +1,6 @@ import client from "@/lib/client"; -import config from "@/lib/config"; import initI18n from "@/lib/i18n"; +import Memory from "@/lib/memory"; import i18next from "i18next"; import { readFileSync } from "node:fs"; import { EOL } from "node:os"; @@ -84,7 +84,8 @@ if (!isMainThread && workerData === "scheduledWeatherNotice") { export async function weatherReply(uniqid: string) { // インデックス - const splitCount = config.weather.splits; + const mem = Memory.memory; + const splitCount = Math.round(3100 / mem.max_length); const total = cityList.length; const chunkSizes = Array(splitCount).fill(0).map((_, i) => Math.floor((total + i) / splitCount) diff --git a/src/index.ts b/src/index.ts index 18be265..dc70c41 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,7 @@ import { schedule } from "node-cron"; import { readFileSync } from "node:fs"; import config from "@/lib/config"; -import { initUserID } from "@/lib/memory"; +import { initData } from "@/lib/memory"; import { styleText } from "node:util"; import { Worker } from "node:worker_threads"; @@ -18,7 +18,7 @@ try { } console.log(); - await initUserID(); + await initData(); new Worker(`${import.meta.dirname}/feature/earthquakeNotice.js`); diff --git a/src/lib/config.ts b/src/lib/config.ts index d85056b..f8e6ae3 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -7,12 +7,21 @@ const schema = z.object({ command: z.object({ interval: z.number().int().positive(), }), - weather: z.object({ - splits: z.number().int().positive(), - }), earthquake: z.object({ + requireMaxScale: z.union([ + z.literal(10), + z.literal(20), + z.literal(30), + z.literal(40), + z.literal(45), + z.literal(50), + z.literal(55), + z.literal(60), + z.literal(70), + ]), + canUnknownMaxScale: z.boolean(), useHistoryData: z.boolean(), - }).optional(), + }), uwuzu: z.object({ token: z.string().length(64), origin: z.string().refine(data => { diff --git a/src/lib/memory.ts b/src/lib/memory.ts index 0e41425..f0c6962 100644 --- a/src/lib/memory.ts +++ b/src/lib/memory.ts @@ -14,6 +14,7 @@ class MemoryClass { lastReadMention: "", lastReadReply: "", userid: "", + max_length: 0, })); } @@ -32,15 +33,26 @@ class MemoryClass { const Memory = new MemoryClass(); -export const initUserID = async () => { - const response = await client.request("me/"); +export const initData = async () => { + await Promise.all([ + (async () => { + const response = await client.request("me/"); - if (!response.success) - throw new Error("meの取得に失敗しました"); + if (!response.success) + throw new Error("meの取得に失敗しました"); - const mem = Memory.memory; - mem.userid = response.userid; - Memory.memory = mem; + const mem = Memory.memory; + mem.userid = response.userid; + Memory.memory = mem; + })(), + (async () => { + const response = await client.request("serverinfo-api"); + + const mem = Memory.memory; + mem.max_length = response.server_info.max_ueuse_length; + Memory.memory = mem; + })(), + ]); } export default Memory; \ No newline at end of file