diff --git a/src/app.ts b/src/app.ts index d4616aa..74f3bb3 100644 --- a/src/app.ts +++ b/src/app.ts @@ -7,7 +7,7 @@ import { TextChannel, } from "discord.js"; import "dotenv/config"; -import { existsSync, rmSync } from "node:fs"; +import { exists, rm } from "node:fs/promises"; import strftime from "strftime"; import { avoidDbSleeping, startStatusLoop } from "./commands/loops.ts"; import { LOG_CHANNEL } from "./config.ts"; @@ -64,7 +64,7 @@ client.once("ready", async () => { // startCatFactLoop(catFactChannel); if (isDev()) return; - if (existsSync("./temp/update.txt")) return rmSync("./temp/update.txt"); + if (await exists("./temp/update.txt")) return await rm("./temp/update.txt"); await logChannel.send(dedent` Logged in as: diff --git a/src/commands/miscellaneous.ts b/src/commands/miscellaneous.ts index ab83375..b8d7830 100644 --- a/src/commands/miscellaneous.ts +++ b/src/commands/miscellaneous.ts @@ -272,8 +272,8 @@ export async function cmdConsole(message: Message, cmd?: string, python = false) const command = cmd ? cmd : python - ? `${pythonCmd} -c "print(${input.replaceAll('"', '\\"')})"` - : input; + ? `${pythonCmd} -c "print(${input.replaceAll('"', '\\"')})"` + : input; try { const { stdout, stderr } = await execPromise(command); if (stderr) await message.channel.send(codeBlock(stderr)); @@ -289,9 +289,10 @@ export async function cmdConsole(message: Message, cmd?: string, python = false) export async function reloadBot(message: Message) { if (!isBotOwner(message.author)) return; - writeUpdateFile(); - exec("pnpm run restart"); + await writeUpdateFile(); + exec("bun run restart"); await message.channel.send("Reload successful!"); + process.exit(0); } export async function calc(message: Message) { @@ -610,5 +611,6 @@ export async function bye(message: Message) { // Closes the MongoDB connection and stops the running daemon via pm2 await message.channel.send("Bai baaaaaaaai!!"); await client.destroy(); - exec("pm2 delete hifumi"); + exec("bun run stop"); + process.exit(0); } diff --git a/src/helpers/utils.ts b/src/helpers/utils.ts index 649a408..1fad57c 100644 --- a/src/helpers/utils.ts +++ b/src/helpers/utils.ts @@ -13,6 +13,7 @@ import { } from "discord.js"; import gifsicle from "gifsicle"; import { existsSync, mkdirSync, rmSync, statSync, writeFileSync } from "node:fs"; +import { exists, mkdir, writeFile } from "node:fs/promises"; import { resolve } from "node:path"; import sharp from "sharp"; import strftime from "strftime"; @@ -105,11 +106,11 @@ export function splitMessage(content: string, maxLength = 2000, delim = " "): st return chunks; } -export function writeUpdateFile() { - if (!existsSync("./temp")) { - mkdirSync("./temp"); +export async function writeUpdateFile() { + if (!(await exists("./temp"))) { + await mkdir("./temp"); } - writeFileSync("./temp/update.txt", Date.now().toString()); + await writeFile("./temp/update.txt", Date.now().toString()); } function getEmbedIndex(arr: EmbedMetadata[], target: EmbedMetadata): number {