dotenvを廃止しconfig.tsへ・天気の分割数をconfigで変更できるように・デバッグ用のサンプルログを.gitignoreに追加・地震情報解析の修正
This commit is contained in:
+22
-28
@@ -1,11 +1,10 @@
|
||||
import WebSocket from "ws";
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
dotenv.config();
|
||||
import config from "../config.js";
|
||||
|
||||
class P2PEarthquakeClient {
|
||||
private ws: WebSocket | null = null;
|
||||
private reconnectInterval: number = 5000;
|
||||
private reconnectInterval: number = config.earthquake.reconnectTimes;
|
||||
private reconnectTimer: NodeJS.Timeout | null = null;
|
||||
private isConnecting: boolean = false;
|
||||
|
||||
@@ -21,7 +20,7 @@ class P2PEarthquakeClient {
|
||||
console.log("P2P地震情報に接続中");
|
||||
|
||||
try {
|
||||
this.ws = new WebSocket("wss://api.p2pquake.net/v2/ws");
|
||||
this.ws = new WebSocket(config.earthquake.websocketUrl);
|
||||
|
||||
this.ws.on("open", () => {
|
||||
console.log("P2P地震情報に接続しました");
|
||||
@@ -119,9 +118,7 @@ class P2PEarthquakeClient {
|
||||
|
||||
// 地名オブジェクトマッピング
|
||||
async function areaMap(): Promise<Record<number, string>> {
|
||||
const res = await fetch(
|
||||
"https://raw.githubusercontent.com/p2pquake/epsp-specifications/master/epsp-area.csv",
|
||||
);
|
||||
const res = await fetch(config.earthquake.areasCsvUrl);
|
||||
|
||||
const text = await res.text();
|
||||
|
||||
@@ -244,42 +241,39 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
}
|
||||
|
||||
// 最大震度
|
||||
let maxScale;
|
||||
let maxScale: string = "最大深度:";
|
||||
|
||||
if (earthquakeInfo.earthquake.maxScale === -1) {
|
||||
if (
|
||||
earthquakeInfo.earthquake.maxScale === -1 ||
|
||||
earthquakeInfo.earthquake.maxScale === null
|
||||
) {
|
||||
maxScale = "最大震度情報なし";
|
||||
} else if (earthquakeInfo.earthquake.maxScale === 10) {
|
||||
maxScale = "震度1";
|
||||
maxScale += "震度1";
|
||||
} else if (earthquakeInfo.earthquake.maxScale === 20) {
|
||||
maxScale = "震度2";
|
||||
maxScale += "震度2";
|
||||
} else if (earthquakeInfo.earthquake.maxScale === 30) {
|
||||
maxScale = "震度3";
|
||||
maxScale += "震度3";
|
||||
} else if (earthquakeInfo.earthquake.maxScale === 40) {
|
||||
maxScale = "震度4";
|
||||
maxScale += "震度4";
|
||||
} else if (earthquakeInfo.earthquake.maxScale === 45) {
|
||||
maxScale = "震度5弱";
|
||||
maxScale += "震度5弱";
|
||||
} else if (earthquakeInfo.earthquake.maxScale === 50) {
|
||||
maxScale = "震度5強";
|
||||
maxScale += "震度5強";
|
||||
} else if (earthquakeInfo.earthquake.maxScale === 55) {
|
||||
maxScale = "震度6弱";
|
||||
maxScale += "震度6弱";
|
||||
} else if (earthquakeInfo.earthquake.maxScale === 60) {
|
||||
maxScale = "震度6強";
|
||||
maxScale += "震度6強";
|
||||
} else if (earthquakeInfo.earthquake.maxScale === 70) {
|
||||
maxScale = "震度7";
|
||||
maxScale += "震度7";
|
||||
}
|
||||
|
||||
// 対象地域
|
||||
let areas: string = "";
|
||||
|
||||
if (earthquakeInfo.points !== null) {
|
||||
const areaMaps: any = await areaMap();
|
||||
|
||||
const areaNames: Array<string> = Array.from(
|
||||
new Set(
|
||||
earthquakeInfo.points.map((i: any) => {
|
||||
areaMaps[i.addr].filter(Boolean);
|
||||
}),
|
||||
),
|
||||
new Set(earthquakeInfo.points.map((i: any) => i.addr).filter(Boolean)),
|
||||
);
|
||||
|
||||
areas = `対象地域:${areaNames.join("・")}`;
|
||||
@@ -297,7 +291,7 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
【地震発生】
|
||||
時刻:${earthquakeInfo.time}
|
||||
${description}
|
||||
最大深度:${maxScale}
|
||||
${maxScale}
|
||||
${areas}
|
||||
国内の津波:${domesticTsunami}
|
||||
`);
|
||||
@@ -328,10 +322,10 @@ async function event(earthquakeInfo: any): Promise<void> {
|
||||
}
|
||||
|
||||
async function ueuse(text: string) {
|
||||
const res = await fetch(`https://${process.env.SERVER}/api/ueuse/create`, {
|
||||
const res = await fetch(`https://${config.uwuzuServer}/api/ueuse/create`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: process.env.TOKEN,
|
||||
token: config.apiToken,
|
||||
text: text,
|
||||
}),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user