From 2689dfd77754744810697e00513979fffed249d4 Mon Sep 17 00:00:00 2001 From: Last2014 Date: Tue, 1 Jul 2025 07:44:44 +0900 Subject: [PATCH] =?UTF-8?q?=E5=9C=B0=E9=9C=87=E9=80=9F=E5=A0=B1=E3=81=AE?= =?UTF-8?q?=E6=83=85=E5=A0=B1=E3=82=92=E5=A2=97=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.ts | 9 ++- scripts/earthquakeNotice.ts | 108 +++++++++++++++++++++++++++++++++--- 2 files changed, 108 insertions(+), 9 deletions(-) diff --git a/main.ts b/main.ts index 418fb05..77dfe1a 100644 --- a/main.ts +++ b/main.ts @@ -1,11 +1,15 @@ +// 定期実行読み込み import * as cron from "node-cron"; +// 機能読み込み import timeNotice from "./scripts/timeNotice.js"; import weatherNotice from "./scripts/weatherNotice.js"; import earthquakeNotice from "./scripts/earthquakeNotice.js" +// フォローバック機能読み込み import followBack from "./scripts/followBack.js"; +// 地震情報観測開始 earthquakeNotice(); // 時報・フォローバック(毎時) @@ -14,11 +18,12 @@ cron.schedule("0 * * * *", () => { followBack(); }); -// 天気お知らせ(毎日7:00) -cron.schedule("0 7 * * *", () => { +// 天気お知らせ(毎日7:01) +cron.schedule("1 7 * * *", () => { setTimeout(() => { weatherNotice(); }, 100) }); +// コンソールで表示 console.log("サーバーが起動しました"); diff --git a/scripts/earthquakeNotice.ts b/scripts/earthquakeNotice.ts index ba2c814..8fa6def 100644 --- a/scripts/earthquakeNotice.ts +++ b/scripts/earthquakeNotice.ts @@ -142,21 +142,88 @@ async function areaMap(): Promise> { return map; } -// 地震発生 +// 情報受信 async function event(earthquakeInfo: any): Promise { console.log(JSON.stringify(earthquakeInfo)); + // ----処理---- + // 緊急地震速報の場合 if (earthquakeInfo.code === 554) { + // 地震詳細 + let descriptionEarthquake: string = ""; + + if (earthquakeInfo.earthquake.description !== "") { + descriptionEarthquake = `この地震について:${earthquakeInfo.earthquake.description}`; + } + + // 発令詳細 + let description: string = ""; + + if (earthquakeInfo.comments.freeFormComment !== "") { + description = `この発令について:${earthquakeInfo.comments.freeFormComment}`; + } + + // テスト・訓練 + let test: string = ""; + + if (earthquakeInfo.test) { + test = "これはテスト、あるいは訓練です"; + } else if (earthquakeInfo.test === false) { + test = "これはテスト・訓練ではありません"; + } else { + test = "この情報にテスト・訓練かの情報はありません"; + } + + // 対象地域 + let areas: string = ""; + + if (earthquakeInfo.areas !== null) { + const areaNames: Array = Array.from( + new Set( + earthquakeInfo.areas.map((i: any) => { + earthquakeInfo.areas[i].name.filter(Boolean); + }), + ), + ); + + areas = `対象地域:${areaNames.join("・")}`; + } + + // 速報取り消し + let cancelled: string = ""; + + if (earthquakeInfo.cancelled) { + cancelled = "※以下の緊急地震速報が取り消されました※"; + } + + // マグニチュード + let magnitude: string = "マグニチュード:"; + + if ( + earthquakeInfo.earthquake.hypocenter.magnitude !== -1 || + earthquakeInfo.earthquake.hypocenter.magnitude === null + ) { + magnitude += "マグニチュードの情報はありません"; + } else { + magnitude += `M${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`; + } + ueuse(` ==地震情報== 【緊急地震速報】 + ${cancelled} 時刻:${earthquakeInfo.time} + ${descriptionEarthquake} + ${description} + ${test} + ${areas} `); } // 地震情報 else if (earthquakeInfo.code === 551) { + // 国内津波 let domesticTsunami; if (earthquakeInfo.earthquake.domesticTsunami === "None") { @@ -176,6 +243,7 @@ async function event(earthquakeInfo: any): Promise { domesticTsunami = "この地震による国内の津波情報はありません"; } + // 最大震度 let maxScale; if (earthquakeInfo.earthquake.maxScale === -1) { @@ -200,11 +268,37 @@ async function event(earthquakeInfo: any): Promise { maxScale = "震度7"; } + // 対象地域 + let areas: string = ""; + + if (earthquakeInfo.points !== null) { + const areaMaps: any = await areaMap(); + + const areaNames: Array = Array.from( + new Set( + earthquakeInfo.points.map((i: any) => { + areaMaps[i.addr].filter(Boolean); + }), + ), + ); + + areas = `対象地域:${areaNames.join("・")}`; + } + + // 詳細 + let description: string = ""; + + if (earthquakeInfo.comments.freeFormComment !== "") { + description = `この地震について:${earthquakeInfo.comments.freeFormComment}`; + } + ueuse(` ==地震情報== - 【地域情報更新】 + 【地震発生】 時刻:${earthquakeInfo.time} + ${description} 最大深度:${maxScale} + ${areas} 国内の津波:${domesticTsunami} `); } @@ -216,19 +310,19 @@ async function event(earthquakeInfo: any): Promise { const areaNames: Array = Array.from( new Set( - earthquakeInfo.areas.map((a: any) => { - areaMaps[a.id].filter(Boolean); + earthquakeInfo.areas.map((i: any) => { + areaMaps[i.id].filter(Boolean); }), ), ); - const result = areaNames.join("・"); + const areas = areaNames.join("・"); ueuse(` ==地震情報== 【地域情報更新】 時刻:${earthquakeInfo.time} - 対象地域:${result} + 対象地域:${areas} `); } } @@ -247,7 +341,7 @@ async function ueuse(text: string) { console.log(JSON.stringify(resData)); } -export default function earthquake(): void { +export default function earthquakeNotice(): void { console.log("地震情報サーバーに接続します"); const client = new P2PEarthquakeClient(); client.start();