noticeUwuzu/checks/version.ts

45 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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