From 13eb492cabfcc9e8e7469ed8d6aaf4b9928cbbe2 Mon Sep 17 00:00:00 2001 From: nin0 Date: Fri, 23 May 2025 19:23:53 -0400 Subject: [PATCH] fix duplicate bottos --- build.mjs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/build.mjs b/build.mjs index 779904a..7e4d332 100644 --- a/build.mjs +++ b/build.mjs @@ -1,5 +1,6 @@ import { build } from "esbuild"; import { spawn } from "child_process"; +import { execSync } from "child_process"; /** * @type {esbuild.Plugin} @@ -34,8 +35,23 @@ await build({ setInterval(() => {}, 100); if (process.argv.includes("start")) { - const proc = spawn("node", ["--env-file=.env", "dist/index.js"], { - stdio: "inherit" - }); + try { + execSync( + `ps aux | grep '[n]ode.*dist/index.js --i-am-apprev' | awk '{print $2}' | xargs -r kill -9`, + { stdio: "ignore" } + ); + } catch { + console.error( + "Failed to kill old bot. Duplicate instances may run.\nIf you are on Windows use WSL/Linux" + ); + } + const proc = spawn( + "node", + ["--env-file=.env", "dist/index.js", "--i-am-apprev"], + { + stdio: "inherit" + } + ); + proc.on("exit", (code) => process.exit(code)); proc.on("close", (code) => process.exit(code)); }