This commit is contained in:
2025-07-06 22:11:59 +09:00
parent 05194ad7b8
commit 22ec582e0a
11 changed files with 200 additions and 9 deletions
+35
View File
@@ -1,5 +1,6 @@
import WebSocket from "ws";
import { differenceInMinutes, subMinutes } from "date-fns";
import sendMail from "../src/mailer.js";
import config from "../config.js";
@@ -276,6 +277,38 @@ async function event(earthquakeInfo: any): Promise<void> {
maxScale += "震度7";
}
// 警告
if (
earthquakeInfo.earthquake.maxScale >= 60 ||
config.emergency.function
) {
console.log("----------------");
console.log("震度6強以上の地震を受信しました");
console.log("サーバーがダウンする可能性があります");
// メール送信
if (config.emergency.function) {
sendMail({
from: "noticeUwuzu自動送信",
to: config.emergency.mail.to,
subject: "【警告】震度6強以上の地震を受信しました",
html: `
※noticeUwuzu自動送信によるメールです。
【警告】
BOT管理者さん、noticeUwuzu自動送信メールです。
震度6強以上の地震を受信したため警告メールが送信されました。
物理、システム的にサーバーがダウンする可能性があります。
ご自身の身をお守りください。
`
});
console.log("管理者へ警告メールを送信しました");
}
console.log("----------------");
}
// 対象地域
let areas: string = "";
@@ -300,6 +333,7 @@ async function event(earthquakeInfo: any): Promise<void> {
if (
earthquakeInfo.earthquake.hypocenter.depth !== null ||
earthquakeInfo.earthquake.hypocenter.depth !== undefined ||
earthquakeInfo.earthquake.hypocenter.depth !== -1
) {
if (earthquakeInfo.earthquake.hypocenter.depth === 0) {
@@ -314,6 +348,7 @@ async function event(earthquakeInfo: any): Promise<void> {
if(
earthquakeInfo.earthquake.hypocenter.magnitude !== null ||
earthquakeInfo.earthquake.hypocenter.magnitude !== undefined ||
earthquakeInfo.earthquake.hypocenter.magnitude !== -1
) {
magnitude = `マグニチュード:${earthquakeInfo.earthquake.hypocenter.magnitude}`;
+1 -1
View File
@@ -16,7 +16,7 @@ export default async function followBack() {
const meData: types.meApi = await resMe.json();
console.log(`BOTプロフィール:${meData}`);
console.log(`BOTプロフィール:${JSON.stringify(meData)}`);
const followers: Array<string> = meData.follower;
+64
View File
@@ -0,0 +1,64 @@
import * as fs from "fs";
import { format, isAfter } from "date-fns";
import { parse } from "date-fns/fp";
import config from "../config.js";
import sendMail from "../src/mailer.js";
const formatParse = parse(new Date(), "yyyy-MM-dd HH:mm:ss.SSS")
// 初期化
if (fs.existsSync("iolog.json") === false) {
fs.writeFileSync("iolog.json", JSON.stringify({
start: format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS"),
stop: "",
}), "utf-8");
}
export default function successExit() {
const iolog = JSON.parse(fs.readFileSync("iolog.json", "utf-8"));
if (config.emergency.function) {
// 前回の終了確認
const start = formatParse(iolog.start);
const stop = formatParse(iolog.stop);
if (isAfter(start, stop)) {
console.log("前回の終了が適切でない可能性があります");
if (config.emergency.mail.function) {
sendMail({
from: "noticeUwuzu自動送信",
to: config.emergency.mail.to,
subject: "【警告】前回終了が不適切な可能性",
html: `
※noticeUwuzu自動送信によるメールです。
【警告】
BOT管理者さん、noticeUwuzu自動送信メールです。
BOTの前回終了で不適切なデータを検出しました。
これは適切な終了時にはデータを残しデータがない場合に送信されます。
電源を強制的に遮断するなどの行為による可能性があります。
その場合は今後やめ、OSからのシャットダウンを使用してください。
BOTのプログラムが破損していないかご確認ください。
`
});
}
console.log("----------------");
}
}
// 起動時に起動時刻を保存
iolog.start = format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
fs.writeFileSync("iolog.json", JSON.stringify(iolog), "utf-8");
// 終了時に終了時刻を保存
process.on("exit", () => {
const iolog = JSON.parse(fs.readFileSync("iolog.json", "utf-8"));
iolog.stop = format(new Date(), "yyyy-MM-dd HH:mm:ss.SSS");
fs.writeFileSync("iolog.json", JSON.stringify(iolog), "utf-8");
});
}
successExit();
+2 -2
View File
@@ -4,8 +4,6 @@ import type * as types from "types/types";
import config from "../config.js";
export default async function timeNotice() {
console.log("----------------");
// 停止時間
// 時刻取得
const start = config.time.stopTimes.start;
@@ -24,6 +22,7 @@ export default async function timeNotice() {
}
if (inRange) {
console.log("----------------");
console.log("時報休止期間のため投稿されませんでした");
return;
} else {
@@ -41,6 +40,7 @@ export default async function timeNotice() {
const ueuseData: types.ueuseCreateApi = await resUeuse.json();
console.log("----------------");
console.log(`時報投稿:${JSON.stringify(ueuseData)}`);
}
}