ゆずねっと向け早急対処
This commit is contained in:
parent
88bd2e88a5
commit
5c0c34bbb4
|
@ -6,6 +6,8 @@ const config: configTypes = {
|
|||
reconnectTimes: 5000,
|
||||
websocketUrl: "wss://api.p2pquake.net/v2/ws",
|
||||
areasCsvUrl: "https://raw.githubusercontent.com/p2pquake/epsp-specifications/master/epsp-area.csv",
|
||||
maxScaleMax: 30,
|
||||
rateLimit: 10,
|
||||
},
|
||||
weather: {
|
||||
splitCount: 4,
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@ interface earthquakeTypes {
|
|||
reconnectTimes: number;
|
||||
websocketUrl: string;
|
||||
areasCsvUrl: string;
|
||||
maxScaleMax: number;
|
||||
rateLimit: number;
|
||||
}
|
||||
|
||||
interface weatherTypes {
|
||||
|
|
Loading…
Reference in New Issue