Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,52 @@ 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))

const startFallbackServer = (missing) => {
const port = Number(process.env.PORT) || 3000
console.error("Missing required bot files:", missing.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: missing
})
)
})
.listen(port, () => {
console.log(`Fallback server listening on port ${port}`)
})
}

const bootstrap = () => {
if (missingPaths.length > 0) {
startFallbackServer(missingPaths)
return
}

startBotRuntime()
}

const startBotRuntime = () => {
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
Expand Down Expand Up @@ -215,3 +248,7 @@ startSesi()
process.on('uncaughtException', function (err) {
console.log('Caught exception: ', err)
})

}

bootstrap()
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down