Compare commits

...

4 Commits

6 changed files with 40 additions and 28 deletions
+1 -2
View File
@@ -4,5 +4,4 @@
/package-lock.json
/config.ts
log*
/iolog.json
*log*
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "noticeuwuzu",
"version": "v5.0@uwuzu1.5.4",
"version": "v5.1@uwuzu1.5.4",
"description": "uwuzu Notice Bot",
"main": "dist/main.js",
"scripts": {
+4 -1
View File
@@ -1,5 +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"));
console.log(fs.readFileSync("asciiart.txt", "utf-8").replace(/(\r?\n)$/, ''));
console.log(`${version}\n`);
}
+31 -19
View File
@@ -157,32 +157,38 @@ async function event(earthquakeInfo: any): Promise<void> {
// 地震詳細
let descriptionEarthquake: string = "";
if (earthquakeInfo.earthquake.description !== "") {
if (
earthquakeInfo.earthquake.description !== "" ||
earthquakeInfo.earthquake.description !== undefined
) {
descriptionEarthquake = `この地震について:${earthquakeInfo.earthquake.description}`;
}
// 発令詳細
let description: string = "";
if (earthquakeInfo.comments.freeFormComment !== "") {
if (
earthquakeInfo.comments.freeFormComment !== "" ||
earthquakeInfo.comments.freeFormComment !== undefined
) {
description = `この発令について:${earthquakeInfo.comments.freeFormComment}`;
}
// テスト・訓練
let test: string = "";
if (earthquakeInfo.test) {
if (earthquakeInfo.test !== undefined) {
test = "この情報にテスト・訓練かの情報はありません";
} else if (earthquakeInfo.test) {
test = "これはテスト、あるいは訓練です";
} else if (earthquakeInfo.test === false) {
test = "これはテスト・訓練ではありません";
} else {
test = "この情報にテスト・訓練かの情報はありません";
}
// 対象地域
let areas: string = "";
if (earthquakeInfo.areas !== null) {
if (earthquakeInfo.areas !== undefined) {
const areaNames: Array<string> = Array.from(
new Set(
earthquakeInfo.areas.map((point: any) => point.name).filter(Boolean),
@@ -203,7 +209,7 @@ async function event(earthquakeInfo: any): Promise<void> {
if (
earthquakeInfo.earthquake.hypocenter.magnitude !== -1 ||
earthquakeInfo.earthquake.hypocenter.magnitude === null
earthquakeInfo.earthquake.hypocenter.magnitude === undefined
) {
magnitude += "マグニチュードの情報はありません";
} else {
@@ -227,7 +233,9 @@ async function event(earthquakeInfo: any): Promise<void> {
// 国内津波
let domesticTsunami;
if (earthquakeInfo.earthquake.domesticTsunami === "None") {
if (earthquakeInfo.earthquake.domesticTsunami === undefined) {
domesticTsunami = "この地震による国内の津波情報はありません";
} else if (earthquakeInfo.earthquake.domesticTsunami === "None") {
domesticTsunami = "この地震による国内の津波の心配はありません";
} else if (earthquakeInfo.earthquake.domesticTsunami === "Unknown") {
domesticTsunami = "この地震による国内の津波情報はありません";
@@ -240,21 +248,22 @@ async function event(earthquakeInfo: any): Promise<void> {
domesticTsunami = "この地震により国内で津波注意報が発令しています";
} else if (earthquakeInfo.earthquake.domesticTsunami === "Warning") {
domesticTsunami = "この地震による国内の津波予報があります";
} else {
domesticTsunami = "この地震による国内の津波情報はありません";
}
// 最大震度
let maxScale: string = "最大深度:";
if (earthquakeInfo.earthquake.maxScale < config.earthquake.maxScaleMin) {
if (
earthquakeInfo.earthquake.maxScale !== undefined &&
earthquakeInfo.earthquake.maxScale < config.earthquake.maxScaleMin
) {
console.log("最低震度に満たしていないため投稿されませんでした");
return;
}
if (
earthquakeInfo.earthquake.maxScale === -1 ||
earthquakeInfo.earthquake.maxScale === null
earthquakeInfo.earthquake.maxScale === -1 &&
earthquakeInfo.earthquake.maxScale === undefined
) {
maxScale = "最大震度情報なし";
} else if (earthquakeInfo.earthquake.maxScale === 10) {
@@ -279,7 +288,8 @@ async function event(earthquakeInfo: any): Promise<void> {
// 警告
if (
earthquakeInfo.earthquake.maxScale >= 60 ||
earthquakeInfo.earthquake.maxScale !== undefined &&
earthquakeInfo.earthquake.maxScale >= 60 &&
config.emergency.function
) {
console.log("----------------");
@@ -290,11 +300,10 @@ async function event(earthquakeInfo: any): Promise<void> {
// メール送信
if (config.emergency.function) {
sendMail({
from: "noticeUwuzu自動送信",
to: config.emergency.mail.to,
subject: "【警告】震度6強以上の地震を受信しました",
html: `
※noticeUwuzu自動送信によるメールです
text: `
※noticeUwuzu自動送信によるメールです
【警告】
BOT管理者さん、noticeUwuzu自動送信メールです。
震度6強以上の地震を受信したため警告メールが送信されました。
@@ -312,7 +321,7 @@ async function event(earthquakeInfo: any): Promise<void> {
// 対象地域
let areas: string = "";
if (earthquakeInfo.points !== null) {
if (earthquakeInfo.points !== undefined) {
const areaNames: Array<string> = Array.from(
new Set(
earthquakeInfo.points.map((point: any) => point.addr).filter(Boolean),
@@ -324,7 +333,10 @@ async function event(earthquakeInfo: any): Promise<void> {
// 詳細
let description: string = "";
if (earthquakeInfo.comments.freeFormComment !== "") {
if (
earthquakeInfo.comments.freeFormComment !== "" &&
earthquakeInfo.comments.freeFormComment !== undefined
) {
description = `この地震について:${earthquakeInfo.comments.freeFormComment}`;
}
+1 -2
View File
@@ -28,10 +28,9 @@ export default function successExit() {
if (config.emergency.mail.function) {
sendMail({
from: "noticeUwuzu自動送信",
to: config.emergency.mail.to,
subject: "【警告】前回終了が不適切な可能性",
html: `
text: `
※noticeUwuzu自動送信によるメールです。
【警告】
BOT管理者さん、noticeUwuzu自動送信メールです。
+2 -3
View File
@@ -1,10 +1,9 @@
import config from "../config";
import config from "../config.js";
import * as nodemailer from "nodemailer";
import type SMTPTransport from "nodemailer/lib/smtp-transport";
export interface EmailMessage {
from: string;
to: string | string[];
subject: string;
text?: string;
@@ -39,7 +38,7 @@ export default async function sendMail(message: EmailMessage): Promise<void> {
const transporter = await createTransporter();
await transporter.sendMail({
from: message.from,
from: config.emergency.mail.user,
to: Array.isArray(message.to) ? message.to.join(",") : message.to,
subject: message.subject,
text: message.text,