-
Notifications
You must be signed in to change notification settings - Fork 66
/
index.js
146 lines (143 loc) ยท 5.59 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
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
import express from "express";
import {
fileURLToPath
} from "url";
import {
dirname,
join,
basename
} from "path";
import {
createRequire
} from "module";
import {
createInterface
} from "readline";
import {
setupMaster,
fork
} from "cluster";
import {
watchFile,
unwatchFile
} from "fs";
import chalk from "chalk";
import os from "os";
import fs, {
promises as fsPromises,
readdirSync
} from "fs";
import cfonts from "cfonts";
import * as glob from "glob";
import terminalImage from "terminal-image";
console.log("๐พ Starting...");
const {
say
} = cfonts, rl = createInterface(process.stdin, process.stdout), __filename = fileURLToPath(import.meta.url), __dirname = dirname(__filename), require = createRequire(import.meta.url), {
name,
author
} = require(join(__dirname, "./package.json"));
say("Bot Whatsapp MD", {
font: "chrome",
align: "center",
gradient: ["blue", "green"]
});
const taylorImage = fs.readFileSync(join(__dirname, "images/robot.png"));
let isRunning = !1,
server = null;
async function start(file) {
const app = express(),
port = process.env.PORT || process.env.SERVER_PORT || 3e3,
htmlDir = join(__dirname, "html"),
sendHtml = (req, res, name) => res.sendFile(join(htmlDir, `${name}.html`));
if (app.get("/", (req, res) => sendHtml(0, res, "home")), app.get("/chat", (req, res) => sendHtml(0, res, "chat")), app.get("/game", (req, res) => sendHtml(0, res, "game")), app.get("/tools", (req, res) => sendHtml(0, res, "tools")), app.get("/music", (req, res) => sendHtml(0, res, "music")), server = app.listen(port, () => {
console.log(chalk.green(`๐ Port ${port} is open`));
}), server.on("error", error => {
"EADDRINUSE" === error.code ? (console.log(`Address localhost:${port} in use. Please retry when the port is available!`), server.close()) : console.error("Server error:", error);
}), isRunning) return;
isRunning = !0;
const args = [join(__dirname, file), ...process.argv.slice(2)];
say([process.argv[0], ...args].join(" "), {
font: "console",
align: "center",
gradient: ["red", "magenta"]
}), setupMaster({
exec: args[0],
args: args.slice(1)
});
const p = fork();
p.on("message", data => {
console.log("[โ
RECEIVED]", data), "reset" === data ? (p.process.kill(), isRunning = !1, start(file)) : "uptime" === data && p.send(process.uptime());
}), p.on("exit", (_, code) => {
isRunning = !1, console.error("[โ] Exited with code:", code), 0 !== code ? start(file) : watchFile(args[0], () => {
unwatchFile(args[0]), start(file);
});
});
const pluginsFolder = join(__dirname, "plugins");
try {
const {
fetchLatestBaileysVersion
} = await import("@whiskeysockets/baileys"), {
version
} = await fetchLatestBaileysVersion();
console.log(chalk.yellow(`๐ก Baileys library version ${version} is installed`));
} catch (e) {
console.error(chalk.red("โ Baileys library is not installed")), shutdownServer();
}
console.log(chalk.yellow(`๐ฅ๏ธ ${os.type()}, ${os.release()} - ${os.arch()}`));
const ramInGB = os.totalmem() / 1073741824;
console.log(chalk.yellow(`๐พ Total RAM: ${ramInGB.toFixed(2)} GB`));
const freeRamInGB = os.freemem() / 1073741824;
console.log(chalk.yellow(`๐ฝ Free RAM: ${freeRamInGB.toFixed(2)} GB`)), console.log(chalk.yellow("๐ Script by wudysoft"));
const packageJsonPath = join(__dirname, "./package.json");
try {
const packageJsonData = await fsPromises.readFile(packageJsonPath, "utf-8"),
packageJsonObj = JSON.parse(packageJsonData);
console.log(chalk.blue.bold("\n๐ฆ Package Information")), console.log(chalk.cyan(`Name: ${packageJsonObj.name}`)),
console.log(chalk.cyan(`Version: ${packageJsonObj.version}`)), console.log(chalk.cyan(`Description: ${packageJsonObj.description}`)),
console.log(chalk.cyan(`Author: ${packageJsonObj.author.name}`));
} catch (err) {
console.error(chalk.red(`โ Unable to read package.json: ${err}`)), shutdownServer();
}
const foldersInfo = getFoldersInfo(pluginsFolder);
console.log(chalk.blue.bold('\n๐ Folders in "plugins" folder and Total Files'));
foldersInfo.sort((a, b) => a.folder.localeCompare(b.folder));
const tableData = foldersInfo.map(({
folder,
files
}) => ({
Folder: folder.slice(0, 15).padEnd(15),
"Total Files": files.toString().slice(0, 10).padEnd(10)
}));
console.table(tableData, ["Folder", "Total Files"], ["color: yellow; background-color: blue; border-radius: 10px;", "color: green; background-color: yellow; border-radius: 10px;"]),
console.log(chalk.blue.bold("\nโฐ Current Time"));
const currentTime = new Date().toLocaleString();
console.log(chalk.cyan(`${currentTime}`)), say("Taylor-V2", {
font: "chrome",
align: "center",
gradient: ["blue", "green"]
}), console.log(await terminalImage.buffer(taylorImage, {
width: 60
})), say("Have fun, thanks for using this script.", {
font: "console",
align: "center",
gradient: ["blue", "green"]
}), setInterval(() => {}, 1e3);
}
function getFoldersInfo(folderPath) {
return glob.sync(join(folderPath, "*/")).map(folder => ({
folder: basename(folder),
files: getTotalFilesInFolder(folder)
}));
}
function getTotalFilesInFolder(folderPath) {
return readdirSync(folderPath).length;
}
function shutdownServer() {
console.error(chalk.red("โ Shutting down the server due to an error.")), server.close(() => {
console.log(chalk.red("๐ Server has been shut down.")), process.exit(1);
});
}
start("main.js");
const tmpDir = "./tmp";
fs.existsSync(tmpDir) || (fs.mkdirSync(tmpDir), console.log("[33m%s[0m", `๐ Created directory ${tmpDir}`));