Compare commits

...

4 Commits

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