Compare commits
37 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 50db83cc8c | |||
| d7a5d8a43e | |||
| 1c10aeb9e4 | |||
| 081d1eca6e | |||
| 0e9c8f8225 | |||
| 724e18ba3b | |||
| 3955d91978 | |||
| d28ca6ce4c | |||
| ad0d975a12 | |||
| 7f07710d23 | |||
| 3b58e7ee2d | |||
| 22ec582e0a | |||
| 05194ad7b8 | |||
| ef374b1639 | |||
| 563d70aacd | |||
| 568ae7abf6 | |||
| c3ab3a8456 | |||
| 678f4aa1b1 | |||
| a96c3f0e4f | |||
| 53ba26f417 | |||
| 6b68b6e1b5 | |||
| e3451323f3 | |||
| 8be3684a78 | |||
| 600626d071 | |||
| 5c0c34bbb4 | |||
| 88bd2e88a5 | |||
| 7c7dfdcf3c | |||
| dd70fe5494 | |||
| 73091bb92f | |||
| 6c69ce80ef | |||
| 7e3c4840d3 | |||
| 007efd85a8 | |||
| 2689dfd777 | |||
| 909258f421 | |||
| de3c970712 | |||
| c5bd22600a | |||
| c4d2990118 |
@@ -1,2 +0,0 @@
|
||||
TOKEN=
|
||||
SERVER=
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/dist/
|
||||
/.env
|
||||
/.env.local
|
||||
/.env*
|
||||
/node_modules/
|
||||
/package-lock.json
|
||||
/config.ts
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
Copyright 2025 Last2014
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
@@ -4,9 +4,8 @@
|
||||
|
||||
uwuzuで動作するお知らせBOTです。
|
||||
|
||||
# .env形式
|
||||
|
||||
`.env.example`をご覧ください。
|
||||
# 設定
|
||||
examples/config.tsをプロジェクトルートへ移動し各設定を更新してください。
|
||||
|
||||
# サーバー起動
|
||||
|
||||
@@ -17,3 +16,6 @@ npm run start
|
||||
```
|
||||
|
||||
※Node.js・npmがインストールされている必要があります。
|
||||
|
||||
# ライセンス
|
||||
Apache 2.0 License
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
# # ###### ##### ### ###### ####### # # # # # # ###### # #
|
||||
## # # # # # # # # # # # # # # # # #
|
||||
# ## # # # # # # ####### # # # # # # # # ## # #
|
||||
# ## # # # # # # # # # # # # # # #
|
||||
# # ###### # ### ###### ####### ###### # # ###### ###### ######
|
||||
@@ -0,0 +1,29 @@
|
||||
import { styleText } from "util";
|
||||
import config from "../config.js";
|
||||
|
||||
export default async function APICheck() {
|
||||
try {
|
||||
const req = await fetch(`https://${config.uwuzu.host}/api/me/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
})
|
||||
});
|
||||
|
||||
const res = await req.json();
|
||||
|
||||
if (res.error_code !== undefined) {
|
||||
console.log(styleText("red", "APIトークンあるいはuwuzuサーバーホストが無効です"));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
if (res.isBot === false) {
|
||||
setTimeout(() => {
|
||||
console.log(styleText("yellow", "使用するアカウントでBOTフラグが設定されていません"));
|
||||
}, 1500);
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(styleText("red", `uwuzuサーバーへ接続できませんでした: ${err}`));
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import * as fs from "fs";
|
||||
import { styleText } from "util";
|
||||
|
||||
export default function ConfigCheck() {
|
||||
if (!fs.existsSync("config.ts")) {
|
||||
console.log(styleText("red", "config.tsがありません"));
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import PackagesIsExist from "./packagesExist.js";
|
||||
import PackagesCheck from "./packages.js";
|
||||
import ConfigCheck from "./config.js";
|
||||
import APICheck from "./api.js";
|
||||
import VersionCheck from "./version.js";
|
||||
|
||||
export default async function Check() {
|
||||
PackagesIsExist();
|
||||
PackagesCheck();
|
||||
ConfigCheck();
|
||||
await APICheck();
|
||||
await VersionCheck();
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import * as fs from "fs";
|
||||
import { styleText } from "util";
|
||||
|
||||
export default function PackagesCheck() {
|
||||
try {
|
||||
if (!fs.existsSync("package.json")) {
|
||||
console.log(styleText("red", "package.jsonがありません。正規のリポジトリでgit pullを実行してください。"));
|
||||
process.exit();
|
||||
}
|
||||
|
||||
// package.json取得
|
||||
const packages = JSON.parse(fs.readFileSync("package.json", "utf-8"));
|
||||
const dependencies = packages.dependencies;
|
||||
|
||||
const packageNames: Array<string> = [];
|
||||
|
||||
Object.keys(dependencies).forEach((packageName) => {
|
||||
let version: string;
|
||||
|
||||
if (dependencies[packageName].charAt(0) === "^") {
|
||||
version = dependencies[packageName].replace('^', '');
|
||||
} else {
|
||||
version = dependencies[packageName]
|
||||
}
|
||||
|
||||
dependencies[packageName] = version;
|
||||
packageNames.push(packageName);
|
||||
});
|
||||
|
||||
// パッケージのバージョン取得
|
||||
const mismatchPackages: Array<string> = [];
|
||||
|
||||
packageNames.forEach((packageName) => {
|
||||
const packagePath = `node_modules/${packageName}/package.json`;
|
||||
|
||||
if (fs.existsSync(packagePath)) {
|
||||
const modulePackage = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
|
||||
|
||||
if (modulePackage.version !== dependencies[packageName]) {
|
||||
mismatchPackages.push(packageName);
|
||||
}
|
||||
} else {
|
||||
console.log(styleText("red", `パッケージ「${packageName}」が見つかりません。`));
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
|
||||
if (mismatchPackages.length !== 0) {
|
||||
console.log(styleText("red", "以下のパッケージのバージョンが異なります:"));
|
||||
mismatchPackages.forEach((mismatch) => {
|
||||
console.log(styleText("red", mismatch));
|
||||
console.log(styleText("red", ` 要求バージョン: ${dependencies[mismatch]}`));
|
||||
});
|
||||
process.exit();
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("パッケージの存在確認でエラーが発生しました: ", err);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import * as fs from "fs";
|
||||
import { styleText } from "util";
|
||||
|
||||
export default function PackagesIsExist() {
|
||||
try {
|
||||
if (!fs.existsSync("node_modules/.package-lock.json")) {
|
||||
console.log(styleText("red", `
|
||||
node_modules/.package-lock.jsonがありません。
|
||||
プロジェクト直下でnpm installを実行してください。
|
||||
`));
|
||||
process.exit();
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("node_modules/.package-lock.jsonの存在確認でエラーが発生しました: ", err);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import * as fs from "fs";
|
||||
import config from "../config.js";
|
||||
|
||||
export default async function VersionCheck() {
|
||||
const nowVersion: string = JSON.parse(fs.readFileSync("package.json", "utf-8")).version;
|
||||
|
||||
// 初期化
|
||||
if (!fs.existsSync("logs/version.txt")) {
|
||||
fs.writeFileSync(
|
||||
"logs/version.txt",
|
||||
nowVersion,
|
||||
"utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
// 最終起動バージョン取得
|
||||
const oldVersion = fs.readFileSync("logs/version.txt", "utf-8");
|
||||
|
||||
if (oldVersion !== nowVersion) {
|
||||
try {
|
||||
fs.writeFileSync(
|
||||
"logs/version.txt",
|
||||
nowVersion,
|
||||
"utf-8",
|
||||
);
|
||||
|
||||
await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
text: `${nowVersion}にBOTがアップデートされました!`,
|
||||
}),
|
||||
});
|
||||
} catch (err) {
|
||||
console.log("アップデート通知にエラーが発生しました: ", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { configTypes } from "types/config";
|
||||
|
||||
// READMEの設定項目を参照
|
||||
const config: configTypes = {
|
||||
// 時報設定
|
||||
time: {
|
||||
// 時報休止期間
|
||||
stopTimes: {
|
||||
start: 23, // 開始
|
||||
stop: 6, // 停止
|
||||
},
|
||||
},
|
||||
// 地震速報設定
|
||||
earthquake: {
|
||||
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)
|
||||
},
|
||||
weather: {
|
||||
splitCount: 4, // 返信の分割数
|
||||
},
|
||||
|
||||
// 緊急時設定
|
||||
emergency: {
|
||||
function: true, // 緊急時のコンソール表示
|
||||
mail: {
|
||||
function: true, // 緊急時のメール送信
|
||||
host: "smtp.example.com", // SMTPサーバー
|
||||
port: 465, // SMTPポート
|
||||
user: "mailUser@example.com", // BOTメール送信元
|
||||
password: "mailPassword", // SMTPパスワード
|
||||
secure: false, // SMTPsecure設定
|
||||
to: "admin@noticeuwuzu.example.com", // 緊急時メール送信先(配列可)
|
||||
},
|
||||
},
|
||||
uwuzu: {
|
||||
apiToken: "TOKEN_EXAMPLE",
|
||||
clientToken: "TOKEN_EXAMPLE",
|
||||
host: "uwuzu.example.com",
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
@@ -1,19 +1,41 @@
|
||||
// 起動チェック
|
||||
import Check from "./checks/main.js";
|
||||
(async () => {
|
||||
await Check();
|
||||
})();
|
||||
|
||||
// 定期実行読み込み
|
||||
import * as cron from "node-cron";
|
||||
|
||||
// 機能読み込み
|
||||
import timeNotice from "./scripts/timeNotice.js";
|
||||
import weatherNotice from "./scripts/weatherNotice.js";
|
||||
import earthquakeNotice from "./scripts/earthquakeNotice.js";
|
||||
|
||||
import followBack from "./scripts/followBack.js";
|
||||
// アスキーアート読み込み
|
||||
import asciiArt from "./scripts/asciiart.js";
|
||||
asciiArt();
|
||||
|
||||
// 時報・フォローバック(毎時)
|
||||
// フォロー機能読み込み
|
||||
import follows from "./scripts/follow/main.js";
|
||||
|
||||
// 正常終了確認読み込み
|
||||
import successExit from "./scripts/successExit.js";
|
||||
successExit();
|
||||
|
||||
// 地震情報観測開始
|
||||
earthquakeNotice();
|
||||
|
||||
/*// 時報・フォローバック(毎時)
|
||||
cron.schedule("0 * * * *", () => {
|
||||
timeNotice();
|
||||
followBack();
|
||||
follows();
|
||||
});
|
||||
|
||||
// 天気お知らせ(毎日7:00)
|
||||
cron.schedule("0 7 * * *", () => {
|
||||
// 天気お知らせ(毎日7:01)
|
||||
cron.schedule("10 0 7 * * *", () => {
|
||||
weatherNotice();
|
||||
});
|
||||
});*/
|
||||
|
||||
console.log("サーバーが起動しました");
|
||||
// 起動表示
|
||||
console.log("BOTサーバーが起動しました");
|
||||
|
||||
+18
-9
@@ -1,36 +1,45 @@
|
||||
{
|
||||
"name": "noticeuwuzu",
|
||||
"version": "v2.0@uwuzu1.5.4",
|
||||
"description": "uwuzu Notice Bot",
|
||||
"name": "notice-uwuzu",
|
||||
"version": "v6.5(LTS)@uwuzu1.5.4",
|
||||
"description": "Notice Bot for uwuzu",
|
||||
"main": "dist/main.js",
|
||||
"scripts": {
|
||||
"start": "node .",
|
||||
"build": "tsc",
|
||||
"main": "tsc && node .",
|
||||
"dev": "tsx main.ts"
|
||||
},
|
||||
"keywords": [
|
||||
"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",
|
||||
"@types/dotenv": "^6.1.1",
|
||||
"@types/node-cron": "^3.0.11",
|
||||
"@types/nodemailer": "^6.4.17",
|
||||
"@types/node": "^24.0.7",
|
||||
"@types/ws": "^8.18.1",
|
||||
"date-fns": "^4.1.0",
|
||||
"dotenv": "^17.0.0",
|
||||
"fs": "^0.0.1-security",
|
||||
"node-cron": "^4.1.1",
|
||||
"tsx": "^4.20.3",
|
||||
"typescript": "^5.8.3"
|
||||
"nodemailer": "^7.0.4",
|
||||
"typescript": "^5.8.3",
|
||||
"ws": "^8.18.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsx": "^4.20.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import * as fs from "fs";
|
||||
|
||||
const version = JSON.parse(fs.readFileSync("package.json", "utf-8")).version;
|
||||
|
||||
export default function asciiArt() {
|
||||
console.log(fs.readFileSync("asciiart.txt", "utf-8").replace(/(\r?\n)$/, ''));
|
||||
console.log(`${version}\n`);
|
||||
}
|
||||
@@ -0,0 +1,497 @@
|
||||
import WebSocket from "ws";
|
||||
import sendMail from "../src/mailer.js";
|
||||
|
||||
import config from "../config.js";
|
||||
import { max } from "date-fns/fp";
|
||||
|
||||
class P2PEarthquakeClient {
|
||||
private ws: WebSocket | null = null;
|
||||
private reconnectInterval: number = config.earthquake.reconnectTimes;
|
||||
private reconnectTimer: NodeJS.Timeout | null = null;
|
||||
private isConnecting: boolean = false;
|
||||
|
||||
public start(): void {
|
||||
this.connect();
|
||||
this.setupCleanup();
|
||||
}
|
||||
|
||||
private connect(): void {
|
||||
if (this.isConnecting) return;
|
||||
|
||||
this.isConnecting = true;
|
||||
console.log("地震情報サーバーに接続中");
|
||||
|
||||
try {
|
||||
this.ws = new WebSocket(config.earthquake.websocketUrl);
|
||||
|
||||
this.ws.on("open", () => {
|
||||
console.log("地震情報サーバーに接続しました");
|
||||
this.isConnecting = false;
|
||||
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer);
|
||||
this.reconnectTimer = null;
|
||||
}
|
||||
});
|
||||
|
||||
this.ws.on("message", (data: WebSocket) => {
|
||||
try {
|
||||
const message = JSON.parse(data.toString());
|
||||
this.handleMessage(message);
|
||||
} catch (err) {
|
||||
console.error(`メッセージのパースでエラーが発生: ${err}`);
|
||||
}
|
||||
});
|
||||
|
||||
this.ws.on("close", (code: number, reason: Buffer) => {
|
||||
console.log(`切断されました: ${code} - ${reason.toString()}`);
|
||||
this.isConnecting = false;
|
||||
this.scheduleReconnect();
|
||||
});
|
||||
|
||||
this.ws.on("error", (error: Error) => {
|
||||
console.error("WebSocketエラー:", error);
|
||||
this.isConnecting = false;
|
||||
this.scheduleReconnect();
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("接続エラー:", error);
|
||||
this.isConnecting = false;
|
||||
this.scheduleReconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private handleMessage(message: any): void {
|
||||
console.log("----------------");
|
||||
|
||||
const supportCode: Array<number> = [
|
||||
551,
|
||||
552,
|
||||
556,
|
||||
];
|
||||
|
||||
if (supportCode.indexOf(message.code) !== -1) {
|
||||
event(message);
|
||||
} else {
|
||||
console.log(`未対応の情報を受信しました(コード: ${message.code})`);
|
||||
console.log(`受信メッセージ:${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
private scheduleReconnect(): void {
|
||||
if (this.reconnectTimer) return;
|
||||
|
||||
console.log("地震情報サーバーから切断されました");
|
||||
console.log(`${this.reconnectInterval / 1000}秒後に再接続を試みます`);
|
||||
|
||||
this.reconnectTimer = setTimeout(() => {
|
||||
this.reconnectTimer = null;
|
||||
this.connect();
|
||||
}, this.reconnectInterval);
|
||||
}
|
||||
|
||||
private setupCleanup(): void {
|
||||
const cleanup = () => {
|
||||
this.stop();
|
||||
process.exit();
|
||||
};
|
||||
|
||||
process.on("SIGINT", cleanup);
|
||||
process.on("SIGTERM", cleanup);
|
||||
}
|
||||
|
||||
public stop(): void {
|
||||
if (this.reconnectTimer) {
|
||||
clearTimeout(this.reconnectTimer);
|
||||
this.reconnectTimer = null;
|
||||
}
|
||||
|
||||
if (this.ws) {
|
||||
this.ws.close();
|
||||
this.ws = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 地名マッピング
|
||||
async function areaMap(): Promise<Record<number, string>> {
|
||||
const res = await fetch(config.earthquake.areasCsvUrl);
|
||||
|
||||
const text = await res.text();
|
||||
|
||||
const lines = text.split("\n");
|
||||
const map: Record<number, string> = {};
|
||||
|
||||
for (const line of lines) {
|
||||
const cols = line.split(",");
|
||||
|
||||
if (cols.length >= 3 && /^\d+$/.test(cols[0])) {
|
||||
const id = Number(cols[0]);
|
||||
const name = cols[2].trim();
|
||||
|
||||
map[id] = name;
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
// 情報受信
|
||||
async function event(earthquakeInfo: any): Promise<void> {
|
||||
console.log(`受信メッセージ:${earthquakeInfo}`);
|
||||
// ----処理----
|
||||
|
||||
// 緊急地震速報の場合
|
||||
if (earthquakeInfo.code === 556) {
|
||||
console.log("緊急地震速報を受信しました");
|
||||
|
||||
// 地震詳細
|
||||
let descriptionEarthquake: string = "";
|
||||
|
||||
if (
|
||||
earthquakeInfo.earthquake.description !== "" ||
|
||||
earthquakeInfo.earthquake.description !== undefined
|
||||
) {
|
||||
descriptionEarthquake = `この地震について:${earthquakeInfo.earthquake.description}`;
|
||||
}
|
||||
|
||||
// 発令詳細
|
||||
let description: string = "";
|
||||
|
||||
if (
|
||||
earthquakeInfo.comments.freeFormComment !== "" ||
|
||||
earthquakeInfo.comments.freeFormComment !== undefined
|
||||
) {
|
||||
description = `この発令について:${earthquakeInfo.comments.freeFormComment}`;
|
||||
}
|
||||
|
||||
// テスト・訓練
|
||||
let test: string = "";
|
||||
|
||||
if (earthquakeInfo.test !== undefined) {
|
||||
test = "この情報にテスト・訓練かの情報はありません";
|
||||
} else if (earthquakeInfo.test) {
|
||||
test = "これはテスト、あるいは訓練です";
|
||||
} else if (earthquakeInfo.test === false) {
|
||||
test = "これはテスト・訓練ではありません";
|
||||
}
|
||||
|
||||
// 対象地域
|
||||
let areas: string = "";
|
||||
|
||||
if (earthquakeInfo.areas !== undefined) {
|
||||
const areaNames: Array<string> = Array.from(
|
||||
new Set(
|
||||
earthquakeInfo.areas.map((point: any) => point.name).filter(Boolean),
|
||||
),
|
||||
);
|
||||
areas = `対象地域:${areaNames.join("・")}`;
|
||||
}
|
||||
|
||||
// 速報取り消し
|
||||
let cancelled: string = "";
|
||||
|
||||
if (earthquakeInfo.cancelled) {
|
||||
cancelled = "※以下の緊急地震速報が取り消されました※";
|
||||
}
|
||||
|
||||
// マグニチュード
|
||||
let magnitude: string = "マグニチュード:";
|
||||
|
||||
if (
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude != -1 ||
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude === undefined
|
||||
) {
|
||||
magnitude += "マグニチュードの情報はありません";
|
||||
} else {
|
||||
magnitude += `M${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`;
|
||||
}
|
||||
|
||||
ueuse(`
|
||||
==地震情報==
|
||||
【緊急地震速報】
|
||||
${cancelled}
|
||||
時刻:${earthquakeInfo.time}
|
||||
${descriptionEarthquake}
|
||||
${description}
|
||||
${test}
|
||||
${areas}
|
||||
`);
|
||||
}
|
||||
|
||||
// 地震情報
|
||||
else if (earthquakeInfo.code === 551) {
|
||||
console.log("地震発生情報を受信しました");
|
||||
|
||||
if (
|
||||
earthquakeInfo.earthquake.maxScale !== undefined &&
|
||||
earthquakeInfo.earthquake.maxScale < config.earthquake.maxScaleMin
|
||||
) {
|
||||
console.log("最低震度に満たしていないため投稿されませんでした");
|
||||
return;
|
||||
}
|
||||
|
||||
// 国内津波
|
||||
let domesticTsunami;
|
||||
|
||||
const TsunamiMessages = {
|
||||
"None": "この地震による国内の津波の心配はありません",
|
||||
"Unknown": "この地震による国内の津波情報はありません",
|
||||
"Checking": "この地震による国内の津波情報を調査中です",
|
||||
"NonEffective": "この地震による国内の津波影響は若干の海面変動が予想されますが被害の心配はありません",
|
||||
"Watch": "この地震により国内で津波注意報が発令しています",
|
||||
"Warning": "この地震による国内の津波予報があります",
|
||||
} as { [key: string]: string };
|
||||
|
||||
if (earthquakeInfo.earthquake.domesticTsunami === undefined) {
|
||||
domesticTsunami = "この地震による国内の津波情報はありません";
|
||||
} else {
|
||||
domesticTsunami = TsunamiMessages[earthquakeInfo.earthquake.domesticTsunami];
|
||||
}
|
||||
|
||||
// 最大震度
|
||||
let maxScale: string = "最大深度:";
|
||||
|
||||
const maxScales = {
|
||||
10: "震度1",
|
||||
20: "震度2",
|
||||
30: "震度3",
|
||||
40: "震度4",
|
||||
45: "震度5弱",
|
||||
50: "震度5強",
|
||||
55: "震度6弱",
|
||||
60: "震度6強",
|
||||
70: "震度7",
|
||||
} as { [key: number]: string };
|
||||
|
||||
if (
|
||||
earthquakeInfo.earthquake.maxScale == -1 ||
|
||||
earthquakeInfo.earthquake.maxScale === undefined
|
||||
) {
|
||||
maxScale = "最大震度:不明";
|
||||
} else {
|
||||
maxScale = `最大震度:${maxScales[earthquakeInfo.earthquake.maxScale]}`;
|
||||
}
|
||||
|
||||
// 警告
|
||||
if (
|
||||
earthquakeInfo.earthquake.maxScale !== undefined &&
|
||||
earthquakeInfo.earthquake.maxScale >= 60 &&
|
||||
config.emergency.function
|
||||
) {
|
||||
console.log("----------------");
|
||||
|
||||
console.log("震度6強以上の地震を受信しました");
|
||||
console.log("サーバーがダウンする可能性があります");
|
||||
|
||||
// メール送信
|
||||
if (config.emergency.function) {
|
||||
sendMail({
|
||||
to: config.emergency.mail.to,
|
||||
subject: "【警告】震度6強以上の地震を受信しました",
|
||||
text: `
|
||||
※noticeUwuzu自動送信によるメールです
|
||||
【警告】
|
||||
BOT管理者さん、noticeUwuzu自動送信メールです。
|
||||
震度6強以上の地震を受信したため警告メールが送信されました。
|
||||
物理、システム的にサーバーがダウンする可能性があります。
|
||||
ご自身の身をお守りください。
|
||||
`
|
||||
});
|
||||
|
||||
console.log("管理者へ警告メールを送信しました");
|
||||
}
|
||||
|
||||
console.log("----------------");
|
||||
}
|
||||
|
||||
// 対象地域
|
||||
let areas;
|
||||
|
||||
if (earthquakeInfo.points !== undefined) {
|
||||
const areaNames: Array<string> = Array.from(
|
||||
new Set(
|
||||
earthquakeInfo.points.map((point: any) => point.addr).filter(Boolean),
|
||||
),
|
||||
);
|
||||
areas = `対象地域:${areaNames.join("・")}`;
|
||||
}
|
||||
|
||||
// 詳細
|
||||
let description;
|
||||
|
||||
if (
|
||||
earthquakeInfo.comments.freeFormComment !== "" &&
|
||||
earthquakeInfo.comments.freeFormComment !== undefined
|
||||
) {
|
||||
description = `この地震について:${earthquakeInfo.comments.freeFormComment}`;
|
||||
}
|
||||
|
||||
// 深さ
|
||||
let depth;
|
||||
|
||||
if (
|
||||
earthquakeInfo.earthquake.hypocenter.depth !== null ||
|
||||
earthquakeInfo.earthquake.hypocenter.depth !== undefined
|
||||
) {
|
||||
if (earthquakeInfo.earthquake.hypocenter.depth === 0) {
|
||||
depth = "深さ:ごく浅い";
|
||||
} else if (earthquakeInfo.earthquake.hypocenter.depth === -1) {
|
||||
depth = "深さ:不明";
|
||||
} else {
|
||||
depth = `深さ:${String(earthquakeInfo.earthquake.hypocenter.depth)}km`;
|
||||
}
|
||||
}
|
||||
|
||||
// マグニチュード
|
||||
let magnitude;
|
||||
|
||||
if(
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude !== null ||
|
||||
earthquakeInfo.earthquake.hypocenter.magnitude !== undefined
|
||||
) {
|
||||
if (earthquakeInfo.earthquake.hypocenter.magnitude === -1) {
|
||||
depth = "マグニチュード:不明";
|
||||
} else {
|
||||
magnitude = `マグニチュード:M${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`;
|
||||
}
|
||||
}
|
||||
|
||||
ueuse(`
|
||||
==地震情報==
|
||||
【地震発生】
|
||||
時刻:${earthquakeInfo.time}
|
||||
${description}
|
||||
${magnitude}
|
||||
${depth}
|
||||
${maxScale}
|
||||
${areas}
|
||||
国内の津波:${domesticTsunami}
|
||||
`);
|
||||
} else if (earthquakeInfo.code === 552) {
|
||||
console.log("津波予報情報を受信しました");
|
||||
|
||||
// 予報取り消し
|
||||
if (earthquakeInfo.cancelled) {
|
||||
ueuse(`
|
||||
==地震情報==
|
||||
【津波予報】
|
||||
※津波予報が取り消されました※
|
||||
時刻:${earthquakeInfo.time}
|
||||
`);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let result: string = `
|
||||
==地震情報==
|
||||
【津波予報】
|
||||
時刻:${earthquakeInfo.time}
|
||||
\n
|
||||
`;
|
||||
|
||||
for (let i = 0; i < earthquakeInfo.areas.length; i++) {
|
||||
const data = earthquakeInfo.areas[i];
|
||||
|
||||
// 種類
|
||||
const gradeMessages = {
|
||||
"MajorWarning": "大津波警報",
|
||||
"Warning": "津波警報",
|
||||
"Watch": "津波注意報",
|
||||
"Unknown": "不明",
|
||||
} as { [key: string]: string };
|
||||
|
||||
let grade;
|
||||
|
||||
if (data.grade === undefined) {
|
||||
grade = "予報種類:不明";
|
||||
} else {
|
||||
grade = `予報種類:${gradeMessages[data.grade]}`;
|
||||
}
|
||||
|
||||
// 直後襲来
|
||||
let immediate;
|
||||
|
||||
if (data.immediate === undefined) {
|
||||
immediate = "津波の襲来が直後かの情報がありません";
|
||||
} else if (data.immediate) {
|
||||
immediate = "### 津波が直ちに襲来します";
|
||||
} else if (!data.immediate) {
|
||||
immediate = "津波は直ちには襲来しません";
|
||||
}
|
||||
|
||||
// 第1波
|
||||
let firstHeight;
|
||||
|
||||
if (data.firstHeight === undefined) {
|
||||
firstHeight = "第1波の情報がありません";
|
||||
} else if (
|
||||
data.firstHeight.arrivalTime === undefined &&
|
||||
data.firstHeight.condition === undefined
|
||||
) {
|
||||
firstHeight = "第1波の情報がありません";
|
||||
} else {
|
||||
let arrivalTime;
|
||||
|
||||
if (data.arrivalTime === undefined) {
|
||||
arrivalTime = "不明";
|
||||
} else {
|
||||
arrivalTime = data.arrivalTime;
|
||||
}
|
||||
|
||||
let condition;
|
||||
|
||||
if (data.condition === undefined) {
|
||||
condition = "不明";
|
||||
} else {
|
||||
condition = data.condition;
|
||||
}
|
||||
|
||||
firstHeight = `
|
||||
第1波到達予想時刻:${arrivalTime}
|
||||
第1波の状態:${condition}
|
||||
`
|
||||
}
|
||||
|
||||
// 予想高さ
|
||||
let maxHeight;
|
||||
|
||||
if (data.maxHeight.description === undefined) {
|
||||
maxHeight = "津波の高さ(予想):不明";
|
||||
} else {
|
||||
maxHeight = `津波の高さ(予想):${data.maxHeight.description}`;
|
||||
}
|
||||
|
||||
result = `
|
||||
【${data.name}】
|
||||
${grade}
|
||||
${immediate}
|
||||
${firstHeight}
|
||||
${maxHeight}\n\n
|
||||
`;
|
||||
}
|
||||
|
||||
ueuse(result);
|
||||
}
|
||||
}
|
||||
|
||||
async function ueuse(text: string) {
|
||||
console.log(text);
|
||||
/*const res = await fetch(`https://${config.uwuzu.host}/api/ueuse/create/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
text: text,
|
||||
}),
|
||||
});
|
||||
|
||||
const resData = await res.json();
|
||||
|
||||
console.log(`地震情報投稿:${JSON.stringify(resData)}`);*/
|
||||
}
|
||||
|
||||
export default function earthquakeNotice(): void {
|
||||
console.log("地震情報サーバーに接続します");
|
||||
const client = new P2PEarthquakeClient();
|
||||
client.start();
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type * as types from "types/types";
|
||||
|
||||
import config from "../../config.js";
|
||||
|
||||
export default async function followBack() {
|
||||
console.log("----------------");
|
||||
|
||||
// フォロワーを取得
|
||||
const resMe = await fetch(
|
||||
`https://${config.uwuzu.host}/api/me/`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const meData: types.meApi = await resMe.json();
|
||||
|
||||
const followers = meData.follower;
|
||||
|
||||
// フォロー
|
||||
for (let i = 0; i < followers.length; i++) {
|
||||
const followerItem = followers[i];
|
||||
|
||||
setTimeout(async () => {
|
||||
const resFollow = await fetch(
|
||||
`https://${config.uwuzu.host}/api/users/follow/`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
userid: followerItem,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const followData: types.followApi = await resFollow.json();
|
||||
|
||||
console.log(`フォロー:${JSON.stringify(followData)}`);
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import followBack from "./follow.js";
|
||||
import unFollowBack from "./unfollow.js";
|
||||
|
||||
export default function follows() {
|
||||
unFollowBack();
|
||||
followBack();
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import config from "../../config.js";
|
||||
import { meApi } from "types/types.js";
|
||||
|
||||
export default async function unFollowBack() {
|
||||
const profile: meApi = await
|
||||
(await fetch(`https://${config.uwuzu.host}/api/me/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
})
|
||||
})).json();
|
||||
|
||||
for (let i = 0; i < profile.followee.length; i++) {
|
||||
const followUser = profile.followee[i];
|
||||
|
||||
if (
|
||||
profile.follower.indexOf(followUser) === -1
|
||||
) {
|
||||
setTimeout(async () => {
|
||||
const req = await fetch(`https://${config.uwuzu.host}/api/users/unfollow/`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
userId: followUser,
|
||||
}),
|
||||
});
|
||||
|
||||
const res = await req.text();
|
||||
|
||||
console.log(`フォロー解除: ${res}`)
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import * as dotenv from "dotenv";
|
||||
|
||||
import type * as types from "../types";
|
||||
|
||||
dotenv.config();
|
||||
|
||||
export default async function followBack() {
|
||||
// uwuzu.netで/api/meのPOSTが死んでいるため簡易的にGET
|
||||
const resMe = await fetch(
|
||||
`https://${process.env.SERVER}/api/me?token=${process.env.TOKEN}`,
|
||||
{
|
||||
method: "GET",
|
||||
},
|
||||
);
|
||||
|
||||
const meData: types.meApi = await resMe.json();
|
||||
|
||||
console.log(meData);
|
||||
|
||||
const followers: Array<string> = meData.follower;
|
||||
|
||||
for (let i = 0; i < followers.length; i++) {
|
||||
const followerItem = followers[i];
|
||||
|
||||
const resFollow = await fetch(
|
||||
`https://${process.env.SERVER}/api/users/follow`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: process.env.TOKEN,
|
||||
userid: followerItem,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const followData: types.followApi = await resFollow.json();
|
||||
|
||||
console.log(JSON.stringify(followData));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import * as fs from "fs";
|
||||
import { isBefore } from "date-fns/fp";
|
||||
|
||||
import config from "../config.js";
|
||||
import sendMail from "../src/mailer.js";
|
||||
|
||||
export default function successExit() {
|
||||
// 初期化
|
||||
if (!fs.existsSync("logs/boot.json")) {
|
||||
fs.writeFileSync("logs/boot.json", JSON.stringify({
|
||||
start: new Date(),
|
||||
stop: "",
|
||||
}), "utf-8");
|
||||
}
|
||||
|
||||
const iolog = JSON.parse(fs.readFileSync("logs/boot.json", "utf-8"));
|
||||
|
||||
if (config.emergency.function) {
|
||||
// 前回の終了確認
|
||||
const start = iolog.start;
|
||||
const stop = iolog.stop;
|
||||
|
||||
if (isBefore(start, stop)) {
|
||||
console.log("前回の終了が適切でない可能性があります");
|
||||
|
||||
if (config.emergency.mail.function) {
|
||||
sendMail({
|
||||
to: config.emergency.mail.to,
|
||||
subject: "【警告】前回終了が不適切な可能性",
|
||||
text: `
|
||||
※noticeUwuzu自動送信によるメールです。
|
||||
【警告】
|
||||
BOT管理者さん、noticeUwuzu自動送信メールです。
|
||||
BOTの前回終了で不適切なデータを検出しました。
|
||||
これは適切な終了時にはデータを残しデータがない場合に送信されます。
|
||||
電源を強制的に遮断するなどの行為による可能性があります。
|
||||
その場合は今後やめ、OSからのシャットダウンを使用してください。
|
||||
BOTのプログラムが破損していないかご確認ください。
|
||||
`
|
||||
});
|
||||
}
|
||||
|
||||
console.log("----------------");
|
||||
}
|
||||
}
|
||||
|
||||
// 起動時に起動時刻を保存
|
||||
iolog.start = new Date();
|
||||
fs.writeFileSync("logs/boot.json", JSON.stringify(iolog), "utf-8");
|
||||
|
||||
// 終了時に終了時刻を保存
|
||||
process.on("exit", () => {
|
||||
const iolog = JSON.parse(fs.readFileSync("logs/boot.json", "utf-8"));
|
||||
iolog.stop = new Date();
|
||||
|
||||
fs.writeFileSync("logs/boot.json", JSON.stringify(iolog), "utf-8");
|
||||
});
|
||||
}
|
||||
|
||||
successExit();
|
||||
+30
-9
@@ -1,25 +1,46 @@
|
||||
import * as dotenv from "dotenv";
|
||||
import { format } from "date-fns";
|
||||
|
||||
import type * as types from "../types";
|
||||
|
||||
dotenv.config();
|
||||
import type * as types from "types/types";
|
||||
import config from "../config.js";
|
||||
|
||||
export default async function timeNotice() {
|
||||
const now = format(new Date(), "HH:mm");
|
||||
// 停止時間
|
||||
// 時刻取得
|
||||
const start = config.time.stopTimes.start;
|
||||
const stop = config.time.stopTimes.stop;
|
||||
|
||||
// 現在の時間を取得
|
||||
const nowHour = new Date().getHours();
|
||||
|
||||
// 停止時刻内かどうかの判定
|
||||
let inRange: boolean = false;
|
||||
|
||||
if (start < stop) {
|
||||
inRange = nowHour >= start && nowHour < stop;
|
||||
} else {
|
||||
inRange = nowHour >= start || nowHour < stop;
|
||||
}
|
||||
|
||||
if (inRange) {
|
||||
console.log("----------------");
|
||||
console.log("時報休止期間のため投稿されませんでした");
|
||||
return;
|
||||
} else {
|
||||
// 投稿
|
||||
const resUeuse = await fetch(
|
||||
`https://${process.env.SERVER}/api/ueuse/create`,
|
||||
`https://${config.uwuzu.host}/api/ueuse/create`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: process.env.TOKEN,
|
||||
text: `${now}になりました`,
|
||||
token: config.uwuzu.apiToken,
|
||||
text: `${format(new Date(), "HH:mm")}になりました`,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const ueuseData: types.ueuseCreateApi = await resUeuse.json();
|
||||
|
||||
console.log(JSON.stringify(ueuseData));
|
||||
console.log("----------------");
|
||||
console.log(`時報投稿:${JSON.stringify(ueuseData)}`);
|
||||
}
|
||||
}
|
||||
|
||||
+102
-31
@@ -1,44 +1,22 @@
|
||||
import * as dotenv from "dotenv";
|
||||
import { cityList } from "../src/weatherId.js";
|
||||
|
||||
import type * as types from "../types";
|
||||
import type * as types from "types/types.js";
|
||||
|
||||
dotenv.config();
|
||||
import config from "../config.js";
|
||||
|
||||
export default async function weatherNotice() {
|
||||
let weatherResults: string = "";
|
||||
console.log("----------------");
|
||||
|
||||
for (const [cityId, cityName] of Object.entries(cityList)) {
|
||||
const res = await fetch(
|
||||
`https://weather.tsukumijima.net/api/forecast/city/${cityId}`,
|
||||
);
|
||||
const data = await res.json();
|
||||
|
||||
const today = data.forecasts[0];
|
||||
const weather = today.telop ?? "取得できませんでした";
|
||||
const maxTemp = today.temperature.max?.celsius ?? "取得できませんでした";
|
||||
const minTemp = today.temperature.min?.celsius ?? "取得できませんでした";
|
||||
const chanceOfRain = data.chanceOfRain?.["T06_12"] ?? "取得できませんでした";
|
||||
|
||||
weatherResults = weatherResults +
|
||||
`【${cityName}】\n
|
||||
天気:${weather}\n
|
||||
最高気温:${maxTemp}℃\n
|
||||
最低気温:${minTemp}℃\n
|
||||
降水確率:${chanceOfRain}
|
||||
`;
|
||||
}
|
||||
|
||||
// 返信用ユーズ
|
||||
// 仮投稿
|
||||
const resUeuse = await fetch(
|
||||
`https://${process.env.SERVER}/api/ueuse/create`,
|
||||
`https://${config.uwuzu.host}/api/ueuse/create`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: process.env.TOKEN,
|
||||
token: config.uwuzu.apiToken,
|
||||
text: `
|
||||
# 本日の天気\n
|
||||
${weatherResults}
|
||||
本日の天気
|
||||
※タイムラインが埋まるため返信に記載しています
|
||||
`,
|
||||
}),
|
||||
},
|
||||
@@ -46,5 +24,98 @@ export default async function weatherNotice() {
|
||||
|
||||
const ueuseData: types.ueuseCreateApi = await resUeuse.json();
|
||||
|
||||
console.log(JSON.stringify(ueuseData));
|
||||
console.log(`天気仮投稿:${JSON.stringify(ueuseData)}`);
|
||||
|
||||
|
||||
// インデックス
|
||||
const splitCount = config.weather.splitCount;
|
||||
const total = cityList.length;
|
||||
const chunkSizes = Array(splitCount).fill(0).map((_, i) =>
|
||||
Math.floor((total + i) / splitCount)
|
||||
);
|
||||
|
||||
// 分割インデックス
|
||||
let start = 0;
|
||||
const ranges = chunkSizes.map(size => {
|
||||
const range = [start, start + size];
|
||||
start += size;
|
||||
return range;
|
||||
});
|
||||
|
||||
// 配列作成
|
||||
const weatherResults = Array(splitCount).fill("");
|
||||
|
||||
// 天気取得
|
||||
for (let chunkIndex = 0; chunkIndex < splitCount; chunkIndex++) {
|
||||
const [chunkStart, chunkEnd] = ranges[chunkIndex];
|
||||
|
||||
for (let i = chunkStart; i < chunkEnd; i++) {
|
||||
const res = await fetch(
|
||||
`https://weather.tsukumijima.net/api/forecast/city/${cityList[i]}`,
|
||||
);
|
||||
|
||||
const data = await res.json();
|
||||
const today = data.forecasts[0];
|
||||
|
||||
// 天気
|
||||
const weather = today.telop ?? "取得できませんでした";
|
||||
|
||||
// 最高気温
|
||||
let maxTemp: string;
|
||||
|
||||
if (today.temperature.max.celsius !== null) {
|
||||
maxTemp = `${today.temperature.max.celsius}℃`;
|
||||
} else {
|
||||
maxTemp = "取得できませんでした";
|
||||
}
|
||||
|
||||
// 最低気温
|
||||
let minTemp: string;
|
||||
|
||||
if (today.temperature.min.celsius !== null) {
|
||||
minTemp = `${today.temperature.min.celsius}℃`;
|
||||
} else {
|
||||
minTemp = "取得できませんでした";
|
||||
}
|
||||
|
||||
// 降水確率
|
||||
let chanceOfRain: string;
|
||||
|
||||
if (
|
||||
today.chanceOfRain.T06_12 !== null ||
|
||||
today.chanceOfRain.T06_12 !== "--%"
|
||||
) {
|
||||
chanceOfRain = today.chanceOfRain.T06_12;
|
||||
} else {
|
||||
chanceOfRain = "取得できませんでした";
|
||||
}
|
||||
|
||||
weatherResults[chunkIndex] += `
|
||||
【${data.location.city}】
|
||||
天気:${weather}
|
||||
最高気温:${maxTemp}
|
||||
最低気温:${minTemp}
|
||||
降水確率:${chanceOfRain}
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
// 分割投稿
|
||||
for (let i = 0; i < splitCount; i++) {
|
||||
const resReply = await fetch(
|
||||
`https://${config.uwuzu.host}/api/ueuse/create`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
token: config.uwuzu.apiToken,
|
||||
text: weatherResults[i],
|
||||
replyid: ueuseData.uniqid
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const replyData: types.ueuseCreateApi = await resReply.json();
|
||||
|
||||
console.log(`天気投稿:${JSON.stringify(replyData)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import config from "../config.js";
|
||||
import * as nodemailer from "nodemailer";
|
||||
|
||||
import type SMTPTransport from "nodemailer/lib/smtp-transport";
|
||||
|
||||
export interface EmailMessage {
|
||||
to: string | string[];
|
||||
subject: string;
|
||||
text?: string;
|
||||
html?: string;
|
||||
}
|
||||
|
||||
async function createTransporter() {
|
||||
const transporter = nodemailer.createTransport({
|
||||
host: config.emergency.mail.host,
|
||||
port: config.emergency.mail.port,
|
||||
secure: config.emergency.mail.secure,
|
||||
auth: {
|
||||
user: config.emergency.mail.user,
|
||||
pass: config.emergency.mail.password,
|
||||
},
|
||||
} as SMTPTransport.Options);
|
||||
|
||||
// 接続テスト
|
||||
try {
|
||||
await transporter.verify();
|
||||
console.log("SMTPサーバーに接続できました");
|
||||
} catch (error) {
|
||||
console.error("SMTP接続テストに失敗:", error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
return transporter;
|
||||
}
|
||||
|
||||
export default async function sendMail(message: EmailMessage): Promise<void> {
|
||||
try {
|
||||
const transporter = await createTransporter();
|
||||
|
||||
await transporter.sendMail({
|
||||
from: config.emergency.mail.user,
|
||||
to: Array.isArray(message.to) ? message.to.join(",") : message.to,
|
||||
subject: message.subject,
|
||||
text: message.text,
|
||||
html: message.html,
|
||||
});
|
||||
console.log("メール送信成功");
|
||||
} catch (error) {
|
||||
console.error("メール送信に失敗しました:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
+49
-49
@@ -1,49 +1,49 @@
|
||||
export const cityList: { [cityId: string]: string } = {
|
||||
"016010": "札幌",
|
||||
"020010": "青森",
|
||||
"030010": "盛岡",
|
||||
"040010": "仙台",
|
||||
"050010": "秋田",
|
||||
"060010": "山形",
|
||||
"070010": "福島",
|
||||
"080010": "水戸",
|
||||
"090010": "宇都宮",
|
||||
"100010": "前橋",
|
||||
"110010": "さいたま",
|
||||
"120010": "千葉",
|
||||
"130010": "東京",
|
||||
"140010": "横浜",
|
||||
"150010": "新潟",
|
||||
"160010": "富山",
|
||||
"170010": "金沢",
|
||||
"180010": "福井",
|
||||
"190010": "甲府",
|
||||
"200010": "長野",
|
||||
"210010": "岐阜",
|
||||
"220010": "静岡",
|
||||
"230010": "名古屋",
|
||||
"240010": "津",
|
||||
"250010": "大津",
|
||||
"260010": "京都",
|
||||
"270000": "大阪",
|
||||
"280010": "神戸",
|
||||
"290010": "奈良",
|
||||
"300010": "和歌山",
|
||||
"310010": "鳥取",
|
||||
"320010": "松江",
|
||||
"330010": "岡山",
|
||||
"340010": "広島",
|
||||
"350010": "山口",
|
||||
"360010": "徳島",
|
||||
"370000": "高松",
|
||||
"380010": "松山",
|
||||
"390010": "高知",
|
||||
"400010": "福岡",
|
||||
"410010": "佐賀",
|
||||
"420010": "長崎",
|
||||
"430010": "熊本",
|
||||
"440010": "大分",
|
||||
"450010": "宮崎",
|
||||
"460010": "鹿児島",
|
||||
"471010": "那覇",
|
||||
};
|
||||
export const cityList: Array<String> = [
|
||||
"016010",
|
||||
"020010",
|
||||
"030010",
|
||||
"040010",
|
||||
"050010",
|
||||
"060010",
|
||||
"070010",
|
||||
"080010",
|
||||
"090010",
|
||||
"100010",
|
||||
"110010",
|
||||
"120010",
|
||||
"130010",
|
||||
"140010",
|
||||
"150010",
|
||||
"160010",
|
||||
"170010",
|
||||
"180010",
|
||||
"190010",
|
||||
"200010",
|
||||
"210010",
|
||||
"220010",
|
||||
"230010",
|
||||
"240010",
|
||||
"250010",
|
||||
"260010",
|
||||
"270000",
|
||||
"280010",
|
||||
"290010",
|
||||
"300010",
|
||||
"310010",
|
||||
"320010",
|
||||
"330010",
|
||||
"340010",
|
||||
"350010",
|
||||
"360010",
|
||||
"370000",
|
||||
"380010",
|
||||
"390010",
|
||||
"400010",
|
||||
"410010",
|
||||
"420010",
|
||||
"430010",
|
||||
"440010",
|
||||
"450010",
|
||||
"460010",
|
||||
"471010",
|
||||
];
|
||||
|
||||
+20
-110
@@ -1,113 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
||||
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "libReplacement": true, /* Enable lib replacement. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "ES2022" /* Specify what module code is generated. */,
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
||||
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
||||
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
||||
// "resolveJsonModule": true, /* Enable importing .json files. */
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
|
||||
/* Interop Constraints */
|
||||
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
||||
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
||||
// "erasableSyntaxOnly": true, /* Do not allow runtime constructs that are not part of ECMAScript. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
||||
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
"target": "ES2024",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"outDir": "./dist",
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"baseUrl": "./",
|
||||
"typeRoots": [
|
||||
"./node_modules/@types",
|
||||
"./types"
|
||||
],
|
||||
"paths": {
|
||||
"ws": ["./node_modules/ws/index.js"],
|
||||
"@types/ws": ["./node_modules/@types/ws/index.d.ts"]
|
||||
},
|
||||
"removeComments": true,
|
||||
},
|
||||
}
|
||||
|
||||
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
interface earthquakeTypes {
|
||||
reconnectTimes: number;
|
||||
websocketUrl: string;
|
||||
areasCsvUrl: string;
|
||||
maxScaleMin: number;
|
||||
}
|
||||
|
||||
interface weatherTypes {
|
||||
splitCount: number;
|
||||
}
|
||||
|
||||
interface stopsTypes {
|
||||
start: number;
|
||||
stop: number;
|
||||
}
|
||||
|
||||
interface timeTypes {
|
||||
stopTimes: stopsTypes;
|
||||
}
|
||||
|
||||
interface emergencyMailTypes {
|
||||
function: Boolean;
|
||||
host: string | undefined;
|
||||
port: number;
|
||||
user: string;
|
||||
password: string;
|
||||
secure: Boolean;
|
||||
to: string;
|
||||
}
|
||||
|
||||
interface emergencyTypes {
|
||||
function: Boolean;
|
||||
mail: emergencyMailTypes;
|
||||
}
|
||||
|
||||
interface uwuzuTypes {
|
||||
apiToken: string;
|
||||
clientToken?: string;
|
||||
host: string;
|
||||
}
|
||||
|
||||
export interface configTypes {
|
||||
time: timeTypes,
|
||||
earthquake: earthquakeTypes;
|
||||
weather: weatherTypes;
|
||||
|
||||
emergency: emergencyTypes;
|
||||
uwuzu: uwuzuTypes;
|
||||
}
|
||||
Vendored
+2
-2
@@ -12,9 +12,9 @@ export interface meApi {
|
||||
user_icon: string;
|
||||
user_header: string;
|
||||
registered_date: string;
|
||||
followee: Array;
|
||||
followee: Array<string>;
|
||||
followee_cnt: number;
|
||||
follower: Array;
|
||||
follower: Array<string>;
|
||||
follower_cnt: number;
|
||||
ueuse_cnt: number;
|
||||
isBot: Boolean;
|
||||
Vendored
+68
@@ -0,0 +1,68 @@
|
||||
declare module 'ws' {
|
||||
import { EventEmitter } from 'events';
|
||||
import { IncomingMessage } from 'http';
|
||||
import { Socket } from 'net';
|
||||
|
||||
export type Data = string | Buffer | ArrayBuffer | Buffer[];
|
||||
|
||||
export interface WebSocketEventMap {
|
||||
close: CloseEvent;
|
||||
error: ErrorEvent;
|
||||
message: MessageEvent;
|
||||
open: Event;
|
||||
}
|
||||
|
||||
export default class WebSocket extends EventEmitter {
|
||||
static readonly CONNECTING: 0;
|
||||
static readonly OPEN: 1;
|
||||
static readonly CLOSING: 2;
|
||||
static readonly CLOSED: 3;
|
||||
|
||||
readonly CONNECTING: 0;
|
||||
readonly OPEN: 1;
|
||||
readonly CLOSING: 2;
|
||||
readonly CLOSED: 3;
|
||||
|
||||
readonly readyState: 0 | 1 | 2 | 3;
|
||||
readonly url: string;
|
||||
readonly protocol: string;
|
||||
|
||||
constructor(address: string | URL, protocols?: string | string[]);
|
||||
|
||||
close(code?: number, reason?: string): void;
|
||||
send(data: Data): void;
|
||||
ping(data?: Data): void;
|
||||
pong(data?: Data): void;
|
||||
terminate(): void;
|
||||
|
||||
on(event: 'close', listener: (code: number, reason: Buffer) => void): this;
|
||||
on(event: 'error', listener: (error: Error) => void): this;
|
||||
on(event: 'message', listener: (data: Data) => void): this;
|
||||
on(event: 'open', listener: () => void): this;
|
||||
on(event: string | symbol, listener: (...args: any[]) => void): this;
|
||||
|
||||
addEventListener(type: 'close', listener: (event: CloseEvent) => void): void;
|
||||
addEventListener(type: 'error', listener: (event: ErrorEvent) => void): void;
|
||||
addEventListener(type: 'message', listener: (event: MessageEvent) => void): void;
|
||||
addEventListener(type: 'open', listener: (event: Event) => void): void;
|
||||
}
|
||||
|
||||
export interface CloseEvent {
|
||||
code: number;
|
||||
reason: string;
|
||||
wasClean: boolean;
|
||||
}
|
||||
|
||||
export interface ErrorEvent {
|
||||
error: Error;
|
||||
message: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export namespace WebSocket {
|
||||
export const CONNECTING: 0;
|
||||
export const OPEN: 1;
|
||||
export const CLOSING: 2;
|
||||
export const CLOSED: 3;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user