-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
180 lines (148 loc) · 4.95 KB
/
Copy pathindex.js
File metadata and controls
180 lines (148 loc) · 4.95 KB
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
172
173
174
175
176
177
178
179
180
//* Don't change this code if not destroy your files and don't steal it the code (by jonell Magallanes Project CC))
const express = require('express');
const fs = require('fs');
const { spawn } = require("child_process");
const chalk = require('chalk');
const path = require('path');
const axios = require("axios");
const app = express();
const PingMonitor = require('ping-monitor');
const pingOptions = {
website: `https://symmetrical-space-disco-7qqr95rrxqrfr6gv.github.dev/pf-signin?id=puzzled-hill-0jqv5pn&cluster=asse&name=symmetrical-space-disco-7qqr95rrxqrfr6gv&port=8080&pb=https%3A%2F%2Fsymmetrical-space-disco-7qqr95rrxqrfr6gv-8080.app.github.dev%2Fauth%2Fpostback%2Ftunnel%3Ftunnel%3D1&cid=1416fadb-5ede-497b-8852-81a221ce80f4`,
title: 'EDUCATIONAL BOT 4.0V',
interval: 1 // minutes
};
// Create a new Ping Monitor instance
const monitor = new PingMonitor(pingOptions);
monitor.on('up', (res) => {
const pingTime = res.ping ? `${res.ping}ms` : 'N/A';
console.log(chalk.green.bold(`${res.website} is UP. Ping Time: ${pingTime}`));
});
monitor.on('down', (res) => {
console.log(chalk.red.bold(`${res.website} is DOWN. Status Message: ${res.statusMessage}`));
});
monitor.on('error', (error) => {
console.log(chalk.red(`An error has occurred: ${error}`));
});
setInterval(() => {
if (monitor.isRunning()) {
console.log(chalk.green.bold('Uptime notification: The website is running smoothly.'));
} else {
console.log(chalk.red.bold('Uptime notification: The website is currently down.'));
}
}, 3600000); // 60 minutes * 60 seconds * 1000 milliseconds
monitor.on('stop', (website) => {
console.log(`${website} monitor has stopped.`);
});
monitor.start();
function ping(targetUrl) {
const startPingTime = Date.now();
axios.get(targetUrl)
.then(() => {
const latency = Date.now() - startPingTime;
console.log(`Ping to ${targetUrl}: ${latency}ms`);
})
.catch((error) => {
console.error(`Error pinging ${targetUrl}: ${error.message}`);
});
}
// Example usage:
setInterval(() => {
ping(`https://symmetrical-space-disco-7qqr95rrxqrfr6gv.github.dev/pf-signin?id=puzzled-hill-0jqv5pn&cluster=asse&name=symmetrical-space-disco-7qqr95rrxqrfr6gv&port=8080&pb=https%3A%2F%2Fsymmetrical-space-disco-7qqr95rrxqrfr6gv-8080.app.github.dev%2Fauth%2Fpostback%2Ftunnel%3Ftunnel%3D1&cid=1416fadb-5ede-497b-8852-81a221ce80f4`);
}, 30000);
const config = require('./config.json');
const commandsPath = './script/commands';
const eventsPath = './script/events';
const getFilesCount = (dirPath) => {
try {
return fs.readdirSync(dirPath).length;
} catch (e) {
return 0;
}
};
let startPingTime = Date.now();
let botStartTime = Date.now();
async function getBotInformation() {
return {
owner: {
name: config.BOTOWNER,
uid: config.ADMINUID,
},
bot: {
name: config.BOTNAME,
uid: config.ADMINUID,
fmd: config.FCA,
repl: config.REPL,
lang: config.language,
ping: Date.now() - startPingTime,
},
fca: {
module: config.FCA,
}
};
}
function sendLiveData(socket) {
setInterval(() => {
const uptime = Date.now() - botStartTime;
socket.emit('real-time-data', { uptime });
}, 1000);
}
app.get('/dashboard', async (req, res) => {
const commandsCount = getFilesCount(commandsPath);
const eventsCount = getFilesCount(eventsPath);
const uptime = Date.now() - botStartTime;
const botInformation = await getBotInformation();
res.json({
botPing:
botInformation.bot.ping,
botLang:
botInformation.bot.lang,
botRepl:
botInformation.bot.repl,
botFmd:
botInformation.bot.fmd,
botName: botInformation.bot.name,
botUid: botInformation.bot.uid,
ownerName: botInformation.owner.name,
ownerUid: botInformation.owner.uid,
prefix: config.PREFIX,
commandsCount: commandsCount,
eventsCount: eventsCount,
uptime: uptime
});
});
app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'harold.html')));
const http = require('http');
const { Server } = require("socket.io");
const httpServer = http.createServer(app);
const io = new Server(httpServer);
io.on('connection', (socket) => {
console.log('New client connected');
sendLiveData(socket);
socket.on('disconnect', () => {
console.log('Client disconnected');
});
});
function startBot() {
const child = spawn("node", ["--trace-warnings", "--async-stack-traces", "jonell.js"], {
cwd: __dirname,
stdio: "inherit",
shell: true
});
child.on("close", (codeExit) => {
console.log(`Bot process exited with code: ${codeExit}`);
if (codeExit !== 0) {
setTimeout(startBot, 3000);
}
});
child.on("error", (error) => {
console.error(`An error occurred starting the bot: ${error}`);
});
}
startBot();
const port = process.env.PORT || 8080;
httpServer.listen(port, () => {
console.log(`Server with real-time updates running on http://localhost:${port}`);
});
module.exports = app;
//Modified by Jonell Magallanes