Compare commits

...

6 Commits

Author SHA1 Message Date
last2014 4e2f587681 Merge pull request 'v25.12.0-alpha.1' (#5) from config-change-251130 into main
Reviewed-on: #5
2026-01-01 11:07:16 +00:00
last2014 83857ce102 25.12.0-alpha.1全部やっちゃった 2026-01-01 20:06:20 +09:00
last2014 c9d2da5aba Merge pull request '25.12.0-alpha.0' (#3) from alias-import-20251130 into main
Reviewed-on: #3
2025-11-30 08:45:10 +00:00
last2014 0ee2728590 25.12.0-alpha.0 2025-11-30 17:44:44 +09:00
last2014 a53f8f3023 フォルダ構成だけ変えた 2025-11-30 16:21:11 +09:00
last2014 a1a6ef40b8 v25.8.11 2025-08-27 01:29:40 +09:00
63 changed files with 3553 additions and 416 deletions
+2 -1
View File
@@ -1,5 +1,6 @@
/dist/ /dist/
/.env* /.env*
/node_modules/ /node_modules/
/package-lock.json
/config.ts /config.ts
/config/**
!/config/example.config.yaml
+36
View File
@@ -0,0 +1,36 @@
# 25.12.0-alpha.1
- New: configをTypeScriptファイルからyamlへ移行しました
- Note: 新しいファイルパスはconfig/config.yamlです
- New: それに伴って複数の依存関係が追加されました
- Delete: また、examples/config.tsを削除しました
- Note: ただし、互換性のためgitignoreは維持しています
- New: package-lock.jsonをgitignoreから削除しました
- New: import.meta.dirnameによるパスの安全性を確保しました
- New: /miqのエイリアスを作成しました
- Chg: tsconfig.json:20に末尾カンマを追加し統一しました
- Fix: earthquakeNotice.tsで条件分岐が誤っていた問題を修正しました
- Delete: 余分な型定義を削除しました
- Delete: tsc-aliasによるresolveFullPathsが実装されているにもかかわらず.jsを使用したimportの.jsを削除しました
# 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に含まれていたデバッグ用の関数を即時実行するコードを削除しました
+1 -1
View File
@@ -2,4 +2,4 @@
## # # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # # # # #
# ## # # # # # # ####### # # # # # # # # ## # # # ## # # # # # # ####### # # # # # # # # ## # #
# ## # # # # # # # # # # # # # # # # ## # # # # # # # # # # # # # # #
# # ###### # ### ###### ####### ###### # # ###### ###### ###### # # ###### # ### ###### ####### ###### # # ###### ###### ######
-9
View File
@@ -1,9 +0,0 @@
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();
}
}
-18
View File
@@ -1,18 +0,0 @@
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";
import LegalCheck from "./legal.js";
import config from "../config.js";
export default async function Check() {
PackagesIsExist();
PackagesCheck();
ConfigCheck();
if (config.debug === undefined) {
LegalCheck()
}
await APICheck();
await VersionCheck();
}
+57
View File
@@ -0,0 +1,57 @@
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 # 返信の分割数
# Make it a quote設定
miq: true # 有効/無効
# 緊急時設定
emergency:
isEnabled: true # 緊急時のコンソール表示
mail:
isEnabled: 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" # 緊急時メール送信先(配列可)
# /report設定
report:
isEnabled: true # 有効/無効
message: "" # 報告者へのメッセージ
# 規約等
legal:
terms: | # 利用規約
利用規約
privacy: | # プライバシーポリシー
プライバシーポリシー
# 管理者情報設定
admin:
name: "あどみん" # BOT管理者名
showMail: false # メールアドレスを公開するか(false:非公開/文字列:メールアドレス)
panel: # 管理パネル
isEnabled: true # 有効/無効
port: 74919 # 配信ポート
# uwuzuサーバー設定
uwuzu:
apiToken: "TOKEN_EXAMPLE" # APIトークン
host: "https://uwuzu.example.com" # サーバーホスト
-68
View File
@@ -1,68 +0,0 @@
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, // 返信の分割数
},
// Make it a quote設定
miq: true, // 有効/無効
// 緊急時設定
emergency: {
isEnabled: true, // 緊急時のコンソール表示
mail: {
isEnabled: 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", // 緊急時メール送信先(配列可)
},
},
// /report設定
report: {
isEnabled: true, // 有効/無効
message: "", // 報告者へのメッセージ
},
// 規約等
legal: {
terms: `
`, // 利用規約
privacy: `
`, // プライバシーポリシー
},
// 管理者情報設定
admin: {
name: "あどみん", // BOT管理者名
showMail: false, // メールアドレスを公開するか(false:非公開/文字列:メールアドレス)
panel: { // 管理パネル
isEnabled: true, // 有効/無効
port: 74919, // 配信ポート
},
},
// uwuzuサーバー設定
uwuzu: {
apiToken: "TOKEN_EXAMPLE", // APIトークン
host: "https://uwuzu.example.com", // サーバーホスト
},
};
export default config;
+27 -42
View File
@@ -1,63 +1,48 @@
// 起動チェック // 起動チェック
import Check from "./checks/main.js"; (await import("@/scripts/checks/main")).default();
(async () => { (await import("@/scripts/successExit")).default();
await Check();
})();
// 定期実行読み込み // アスキーアート
import * as cron from "node-cron"; (await import("@/scripts/asciiart")).default();
// 機能読み込み
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();
// 地震情報観測開始 // 地震情報観測開始
earthquakeNotice(); (await import("@/scripts/earthquakeNotice")).default();
// 時報(1時間/1回) // 定期実行
cron.schedule("0 * * * *", () => { import * as cron from "node-cron";
timeNotice();
/// 時報(1時間毎)
cron.schedule("0 * * * *", async () => {
(await import("@/scripts/timeNotice")).default();
}); });
// コマンド(10分/1回) // コマンド(10分)
cron.schedule("*/10 * * * *", () => { cron.schedule("*/10 * * * *", async () => {
Commands(); (await import("@/scripts/commands/main")).default();
}); });
// 祝日などお知らせ(毎日0:00) // 祝日など(毎日0:00)
cron.schedule("0 0 * * *", () => { cron.schedule("0 0 * * *", async () => {
EventDays(); (await import("@/scripts/eventday")).default();
}); });
// 天気お知らせ(毎日7:00) // 天気お知らせ(毎日7:00)
import { setTimeout } from "timers"; cron.schedule("0 7 * * *", async () => {
cron.schedule("0 7 * * *", () => { (await import("@/scripts/weatherNotice")).weatherNotice();
setTimeout(() => {
weatherNotice();
}, 100);
}); });
// 管理パネル // 管理パネル
import AdminPanel from "./panel/main.js"; await (await import("./panel/main")).default()
(async () => {
await AdminPanel();
})();
// 起動表示 // 起動表示
console.log("BOTサーバーが起動しました"); console.log("BOTサーバーが起動しました");
import config from "./config.js"; if ((await import("./config")).default.debug) {
import { styleText } from "util"; // TLSを任意に設定
if (config.debug !== undefined) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
console.log(styleText(["bgRed", "cyan", "bold"], "デバッグモードで起動中"));
console.log((await import("node:util")).styleText(
["bgRed", "cyan", "bold"],
"デバッグモードで起動中"
));
} }
+3084
View File
File diff suppressed because it is too large Load Diff
+11 -7
View File
@@ -1,15 +1,14 @@
{ {
"name": "notice-uwuzu", "name": "notice-uwuzu",
"version": "v25.8.10@uwuzu1.6.4", "version": "v25.8.11@uwuzu1.6.4",
"tag": "v25.8.10", "tag": "v25.8.11",
"description": "Notice Bot for uwuzu", "description": "Notice Bot for uwuzu",
"main": "dist/main.js", "main": "dist/main.js",
"scripts": { "scripts": {
"start": "node .", "start": "node .",
"build": "tsc", "build": "tsc && tsc-alias",
"main": "tsc && node .",
"dev": "tsx main.ts", "dev": "tsx main.ts",
"clean": "tsc && node dist/scripts/clean/main.js" "clean": "npm run build && node dist/scripts/clean/main.js"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@@ -45,16 +44,21 @@
"@types/sharp": "^0.31.1", "@types/sharp": "^0.31.1",
"@types/ws": "^8.18.1", "@types/ws": "^8.18.1",
"canvas": "^3.2.0", "canvas": "^3.2.0",
"chardet": "^2.1.1",
"child_process": "^1.0.2", "child_process": "^1.0.2",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"esm-path": "git+https://gitea.last2014.com/last2014/esm-path.git#1.0.0",
"express": "^5.1.0", "express": "^5.1.0",
"fs": "^0.0.1-security", "fs": "^0.0.1-security",
"iconv-lite": "^0.7.0",
"node-cron": "^4.1.1", "node-cron": "^4.1.1",
"nodemailer": "^7.0.4", "nodemailer": "^7.0.4",
"sharp": "^0.34.3", "sharp": "^0.34.3",
"timers": "^0.1.1", "tsc-alias": "^1.8.16",
"typescript": "^5.9.2", "typescript": "^5.9.2",
"ws": "^8.18.3" "ws": "^8.18.3",
"yaml": "^2.8.2",
"zod": "^4.1.13"
}, },
"devDependencies": { "devDependencies": {
"tsx": "^4.20.3" "tsx": "^4.20.3"
+8 -16
View File
@@ -1,15 +1,7 @@
import express from "express"; import express from "express";
import * as os from "os"; import * as os from "os";
import config from "../config.js"; import config from "../config";
import { NetworkInterfaceDetails } from "types/types"; 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";
export default async function AdminPanel() { export default async function AdminPanel() {
// 無効 // 無効
@@ -22,12 +14,12 @@ export default async function AdminPanel() {
const port = config.admin.panel.port; const port = config.admin.panel.port;
// ルーティング // ルーティング
app.use(ueusePost); app.use((await import("./route/ueuse")).default);
app.use(CommandExecute); app.use((await import("./route/command")).default);
app.use(WeatherUeuse); app.use((await import("./route/weather")).default);
app.use(API); app.use((await import("./route/api")).default);
app.use(Token); app.use((await import("./route/token")).default);
app.use(Debug); app.use((await import("./route/debug")).default);
app.use(express.static("panel/public")); app.use(express.static("panel/public"));
app.listen(port, () => { app.listen(port, () => {
+1 -1
View File
@@ -1,7 +1,7 @@
import express from "express"; import express from "express";
const API = express.Router(); const API = express.Router();
import config from "../../config.js"; import config from "../../config";
API.use(express.json()); API.use(express.json());
API.use(express.urlencoded({ extended: true })); API.use(express.urlencoded({ extended: true }));
+1 -1
View File
@@ -1,7 +1,7 @@
import express from "express"; import express from "express";
const CommandExecute = express.Router(); const CommandExecute = express.Router();
import Commands from "../../scripts/commands/main.js"; import Commands from "@/scripts/commands/main";
CommandExecute.post("/actions/command-execute", (req, res) => { CommandExecute.post("/actions/command-execute", (req, res) => {
try { try {
+1 -1
View File
@@ -1,7 +1,7 @@
import express from "express"; import express from "express";
const Debug = express.Router(); const Debug = express.Router();
import config from "../../config.js"; import config from "../../config";
Debug.post("/actions/debug", (req, res, next) => { Debug.post("/actions/debug", (req, res, next) => {
res.status(501) res.status(501)
+1 -1
View File
@@ -1,7 +1,7 @@
import express from "express"; import express from "express";
const EventdayUeuse = express.Router(); const EventdayUeuse = express.Router();
import EventDays from "../../scripts/eventday.js"; import EventDays from "@/scripts/eventday";
EventdayUeuse.post("/actions/eventday", (req, res) => { EventdayUeuse.post("/actions/eventday", (req, res) => {
try { try {
+1 -1
View File
@@ -1,7 +1,7 @@
import express from "express"; import express from "express";
const Token = express.Router(); const Token = express.Router();
import config from "../../config.js"; import config from "../../config";
Token.post("/actions/token", (req, res, next) => { Token.post("/actions/token", (req, res, next) => {
res.status(501) res.status(501)
+1 -1
View File
@@ -1,7 +1,7 @@
import express from "express"; import express from "express";
const ueusePost = express.Router(); const ueusePost = express.Router();
import config from "../../config.js"; import config from "../../config";
ueusePost.use(express.json()); ueusePost.use(express.json());
ueusePost.use(express.urlencoded({ extended: true })); ueusePost.use(express.urlencoded({ extended: true }));
+1 -1
View File
@@ -1,7 +1,7 @@
import express from "express"; import express from "express";
const WeatherUeuse = express.Router(); const WeatherUeuse = express.Router();
import { weatherNotice } from "../../scripts/weatherNotice.js"; import { weatherNotice } from "@/scripts/weatherNotice";
WeatherUeuse.post("/actions/weather", (req, res) => { WeatherUeuse.post("/actions/weather", (req, res) => {
try { try {
-8
View File
@@ -1,8 +0,0 @@
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`);
}
-7
View File
@@ -1,7 +0,0 @@
import logsDelete from "./logsDel.js";
import packageLockJsonDelete from "./packageLockDel.js";
import npmInstall from "./npmInstall.js";
logsDelete();
packageLockJsonDelete();
npmInstall();
-7
View File
@@ -1,7 +0,0 @@
import { ueuse } from "types/types";
import { Reply } from "../main.js";
import config from "../../../config.js";
export default function PrivacyPolicy(data: ueuse) {
Reply(config.legal.privacy, data.uniqid);
}
-7
View File
@@ -1,7 +0,0 @@
import { ueuse } from "types/types";
import { Reply } from "../main.js";
import config from "../../../config.js";
export default function Terms(data: ueuse) {
Reply(config.legal.terms, data.uniqid);
}
-6
View File
@@ -1,6 +0,0 @@
import { weatherReply } from "../weatherNotice.js";
import { ueuse } from "types/types";
export default function Weather(data: ueuse) {
weatherReply(data.uniqid);
}
@@ -1,9 +1,4 @@
interface eventdaysValue { export default {
name: string;
message: string;
}
const eventdays = {
"01/01": { "01/01": {
name: "元日", name: "元日",
message: "はい年越した瞬間地球にいなかった~", message: "はい年越した瞬間地球にいなかった~",
@@ -65,6 +60,7 @@ const eventdays = {
name: "大晦日", name: "大晦日",
message: "大掃除!!大掃除!!", message: "大掃除!!大掃除!!",
}, },
} as { [key: string]: eventdaysValue }; } as { [key: string]: {
name: string;
export default eventdays; message: string;
} };
@@ -1,4 +1,4 @@
export const cityList: Array<String> = [ export const cityList = [
"016010", "016010",
"020010", "020010",
"030010", "030010",
+94
View File
@@ -0,0 +1,94 @@
import * as z from "zod/v3";
import { readFileSync } from "fs";
import { autoDecode } from "@/lib/encode";
import { getDirname } from "esm-path";
import * as yaml from "yaml";
const schema = z.object({
time: z.object({
stopTimes: z.object({
start: z.number().min(0).max(23),
stop: z.number().min(0).max(23),
}),
}),
earthquake: z.object({
reconnectTimes: z.number().min(0),
websocketUrl: z.string().url(),
areasCsvUrl: z.string().url(),
maxScaleMin: z.union([
z.literal(-1),
z.literal(10),
z.literal(20),
z.literal(30),
z.literal(40),
z.literal(45),
z.literal(50),
z.literal(55),
z.literal(60),
z.literal(70),
]), // z.enum()は文字列のみ(https://github.com/colinhacks/zod/issues/338)
}),
weather: z.object({
splitCount: z.number().min(1),
}),
miq: z.boolean(),
emergency: z.union([z.object({
isEnabled: z.literal(true),
mail: z.union([z.object({
isEnabled: z.literal(true),
host: z.string(),
port: z.number().min(0).max(65535),
user: z.string(),
password: z.string(),
secure: z.boolean(),
to: z.union([
z.string(),
z.array(z.string())
]),
}), z.object({
isEnabled: z.literal(false),
})]),
}), z.object({
isEnabled: z.literal(false),
})]),
report: z.union([z.object({
isEnabled: z.literal(true),
message: z.string(),
}), z.object({
isEnabled: z.literal(false),
})]),
legal: z.object({
terms: z.string(),
privacy: z.string(),
}),
admin: z.object({
name: z.string(),
showMail: z.union([
z.string(),
z.literal(false)
]),
panel: z.union([z.object({
isEnabled: z.literal(true),
port: z.number().min(0).max(65535),
}), z.object({
isEnabled: z.literal(false),
})]),
}),
uwuzu: z.object({
apiToken: z.string(),
host: z.string(),
}),
debug: z.literal(true).optional(),
});
const file = readFileSync(`${import.meta.dirname}/../../config/config.yaml`);
const text = autoDecode(file);
const configObj = yaml.parse(text);
const parsed = schema.safeParse(configObj);
if (!parsed.success) {
throw new Error("Config is invalid.")
}
const config = parsed.data;
export default config;
+7
View File
@@ -0,0 +1,7 @@
import { decode } from "iconv-lite";
import { detect } from "chardet";
export function autoDecode(buffer: Buffer) {
const encoding = detect(buffer) ?? "utf-8";
return decode(buffer, encoding);
}
+1 -1
View File
@@ -1,4 +1,4 @@
import config from "../config.js"; import config from "@/lib/config";
import * as nodemailer from "nodemailer"; import * as nodemailer from "nodemailer";
import type SMTPTransport from "nodemailer/lib/smtp-transport"; import type SMTPTransport from "nodemailer/lib/smtp-transport";
+8
View File
@@ -0,0 +1,8 @@
import * as fs from "fs";
const version = JSON.parse(fs.readFileSync(`${import.meta.dirname}/../../package.json`, "utf-8")).version;
export default function asciiArt() {
console.log(fs.readFileSync(`${import.meta.dirname}/../../asciiart.txt`, "utf-8"));
console.log(`${version}\n`);
}
+1 -1
View File
@@ -1,5 +1,5 @@
import { styleText } from "util"; import { styleText } from "util";
import config from "../config.js"; import config from "@/lib/config";
export default async function APICheck() { export default async function APICheck() {
try { try {
+9
View File
@@ -0,0 +1,9 @@
import * as fs from "fs";
import { styleText } from "util";
export default function ConfigCheck() {
if (!fs.existsSync(`${import.meta.dirname}/../../../config/config.yaml`)) {
console.log(styleText("red", "config/config.yamlがありません"));
process.exit();
}
}
@@ -1,4 +1,4 @@
import config from "../config.js"; import config from "@/lib/config";
import { styleText } from "util"; import { styleText } from "util";
export default function LegalCheck() { export default function LegalCheck() {
+18
View File
@@ -0,0 +1,18 @@
import PackagesIsExist from "@/scripts/checks/packagesExist";
import PackagesCheck from "@/scripts/checks/packages";
import ConfigCheck from "@/scripts/checks/config";
import APICheck from "@/scripts/checks/api";
import VersionCheck from "@/scripts/checks/version";
import LegalCheck from "@/scripts/checks/legal";
import config from "@/lib/config";
export default async function Check() {
PackagesIsExist();
PackagesCheck();
ConfigCheck();
if (config.debug === undefined) {
LegalCheck()
}
await APICheck();
await VersionCheck();
}
@@ -3,13 +3,13 @@ import { styleText } from "util";
export default function PackagesCheck() { export default function PackagesCheck() {
try { try {
if (!fs.existsSync("package.json")) { if (!fs.existsSync(`${import.meta.dirname}/../../../package.json`)) {
console.log(styleText("red", "package.jsonがありません。正規のリポジトリでgit pullを実行してください。")); console.log(styleText("red", "package.jsonがありません。正規のリポジトリでgit pullを実行してください。"));
process.exit(); process.exit();
} }
// package.json取得 // package.json取得
const packages = JSON.parse(fs.readFileSync("package.json", "utf-8")); const packages = JSON.parse(fs.readFileSync(`${import.meta.dirname}/../../../package.json`, "utf-8"));
const dependencies = packages.dependencies; const dependencies = packages.dependencies;
const packageNames: Array<string> = []; const packageNames: Array<string> = [];
@@ -31,7 +31,7 @@ export default function PackagesCheck() {
const mismatchPackages: Array<string> = []; const mismatchPackages: Array<string> = [];
packageNames.forEach((packageName) => { packageNames.forEach((packageName) => {
const packagePath = `node_modules/${packageName}/package.json`; const packagePath = `${import.meta.dirname}/../../../node_modules/${packageName}/package.json`;
if (fs.existsSync(packagePath)) { if (fs.existsSync(packagePath)) {
const modulePackage = JSON.parse(fs.readFileSync(packagePath, "utf-8")); const modulePackage = JSON.parse(fs.readFileSync(packagePath, "utf-8"));
@@ -3,7 +3,7 @@ import { styleText } from "util";
export default function PackagesIsExist() { export default function PackagesIsExist() {
try { try {
if (!fs.existsSync("node_modules/.package-lock.json")) { if (!fs.existsSync(`${import.meta.dirname}/../../../node_modules/.package-lock.json`)) {
console.log(styleText("red", ` console.log(styleText("red", `
node_modules/.package-lock.jsonがありません node_modules/.package-lock.jsonがありません
npm installを実行してください npm installを実行してください
@@ -1,25 +1,25 @@
import config from "../config.js"; import config from "@/lib/config";
import { readFileSync, writeFileSync, existsSync } from "fs"; import { readFileSync, writeFileSync, existsSync } from "fs";
export default async function VersionCheck() { export default async function VersionCheck() {
const packageJson = JSON.parse(readFileSync("package.json", "utf-8")); const packageJson = JSON.parse(readFileSync(`${import.meta.dirname}/../../../package.json`, "utf-8"));
// 初期化 // 初期化
if (!existsSync("logs/version.txt")) { if (!existsSync(`${import.meta.dirname}/../../../logs/version.txt`)) {
writeFileSync( writeFileSync(
"logs/version.txt", `${import.meta.dirname}/../../../logs/version.txt`,
packageJson.version, packageJson.version,
"utf-8", "utf-8",
); );
} }
// 最終起動バージョン取得 // 最終起動バージョン取得
const oldVersion = readFileSync("logs/version.txt", "utf-8"); const oldVersion = readFileSync(`${import.meta.dirname}/../../../logs/version.txt`, "utf-8");
if (oldVersion !== packageJson.version) { if (oldVersion !== packageJson.version) {
try { try {
writeFileSync( writeFileSync(
"logs/version.txt", `${import.meta.dirname}/../../../logs/version.txt`,
packageJson.version, packageJson.version,
"utf-8", "utf-8",
); );
@@ -4,8 +4,8 @@ export default function logsDelete() {
console.log("ログを削除中します"); console.log("ログを削除中します");
try { try {
unlinkSync("logs/boot.json"); unlinkSync(`${import.meta.dirname}/../../../logs/boot.json`);
unlinkSync("logs/version.txt"); unlinkSync(`${import.meta.dirname}/../../../logs/version.txt`);
console.log("ログファイルを削除しました"); console.log("ログファイルを削除しました");
console.log("----------------"); console.log("----------------");
+5
View File
@@ -0,0 +1,5 @@
(await import("@/scripts/clean/logsDel")).default();
(await import("@/scripts/clean/packageLockDel")).default();
(await import("@/scripts/clean/npmInstall")).default();
export {};
@@ -4,7 +4,7 @@ export default function packageLockJsonDelete() {
console.log("package-lock.jsonを削除します"); console.log("package-lock.jsonを削除します");
try { try {
unlinkSync("package-lock.json"); unlinkSync(`${import.meta.dirname}/../../../package-lock.json`);
console.log("package-lock.jsonを削除しました"); console.log("package-lock.jsonを削除しました");
console.log("----------------"); console.log("----------------");
@@ -1,6 +1,6 @@
import { meApi, ueuse } from "../../types/types"; import { meApi, ueuse } from "@/types/types";
import config from "../../config.js"; import config from "@/lib/config";
import { Reply } from "./main.js"; import { Reply } from "@/scripts/commands/main";
export default async function Delete(data: ueuse) { export default async function Delete(data: ueuse) {
const meReq = await fetch(`${config.uwuzu.host}/api/me/`, { const meReq = await fetch(`${config.uwuzu.host}/api/me/`, {
@@ -1,6 +1,6 @@
import { ueuse } from "types/types"; import { ueuse } from "@/types/types";
import config from "../../config.js"; import config from "@/lib/config";
import { Reply } from "./main.js"; import { Reply } from "@/scripts/commands/main";
export default async function Follow(data: ueuse) { export default async function Follow(data: ueuse) {
const followReq = await fetch(`${config.uwuzu.host}/api/users/follow`, { const followReq = await fetch(`${config.uwuzu.host}/api/users/follow`, {
@@ -1,6 +1,6 @@
import { ueuse } from "types/types"; import { ueuse } from "@/types/types";
import { readFileSync } from "fs"; import { readFileSync } from "fs";
import { Reply } from "./main.js"; import { Reply } from "@/scripts/commands/main";
const helpsMin = { const helpsMin = {
"info": "このBOTについての概要を返信するコマンドです。", "info": "このBOTについての概要を返信するコマンドです。",
@@ -1,10 +1,8 @@
import { ueuse } from "types/types"; import { ueuse } from "@/types/types";
import { readFileSync } from "fs"; import config from "@/lib/config";
import { Reply } from "./main.js";
import config from "../../config.js";
export default async function Info(data: ueuse) { 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}`; const releaseUrl = `${packageJson.repository.url}/releases/tag/${packageJson.tag}`;
let editor = ""; let editor = "";
@@ -29,7 +27,7 @@ export default async function Info(data: ueuse) {
isReport = "無効"; isReport = "無効";
} }
const ueuse = await Reply(` const ueuse = await (await import("@/scripts/commands/main")).Reply(`
BOTについて BOTについて
BOTはオープンソースソフトウェアであるnoticeUwuzuを利用して運営されています BOTはオープンソースソフトウェアであるnoticeUwuzuを利用して運営されています
noticeUwuzuはApache License 2.0 noticeUwuzuはApache License 2.0
+8
View File
@@ -0,0 +1,8 @@
import { ueuse } from "@/types/types";
export default async function PrivacyPolicy(data: ueuse) {
(await import("@/scripts/commands/main")).Reply(
(await import("@/lib/config")).default.legal.privacy,
data.uniqid
);
}
+8
View File
@@ -0,0 +1,8 @@
import { ueuse } from "@/types/types";
export default async function Terms(data: ueuse) {
(await import("@/scripts/commands/main")).Reply(
(await import("@/lib/config")).default.legal.terms,
data.uniqid
);
}
@@ -1,28 +1,12 @@
import * as fs from "fs"; import * as fs from "fs";
import config from "../../config.js"; import config from "@/lib/config";
import type { ueuse } from "types/types"; import type { ueuse } from "@/types/types";
const initialFile: Array<string> = [];
// コマンド読み込み
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";
// 初期化 // 初期化
if (!fs.existsSync("data/alreadyCommands.json")) { if (!fs.existsSync("data/alreadyCommands.json")) {
fs.writeFileSync( fs.writeFileSync(
"data/alreadyCommands.json", "data/alreadyCommands.json",
JSON.stringify(initialFile), JSON.stringify([]),
"utf-8", "utf-8",
); );
} }
@@ -162,40 +146,40 @@ export default async function Commands() {
switch (commandName) { switch (commandName) {
case "info": case "info":
Info(data); (await import("@/scripts/commands/info")).default(data);
break; break;
case "help": case "help":
Help(data); (await import("@/scripts/commands/help")).default(data);
break; break;
case "legal terms": case "legal terms":
Terms(data); (await import("@/scripts/commands/legal/terms")).default(data);
break; break;
case "legal privacy": case "legal privacy":
PrivacyPolicy(data); (await import("@/scripts/commands/legal/privacy")).default(data);
break; break;
case "report": case "report":
Report(data); (await import("@/scripts/commands/report")).default(data);
break; break;
case "follow": case "follow":
Follow(data); (await import("@/scripts/commands/follow")).default(data);
break; break;
case "unfollow": case "unfollow":
UnFollow(data); (await import("@/scripts/commands/unfollow")).default(data);
break; break;
case "weather": case "weather":
Weather(data); (await import("@/scripts/commands/weather")).default(data);
break; break;
case "miq": case "miq":
MakeItAQuote(data); (await import("@/scripts/commands/miq/main")).default(data);
break; break;
case "miq permission": case "miq permission":
MiQPermission(data); (await import("@/scripts/commands/miq/permission")).default(data);
break; break;
case "miq allow": case "miq allow":
MiQAllow(data); (await import("@/scripts/commands/miq/allow")).default(data);
break; break;
case "delete": case "delete":
Delete(data); (await import("@/scripts/commands/delete")).default(data);
break; break;
default: default:
const reply = await Reply(` const reply = await Reply(`
@@ -1,9 +1,8 @@
import { meApi, ueuse } from "../../../types/types"; import { meApi, ueuse } from "@/types/types";
import { readFileSync } from "fs"; import config from "@/lib/config";
import config from "../../../config.js"; import { Reply } from "@/scripts/commands/main";
import { Reply } from "../main.js"; import { Permission } from "@/scripts/commands/miq/permission";
import { Permission } from "./permission"; import MiQ from "miq/main";
import MiQ from "../../../miq/main.js";
export default async function MiQAllow(data: ueuse) { export default async function MiQAllow(data: ueuse) {
if (!config.miq) { if (!config.miq) {
@@ -22,7 +21,7 @@ export default async function MiQAllow(data: ueuse) {
// 権限一覧取得 // 権限一覧取得
const permissions: { [user: string]: Permission } = 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") { if (permissions[data.account.userid] !== "consent") {
console.log("MiQ許可制(許可制以外)", await Reply(` console.log("MiQ許可制(許可制以外)", await Reply(`
@@ -1,9 +1,7 @@
import { ueuse } from "../../../types/types"; import { ueuse } from "@/types/types";
import MiQ from "../../../miq/main.js"; import config from "@/lib/config";
import config from "../../../config.js"; import { Reply } from "@/scripts/commands/main";
import { Reply } from "../main.js"; import type { Permission } from "@/scripts/commands/miq/permission";
import { readFileSync, writeFileSync } from "fs";
import { Permission } from "./permission";
export default async function MakeItAQuote(data: ueuse) { export default async function MakeItAQuote(data: ueuse) {
if (!config.miq) { if (!config.miq) {
@@ -47,12 +45,12 @@ export default async function MakeItAQuote(data: ueuse) {
// 権限一覧取得 // 権限一覧取得
const permissions: { [user: string]: Permission } = 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) { if (permissions[ueuseData.account.userid] === undefined) {
permissions[ueuseData.account.userid] = "consent"; permissions[ueuseData.account.userid] = "consent";
writeFileSync( (await import("fs")).writeFileSync(
"data/miqPermissions.json", "data/miqPermissions.json",
JSON.stringify(permissions), JSON.stringify(permissions),
"utf-8" "utf-8"
@@ -70,7 +68,10 @@ export default async function MakeItAQuote(data: ueuse) {
return; return;
} }
if (permissions[ueuseData.account.userid] === "consent") { if (
permissions[ueuseData.account.userid] === "consent" &&
data.account.userid !== ueuseData.account.userid
) {
console.log("MiQ(許可制)", await Reply(` console.log("MiQ(許可制)", await Reply(`
稿 稿
Make it a Quoteを使用するには Make it a Quoteを使用するには
@@ -79,7 +80,7 @@ export default async function MakeItAQuote(data: ueuse) {
return; return;
} }
const img = await MiQ({ const img = await (await import("../../../../miq/main")).default({
type: "Base64Data", type: "Base64Data",
color: color, color: color,
text: ueuseData.text, text: ueuseData.text,
@@ -1,11 +1,10 @@
import { ueuse } from "../../../types/types"; import { ueuse } from "@/types/types";
import { Reply } from "../main.js"; import { Reply } from "@/scripts/commands/main";
import config from "../../../config.js"; import { writeFileSync } from "fs";
import { readFileSync, writeFileSync, existsSync } from "fs";
// 初期化 // 初期化
const initialFile = {}; const initialFile = {};
if (!existsSync("data/miqPermissions.json")) { if (!(await import("fs")).existsSync("data/miqPermissions.json")) {
writeFileSync( writeFileSync(
"data/miqPermissions.json", "data/miqPermissions.json",
JSON.stringify(initialFile), JSON.stringify(initialFile),
@@ -25,7 +24,7 @@ const PermissionsNames: { [name: string]: string } = {
} }
export default async function MiQPermission(data: ueuse) { export default async function MiQPermission(data: ueuse) {
if (!config.miq) { if (!(await import("../../../../config")).default.miq) {
await Reply(` await Reply(`
BOT管理者によってMake it a quoteが無効化されています BOT管理者によってMake it a quoteが無効化されています
\`/miq\`はご利用いただけません。 \`/miq\`はご利用いただけません。
@@ -34,7 +33,7 @@ export default async function MiQPermission(data: ueuse) {
} }
const permissions: { [user: string]: string } = 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) { if (permissions[data.account.userid] === undefined) {
@@ -1,7 +1,6 @@
import { ueuse } from "types/types"; import { ueuse } from "@/types/types";
import { Reply } from "./main.js"; import { Reply } from "@/scripts/commands/main";
import config from "../../config.js"; import config from "@/lib/config";
import sendMail from "../../src/mailer.js";
export default async function Report(data: ueuse) { export default async function Report(data: ueuse) {
if ( if (
@@ -40,7 +39,7 @@ export default async function Report(data: ueuse) {
} }
try { try {
sendMail({ (await import("@/lib/mailer")).default({
to: config.emergency.mail.to, to: config.emergency.mail.to,
subject: "【報告】BOT利用者からの報告", subject: "【報告】BOT利用者からの報告",
text: ` text: `
@@ -1,6 +1,6 @@
import { ueuse } from "types/types"; import { ueuse } from "@/types/types";
import config from "../../config.js"; import config from "@/lib/config";
import { Reply } from "./main.js"; import { Reply } from "@/scripts/commands/main";
export default async function UnFollow(data: ueuse) { export default async function UnFollow(data: ueuse) {
const unfollowReq = await fetch(`${config.uwuzu.host}/api/users/unfollow`, { const unfollowReq = await fetch(`${config.uwuzu.host}/api/users/unfollow`, {
+6
View File
@@ -0,0 +1,6 @@
import { weatherReply } from "@/scripts/weatherNotice";
import { ueuse } from "@/types/types";
export default function Weather(data: ueuse) {
weatherReply(data.uniqid);
}
@@ -1,7 +1,6 @@
import WebSocket from "ws"; import WebSocket from "ws";
import sendMail from "../src/mailer.js"; import sendMail from "@/lib/mailer";
import config from "@/lib/config";
import config from "../config.js";
class P2PEarthquakeClient { class P2PEarthquakeClient {
private ws: WebSocket | null = null; private ws: WebSocket | null = null;
@@ -284,7 +283,7 @@ async function event(earthquakeInfo: any): Promise<void> {
console.log("サーバーがダウンする可能性があります"); console.log("サーバーがダウンする可能性があります");
// メール送信 // メール送信
if (config.emergency.isEnabled) { if (config.emergency.mail.isEnabled) {
sendMail({ sendMail({
to: config.emergency.mail.to, to: config.emergency.mail.to,
subject: "【警告】震度6強以上の地震を受信しました", subject: "【警告】震度6強以上の地震を受信しました",
@@ -1,6 +1,6 @@
import { format } from "date-fns"; import { format } from "date-fns";
import eventdays from "./eventdayData.js"; import eventdays from "@/constants/eventday";
import config from "../config.js"; import config from "@/lib/config";
export default async function EventDays() { export default async function EventDays() {
const now = format(new Date(), "MM/dd"); const now = format(new Date(), "MM/dd");
@@ -1,8 +1,7 @@
import * as fs from "fs"; import * as fs from "fs";
import { isAfter } from "date-fns"; import { isAfter } from "date-fns";
import config from "@/lib/config";
import config from "../config.js"; import sendMail from "@/lib/mailer";
import sendMail from "../src/mailer.js";
export default function successExit() { export default function successExit() {
// 初期化 // 初期化
@@ -56,5 +55,3 @@ export default function successExit() {
fs.writeFileSync("logs/boot.json", JSON.stringify(iolog), "utf-8"); fs.writeFileSync("logs/boot.json", JSON.stringify(iolog), "utf-8");
}); });
} }
successExit();
@@ -1,7 +1,6 @@
import { format } from "date-fns"; import { format } from "date-fns";
import type * as types from "@/types/types";
import type * as types from "types/types"; import config from "@/lib/config";
import config from "../config.js";
export default async function timeNotice() { export default async function timeNotice() {
// 停止時間 // 停止時間
@@ -1,8 +1,6 @@
import { cityList } from "../src/weatherId.js"; import { cityList } from "@/constants/weather";
import type * as types from "@/types/types";
import type * as types from "types/types"; import config from "@/lib/config";
import config from "../config.js";
export async function weatherNotice() { export async function weatherNotice() {
console.log("----------------"); console.log("----------------");
+58
View File
@@ -0,0 +1,58 @@
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: {
isEnabled: true;
mail: {
isEnabled: true;
host: string;
port: number;
user: string;
password: string;
secure: boolean;
to: string | string[];
} | {
isEnabled: false;
};
} | {
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;
}
View File
View File
+8 -3
View File
@@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"target": "ES2024", "target": "ES2024",
"module": "ESNext", "module": "ESNext",
"moduleResolution": "node", "moduleResolution": "bundler",
"outDir": "./dist", "outDir": "./dist",
"esModuleInterop": true, "esModuleInterop": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
@@ -12,12 +12,17 @@
"baseUrl": "./", "baseUrl": "./",
"typeRoots": [ "typeRoots": [
"./node_modules/@types", "./node_modules/@types",
"./types" "./src/types"
], ],
"paths": { "paths": {
"@/*": ["./src/*"],
"miq": ["./miq/*"],
"ws": ["./node_modules/ws/index.js"], "ws": ["./node_modules/ws/index.js"],
"@types/ws": ["./node_modules/@types/ws/index.d.ts"] "@types/ws": ["./node_modules/@types/ws/index.d.ts"],
}, },
"removeComments": true, "removeComments": true,
}, },
"tsc-alias": {
"resolveFullPaths": true,
},
} }
-87
View File
@@ -1,87 +0,0 @@
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;
miq: boolean;
emergency: emergencyFullTypes | emergencyMinTypes;
report: reportTypes;
legal: legalTypes;
admin: adminTypes;
uwuzu: uwuzuTypes;
debug?: true;
}