v7.2@uwuzu1.5.4をリリース

This commit is contained in:
Last2014 2025-08-02 19:39:50 +09:00
parent f6f7030d8c
commit 718e97ed45
14 changed files with 215 additions and 47 deletions

View File

@ -12,6 +12,13 @@ Automatic notification bot for uwuzu
- Earthquake occurs - Earthquake occurs
- Tsunami forecast - Tsunami forecast
- Weather notification - Weather notification
- Commands that users can use freely
- About BOT
- Command Help
- Report to the operator
- Follow back
- Unfollow
- Weather Repost
- Startup requirements check - Startup requirements check
- Check package existence - Check package existence
- Required package version check - Required package version check

View File

@ -1,35 +1,41 @@
import * as fs from "fs";
import config from "../config.js"; import config from "../config.js";
import { readFileSync, writeFileSync, existsSync } from "fs";
export default async function VersionCheck() { export default async function VersionCheck() {
const nowVersion: string = JSON.parse(fs.readFileSync("package.json", "utf-8")).version; const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
// 初期化 // 初期化
if (!fs.existsSync("logs/version.txt")) { if (!existsSync("logs/version.txt")) {
fs.writeFileSync( writeFileSync(
"logs/version.txt", "logs/version.txt",
nowVersion, packageJson.version,
"utf-8", "utf-8",
); );
} }
// 最終起動バージョン取得 // 最終起動バージョン取得
const oldVersion = fs.readFileSync("logs/version.txt", "utf-8"); const oldVersion = readFileSync("logs/version.txt", "utf-8");
if (oldVersion !== nowVersion) { if (oldVersion !== packageJson.version) {
try { try {
fs.writeFileSync( writeFileSync(
"logs/version.txt", "logs/version.txt",
nowVersion, packageJson.version,
"utf-8", "utf-8",
); );
const releaseUrl = `${packageJson.repository.url}/releases/tag/${packageJson.tag}`;
await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, { await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
token: config.uwuzu.apiToken, token: config.uwuzu.apiToken,
text: `${nowVersion}にBOTがアップデートされました`, text: `
${packageJson.version}BOTがアップデートされました
${releaseUrl}
`,
}), }),
cache: "no-store",
}); });
} catch (err) { } catch (err) {
console.log("アップデート通知にエラーが発生しました: ", err); console.log("アップデート通知にエラーが発生しました: ", err);

View File

@ -24,6 +24,7 @@ const config: configTypes = {
// 緊急時設定 // 緊急時設定
emergency: { emergency: {
function: true, // 緊急時のコンソール表示 function: true, // 緊急時のコンソール表示
report: false, // reportコマンド
mail: { mail: {
function: true, // 緊急時のメール送信 function: true, // 緊急時のメール送信
host: "smtp.example.com", // SMTPサーバー host: "smtp.example.com", // SMTPサーバー

View File

@ -1,6 +1,7 @@
{ {
"name": "notice-uwuzu", "name": "notice-uwuzu",
"version": "v7.1.1(LTS)@uwuzu1.5.4", "version": "v7.2@uwuzu1.5.4",
"tag": "v7.2",
"description": "Notice Bot for uwuzu", "description": "Notice Bot for uwuzu",
"main": "dist/main.js", "main": "dist/main.js",
"scripts": { "scripts": {
@ -10,6 +11,10 @@
"dev": "tsx main.ts", "dev": "tsx main.ts",
"clean": "tsc && node dist/scripts/clean/main.js" "clean": "tsc && node dist/scripts/clean/main.js"
}, },
"repository": {
"type": "git",
"url": "https://gitea.last2014.com/last2014/noticeUwuzu"
},
"keywords": [ "keywords": [
"uwuzu", "uwuzu",
"bot", "bot",

View File

@ -1,5 +1,6 @@
import { ueuse } from "types/types.js"; import { ueuse } from "types/types.js";
import config from "../../config.js"; import config from "../../config.js";
import { Reply } from "./main.js";
export default async function Follow(data: ueuse) { export default async function Follow(data: ueuse) {
const followReq = await fetch(`https://${config.uwuzu.host}/api/users/follow`, { const followReq = await fetch(`https://${config.uwuzu.host}/api/users/follow`, {
@ -8,6 +9,7 @@ export default async function Follow(data: ueuse) {
token: config.uwuzu.apiToken, token: config.uwuzu.apiToken,
userid: data.account.userid, userid: data.account.userid,
}), }),
cache: "no-store",
}); });
const followRes = await followReq.json(); const followRes = await followReq.json();
@ -15,18 +17,9 @@ export default async function Follow(data: ueuse) {
console.log("フォロー: ", followRes); console.log("フォロー: ", followRes);
const noticeReq = await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, { const notice = await Reply(`
method: "POST", ${data.account.username}
body: JSON.stringify({ `, data.uniqid);
token: config.uwuzu.apiToken,
text: `
${data.account.username}
`,
replyid: data.uniqid,
}),
});
const noticeRes = await noticeReq.json(); console.log("フォロー通知: ", notice);
console.log("フォロー通知: ", noticeRes);
} }

28
scripts/commands/help.ts Normal file
View File

@ -0,0 +1,28 @@
import { ueuse } from "types/types.js";
import { readFileSync } from "fs";
import { Reply } from "./main.js";
const helps = {
"info": "このBOTについての概要を返信するコマンドです。",
"help": "このコマンドです。コマンドの概要を返信します。",
"follow": "コマンド送信者をフォローします。",
"unfollow": "コマンド送信者をフォロー解除します。",
"weather": "天気を返信します。7:00に投稿されるものとは異なり再取得します。",
} as { [key: string]: string };
export default async function Help(data: ueuse) {
const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
const helpMsg =
Object.entries(helps)
.map(([command, message]) =>
`\`/${command}\`${message}`
).join('\n');
const ueuse = await Reply(`
${helpMsg}
${packageJson.repository.url}/wiki
`, data.uniqid);
console.log("ヘルプ:", ueuse);
}

26
scripts/commands/info.ts Normal file
View File

@ -0,0 +1,26 @@
import { ueuse } from "types/types.js";
import { readFileSync } from "fs";
import { Reply } from "./main.js";
export default async function Info(data: ueuse) {
const packageJson = JSON.parse(readFileSync("package.json", "utf-8"));
const releaseUrl = `${packageJson.repository.url}/releases/tag/${packageJson.tag}`;
let editor = "";
if (packageJson.author.name !== "Last2014") {
editor = `\nEdited by ${packageJson.author.name}`;
}
const ueuse = await Reply(`
${packageJson.version}
${releaseUrl}
\`/help\`をご利用ください。
Created by Last2014${editor}
`, data.uniqid);
console.log("概要:", ueuse);
}

View File

@ -5,9 +5,12 @@ import type { ueuse } from "types/types.js";
const initialFile: Array<string> = []; const initialFile: Array<string> = [];
// コマンド読み込み // コマンド読み込み
import Info from "./info.js";
import Follow from "./follow.js"; import Follow from "./follow.js";
import UnFollow from "./unfollow.js"; import UnFollow from "./unfollow.js";
import Weather from "./weather.js"; import Weather from "./weather.js";
import Help from "./help.js";
import Report from "./report.js";
// 初期化 // 初期化
if (!fs.existsSync("logs/alreadyCommands.json")) { if (!fs.existsSync("logs/alreadyCommands.json")) {
@ -31,7 +34,7 @@ function cutAfterChar(str: string, char: string) {
return str.substring(index + 1); return str.substring(index + 1);
} }
async function Reply(text: string, reply: string) { export async function Reply(text: string, reply: string) {
const req = await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, { const req = await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
method: "POST", method: "POST",
body: JSON.stringify({ body: JSON.stringify({
@ -39,6 +42,7 @@ async function Reply(text: string, reply: string) {
text: text, text: text,
replyid: reply, replyid: reply,
}), }),
cache: "no-store",
}); });
const res = await req.json(); const res = await req.json();
@ -63,6 +67,7 @@ export default async function Commands() {
body: JSON.stringify({ body: JSON.stringify({
token: config.uwuzu.apiToken, token: config.uwuzu.apiToken,
}), }),
cache: "no-store",
} }
); );
@ -79,7 +84,11 @@ export default async function Commands() {
break; break;
} }
if (data.text.charAt(0) === "!") { if (
data.text.charAt(0) === "!" ||
data.text.charAt(0) === "" ||
data.abi === "ignore"
) {
break; break;
} }
@ -89,6 +98,21 @@ export default async function Commands() {
const commandName = cutAfterChar(data.text, "/"); const commandName = cutAfterChar(data.text, "/");
switch (commandName) { switch (commandName) {
case "":
alreadyAdd(data.uniqid);
break;
case "info":
alreadyAdd(data.uniqid);
Info(data);
break;
case "help":
alreadyAdd(data.uniqid);
Help(data);
break;
case "report":
alreadyAdd(data.uniqid);
Report(data);
break;
case "follow": case "follow":
alreadyAdd(data.uniqid); alreadyAdd(data.uniqid);
Follow(data); Follow(data);

View File

@ -0,0 +1,69 @@
import { ueuse } from "types/types.js";
import { Reply } from "./main.js";
import config from "config.js";
import sendMail from "../../src/mailer.js";
export default async function Report(data: ueuse) {
if (
data.abi === "none" ||
data.abi === ""
) {
console.log("報告(内容なし)", await Reply(`
(\`/report\`をまたご利用ください。)
`, data.uniqid));
return;
}
if (data.abi === "ignore") {
return;
}
if (!config.emergency.mail.function) {
console.log("報告(メールオフ)", await Reply(`
BOTの運営者によってメール送信機能が無効化されています
`, data.uniqid));
return;
}
if (!config.emergency.report) {
console.log("報告(機能オフ)", await Reply(`
BOTの運営者によって報告機能が無効化されています
`, data.uniqid));
return;
}
try {
sendMail({
to: config.emergency.mail.to,
subject: "【報告】BOT利用者からの報告",
text: `
noticeUwuzu自動送信によるメールです
BOT管理者さんnoticeUwuzu自動送信メールです
@${data.account.userid}@${config.uwuzu.host}/reportコマンドを利用した報告がありました
https://${config.uwuzu.host}/!${data.uniqid}
${data.abi}
`,
});
console.log("報告(完了)", await Reply(`
URL
BOTからブロックされる可能性があります
`, data.uniqid));
return;
} catch (err) {
console.log("/reportエラー", err);
console.log("報告(エラー)", await Reply(`
`, data.uniqid));
return;
}
}

View File

@ -1,5 +1,6 @@
import { ueuse } from "types/types.js"; import { ueuse } from "types/types.js";
import config from "../../config.js"; import config from "../../config.js";
import { Reply } from "./main.js";
export default async function UnFollow(data: ueuse) { export default async function UnFollow(data: ueuse) {
const unfollowReq = await fetch(`https://${config.uwuzu.host}/api/users/unfollow`, { const unfollowReq = await fetch(`https://${config.uwuzu.host}/api/users/unfollow`, {
@ -8,24 +9,17 @@ export default async function UnFollow(data: ueuse) {
token: config.uwuzu.apiToken, token: config.uwuzu.apiToken,
userid: data.account.userid, userid: data.account.userid,
}), }),
cache: "no-store",
}); });
const unfollowRes = await unfollowReq.json(); const unfollowRes = await unfollowReq.json();
console.log("フォロー解除: ", unfollowRes); console.log("フォロー解除: ", unfollowRes);
const noticeReq = await fetch(`https://${config.uwuzu.host}/api/ueuse/create`, {
method: "POST",
body: JSON.stringify({
token: config.uwuzu.apiToken,
text: `
${data.account.username}
`,
replyid: data.uniqid,
}),
});
const noticeRes = await noticeReq.json(); const notice = await Reply(`
${data.account.username}
`, data.uniqid);
console.log("フォロー解除通知: ", noticeRes); console.log("フォロー解除通知: ", notice);
} }

View File

@ -73,7 +73,7 @@ class P2PEarthquakeClient {
event(message); event(message);
} else { } else {
console.log(`未対応の情報を受信しました(コード: ${message.code})`); console.log(`未対応の情報を受信しました(コード: ${message.code})`);
console.log(`受信メッセージ:${message}`); console.log("受信メッセージ:", message);
} }
} }
@ -137,7 +137,7 @@ async function areaMap(): Promise<Record<number, string>> {
// 情報受信 // 情報受信
async function event(earthquakeInfo: any): Promise<void> { async function event(earthquakeInfo: any): Promise<void> {
console.log(`受信メッセージ:${earthquakeInfo}`); console.log("受信メッセージ:", earthquakeInfo);
// ----処理---- // ----処理----
// 緊急地震速報の場合 // 緊急地震速報の場合
@ -289,12 +289,12 @@ async function event(earthquakeInfo: any): Promise<void> {
to: config.emergency.mail.to, to: config.emergency.mail.to,
subject: "【警告】震度6強以上の地震を受信しました", subject: "【警告】震度6強以上の地震を受信しました",
text: ` text: `
noticeUwuzu自動送信によるメールです noticeUwuzu自動送信によるメールです
BOT管理者さんnoticeUwuzu自動送信メールです BOT管理者さんnoticeUwuzu自動送信メールです
6 6
` `
}); });
@ -314,6 +314,8 @@ async function event(earthquakeInfo: any): Promise<void> {
), ),
); );
areas = `対象地域:${areaNames.join("・")}`; areas = `対象地域:${areaNames.join("・")}`;
} else {
areas = "対象地域:不明";
} }
// 詳細 // 詳細
@ -324,6 +326,8 @@ async function event(earthquakeInfo: any): Promise<void> {
earthquakeInfo.comments.freeFormComment !== undefined earthquakeInfo.comments.freeFormComment !== undefined
) { ) {
description = `この地震について:${earthquakeInfo.comments.freeFormComment}`; description = `この地震について:${earthquakeInfo.comments.freeFormComment}`;
} else {
description = "";
} }
// 深さ // 深さ
@ -340,6 +344,8 @@ async function event(earthquakeInfo: any): Promise<void> {
} else { } else {
depth = `深さ:${String(earthquakeInfo.earthquake.hypocenter.depth)}km`; depth = `深さ:${String(earthquakeInfo.earthquake.hypocenter.depth)}km`;
} }
} else {
depth = "深さ:不明";
} }
// マグニチュード // マグニチュード
@ -350,10 +356,12 @@ async function event(earthquakeInfo: any): Promise<void> {
earthquakeInfo.earthquake.hypocenter.magnitude !== undefined earthquakeInfo.earthquake.hypocenter.magnitude !== undefined
) { ) {
if (earthquakeInfo.earthquake.hypocenter.magnitude === -1) { if (earthquakeInfo.earthquake.hypocenter.magnitude === -1) {
depth = "マグニチュード:不明"; magnitude = "マグニチュード:不明";
} else { } else {
magnitude = `マグニチュードM${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`; magnitude = `マグニチュードM${String(earthquakeInfo.earthquake.hypocenter.magnitude)}`;
} }
} else {
magnitude = "マグニチュード:不明";
} }
ueuse(` ueuse(`
@ -417,6 +425,8 @@ async function event(earthquakeInfo: any): Promise<void> {
immediate = "### 津波が直ちに襲来します"; immediate = "### 津波が直ちに襲来します";
} else if (!data.immediate) { } else if (!data.immediate) {
immediate = "津波は直ちには襲来しません"; immediate = "津波は直ちには襲来しません";
} else {
immediate = "津波の襲来が直後かの情報がありません";
} }
// 第1波 // 第1波
@ -481,6 +491,7 @@ async function ueuse(text: string) {
token: config.uwuzu.apiToken, token: config.uwuzu.apiToken,
text: text, text: text,
}), }),
cache: "no-store",
}); });
const resData = await res.json(); const resData = await res.json();

View File

@ -35,6 +35,7 @@ export default async function timeNotice() {
token: config.uwuzu.apiToken, token: config.uwuzu.apiToken,
text: `${format(new Date(), "HH:mm")}になりました`, text: `${format(new Date(), "HH:mm")}になりました`,
}), }),
cache: "no-store",
}, },
); );

View File

@ -19,6 +19,7 @@ export async function weatherNotice() {
`, `,
}), }),
cache: "no-store",
}, },
); );
@ -114,6 +115,7 @@ export async function weatherReply(uniqid: string) {
text: weatherResults[i], text: weatherResults[i],
replyid: uniqid, replyid: uniqid,
}), }),
cache: "no-store",
}, },
); );

1
types/config.d.ts vendored
View File

@ -31,6 +31,7 @@ interface emergencyMailTypes {
interface emergencyTypes { interface emergencyTypes {
function: Boolean; function: Boolean;
mail: emergencyMailTypes; mail: emergencyMailTypes;
report: Boolean;
} }
interface uwuzuTypes { interface uwuzuTypes {