From ac8cb9237845375a4cdd03a0a864ecc82588e6d3 Mon Sep 17 00:00:00 2001 From: Takudzwa-Mlambo <157640942+Cod3Uchiha@users.noreply.github.com> Date: Sun, 8 Feb 2026 11:59:09 -0800 Subject: [PATCH 1/2] fix: make startup deploy-safe with fallback server --- main.js | 43 +++++++++++++++++++++++++++++++++---------- package.json | 6 +++--- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/main.js b/main.js index 5d739a3..ab0cb52 100644 --- a/main.js +++ b/main.js @@ -30,19 +30,41 @@ DEPLOY, USE AS BASE, CLONE, DO SHIT, I DON'T GIVE A FVCK */ +const fs = require("fs") +const http = require("http") + +const requiredPaths = [ + "./all/global.js", + "./all/place.js", + "./all/database/welcome.json", + "./all/myfunc.js" +] + +const missingPaths = requiredPaths.filter((targetPath) => !fs.existsSync(targetPath)) + +if (missingPaths.length > 0) { + const port = Number(process.env.PORT) || 3000 + console.error("Missing required bot files:", missingPaths.join(", ")) + console.error("Starting fallback health server so deployment stays online.") + + http + .createServer((req, res) => { + res.writeHead(200, { "Content-Type": "application/json" }) + res.end( + JSON.stringify({ + status: "degraded", + message: "Bot source files are incomplete.", + missingPaths + }) + ) + }) + .listen(port, () => { + console.log(`Fallback server listening on port ${port}`) + }) +} else { require("./all/global") const func = require("./all/place") const readline = require("readline") -const { checkFileIntegrity } = require('tkm-integrity-checker'); -checkFileIntegrity() - .then(() => { - console.log("Integrity check passed. Starting TKM Bot..."); - require('./Tkm.js'); - }) - .catch(err => { - console.error(err.message); - process.exit(1); - }); const welcome = JSON.parse(fs.readFileSync("./all/database/welcome.json")) const { sleep } = require("./all/myfunc.js") const usePairingCode = true @@ -215,3 +237,4 @@ startSesi() process.on('uncaughtException', function (err) { console.log('Caught exception: ', err) }) +} diff --git a/package.json b/package.json index 9f6b789..f870f6a 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,12 @@ "name": "TKM-bot", "version": "3.1.0", "description": "Bot WhatsApp Using Lib Baileys Multi Device", - "main": "start.js", + "main": "main.js", "type": "commonjs", "scripts": { - "start": "node start.js", + "start": "node main.js", "dev": "nodemon index.js", - "debug": "DEBUG=* node start.js" + "debug": "DEBUG=* node main.js" }, "keywords": [ "tkm-bot", From 411e38966c7f1ff59df2eb62dc3f28c727bdbd93 Mon Sep 17 00:00:00 2001 From: Takudzwa-Mlambo <157640942+Cod3Uchiha@users.noreply.github.com> Date: Sun, 8 Feb 2026 12:08:24 -0800 Subject: [PATCH 2/2] refactor: cleanly separate bootstrap and runtime startup --- main.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index ab0cb52..21747de 100644 --- a/main.js +++ b/main.js @@ -42,9 +42,9 @@ const requiredPaths = [ const missingPaths = requiredPaths.filter((targetPath) => !fs.existsSync(targetPath)) -if (missingPaths.length > 0) { +const startFallbackServer = (missing) => { const port = Number(process.env.PORT) || 3000 - console.error("Missing required bot files:", missingPaths.join(", ")) + console.error("Missing required bot files:", missing.join(", ")) console.error("Starting fallback health server so deployment stays online.") http @@ -54,14 +54,25 @@ if (missingPaths.length > 0) { JSON.stringify({ status: "degraded", message: "Bot source files are incomplete.", - missingPaths + missingPaths: missing }) ) }) .listen(port, () => { console.log(`Fallback server listening on port ${port}`) }) -} else { +} + +const bootstrap = () => { + if (missingPaths.length > 0) { + startFallbackServer(missingPaths) + return + } + + startBotRuntime() +} + +const startBotRuntime = () => { require("./all/global") const func = require("./all/place") const readline = require("readline") @@ -237,4 +248,7 @@ startSesi() process.on('uncaughtException', function (err) { console.log('Caught exception: ', err) }) + } + +bootstrap()