-
Notifications
You must be signed in to change notification settings - Fork 506
/
Copy pathindex.js
171 lines (152 loc) · 5.04 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
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
import './config.js'
import { fetchLatestBaileysVersion } from '@adiwajshing/baileys'
import cfont from "cfonts";
import { spawn } from 'child_process';
import { createInterface } from "readline";
import { promises as fsPromises } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { sizeFormatter } from 'human-readable';
import axios from 'axios';
import os from 'os';
import path from 'path';
import moment from 'moment-timezone'
import fs from 'fs';
import yargs from "yargs";
import express from 'express';
import chalk from 'chalk';
let formatSize = sizeFormatter({
std: 'JEDEC',
decimalPlaces: '2',
keepTrailingZeroes: false,
render: (literal, symbol) => `${literal} ${symbol}B`
})
const {
say } = cfont
const {
tz } = moment
const app = express();
const port = process.env.PORT || 8082;
const time = tz('Africa/casablanca').format('HH:mm:ss');
const currentFilePath = new URL(import.meta.url).pathname;
const __dirname = dirname(fileURLToPath(import.meta.url))
let bot_ku = 'SILANA BOT'
say(bot_ku, {
font: "simpleBlock",
align: "center",
gradient: ["yellow", "cyan", "red"],
transitionGradient: 1,
})
say('by ' + info.nameown, {
font: "tiny",
align: "center",
colors: ["white"]
})
app.listen(port, () => {
console.log(chalk.green(`⚡ Port ${port} has opened`));
});
const folderPath = './tmp';
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath);
console.log(chalk.green('Folder tmp created successfully.'));
}
let isRunning = false;
const rl = createInterface(process.stdin, process.stdout)
async function start(file) {
if (isRunning) return;
isRunning = true;
const args = [join(dirname(currentFilePath), file), ...process.argv.slice(2)];
const p = spawn(process.argv[0], args, {
stdio: ['inherit', 'inherit', 'inherit', 'ipc'],
});
p.on("message", data => {
console.log(chalk.magenta("[ ✅ Accepted ]", data))
switch (data) {
case "reset":
p.process.kill()
isRunning = false
start.apply(this, arguments)
break
case "uptime":
p.send(process.uptime())
break
}
})
p.on("exit", (_, code) => {
isRunning = false
console.error("[❗] Exit with code :", code)
if (code !== 0) return start(file)
watchFile(args[0], () => {
unwatchFile(args[0])
start(file)
})
})
let opts = new Object(yargs(process.argv.slice(2)).exitProcess(false).parse())
if (!opts["test"])
if (!rl.listenerCount()) rl.on("line", line => {
p.emit("message", line.trim())
})
const packageJsonPath = join(dirname(currentFilePath), './package.json');
const pluginsFolder = join(dirname(currentFilePath), 'plugins');
const totalFoldersAndFiles = await getTotalFoldersAndFiles(pluginsFolder);
fs.readdir(pluginsFolder, async (err, files) => {
if (err) {
console.error(chalk.red(`Folder Plugins Error: ${err}`));
return;
}
try {
console.log(chalk.bgGreen(chalk.white(`Library Baileys Versi ${(await fetchLatestBaileysVersion()).version} Telah Terinstall`)));
} catch (e) {
console.error(chalk.bgRed(chalk.white('Baileys Library Not Installed')));
}
})
try {
const packageJsonData = await fsPromises.readFile(packageJsonPath, 'utf-8');
const packageJsonObj = JSON.parse(packageJsonData);
// let fitur = Object.values(plugins).filter(v => v.help ).map(v => v.help).flat(1)
const { data } = await axios.get('https://api.ipify.org')
const ramInGB = os.totalmem() / (1024 * 1024 * 1024);
const freeRamInGB = os.freemem() / (1024 * 1024 * 1024);
console.log(`╭──⎔ Dashboard System ⎔
┣ Name Bot: ${chalk.white(packageJsonObj.name)}
┣ Version: ${chalk.white(packageJsonObj.version)}
┣ Description: ${chalk.white(packageJsonObj.description)}
┣ Os: ${chalk.white(os.type())}
┣ Memory: ${chalk.white(freeRamInGB.toFixed(2) + ' / ' + ramInGB.toFixed(2))}
┣ IP: ${chalk.red(data)}
┣ Owner: ${chalk.white(global.info.nomerown)}
╰──⎔⎔
╭──⎔⎔ ${chalk.bgCyan(chalk.white('Bot Specifications'))} ⎔⎔
┣ Feature: ${chalk.white(totalFoldersAndFiles.files)} Feature
╰──⎔⎔
⎔──⎔⎔ Creator: ${chalk.bold.cyan('NOUREDDINE OUAFY')} ⎔⎔──⎔`)
} catch (err) {
console.error(chalk.red(`Can not read File package.json: ${err}`));
}
setInterval(() => {}, 1000);
}
function getTotalFoldersAndFiles(folderPath) {
return new Promise((resolve, reject) => {
fs.readdir(folderPath, (err, files) => {
if (err) {
reject(err);
} else {
let folders = 0;
let filesCount = 0;
files.forEach((file) => {
const filePath = join(folderPath, file);
if (fs.statSync(filePath).isDirectory()) {
folders++;
} else {
filesCount++;
}
});
resolve({ folders, files: filesCount });
}
});
});
}
/**
Memulai sistem
**/
start('main.js');