forked from ERLANRAHMAT/BETABOTZ-MD2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
111 lines (92 loc) · 3.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const http = require('http');
const os = require('os');
const port = 3000; //custom ports here
const server = http.createServer();
console.log('\x1b[33m%s\x1b[0m', `🌐 Port ${port} is open`);
server.on('request', (req, res) => {
if (req.url === '/') {
res.writeHead(200, {'Content-Type': 'application/json'});
const data = {
status: 'true',
message: 'Welcome User👋',
author: 'BOTCAHX'
};
const result = {
response: data
};
res.end(JSON.stringify(result, null, 2));
}
});
server.listen(port);
cluster = require("cluster");
const { spawn } = require("child_process");
const path = require("path");
const fs = require("fs");
let isRunning = false;
function start(file) {
if (isRunning) return;
isRunning = true;
const args = [path.join(__dirname, file), ...process.argv.slice(2)];
const p = spawn(process.argv[0], args, {
stdio: ["inherit", "inherit", "inherit", "ipc"],
});
p.on("message", (data) => {
console.log('\x1b[36m%s\x1b[0m', `🟢 RECEIVED ${data}`);
switch (data) {
case "reset":
p.kill();
isRunning = false;
start.apply(this, arguments);
break;
case "uptime":
p.send(process.uptime());
break;
}
});
p.on("exit", (code) => {
isRunning = false;
console.error('\x1b[31m%s\x1b[0m', `Exited with code: ${code}`);
if (code === 0) return;
fs.watchFile(args[0], () => {
fs.unwatchFile(args[0]);
start("main.js");
});
});
p.on("error", (err) => {
console.error('\x1b[31m%s\x1b[0m', `Error: ${err}`);
p.kill();
isRunning = false;
start("main.js");
});
const pluginsFolder = path.join(__dirname, "plugins");
fs.readdir(pluginsFolder, (err, files) => {
if (err) {
console.error('\x1b[31m%s\x1b[0m', `Error reading plugins folder: ${err}`);
return;
}
console.log('\x1b[33m%s\x1b[0m', `🟡 Found ${files.length} plugins in folder ${pluginsFolder}`);
try {
require.resolve('@adiwajshing/baileys');
console.log('\x1b[33m%s\x1b[0m', `🟡 Baileys library version ${require('@adiwajshing/baileys/package.json').version} is installed`);
} catch (e) {
console.error('\x1b[31m%s\x1b[0m', `❌ Baileys library is not installed`);
}
});
console.log(`🖥️ \x1b[33m${os.type()}\x1b[0m, \x1b[33m${os.release()}\x1b[0m - \x1b[33m${os.arch()}\x1b[0m`);
const ramInGB = os.totalmem() / (1024 * 1024 * 1024);
console.log(`💾 \x1b[33mTotal RAM: ${ramInGB.toFixed(2)} GB\x1b[0m`);
const freeRamInGB = os.freemem() / (1024 * 1024 * 1024);
console.log(`💽 \x1b[33mFree RAM: ${freeRamInGB.toFixed(2)} GB\x1b[0m`);
console.log('\x1b[33m%s\x1b[0m', `📃 Script by BOTCAHX`);
setInterval(() => {}, 1000);
}
start("main.js");
process.on('unhandledRejection', () => {
console.error('\x1b[31m%s\x1b[0m', 'Unhandled promise rejection. Script will restart...');
start('main.js');
});
process.on('exit', (code) => {
console.error(`Exited with code: ${code}`);
console.error('Script will restart...');
start('main.js');
});