noticeUwuzu v6.0@uwuzu1.5.4
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
import WebSocket from "ws";
|
||||
import { differenceInMinutes, subMinutes } from "date-fns";
|
||||
import sendMail from "../src/mailer.js";
|
||||
|
||||
import config from "../config.js";
|
||||
|
||||
let rateLimit: Date | null = null;
|
||||
|
||||
class P2PEarthquakeClient {
|
||||
private ws: WebSocket | null = null;
|
||||
private reconnectInterval: number = config.earthquake.reconnectTimes;
|
||||
@@ -75,10 +72,6 @@ class P2PEarthquakeClient {
|
||||
console.log("緊急地震速報を受信しました");
|
||||
this.executeEventFunc(message);
|
||||
break;
|
||||
case 555: // 地域情報更新情報
|
||||
console.log("地域情報更新を受信しました");
|
||||
this.executeEventFunc(message);
|
||||
break;
|
||||
default:
|
||||
console.log(`未対応の情報を受信しました(コード: ${message.code})`);
|
||||
break;
|
||||
@@ -208,7 +201,7 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
let magnitude: string = "マグニチュード:";
|
||||
|
||||
if (
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude !== -1 ||
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude != -1 ||
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude === undefined
|
||||
) {
|
||||
magnitude += "マグニチュードの情報はありません";
|
||||
@@ -262,7 +255,7 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
}
|
||||
|
||||
if (
|
||||
earthquakeInfo.earthquake.maxScale === -1 &&
|
||||
earthquakeInfo.earthquake.maxScale == -1 &&
|
||||
earthquakeInfo.earthquake.maxScale === undefined
|
||||
) {
|
||||
maxScale = "最大震度情報なし";
|
||||
@@ -346,7 +339,7 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
if (
|
||||
earthquakeInfo.earthquake.hypocenter.depth !== null ||
|
||||
earthquakeInfo.earthquake.hypocenter.depth !== undefined ||
|
||||
earthquakeInfo.earthquake.hypocenter.depth !== -1
|
||||
earthquakeInfo.earthquake.hypocenter.depth != -1
|
||||
) {
|
||||
if (earthquakeInfo.earthquake.hypocenter.depth === 0) {
|
||||
depth = "深さ:ごく浅い";
|
||||
@@ -361,9 +354,9 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
if(
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude !== null ||
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude !== undefined ||
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude !== -1
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude != -1
|
||||
) {
|
||||
magnitude = `マグニチュード:${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`;
|
||||
magnitude = `マグニチュード:M${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`;
|
||||
}
|
||||
|
||||
ueuse(`
|
||||
@@ -378,49 +371,13 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
国内の津波:${domesticTsunami}
|
||||
`);
|
||||
}
|
||||
|
||||
// 地域情報更新の場合
|
||||
else if (earthquakeInfo.code === 555) {
|
||||
if (rateLimit === null) {
|
||||
rateLimit = subMinutes(new Date(), config.earthquake.rateLimit + 15);
|
||||
}
|
||||
|
||||
// 対象地域マッピング
|
||||
const areaMaps: any = await areaMap();
|
||||
|
||||
const areaNames: Array<string> = Array.from(
|
||||
new Set(
|
||||
earthquakeInfo.areas
|
||||
.map((i: any) => {
|
||||
return areaMaps[i.id];
|
||||
})
|
||||
.filter(Boolean),
|
||||
),
|
||||
);
|
||||
|
||||
const areas = areaNames.join("・");
|
||||
|
||||
if (Math.abs(differenceInMinutes(rateLimit, new Date())) >= config.earthquake.rateLimit) {
|
||||
ueuse(`
|
||||
==地震情報==
|
||||
【地域情報更新】
|
||||
時刻:${earthquakeInfo.time}
|
||||
対象地域:${areas}
|
||||
`);
|
||||
|
||||
rateLimit = new Date();
|
||||
} else {
|
||||
console.log("レート制限に満たしていないため投稿されませんでした");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function ueuse(text: string) {
|
||||
const res = await fetch(`https://${config.uwuzuServer}/api/ueuse/create`, {
|
||||
const res = await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.apiToken,
|
||||
token: config.uwuzu.apiToken,
|
||||
text: text,
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user