ゆずねっと向け早急対処
This commit is contained in:
+28
-15
@@ -1,7 +1,10 @@
|
||||
import WebSocket from "ws";
|
||||
import { differenceInMinutes } from "date-fns";
|
||||
|
||||
import config from "../config.js";
|
||||
|
||||
let rateLimit: Date;
|
||||
|
||||
class P2PEarthquakeClient {
|
||||
private ws: WebSocket | null = null;
|
||||
private reconnectInterval: number = config.earthquake.reconnectTimes;
|
||||
@@ -178,9 +181,7 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
if (earthquakeInfo.areas !== null) {
|
||||
const areaNames: Array<string> = Array.from(
|
||||
new Set(
|
||||
earthquakeInfo.areas
|
||||
.map((point: any) => point.name)
|
||||
.filter(Boolean)
|
||||
earthquakeInfo.areas.map((point: any) => point.name).filter(Boolean),
|
||||
),
|
||||
);
|
||||
areas = `対象地域:${areaNames.join("・")}`;
|
||||
@@ -242,6 +243,10 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
// 最大震度
|
||||
let maxScale: string = "最大深度:";
|
||||
|
||||
if (earthquakeInfo.earthquake.maxScale < config.earthquake.maxScaleMax) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (
|
||||
earthquakeInfo.earthquake.maxScale === -1 ||
|
||||
earthquakeInfo.earthquake.maxScale === null
|
||||
@@ -273,9 +278,7 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
if (earthquakeInfo.points !== null) {
|
||||
const areaNames: Array<string> = Array.from(
|
||||
new Set(
|
||||
earthquakeInfo.points
|
||||
.map((point: any) => point.addr)
|
||||
.filter(Boolean)
|
||||
earthquakeInfo.points.map((point: any) => point.addr).filter(Boolean),
|
||||
),
|
||||
);
|
||||
areas = `対象地域:${areaNames.join("・")}`;
|
||||
@@ -301,25 +304,35 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
|
||||
// 地域情報更新の場合
|
||||
else if (earthquakeInfo.code === 555) {
|
||||
if (rateLimit === null) {
|
||||
rateLimit = new Date();
|
||||
}
|
||||
|
||||
// 対象地域マッピング
|
||||
const areaMaps: any = await areaMap();
|
||||
|
||||
const areaNames: Array<string> = Array.from(
|
||||
new Set(
|
||||
earthquakeInfo.areas.map((i: any) => {
|
||||
return areaMaps[i.id];
|
||||
}).filter(Boolean)
|
||||
earthquakeInfo.areas
|
||||
.map((i: any) => {
|
||||
return areaMaps[i.id];
|
||||
})
|
||||
.filter(Boolean),
|
||||
),
|
||||
);
|
||||
|
||||
const areas = areaNames.join("・");
|
||||
|
||||
ueuse(`
|
||||
==地震情報==
|
||||
【地域情報更新】
|
||||
時刻:${earthquakeInfo.time}
|
||||
対象地域:${areas}
|
||||
`);
|
||||
if (differenceInMinutes(new Date(), rateLimit) <= config.earthquake.rateLimit) {
|
||||
ueuse(`
|
||||
==地震情報==
|
||||
【地域情報更新】
|
||||
時刻:${earthquakeInfo.time}
|
||||
対象地域:${areas}
|
||||
`);
|
||||
|
||||
rateLimit = new Date();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user