Chg: pnpm 11.1.3 / Del: helpコマンドとmiqコマンドを除く全てのi18n / Feat: 朝四時に何してるんだい?

This commit is contained in:
2026-05-21 22:22:45 +09:00
parent b2ff3e481a
commit 6fc5ab9d0d
10 changed files with 161 additions and 223 deletions
+109 -101
View File
@@ -1,16 +1,12 @@
import { createUeuse } from "@/lib/client";
import config from "@/lib/config";
import initI18n from "@/lib/i18n";
import Memory from "@/lib/memory";
import { format } from "date-fns";
import i18next from "i18next";
import { readFileSync } from "node:fs";
import { EOL } from "node:os";
import { WebSocket } from "ws";
import generateImage from "@/feature/earthquake/generateImage";
await initI18n();
if (config.earthquake?.useHistoryData) {
console.log("過去の地震情報を配信します");
const history = JSON.parse(readFileSync(`${import.meta.dirname}/../../260420.json`, "utf-8"));
@@ -169,32 +165,32 @@ const processMessage = async (message: any) => {
.join(EOL.repeat(2))
.trim();
const earthquakeNoticeText = [];
earthquakeNoticeText.push(`### ${typeMessage[message.issue.type] ?? "地震情報"}`);
earthquakeNoticeText.push(`⏰時刻: ${format(new Date(message.earthquake.time), "yyyy年M月d日 H:mm")}`);
earthquakeNoticeText.push(`🫨最大震度: scaleMessages[String(message.earthquake.maxScale)]`);
earthquakeNoticeText.push(`📍震源地: ${message.earthquake.hypocenter.name === ""
? "不明"
: message.earthquake.hypocenter.name}`);
earthquakeNoticeText.push(`💪マグニチュード: ${message.earthquake.hypocenter.magnitude === -1
? "不明"
: `M${message.earthquake.hypocenter.magnitude.toFixed(1)}`}`);
earthquakeNoticeText.push(`🪨深さ: ${message.earthquake.hypocenter.depth === 0
? "ごく浅い"
: message.earthquake.hypocenter.depth === -1
? "不明"
: `${message.earthquake.hypocenter.depth}km`}`);
earthquakeNoticeText.push(domesticTsunamiMessages[(message.earthquake.domesticTsunami ?? "Unknown")]);
earthquakeNoticeText.push(foreignTsunamiMessages[(message.earthquake.foreignTsunami ?? "Unknown")]);
earthquakeNoticeText.push(...(pointsMsg === ""
? []
: [EOL + pointsMsg]));
earthquakeNoticeText.push(...(message.comments.freeFormComment === ""
? []
: [message.comments.freeFormComment]));
earthquakeNoticeText.push(`🔬情報源: P2P地震速報 - ${message.issue.source ?? "不明"}`);
const earthquakeUeuses = await createUeuse({
text: i18next.t("earthquakeNotice", {
type: typeMessage[message.issue.type] ?? "地震情報",
occuredTime: format(new Date(message.earthquake.time), "yyyy年M月d日 H:mm"),
maxScale: scaleMessages[String(message.earthquake.maxScale)],
epicenter: message.earthquake.hypocenter.name === ""
? "不明"
: message.earthquake.hypocenter.name,
magnitude: message.earthquake.hypocenter.magnitude === -1
? "不明"
: `M${message.earthquake.hypocenter.magnitude.toFixed(1)}`,
depth: message.earthquake.hypocenter.depth === 0
? "ごく浅い"
: (message.earthquake.hypocenter.depth === -1
? "不明"
: `${message.earthquake.hypocenter.depth}km`),
domesticTsunami: domesticTsunamiMessages[(message.earthquake.domesticTsunami ?? "Unknown")],
foreignTsunami: foreignTsunamiMessages[(message.earthquake.foreignTsunami ?? "Unknown")],
points: pointsMsg === ""
? ""
: EOL.repeat(2) + pointsMsg,
source: message.issue.source ?? "不明",
comment: message.comments.freeFormComment === ""
? ""
: EOL + message.comments.freeFormComment + EOL,
}),
text: earthquakeNoticeText.join(EOL),
}, "地震発生情報");
try {
@@ -203,12 +199,15 @@ const processMessage = async (message: any) => {
if (typeof image === "string") {
throw "情報が不足しているため、地震の画像生成ができませんでした";
} else {
const infoUeuseURL = earthquakeUeuses[0]?.uniqid
? `${config.uwuzu.origin}/!${earthquakeUeuses[0].uniqid}`
: "不明";
const earthquakeImageText = [];
earthquakeImageText.push("地震の震度分布画像を生成しました。");
earthquakeImageText.push(`地震情報ユーズ: ${infoUeuseURL}`);
await createUeuse({
text: i18next.t("earthquakeImageGenerated", {
url: earthquakeUeuses[0]?.uniqid
? `${config.uwuzu.origin}/!${earthquakeUeuses[0].uniqid}`
: "不明",
}),
text: earthquakeImageText.join(EOL),
media: {
photo: [
image.toString("base64"),
@@ -226,12 +225,14 @@ const processMessage = async (message: any) => {
console.log("津波予報情報を受信しました");
if (message.cancelled) {
const tsunamiCancelledNoticeText = [];
tsunamiCancelledNoticeText.push("### 津波予報**解除**");
tsunamiCancelledNoticeText.push(`⏰発表時刻: ${format(new Date(message.issue.time), "yyyy年M月d日 H:mm:ss")}`);
tsunamiCancelledNoticeText.push(`🔬情報源: P2P地震速報 - ${message.issue.source ?? "不明"}`);
await createUeuse({
text: i18next.t("tsunamiCancelNotice", {
announceTime: format(new Date(message.issue.time), "yyyy年M月d日 H:mm:ss"),
source: message.issue.source ?? "不明",
}),
text: tsunamiCancelledNoticeText.join(EOL),
}, "津波予報解除情報");
break;
}
@@ -244,30 +245,31 @@ const processMessage = async (message: any) => {
let areasMsg = "";
for (const area of message.areas) {
areasMsg += i18next.t("tsunamiAreaMsg", {
name: area.name,
immediate: area.immediate
? EOL + "🚨***直ちに津波が来襲すると予想されています。***"
: "",
grade: gradeMessages[area.grade],
arrivalTime: format(new Date(area.firstHeight.arrivalTime), "yyyy年M月d日 H:mm"),
condition: area.firstHeight.condition
? `${area.firstHeight.condition}されています`
: "不明",
maxHeight: area.maxHeight.value === 0.2
? "0.2m未満"
: (area.maxHeight.value
? `${area.maxHeight.value}m`
: area.maxHeight.description),
}) + EOL.repeat(2);
const tsunamiAreaText = [];
tsunamiAreaText.push(`${area.name}`);
tsunamiAreaText.push(...(area.immediate
? ["🚨***直ちに津波が来襲すると予想されています。***"]
: []));
tsunamiAreaText.push(`🏷️種別: ${gradeMessages[area.grade]}`);
tsunamiAreaText.push(`⏳第1波到達予想時刻: ${format(new Date(area.firstHeight.arrivalTime), "yyyy年M月d日 H:mm")}`);
tsunamiAreaText.push(`🌊第1波の状態: ${area.firstHeight.condition
? `${area.firstHeight.condition}されています`
: "不明"}`);
tsunamiAreaText.push(`🗼予想される津波の高さ: ${area.maxHeight.value === 0.2
? "0.2m未満"
: (area.maxHeight.value
? `${area.maxHeight.value}m`
: area.maxHeight.description)}`);
areasMsg += tsunamiAreaText.join(EOL) + EOL.repeat(2);
}
const tsunamiNoticeText = [];
tsunamiNoticeText.push("### 津波予報**発表**");
tsunamiNoticeText.push(`⏰発表時刻: ${format(new Date(message.issue.time), "yyyy年M月d日 H:mm:ss")}`);
tsunamiNoticeText.push(EOL + areasMsg.trim() + EOL);
tsunamiNoticeText.push(`🔬情報源: P2P地震速報 - message.issue.source ?? "不明"`);
await createUeuse({
text: i18next.t("tsunamiForecastNotice", {
announceTime: format(new Date(message.issue.time), "yyyy年M月d日 H:mm:ss"),
areasMsg: areasMsg.trim(),
source: message.issue.source ?? "不明",
}),
text: tsunamiNoticeText.join(EOL),
}, "津波予報情報");
}
break;
@@ -276,13 +278,15 @@ const processMessage = async (message: any) => {
console.log("緊急地震速報(警報)を受信しました");
if (message.cancelled) {
const eewCancelledNotice = [];
eewCancelledNotice.push("### 緊急地震速報(警報)**解除**");
eewCancelledNotice.push(message.test
? "⚒️これは**テストです。**"
: "🚨これは**テストではありません。**");
eewCancelledNotice.push(`⏰発表時刻: ${format(new Date(message.issue.time), "yyyy年M月d日 H:mm:ss")}`);
eewCancelledNotice.push(EOL + "🔬情報源: P2P地震速報");
await createUeuse({
text: i18next.t("eewCancelNotice", {
isTest: message.test
? "⚒️これは**テストです。**"
: "🚨これは**テストではありません。**",
announceTime: format(new Date(message.issue.time), "yyyy年M月d日 H:mm:ss"),
}),
text: eewCancelledNotice.join(EOL),
}, "緊急地震速報(警報)解除情報");
}
@@ -294,45 +298,49 @@ const processMessage = async (message: any) => {
let areasMsg = "";
for (const area of message.areas) {
areasMsg += i18next.t("eewAreaMsg", {
name: area.name,
maxScale: scaleMessages[String(Math.floor(area.scaleFrom))] +
(area.scaleTo === 99
? "程度以上"
: area.scaleFrom !== area.scaleTo
? `から${scaleMessages[String(Math.floor(area.scaleTo))]}`
: ""),
kind: kindMessages[area.kindCode] ?? "😕主要動の***到達予想は***ありません。",
arrivalTime: typeof area.arrivalTime === "string" && area.arrivalTime !== ""
? format(new Date(area.arrivalTime), "yyyy年M月d日 H:mm:ss")
: "不明",
}) + EOL.repeat(2);
const eewAreaText = [];
eewAreaText.push(`${area.name}`);
eewAreaText.push(`🫨最大予測震度: ${scaleMessages[String(Math.floor(area.scaleFrom))] +
(area.scaleTo === 99
? "程度以上"
: area.scaleFrom !== area.scaleTo
? `から${scaleMessages[String(Math.floor(area.scaleTo))]}`
: "")}`);
eewAreaText.push(`⏰到達予想時刻: ${typeof area.arrivalTime === "string" && area.arrivalTime !== ""
? format(new Date(area.arrivalTime), "yyyy年M月d日 H:mm:ss")
: "不明"}`);
eewAreaText.push(kindMessages[area.kindCode] ?? "😕主要動の***到達予想は***ありません。");
areasMsg += eewAreaText.join(EOL) + EOL.repeat(2);
}
const eewNoticeText = [];
eewNoticeText.push("### ***緊急地震速報(警報)***");
eewNoticeText.push(message.test
? "⚒️これは**テストです。**"
: "🚨これは**テストではありません。**");
eewNoticeText.push(...(message.earthquake.condition === "仮定震源要素"
? ["❓これは、仮定震源要素です。そのため、震源に関する情報が保証できません。"]
: []));
eewNoticeText.push(`⏰発表時刻: ${format(new Date(message.issue.time), "yyyy年M月d日 H:mm:ss")}`);
eewNoticeText.push(`⏰地震発生時刻: ${format(new Date(message.earthquake.originTime), "yyyy年M月d日 H:mm:ss")}`);
eewNoticeText.push(`⏰地震発現時刻: ${format(new Date(message.earthquake.arrivalTime), "yyyy年M月d日 H:mm:ss")}`);
eewNoticeText.push(`📍震源地: ${message.earthquake.hypocenter.name ?? "不明"}`);
eewNoticeText.push(`💪マグニチュード: ${message.earthquake.hypocenter.magnitude === undefined ||
message.earthquake.hypocenter.magnitude === -1
? "不明"
: `M${message.earthquake.hypocenter.magnitude.toFixed(1)}`}`);
eewNoticeText.push(`🪨深さ: ${message.earthquake.hypocenter.depth === undefined ||
message.earthquake.hypocenter.depth === -1
? "不明"
: `${Math.floor(message.earthquake.hypocenter.depth)}km`}`);
eewNoticeText.push(...(areasMsg !== ""
? [EOL + areasMsg.trim()]
: []));
eewNoticeText.push(EOL + "🔬情報源: P2P地震速報");
await createUeuse({
text: i18next.t("eewNotice", {
isTest: message.test
? "⚒️これは**テストです。**"
: "🚨これは**テストではありません。**",
announceTime: format(new Date(message.issue.time), "yyyy年M月d日 H:mm:ss"),
occuredTime: format(new Date(message.earthquake.originTime), "yyyy年M月d日 H:mm:ss"),
arrivalTime: format(new Date(message.earthquake.arrivalTime), "yyyy年M月d日 H:mm:ss"),
isAssume: message.earthquake.condition === "仮定震源要素"
? `${EOL}❓これは、仮定震源要素です。そのため、震源に関する情報が保証できません。`
: "",
epicenter: message.earthquake.hypocenter.name ?? "不明",
depth: message.earthquake.hypocenter.depth === undefined ||
message.earthquake.hypocenter.depth === -1
? "不明"
: `${Math.floor(message.earthquake.hypocenter.depth)}km`,
magnitude: message.earthquake.hypocenter.magnitude === undefined ||
message.earthquake.hypocenter.magnitude === -1
? "不明"
: `M${message.earthquake.hypocenter.magnitude.toFixed(1)}`,
areas: areasMsg !== ""
? EOL.repeat(2) + areasMsg.trim()
: "",
}),
text: eewNoticeText.join(EOL),
}, "緊急地震速報(警報)情報");
}
break;