From 95aa0bdb45571a6e36039610eee5b464b4340ba0 Mon Sep 17 00:00:00 2001 From: Last2014 Date: Sun, 3 May 2026 14:23:49 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=E5=9C=B0=E9=9C=87=E7=99=BA=E7=94=9F?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=81=AE=E5=9C=B0=E5=9F=9F=E3=82=92=E9=83=BD?= =?UTF-8?q?=E9=81=93=E5=BA=9C=E7=9C=8C=E3=81=A7=E3=82=B0=E3=83=AB=E3=83=BC?= =?UTF-8?q?=E3=83=97=E5=8C=96=E3=81=99=E3=82=8B=E6=A9=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/feature/earthquakeNotice.ts | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/feature/earthquakeNotice.ts b/src/feature/earthquakeNotice.ts index 5fcc4bd..e9572a4 100644 --- a/src/feature/earthquakeNotice.ts +++ b/src/feature/earthquakeNotice.ts @@ -142,32 +142,34 @@ const processMessage = async (message: any) => { "Potential": "🚨この地震によって**一般的に**この規模では津波の可能性があると考えられています。", } - let points: Record = {}; + const grouped: Record }> = {}; + for (const point of message.points) { - const scaleMsg = scaleMessages[String(point.scale)]; - if (!scaleMsg) - continue; - - points[scaleMsg]?.push(point); - } - - const grouped: Record = {}; - for (const point of message.points) { - const { addr, scale } = point; + const { addr, scale, pref } = point; const label = scaleMessages[String(scale)] ?? "不明"; if (!grouped[label]) { - grouped[label] = { scale, addrs: [] }; + grouped[label] = { scale, prefs: {} }; } - grouped[label].addrs.push(addr); + if (!grouped[label].prefs[pref]) { + grouped[label].prefs[pref] = []; + } + + grouped[label].prefs[pref].push(addr); } const pointsMsg = Object.entries(grouped) .sort((a, b) => b[1].scale - a[1].scale) - .map(([label, { addrs }]) => - `【${label}】${EOL}${addrs.join("・")}`) - .join(EOL.repeat(2)).trim(); + .map(([label, { prefs }]) => { + const prefLines = Object.entries(prefs) + .map(([pref, addrs]) => `${pref}: ${addrs.join("・")}`) + .join(EOL); + + return `【${label}】${EOL}${prefLines}`; + }) + .join(EOL.repeat(2)) + .trim(); await createUeuse({ text: i18next.t("earthquakeNotice", {