forked from Tanmyname/Shizuka-V1.2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.js
171 lines (147 loc) Β· 5.04 KB
/
system.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
const cluster = require('cluster');
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const os = require('os');
const express = require('express');
const app = express();
// Variabel untuk mengontrol status running
let isRunning = false;
// Express.js
const ports = [4000, 3000, 5000, 8000, 8080];
let availablePortIndex = 0;
function checkPort(port) {
return new Promise((resolve, reject) => {
const server = app.listen(port, () => {
server.close();
resolve(true);
});
server.on('error', reject);
});
}
async function startServer() {
const port = ports[availablePortIndex];
const isPortAvailable = await checkPort(port);
if (isPortAvailable) {
console.log('\x1b[33m%s\x1b[0m', `π Port ${port} is open`);
app.get('/', (req, res) => {
res.setHeader('Content-Type', 'application/json');
const data = {
status: 'true',
message: 'Bot Successfully Activated!',
author: 'FERNAZER CODE'
};
const result = {
response: data
};
res.send(JSON.stringify(result, null, 2));
});
} else {
console.log(`Port ${port} is already in use. Trying another port...`);
availablePortIndex++;
if (availablePortIndex >= ports.length) {
console.log('No more available ports. Exiting...');
process.exit(1);
} else {
ports[availablePortIndex] = parseInt(port) + 1;
startServer();
}
}
}
function displayRunningText() {
const runningText = "π Running Shizuka V1.2 π";
const colors = ['\x1b[32m', '\x1b[34m', '\x1b[31m']; // Hijau, Biru, Merah
let colorIndex = 0;
const termWidth = process.stdout.columns || 80; // Lebar terminal
const padding = Math.max(0, (termWidth - runningText.length) / 2);
const centeredText = ' '.repeat(Math.floor(padding)) + runningText;
const interval = setInterval(() => {
process.stdout.write(`${colors[colorIndex]}${centeredText}\x1b[0m\r`);
colorIndex = (colorIndex + 1) % colors.length;
}, 333); // Ganti warna setiap 333ms
setTimeout(() => {
clearInterval(interval);
console.log(`\n${centeredText}`);
}, 3000); // Tampilkan selama 3 detik
}
function start(file) {
if (isRunning) return;
isRunning = true;
console.clear();
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}`);
start('index.js');
if (code === 0) return;
fs.watchFile(args[0], () => {
fs.unwatchFile(args[0]);
console.error('\x1b[31m%s\x1b[0m', `File ${args[0]} has been modified. Script will restart...`);
start("index.js");
});
});
p.on("error", (err) => {
console.error('\x1b[31m%s\x1b[0m', `Error: ${err}`);
p.kill();
isRunning = false;
console.error('\x1b[31m%s\x1b[0m', `Error occurred. Script will restart...`);
start("index.js");
});
const pluginsFolder = path.join(__dirname, "node_modules");
fs.readdir(pluginsFolder, (err, files) => {
if (err) {
console.error('\x1b[31m%s\x1b[0m', `Error reading verifikasi folder: ${err}`);
return;
}
//console.log('\x1b[33m%s\x1b[0m', `π‘ Found ${files.length} verifikasi in folder ${pluginsFolder}`);
try {
require.resolve('@whiskeysockets/baileys');
// console.log('\x1b[33m%s\x1b[0m', `π‘ Baileys library version ${require('@whiskeysockets/baileys/package.json').version} is installed`);
} catch (e) {
console.error('\x1b[31m%s\x1b[0m', `β Baileys library is not installed`);
}
});
console.log('\x1b[33m%s\x1b[0m', `π Shizuka V1.2 `);
console.log('\x1b[33m%s\x1b[0m', `π Github :Tanmyname `);
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', `π Creator @Tan `);
const tmpDir = './tmp';
if (!fs.existsSync(tmpDir)) {
fs.mkdirSync(tmpDir);
console.log('\x1b[33m%s\x1b[0m', `π Created directory ${tmpDir}`);
}
setInterval(() => {}, 1000);
}
displayRunningText();
setTimeout(() => {
start("index.js");
}, 3000);
process.on('unhandledRejection', (reason) => {
console.error('\x1b[31m%s\x1b[0m', `Unhandled promise rejection: ${reason}`);
console.error('\x1b[31m%s\x1b[0m', 'Unhandled promise rejection. Script will restart...');
start('index.js');
});
process.on('exit', (code) => {
console.error(`Exited with code: ${code}`);
console.error('Script will restart...');
start('index.js');
});