Compare commits

..

5 Commits

6 changed files with 46 additions and 35 deletions
+13 -10
View File
@@ -2,25 +2,28 @@ import type { configTypes } from "types/config";
// READMEの設定項目を参照
const config: configTypes = {
// 時報設定
time: {
// 時報休止期間
stopTimes: {
start: new Date("23:00"),
stop: new Date("6:00"),
start: 23, // 開始
stop: 6, // 停止
}
},
// 地震速報設定
earthquake: {
reconnectTimes: 5000,
websocketUrl: "wss://api.p2pquake.net/v2/ws",
areasCsvUrl: "https://raw.githubusercontent.com/p2pquake/epsp-specifications/master/epsp-area.csv",
maxScaleMax: 30,
rateLimit: 30,
reconnectTimes: 5000, // 再接続時間(ミリ秒)
websocketUrl: "wss://api.p2pquake.net/v2/ws", // WebSocketのURL
areasCsvUrl: "https://raw.githubusercontent.com/p2pquake/epsp-specifications/master/epsp-area.csv", // 対象地域CSVファイルのURL
maxScaleMin: 30, // 地震発生の際の最低震度(10-70)
rateLimit: 30, // 地域情報更新のレート制限(分)
},
weather: {
splitCount: 4,
splitCount: 4, // 返信の分割数
},
apiToken: "TOKEN_EXAMPLE",
uwuzuServer: "uwuzu.example.com",
apiToken: "TOKEN_EXAMPLE", // BOTアカウントのAPIトークン
uwuzuServer: "uwuzu.example.com", // uwuzuのサーバー
};
export default config;
+1 -1
View File
@@ -26,4 +26,4 @@ cron.schedule("1 7 * * *", () => {
});
// コンソールで表示
console.log("サーバーが起動しました");
console.log("BOTサーバーが起動しました");
+5 -4
View File
@@ -1,6 +1,6 @@
{
"name": "noticeuwuzu",
"version": "v4.0@uwuzu1.5.4",
"version": "v4.2@uwuzu1.5.4",
"description": "uwuzu Notice Bot",
"main": "dist/main.js",
"scripts": {
@@ -12,16 +12,17 @@
"uwuzu",
"bot",
"cron",
"notice",
"weather",
"time",
"timenotice",
"notice"
"earthquake"
],
"author": {
"name": "Last2014",
"url": "https://last2014.com",
"email": "info@last2014.com"
},
"license": "ISC",
"license": "Apache-2.0",
"type": "module",
"dependencies": {
"@types/date-fns": "^2.5.3",
+12 -9
View File
@@ -1,9 +1,9 @@
import WebSocket from "ws";
import { differenceInMinutes } from "date-fns";
import { differenceInMinutes, subMinutes } from "date-fns";
import config from "../config.js";
let rateLimit: Date;
let rateLimit: Date | null = null;
class P2PEarthquakeClient {
private ws: WebSocket | null = null;
@@ -63,6 +63,8 @@ class P2PEarthquakeClient {
}
private handleMessage(message: any): void {
console.log("----------------");
switch (message.code) {
case 551: // 地震情報
console.log("地震情報を受信しました");
@@ -72,12 +74,12 @@ class P2PEarthquakeClient {
console.log("緊急地震速報を受信しました");
this.executeEventFunc(message);
break;
case 555: // 震度情報
console.log("震度情報を受信しました");
case 555: // 地域情報更新情報
console.log("地域情報更新情報を受信しました");
this.executeEventFunc(message);
break;
default:
console.log(`その他の情報 (コード: ${message.code})`);
console.log(`未対応の情報を受信しました(コード: ${message.code})`);
break;
}
}
@@ -144,7 +146,7 @@ async function areaMap(): Promise<Record<number, string>> {
// 情報受信
async function event(earthquakeInfo: any): Promise<void> {
console.log(JSON.stringify(earthquakeInfo));
console.log(`受信データ:${JSON.stringify(earthquakeInfo)}`);
// ----処理----
@@ -243,7 +245,8 @@ async function event(earthquakeInfo: any): Promise<void> {
// 最大震度
let maxScale: string = "最大深度:";
if (earthquakeInfo.earthquake.maxScale < config.earthquake.maxScaleMax) {
if (earthquakeInfo.earthquake.maxScale < config.earthquake.maxScaleMin) {
console.log("最低震度に満たしていないため投稿されませんでした");
return;
}
@@ -331,7 +334,7 @@ async function event(earthquakeInfo: any): Promise<void> {
// 地域情報更新の場合
else if (earthquakeInfo.code === 555) {
if (rateLimit === null) {
rateLimit = new Date();
rateLimit = subMinutes(new Date(), 15);
}
// 対象地域マッピング
@@ -349,7 +352,7 @@ async function event(earthquakeInfo: any): Promise<void> {
const areas = areaNames.join("・");
if (differenceInMinutes(rateLimit, new Date()) >= config.earthquake.rateLimit) {
if (Math.abs(differenceInMinutes(rateLimit, new Date())) >= config.earthquake.rateLimit) {
ueuse(`
==地震情報==
【地域情報更新】
+12 -8
View File
@@ -1,20 +1,24 @@
import { format, isAfter, isBefore } from "date-fns";
import { format } from "date-fns";
import type * as types from "types/types";
import config from "../config.js";
// 停止時間
// 時刻取得
const now = new Date();
const start = config.time.stopTimes.start;
const stop = config.time.stopTimes.stop;
// 停止時刻外
let inRange: Boolean = false;
// 現在の時間を取得
const nowHour = new Date().getHours();
if (isBefore(start, stop)) {
inRange = isAfter(now, start) && isBefore(now, stop);
// 停止時刻内かどうかの判定
let inRange: boolean = false;
if (start < stop) {
inRange = nowHour >= start && nowHour < stop;
} else {
inRange = isAfter(now, start) || isBefore(now, stop);
inRange = nowHour >= start || nowHour < stop;
}
@@ -27,7 +31,7 @@ export default async function timeNotice() {
method: "POST",
body: JSON.stringify({
token: config.apiToken,
text: `${now}になりました`,
text: `${format(new Date(), "HH:mm")}になりました`,
}),
},
);
+3 -3
View File
@@ -2,7 +2,7 @@ interface earthquakeTypes {
reconnectTimes: number;
websocketUrl: string;
areasCsvUrl: string;
maxScaleMax: number;
maxScaleMin: number;
rateLimit: number;
}
@@ -11,8 +11,8 @@ interface weatherTypes {
}
interface stopsTypes {
start: Date;
stop: Date;
start: number;
stop: number;
}
interface timeTypes {