From 0ee272859063e3a7b9c0fe01883bca572e64a3d3 Mon Sep 17 00:00:00 2001 From: Last2014 Date: Sun, 30 Nov 2025 17:44:44 +0900 Subject: [PATCH] 25.12.0-alpha.0 --- CHANGELOG.md | 22 +++ asciiart.txt | 2 +- examples/config.ts | 4 +- main.ts | 69 ++++----- package.json | 7 +- panel/main.ts | 24 +-- panel/route/api.ts | 2 +- panel/route/command.ts | 2 +- panel/route/debug.ts | 2 +- panel/route/eventday.ts | 2 +- panel/route/token.ts | 2 +- panel/route/ueuse.ts | 2 +- panel/route/weather.ts | 2 +- .../eventdayData.ts => constants/eventday.ts} | 14 +- src/constants/{weatherId.ts => weather.ts} | 0 src/lib/mailer.ts | 2 +- src/scripts/asciiart.ts | 2 +- {checks => src/scripts/checks}/api.ts | 0 {checks => src/scripts/checks}/config.ts | 0 {checks => src/scripts/checks}/legal.ts | 0 {checks => src/scripts/checks}/main.ts | 0 {checks => src/scripts/checks}/packages.ts | 0 .../scripts/checks}/packagesExist.ts | 0 {checks => src/scripts/checks}/version.ts | 0 src/scripts/clean/main.ts | 10 +- src/scripts/commands/delete.ts | 6 +- src/scripts/commands/follow.ts | 6 +- src/scripts/commands/help.ts | 4 +- src/scripts/commands/info.ts | 10 +- src/scripts/commands/legal/privacy.ts | 11 +- src/scripts/commands/legal/terms.ts | 11 +- src/scripts/commands/main.ts | 46 ++---- src/scripts/commands/miq/allow.ts | 13 +- src/scripts/commands/miq/main.ts | 16 +- src/scripts/commands/miq/permission.ts | 13 +- src/scripts/commands/report.ts | 9 +- src/scripts/commands/unfollow.ts | 6 +- src/scripts/commands/weather.ts | 4 +- src/scripts/earthquakeNotice.ts | 5 +- src/scripts/eventday.ts | 4 +- src/scripts/successExit.ts | 7 +- src/scripts/timeNotice.ts | 5 +- src/scripts/weatherNotice.ts | 8 +- src/types/config.d.ts | 138 +++++++----------- tsconfig.json | 8 +- 45 files changed, 220 insertions(+), 280 deletions(-) create mode 100644 CHANGELOG.md rename src/{scripts/eventdayData.ts => constants/eventday.ts} (89%) rename src/constants/{weatherId.ts => weather.ts} (100%) rename {checks => src/scripts/checks}/api.ts (100%) rename {checks => src/scripts/checks}/config.ts (100%) rename {checks => src/scripts/checks}/legal.ts (100%) rename {checks => src/scripts/checks}/main.ts (100%) rename {checks => src/scripts/checks}/packages.ts (100%) rename {checks => src/scripts/checks}/packagesExist.ts (100%) rename {checks => src/scripts/checks}/version.ts (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..51c6a94 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,22 @@ +# 25.12.0-alpha.0 +- New: リリースノートを記録する方針を取り始めました +- Change: tsc-aliasによるエイリアスインポートを導入しました + - New: resolveFullPathsが有効です + - Del: それに伴いインポートから末尾の.jsを削除しました + - New: エイリアスに`@/`(`./src`)が追加されました +- Change: config.d.tsの名称をconfigTypeからConfigへ変更しました + - Change: config.d.tsの余分なinterface定義を1つのConfigとして再定義しました +- Change: moduleResolutionをnodeからbundlerへ変更しました +- Change: typeRootのsrc/typesを./src/typesへ変更しました +- Change: 同一ファイルでの使用数が1つのみのインポートを静的インポートから動的インポートへ変更しました +- Change: ディレクトリ構造を大幅に変更しました + - Migrate: /src/wiatherId.tsを/src/constantsへ移動しました + - Migrate: /scriptを/srcへ移動しました + - Migrate: /typesを/src/typesへ移動しました + - Migrate: /src/mailer.tsを/src/libへ移動しました + - Migrate: /checksを/src/scriptsへ移動しました +- Change: eventdayData.tsを単一のexport文のみに短縮しました +- Delete: asciiart.txtの末尾に含まれている改行を削除しました + - Delete: それに伴いasciiart.tsの改行を削除する正規表現を削除しました +- Delete: package.jsonのscriptsからmainを削除しました +- Delete: successExit.tsに含まれていたデバッグ用の関数を即時実行するコードを削除しました \ No newline at end of file diff --git a/asciiart.txt b/asciiart.txt index f97a7aa..ffd6708 100644 --- a/asciiart.txt +++ b/asciiart.txt @@ -2,4 +2,4 @@ ## # # # # # # # # # # # # # # # # # # ## # # # # # # ####### # # # # # # # # ## # # # ## # # # # # # # # # # # # # # # -# # ###### # ### ###### ####### ###### # # ###### ###### ###### +# # ###### # ### ###### ####### ###### # # ###### ###### ###### \ No newline at end of file diff --git a/examples/config.ts b/examples/config.ts index ecc3242..38692aa 100644 --- a/examples/config.ts +++ b/examples/config.ts @@ -1,7 +1,7 @@ -import type { configTypes } from "types/config"; +import type Config from "src/types/config"; // READMEの設定項目を参照 -const config: configTypes = { +const config: Config = { // 時報設定 time: { // 時報休止期間 diff --git a/main.ts b/main.ts index db54ccb..20ca86d 100644 --- a/main.ts +++ b/main.ts @@ -1,63 +1,48 @@ // 起動チェック -import Check from "./checks/main.js"; -(async () => { - await Check(); -})(); +(await import("@/scripts/checks/main")).default(); +(await import("@/scripts/successExit")).default(); -// 定期実行読み込み -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 EventDays from "./scripts/eventday.js"; -import Commands from "./scripts/commands/main.js"; - -// その他機能 -import asciiArt from "./scripts/asciiart.js"; -asciiArt(); -import successExit from "./scripts/successExit.js"; -successExit(); +// アスキーアート +(await import("@/scripts/asciiart")).default(); // 地震情報観測開始 -earthquakeNotice(); +(await import("@/scripts/earthquakeNotice")).default(); -// 時報(1時間/1回) -cron.schedule("0 * * * *", () => { - timeNotice(); +// 定期実行 +import * as cron from "node-cron"; + +/// 時報(1時間毎) +cron.schedule("0 * * * *", async () => { + (await import("@/scripts/timeNotice")).default(); }); -// コマンド(10分/1回) -cron.schedule("*/10 * * * *", () => { - Commands(); +// コマンド(10分毎) +cron.schedule("*/10 * * * *", async () => { + (await import("@/scripts/commands/main")).default(); }); -// 祝日などお知らせ(毎日0:00) -cron.schedule("0 0 * * *", () => { - EventDays(); +// 祝日など(毎日0:00) +cron.schedule("0 0 * * *", async () => { + (await import("@/scripts/eventday")).default(); }); // 天気お知らせ(毎日7:00) -import { setTimeout } from "timers"; -cron.schedule("0 7 * * *", () => { - setTimeout(() => { - weatherNotice(); - }, 100); +cron.schedule("0 7 * * *", async () => { + (await import("@/scripts/weatherNotice")).weatherNotice(); }); // 管理パネル -import AdminPanel from "./panel/main.js"; -(async () => { - await AdminPanel(); -})(); +await (await import("./panel/main")).default() // 起動表示 console.log("BOTサーバーが起動しました"); -import config from "./config.js"; -import { styleText } from "util"; -if (config.debug !== undefined) { +if ((await import("./config")).default.debug) { + // TLSを任意に設定 process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; - console.log(styleText(["bgRed", "cyan", "bold"], "デバッグモードで起動中")); + + console.log((await import("node:util")).styleText( + ["bgRed", "cyan", "bold"], + "デバッグモードで起動中" + )); } diff --git a/package.json b/package.json index 9d3bddc..86e6350 100644 --- a/package.json +++ b/package.json @@ -6,10 +6,9 @@ "main": "dist/main.js", "scripts": { "start": "node .", - "build": "tsc", - "main": "tsc && node .", + "build": "tsc && tsc-alias", "dev": "tsx main.ts", - "clean": "tsc && node dist/scripts/clean/main.js" + "clean": "npm run build && node dist/scripts/clean/main.js" }, "repository": { "type": "git", @@ -52,7 +51,7 @@ "node-cron": "^4.1.1", "nodemailer": "^7.0.4", "sharp": "^0.34.3", - "timers": "^0.1.1", + "tsc-alias": "^1.8.16", "typescript": "^5.9.2", "ws": "^8.18.3" }, diff --git a/panel/main.ts b/panel/main.ts index 2cc31f1..8207a25 100644 --- a/panel/main.ts +++ b/panel/main.ts @@ -1,15 +1,7 @@ import express from "express"; import * as os from "os"; -import config from "../config.js"; -import { NetworkInterfaceDetails } from "types/types"; - -// バックエンドルーティング -import CommandExecute from "./route/command.js"; -import ueusePost from "./route/ueuse.js"; -import WeatherUeuse from "./route/weather.js"; -import API from "./route/api.js"; -import Token from "./route/token.js"; -import Debug from "./route/debug.js"; +import config from "../config"; +import { NetworkInterfaceDetails } from "@/types/types"; export default async function AdminPanel() { // 無効 @@ -22,12 +14,12 @@ export default async function AdminPanel() { const port = config.admin.panel.port; // ルーティング - app.use(ueusePost); - app.use(CommandExecute); - app.use(WeatherUeuse); - app.use(API); - app.use(Token); - app.use(Debug); + app.use((await import("./route/ueuse")).default); + app.use((await import("./route/command")).default); + app.use((await import("./route/weather")).default); + app.use((await import("./route/api")).default); + app.use((await import("./route/token")).default); + app.use((await import("./route/debug")).default); app.use(express.static("panel/public")); app.listen(port, () => { diff --git a/panel/route/api.ts b/panel/route/api.ts index 5914aeb..1e6b89d 100644 --- a/panel/route/api.ts +++ b/panel/route/api.ts @@ -1,7 +1,7 @@ import express from "express"; const API = express.Router(); -import config from "../../config.js"; +import config from "../../config"; API.use(express.json()); API.use(express.urlencoded({ extended: true })); diff --git a/panel/route/command.ts b/panel/route/command.ts index 44b89c8..3e10e16 100644 --- a/panel/route/command.ts +++ b/panel/route/command.ts @@ -1,7 +1,7 @@ import express from "express"; const CommandExecute = express.Router(); -import Commands from "../../scripts/commands/main.js"; +import Commands from "@/scripts/commands/main"; CommandExecute.post("/actions/command-execute", (req, res) => { try { diff --git a/panel/route/debug.ts b/panel/route/debug.ts index 57109dc..5aee3db 100644 --- a/panel/route/debug.ts +++ b/panel/route/debug.ts @@ -1,7 +1,7 @@ import express from "express"; const Debug = express.Router(); -import config from "../../config.js"; +import config from "../../config"; Debug.post("/actions/debug", (req, res, next) => { res.status(501) diff --git a/panel/route/eventday.ts b/panel/route/eventday.ts index 0b1a0ae..a9e00eb 100644 --- a/panel/route/eventday.ts +++ b/panel/route/eventday.ts @@ -1,7 +1,7 @@ import express from "express"; const EventdayUeuse = express.Router(); -import EventDays from "../../scripts/eventday.js"; +import EventDays from "@/scripts/eventday"; EventdayUeuse.post("/actions/eventday", (req, res) => { try { diff --git a/panel/route/token.ts b/panel/route/token.ts index 2ad2a80..70b4ca1 100644 --- a/panel/route/token.ts +++ b/panel/route/token.ts @@ -1,7 +1,7 @@ import express from "express"; const Token = express.Router(); -import config from "../../config.js"; +import config from "../../config"; Token.post("/actions/token", (req, res, next) => { res.status(501) diff --git a/panel/route/ueuse.ts b/panel/route/ueuse.ts index 50cec6b..0a25b4b 100644 --- a/panel/route/ueuse.ts +++ b/panel/route/ueuse.ts @@ -1,7 +1,7 @@ import express from "express"; const ueusePost = express.Router(); -import config from "../../config.js"; +import config from "../../config"; ueusePost.use(express.json()); ueusePost.use(express.urlencoded({ extended: true })); diff --git a/panel/route/weather.ts b/panel/route/weather.ts index a62bd22..6482d6e 100644 --- a/panel/route/weather.ts +++ b/panel/route/weather.ts @@ -1,7 +1,7 @@ import express from "express"; const WeatherUeuse = express.Router(); -import { weatherNotice } from "../../scripts/weatherNotice.js"; +import { weatherNotice } from "@/scripts/weatherNotice"; WeatherUeuse.post("/actions/weather", (req, res) => { try { diff --git a/src/scripts/eventdayData.ts b/src/constants/eventday.ts similarity index 89% rename from src/scripts/eventdayData.ts rename to src/constants/eventday.ts index 510f782..4a9fbbc 100644 --- a/src/scripts/eventdayData.ts +++ b/src/constants/eventday.ts @@ -1,9 +1,4 @@ -interface eventdaysValue { - name: string; - message: string; -} - -const eventdays = { +export default { "01/01": { name: "元日", message: "はい年越した瞬間地球にいなかった~", @@ -65,6 +60,7 @@ const eventdays = { name: "大晦日", message: "大掃除!!大掃除!!", }, -} as { [key: string]: eventdaysValue }; - -export default eventdays; +} as { [key: string]: { + name: string; + message: string; +} }; diff --git a/src/constants/weatherId.ts b/src/constants/weather.ts similarity index 100% rename from src/constants/weatherId.ts rename to src/constants/weather.ts diff --git a/src/lib/mailer.ts b/src/lib/mailer.ts index f68270a..d07c872 100644 --- a/src/lib/mailer.ts +++ b/src/lib/mailer.ts @@ -1,4 +1,4 @@ -import config from "../../config.js"; +import config from "../../config"; import * as nodemailer from "nodemailer"; import type SMTPTransport from "nodemailer/lib/smtp-transport"; diff --git a/src/scripts/asciiart.ts b/src/scripts/asciiart.ts index 5c0d996..3c324c0 100644 --- a/src/scripts/asciiart.ts +++ b/src/scripts/asciiart.ts @@ -3,6 +3,6 @@ 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(fs.readFileSync("asciiart.txt", "utf-8")); console.log(`${version}\n`); } diff --git a/checks/api.ts b/src/scripts/checks/api.ts similarity index 100% rename from checks/api.ts rename to src/scripts/checks/api.ts diff --git a/checks/config.ts b/src/scripts/checks/config.ts similarity index 100% rename from checks/config.ts rename to src/scripts/checks/config.ts diff --git a/checks/legal.ts b/src/scripts/checks/legal.ts similarity index 100% rename from checks/legal.ts rename to src/scripts/checks/legal.ts diff --git a/checks/main.ts b/src/scripts/checks/main.ts similarity index 100% rename from checks/main.ts rename to src/scripts/checks/main.ts diff --git a/checks/packages.ts b/src/scripts/checks/packages.ts similarity index 100% rename from checks/packages.ts rename to src/scripts/checks/packages.ts diff --git a/checks/packagesExist.ts b/src/scripts/checks/packagesExist.ts similarity index 100% rename from checks/packagesExist.ts rename to src/scripts/checks/packagesExist.ts diff --git a/checks/version.ts b/src/scripts/checks/version.ts similarity index 100% rename from checks/version.ts rename to src/scripts/checks/version.ts diff --git a/src/scripts/clean/main.ts b/src/scripts/clean/main.ts index ebcd921..29dacc3 100644 --- a/src/scripts/clean/main.ts +++ b/src/scripts/clean/main.ts @@ -1,7 +1,5 @@ -import logsDelete from "./logsDel.js"; -import packageLockJsonDelete from "./packageLockDel.js"; -import npmInstall from "./npmInstall.js"; +(await import("@/scripts/clean/logsDel")).default(); +(await import("@/scripts/clean/packageLockDel")).default(); +(await import("@/scripts/clean/npmInstall")).default(); -logsDelete(); -packageLockJsonDelete(); -npmInstall(); +export {}; \ No newline at end of file diff --git a/src/scripts/commands/delete.ts b/src/scripts/commands/delete.ts index 2da69a5..20a1482 100644 --- a/src/scripts/commands/delete.ts +++ b/src/scripts/commands/delete.ts @@ -1,6 +1,6 @@ -import { meApi, ueuse } from "../../src/types/types"; -import config from "../../config.js"; -import { Reply } from "./main.js"; +import { meApi, ueuse } from "@/types/types"; +import config from "../../../config"; +import { Reply } from "@/scripts/commands/main"; export default async function Delete(data: ueuse) { const meReq = await fetch(`${config.uwuzu.host}/api/me/`, { diff --git a/src/scripts/commands/follow.ts b/src/scripts/commands/follow.ts index 6b01ebf..2ca49dd 100644 --- a/src/scripts/commands/follow.ts +++ b/src/scripts/commands/follow.ts @@ -1,6 +1,6 @@ -import { ueuse } from "src/types/types.js"; -import config from "../../config.js"; -import { Reply } from "./main.js"; +import { ueuse } from "@/types/types"; +import config from "../../../config"; +import { Reply } from "@/scripts/commands/main"; export default async function Follow(data: ueuse) { const followReq = await fetch(`${config.uwuzu.host}/api/users/follow`, { diff --git a/src/scripts/commands/help.ts b/src/scripts/commands/help.ts index fd437a6..c1537ed 100644 --- a/src/scripts/commands/help.ts +++ b/src/scripts/commands/help.ts @@ -1,6 +1,6 @@ -import { ueuse } from "src/types/types.js"; +import { ueuse } from "@/types/types"; import { readFileSync } from "fs"; -import { Reply } from "./main.js"; +import { Reply } from "@/scripts/commands/main"; const helpsMin = { "info": "このBOTについての概要を返信するコマンドです。", diff --git a/src/scripts/commands/info.ts b/src/scripts/commands/info.ts index 2049370..a55e70a 100644 --- a/src/scripts/commands/info.ts +++ b/src/scripts/commands/info.ts @@ -1,10 +1,8 @@ -import { ueuse } from "src/types/types.js"; -import { readFileSync } from "fs"; -import { Reply } from "./main.js"; -import config from "../../config.js"; +import { ueuse } from "@/types/types"; +import config from "../../../config"; export default async function Info(data: ueuse) { - const packageJson = JSON.parse(readFileSync("package.json", "utf-8")); + const packageJson = JSON.parse((await import("fs")).readFileSync("package.json", "utf-8")); const releaseUrl = `${packageJson.repository.url}/releases/tag/${packageJson.tag}`; let editor = ""; @@ -29,7 +27,7 @@ export default async function Info(data: ueuse) { isReport = "無効"; } - const ueuse = await Reply(` + const ueuse = await (await import("@/scripts/commands/main")).Reply(` 【BOTについて】 このBOTはオープンソースソフトウェアであるnoticeUwuzuを利用して運営されています。 noticeUwuzuはApache License 2.0によって保護されています。 diff --git a/src/scripts/commands/legal/privacy.ts b/src/scripts/commands/legal/privacy.ts index 3f45ab0..596b51a 100644 --- a/src/scripts/commands/legal/privacy.ts +++ b/src/scripts/commands/legal/privacy.ts @@ -1,7 +1,8 @@ -import { ueuse } from "src/types/types.js"; -import { Reply } from "../main.js"; -import config from "../../../config.js"; +import { ueuse } from "@/types/types"; -export default function PrivacyPolicy(data: ueuse) { - Reply(config.legal.privacy, data.uniqid); +export default async function PrivacyPolicy(data: ueuse) { + (await import("@/scripts/commands/main")).Reply( + (await import("../../../../config")).default.legal.privacy, + data.uniqid + ); } diff --git a/src/scripts/commands/legal/terms.ts b/src/scripts/commands/legal/terms.ts index 5532a7d..7ff4800 100644 --- a/src/scripts/commands/legal/terms.ts +++ b/src/scripts/commands/legal/terms.ts @@ -1,7 +1,8 @@ -import { ueuse } from "src/types/types.js"; -import { Reply } from "../main.js"; -import config from "../../../config.js"; +import { ueuse } from "@/types/types"; -export default function Terms(data: ueuse) { - Reply(config.legal.terms, data.uniqid); +export default async function Terms(data: ueuse) { + (await import("@/scripts/commands/main")).Reply( + (await import("../../../../config")).default.legal.terms, + data.uniqid + ); } diff --git a/src/scripts/commands/main.ts b/src/scripts/commands/main.ts index f2ec6d5..c67eb3a 100644 --- a/src/scripts/commands/main.ts +++ b/src/scripts/commands/main.ts @@ -1,28 +1,12 @@ import * as fs from "fs"; -import config from "../../config.js"; -import type { ueuse } from "src/types/types.js"; - -const initialFile: Array = []; - -// コマンド読み込み -import Info from "./info.js"; -import Help from "./help.js"; -import Follow from "./follow.js"; -import UnFollow from "./unfollow.js"; -import Weather from "./weather.js"; -import Report from "./report.js"; -import Terms from "./legal/terms.js" -import PrivacyPolicy from "./legal/privacy.js"; -import Delete from "./delete.js"; -import MakeItAQuote from "./miq/main.js"; -import MiQPermission from "./miq/permission.js"; -import MiQAllow from "./miq/allow.js"; +import config from "../../../config"; +import type { ueuse } from "@/types/types"; // 初期化 if (!fs.existsSync("data/alreadyCommands.json")) { fs.writeFileSync( "data/alreadyCommands.json", - JSON.stringify(initialFile), + JSON.stringify([]), "utf-8", ); } @@ -162,40 +146,40 @@ export default async function Commands() { switch (commandName) { case "info": - Info(data); + (await import("@/scripts/commands/info")).default(data); break; case "help": - Help(data); + (await import("@/scripts/commands/help")).default(data); break; case "legal terms": - Terms(data); + (await import("@/scripts/commands/legal/terms")).default(data); break; case "legal privacy": - PrivacyPolicy(data); + (await import("@/scripts/commands/legal/privacy")).default(data); break; case "report": - Report(data); + (await import("@/scripts/commands/report")).default(data); break; case "follow": - Follow(data); + (await import("@/scripts/commands/follow")).default(data); break; case "unfollow": - UnFollow(data); + (await import("@/scripts/commands/unfollow")).default(data); break; case "weather": - Weather(data); + (await import("@/scripts/commands/weather")).default(data); break; case "miq": - MakeItAQuote(data); + (await import("@/scripts/commands/miq/main")).default(data); break; case "miq permission": - MiQPermission(data); + (await import("@/scripts/commands/miq/permission")).default(data); break; case "miq allow": - MiQAllow(data); + (await import("@/scripts/commands/miq/allow")).default(data); break; case "delete": - Delete(data); + (await import("@/scripts/commands/delete")).default(data); break; default: const reply = await Reply(` diff --git a/src/scripts/commands/miq/allow.ts b/src/scripts/commands/miq/allow.ts index b2d23ed..69fbf37 100644 --- a/src/scripts/commands/miq/allow.ts +++ b/src/scripts/commands/miq/allow.ts @@ -1,9 +1,8 @@ -import { meApi, ueuse } from "../../../src/types/types"; -import { readFileSync } from "fs"; -import config from "../../../config.js"; -import { Reply } from "../main.js"; -import { Permission } from "./permission"; -import MiQ from "../../../miq/main.js"; +import { meApi, ueuse } from "@/types/types"; +import config from "../../../../config"; +import { Reply } from "@/scripts/commands/main"; +import { Permission } from "@/scripts/commands/miq/permission"; +import MiQ from "../../../../miq/main"; export default async function MiQAllow(data: ueuse) { if (!config.miq) { @@ -22,7 +21,7 @@ export default async function MiQAllow(data: ueuse) { // 権限一覧取得 const permissions: { [user: string]: Permission } = - JSON.parse(readFileSync("data/miqPermissions.json", "utf-8")); + JSON.parse((await import("fs")).readFileSync("data/miqPermissions.json", "utf-8")); if (permissions[data.account.userid] !== "consent") { console.log("MiQ許可制(許可制以外):", await Reply(` diff --git a/src/scripts/commands/miq/main.ts b/src/scripts/commands/miq/main.ts index 350c873..ef0cc09 100644 --- a/src/scripts/commands/miq/main.ts +++ b/src/scripts/commands/miq/main.ts @@ -1,9 +1,7 @@ -import { ueuse } from "../../../src/types/types"; -import MiQ from "../../../miq/main.js"; -import config from "../../../config.js"; -import { Reply } from "../main.js"; -import { readFileSync, writeFileSync } from "fs"; -import { Permission } from "./permission"; +import { ueuse } from "@/types/types"; +import config from "../../../../config"; +import { Reply } from "@/scripts/commands/main"; +import type { Permission } from "@/scripts/commands/miq/permission"; export default async function MakeItAQuote(data: ueuse) { if (!config.miq) { @@ -47,12 +45,12 @@ export default async function MakeItAQuote(data: ueuse) { // 権限一覧取得 const permissions: { [user: string]: Permission } = - JSON.parse(readFileSync("data/miqPermissions.json", "utf-8")); + JSON.parse((await import("fs")).readFileSync("data/miqPermissions.json", "utf-8")); // 初期化 if (permissions[ueuseData.account.userid] === undefined) { permissions[ueuseData.account.userid] = "consent"; - writeFileSync( + (await import("fs")).writeFileSync( "data/miqPermissions.json", JSON.stringify(permissions), "utf-8" @@ -82,7 +80,7 @@ export default async function MakeItAQuote(data: ueuse) { return; } - const img = await MiQ({ + const img = await (await import("../../../../miq/main")).default({ type: "Base64Data", color: color, text: ueuseData.text, diff --git a/src/scripts/commands/miq/permission.ts b/src/scripts/commands/miq/permission.ts index d82587a..2923091 100644 --- a/src/scripts/commands/miq/permission.ts +++ b/src/scripts/commands/miq/permission.ts @@ -1,11 +1,10 @@ -import { ueuse } from "../../../src/types/types"; -import { Reply } from "../main.js"; -import config from "../../../config.js"; -import { readFileSync, writeFileSync, existsSync } from "fs"; +import { ueuse } from "@/types/types"; +import { Reply } from "@/scripts/commands/main"; +import { writeFileSync } from "fs"; // 初期化 const initialFile = {}; -if (!existsSync("data/miqPermissions.json")) { +if (!(await import("fs")).existsSync("data/miqPermissions.json")) { writeFileSync( "data/miqPermissions.json", JSON.stringify(initialFile), @@ -25,7 +24,7 @@ const PermissionsNames: { [name: string]: string } = { } export default async function MiQPermission(data: ueuse) { - if (!config.miq) { + if (!(await import("../../../../config")).default.miq) { await Reply(` BOT管理者によってMake it a quoteが無効化されています。 そのため\`/miq\`はご利用いただけません。 @@ -34,7 +33,7 @@ export default async function MiQPermission(data: ueuse) { } const permissions: { [user: string]: string } = - JSON.parse(readFileSync("data/miqPermissions.json", "utf-8")); + JSON.parse((await import("fs")).readFileSync("data/miqPermissions.json", "utf-8")); // 初期化 if (permissions[data.account.userid] === undefined) { diff --git a/src/scripts/commands/report.ts b/src/scripts/commands/report.ts index e2e196c..f321b67 100644 --- a/src/scripts/commands/report.ts +++ b/src/scripts/commands/report.ts @@ -1,7 +1,6 @@ -import { ueuse } from "src/types/types.js"; -import { Reply } from "./main.js"; -import config from "../../config.js"; -import sendMail from "../../src/lib/mailer.js"; +import { ueuse } from "@/types/types"; +import { Reply } from "./main"; +import config from "../../../config"; export default async function Report(data: ueuse) { if ( @@ -40,7 +39,7 @@ export default async function Report(data: ueuse) { } try { - sendMail({ + (await import("@/lib/mailer")).default({ to: config.emergency.mail.to, subject: "【報告】BOT利用者からの報告", text: ` diff --git a/src/scripts/commands/unfollow.ts b/src/scripts/commands/unfollow.ts index 21fa513..941bf56 100644 --- a/src/scripts/commands/unfollow.ts +++ b/src/scripts/commands/unfollow.ts @@ -1,6 +1,6 @@ -import { ueuse } from "src/types/types.js"; -import config from "../../config.js"; -import { Reply } from "./main.js"; +import { ueuse } from "@/types/types"; +import config from "../../../config"; +import { Reply } from "./main"; export default async function UnFollow(data: ueuse) { const unfollowReq = await fetch(`${config.uwuzu.host}/api/users/unfollow`, { diff --git a/src/scripts/commands/weather.ts b/src/scripts/commands/weather.ts index ff82410..90cafdf 100644 --- a/src/scripts/commands/weather.ts +++ b/src/scripts/commands/weather.ts @@ -1,5 +1,5 @@ -import { weatherReply } from "../weatherNotice.js"; -import { ueuse } from "src/types/types.js"; +import { weatherReply } from "@/scripts/weatherNotice"; +import { ueuse } from "@/types/types.js"; export default function Weather(data: ueuse) { weatherReply(data.uniqid); diff --git a/src/scripts/earthquakeNotice.ts b/src/scripts/earthquakeNotice.ts index b0ee0f2..2d743df 100644 --- a/src/scripts/earthquakeNotice.ts +++ b/src/scripts/earthquakeNotice.ts @@ -1,7 +1,6 @@ import WebSocket from "ws"; -import sendMail from "../src/lib/mailer.js"; - -import config from "../config.js"; +import sendMail from "@/lib/mailer"; +import config from "../../config.js"; class P2PEarthquakeClient { private ws: WebSocket | null = null; diff --git a/src/scripts/eventday.ts b/src/scripts/eventday.ts index ba69b42..9208edc 100644 --- a/src/scripts/eventday.ts +++ b/src/scripts/eventday.ts @@ -1,6 +1,6 @@ import { format } from "date-fns"; -import eventdays from "./eventdayData.js"; -import config from "../config.js"; +import eventdays from "@/constants/eventday"; +import config from "../../config"; export default async function EventDays() { const now = format(new Date(), "MM/dd"); diff --git a/src/scripts/successExit.ts b/src/scripts/successExit.ts index 4f54d79..1238522 100644 --- a/src/scripts/successExit.ts +++ b/src/scripts/successExit.ts @@ -1,8 +1,7 @@ import * as fs from "fs"; import { isAfter } from "date-fns"; - -import config from "../config.js"; -import sendMail from "../src/lib/mailer.js"; +import config from "../../config"; +import sendMail from "@/lib/mailer"; export default function successExit() { // 初期化 @@ -56,5 +55,3 @@ export default function successExit() { fs.writeFileSync("logs/boot.json", JSON.stringify(iolog), "utf-8"); }); } - -successExit(); diff --git a/src/scripts/timeNotice.ts b/src/scripts/timeNotice.ts index 9bbf67b..d80f791 100644 --- a/src/scripts/timeNotice.ts +++ b/src/scripts/timeNotice.ts @@ -1,7 +1,6 @@ import { format } from "date-fns"; - -import type * as types from "src/types/types.js"; -import config from "../config.js"; +import type * as types from "@/types/types"; +import config from "../../config"; export default async function timeNotice() { // 停止時間 diff --git a/src/scripts/weatherNotice.ts b/src/scripts/weatherNotice.ts index 082486e..a261402 100644 --- a/src/scripts/weatherNotice.ts +++ b/src/scripts/weatherNotice.ts @@ -1,8 +1,6 @@ -import { cityList } from "../src/constants/weatherId.js"; - -import type * as types from "src/types/types.js"; - -import config from "../config.js"; +import { cityList } from "@/constants/weather"; +import type * as types from "@/types/types"; +import config from "../../config"; export async function weatherNotice() { console.log("----------------"); diff --git a/src/types/config.d.ts b/src/types/config.d.ts index cfa91ae..3648020 100644 --- a/src/types/config.d.ts +++ b/src/types/config.d.ts @@ -1,87 +1,59 @@ -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 emergencyMailFullTypes { - isEnabled: true; - host: string; - port: number; - user: string; - password: string; - secure: boolean; - to: string | string[]; -} - -interface emergencyMailMinTypes { - isEnabled: false; - mail: undefined; -} - -interface emergencyFullTypes { - isEnabled: true; - mail: emergencyMailFullTypes | emergemcyMailMinTypes; -} - -interface emergencyMinTypes { - isEnabled: false; -} - -interface reportTypes { - isEnabled: boolean; - message: string; -} - -interface legalTypes { - terms: string; - privacy: string; -} - -interface PanelFullTypes { - isEnabled: true; - port: number; -} - -interface PanelMinTypes { - isEnabled: false; -} - -interface adminTypes { - name: string; - showMail: string | false; - panel: PanelFullTypes | PanelMinTypes; -} - -interface uwuzuTypes { - apiToken: string; - host: string; -} - -export interface configTypes { - time: timeTypes, - earthquake: earthquakeTypes; - weather: weatherTypes; +export default interface Config { + time: { + stopTimes: { + start: number; + stop: number; + }; + }; + earthquake: { + reconnectTimes: number; + websocketUrl: string; + areasCsvUrl: string; + maxScaleMin: number; + }; + weather: { + splitCount: number; + }; miq: boolean; - emergency: emergencyFullTypes | emergencyMinTypes; - report: reportTypes; - legal: legalTypes; - admin: adminTypes; - uwuzu: uwuzuTypes; + emergency: { + isEnabled: true; + mail: { + isEnabled: true; + host: string; + port: number; + user: string; + password: string; + secure: boolean; + to: string | string[]; + } | { + isEnabled: false; + mail: undefined; + }; + } | { + isEnabled: false; + }; + report: { + isEnabled: boolean; + message: string; + }; + legal: { + terms: string; + privacy: string; + }; + admin: { + name: string; + showMail: string | false; + panel: { + isEnabled: true; + port: number; + } | { + isEnabled: false; + }; + }; + uwuzu: { + apiToken: string; + host: string; + }; debug?: true; } diff --git a/tsconfig.json b/tsconfig.json index 44d57b8..00f6631 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "ES2024", "module": "ESNext", - "moduleResolution": "node", + "moduleResolution": "bundler", "outDir": "./dist", "esModuleInterop": true, "allowSyntheticDefaultImports": true, @@ -12,12 +12,16 @@ "baseUrl": "./", "typeRoots": [ "./node_modules/@types", - "./types" + "./src/types" ], "paths": { + "@/*": ["./src/*"], "ws": ["./node_modules/ws/index.js"], "@types/ws": ["./node_modules/@types/ws/index.d.ts"] }, "removeComments": true, }, + "tsc-alias": { + "resolveFullPaths": true, + }, }