Feat: 地震の震度分布画像生成 / Chg: 震度分布画像のズームレベルを8から9へ / Chg: 震度分布画像の生成条件を震源と位置が存在するへ変更 / Feat: 震度分布画に全タイルが埋まる機能 / Feat: 震度分布画像の震源がタイル単位で中央になる機能 / Feat: 震度分布画像で欠けているタイルが描画される機能 / Chg: 震度分布画像のアセットを並列に取得 / Feat: 震度分布画像のアセットの位置が中央基準になる機能 / Chg: 震度分布画像の震源のアセットに縁取りを追加 / Chg: 震度分布画像の震度ではないアセットを拡大 / Chg: ユーズの分割の案内文を太字に / Del: 最大震度が不明な場合に投稿するかどうかのconfigを削除
This commit is contained in:
@@ -7,6 +7,7 @@ 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();
|
||||
|
||||
@@ -104,15 +105,6 @@ 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
|
||||
@@ -177,33 +169,61 @@ const processMessage = async (message: any) => {
|
||||
.join(EOL.repeat(2))
|
||||
.trim();
|
||||
|
||||
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,
|
||||
}),
|
||||
}, "地震発生情報");
|
||||
let earthquakeUniqid: string | null = null;
|
||||
|
||||
await Promise.allSettled([
|
||||
(async () => {
|
||||
const ueuses = 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,
|
||||
}),
|
||||
}, "地震発生情報");
|
||||
|
||||
earthquakeUniqid = ueuses[0]?.uniqid ?? null;
|
||||
})(),
|
||||
(async () => {
|
||||
const result = await generateImage(message);
|
||||
|
||||
if (typeof result === "string") {
|
||||
console.warn("情報が不足しているため、地震の画像生成ができませんでした");
|
||||
return;
|
||||
}
|
||||
|
||||
while (typeof (earthquakeUniqid as string | null) !== "string") {}
|
||||
|
||||
await createUeuse({
|
||||
text: "この地震の震度分布画像を生成しました。",
|
||||
media: {
|
||||
photo: [
|
||||
result.toString("base64"),
|
||||
]
|
||||
},
|
||||
reuseid: (earthquakeUniqid as unknown as string),
|
||||
}, "震度分布画像");
|
||||
})(),
|
||||
]);
|
||||
}
|
||||
break;
|
||||
case 552:
|
||||
|
||||
Reference in New Issue
Block a user