Skip to content

Commit

Permalink
bun is too fast for pm2 :derp:
Browse files Browse the repository at this point in the history
  • Loading branch information
TiltedToast committed Feb 2, 2024
1 parent 6aab8b8 commit c6f9910
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 7 additions & 5 deletions src/commands/miscellaneous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
9 changes: 5 additions & 4 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit c6f9910

Please sign in to comment.