noticeUwuzu/checks/version.ts

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