地震速報の情報を増量

This commit is contained in:
Last2014 2025-07-01 07:44:44 +09:00
parent 909258f421
commit 2689dfd777
2 changed files with 108 additions and 9 deletions

View File

@ -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("サーバーが起動しました");

View File

@ -142,21 +142,88 @@ async function areaMap(): Promise<Record<number, string>> {
return map;
}
// 地震発生
// 情報受信
async function event(earthquakeInfo: any): Promise<void> {
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<string> = 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<void> {
domesticTsunami = "この地震による国内の津波情報はありません";
}
// 最大震度
let maxScale;
if (earthquakeInfo.earthquake.maxScale === -1) {
@ -200,11 +268,37 @@ async function event(earthquakeInfo: any): Promise<void> {
maxScale = "震度7";
}
// 対象地域
let areas: string = "";
if (earthquakeInfo.points !== null) {
const areaMaps: any = await areaMap();
const areaNames: Array<string> = 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<void> {
const areaNames: Array<string> = 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();