Fix: distに震度分布画像のアセットと地域マップがコピーされるように / Del: 正確にスケジュールが動作する機能 / Fix: 返信とメンションの返答が記録されない問題 / Fix: 震度分布画像が投稿されない問題 / Chg: 震度分布画像のメッセージを変更 / Fix: 条件に合わなくても震度分布画像を生成する問題 / Fix: 震度分布画像に隙間が空く問題
This commit is contained in:
@@ -154,7 +154,9 @@ function getEdge<T extends any[]>(arr: T, property: keyof T[number]) {
|
||||
export default async function generateImage(message: any) {
|
||||
if (
|
||||
message.earthquake.hypocenter === undefined ||
|
||||
message.points === undefined
|
||||
message.earthquake.hypocenter?.name === "" ||
|
||||
!(Array.isArray(message.points)) ||
|
||||
message.points.length === 0
|
||||
)
|
||||
return "input_lack";
|
||||
|
||||
@@ -289,34 +291,12 @@ export default async function generateImage(message: any) {
|
||||
|
||||
xSize = tileXCount.most - tileXCount.least + 1;
|
||||
ySize = tileYCount.most - tileYCount.least + 1;
|
||||
|
||||
if (xSize > ySize) {
|
||||
tileSize = Math.round(WIDTH / xSize);
|
||||
} else {
|
||||
tileSize = Math.round(HEIGHT / ySize);
|
||||
}
|
||||
|
||||
// 全画面
|
||||
if (WIDTH - xSize * tileSize > 10) {
|
||||
const requireTilesX = Math.ceil(WIDTH / tileSize);
|
||||
const halfTilesX = Math.ceil(requireTilesX / 2);
|
||||
|
||||
tileXCount = {
|
||||
least: tileXCount.least - halfTilesX,
|
||||
most: tileXCount.most + halfTilesX,
|
||||
}
|
||||
}
|
||||
|
||||
if (HEIGHT - ySize * tileSize > 10) {
|
||||
const requireTilesY = Math.ceil(HEIGHT / tileSize);
|
||||
const halfTilesY = Math.ceil(requireTilesY / 2);
|
||||
|
||||
tileYCount = {
|
||||
least: tileYCount.least - halfTilesY,
|
||||
most: tileYCount.most + halfTilesY,
|
||||
}
|
||||
}
|
||||
|
||||
// 震源を中心とする
|
||||
const epicenterPosition = positions.filter(position => position.type === "epicenter")[0];
|
||||
if (!epicenterPosition)
|
||||
@@ -362,13 +342,37 @@ export default async function generateImage(message: any) {
|
||||
// タイルサイズ再計算
|
||||
xSize = tileXCount.most - tileXCount.least + 1;
|
||||
ySize = tileYCount.most - tileYCount.least + 1;
|
||||
|
||||
if (xSize > ySize) {
|
||||
tileSize = Math.round(WIDTH / xSize);
|
||||
} else {
|
||||
tileSize = Math.round(HEIGHT / ySize);
|
||||
}
|
||||
|
||||
// 全画面
|
||||
if (WIDTH - xSize * tileSize > 5) {
|
||||
const requireTilesX = Math.ceil(WIDTH / tileSize);
|
||||
const halfTilesX = Math.ceil(requireTilesX / 2);
|
||||
|
||||
tileXCount = {
|
||||
least: tileXCount.least - halfTilesX,
|
||||
most: tileXCount.most + halfTilesX,
|
||||
}
|
||||
}
|
||||
|
||||
if (HEIGHT - ySize * tileSize > 5) {
|
||||
const requireTilesY = Math.ceil(HEIGHT / tileSize);
|
||||
const halfTilesY = Math.ceil(requireTilesY / 2);
|
||||
|
||||
tileYCount = {
|
||||
least: tileYCount.least - halfTilesY,
|
||||
most: tileYCount.most + halfTilesY,
|
||||
}
|
||||
}
|
||||
|
||||
// タイル幅再計算
|
||||
xSize = tileXCount.most - tileXCount.least + 1;
|
||||
ySize = tileYCount.most - tileYCount.least + 1;
|
||||
|
||||
// 欠けているタイルを取得
|
||||
for (let xIndex = 0; xIndex < xSize; xIndex++) {
|
||||
const itX = xIndex + tileXCount.least;
|
||||
|
||||
@@ -169,61 +169,56 @@ const processMessage = async (message: any) => {
|
||||
.join(EOL.repeat(2))
|
||||
.trim();
|
||||
|
||||
let earthquakeUniqid: string | null = null;
|
||||
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,
|
||||
}),
|
||||
}, "地震発生情報");
|
||||
|
||||
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") {}
|
||||
try {
|
||||
const image = await generateImage(message);
|
||||
|
||||
if (typeof image === "string") {
|
||||
throw "情報が不足しているため、地震の画像生成ができませんでした";
|
||||
} else {
|
||||
await createUeuse({
|
||||
text: "この地震の震度分布画像を生成しました。",
|
||||
text: i18next.t("earthquakeImageGenerated", {
|
||||
url: earthquakeUeuses[0]?.uniqid
|
||||
? `${config.uwuzu.origin}/!${earthquakeUeuses[0].uniqid}`
|
||||
: "不明",
|
||||
}),
|
||||
media: {
|
||||
photo: [
|
||||
result.toString("base64"),
|
||||
]
|
||||
image.toString("base64"),
|
||||
],
|
||||
},
|
||||
reuseid: (earthquakeUniqid as unknown as string),
|
||||
}, "震度分布画像");
|
||||
})(),
|
||||
]);
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 552:
|
||||
|
||||
Reference in New Issue
Block a user