-
Notifications
You must be signed in to change notification settings - Fork 367
/
server.js
84 lines (72 loc) · 2.07 KB
/
server.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
const express = require("express");
const cors = require("cors");
const { version } = require("discord.js");
const os = require("systeminformation");
const { msToDuration, formatBytes } = require("./handlers/functions");
module.exports = async (client) => {
const app = express();
const port = process.env.PORT || 3000;
// Middleware
app.use(cors());
app.use(express.json());
app.use(
express.urlencoded({
extended: true,
})
);
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send("Something went wrong!");
});
app.get("/", (req, res) => {
res.send(`Hello World`);
});
app.get("/home", (req, res) => {
res.send(client.user);
});
app.get("/commands", (req, res) => {
function cmdData(cmd) {
return {
name: cmd.name,
description: cmd.description,
category: cmd.category,
};
}
const commands = {
mcommands: client.mcommands.map((cmd) => cmdData(cmd)),
mcategories: client.mcategories.map((cat) => cat),
scommands: client.commands.map((cmd) => cmdData(cmd)),
scategories: client.scategories.map((cat) => cat),
};
res.send(commands);
});
app.get("/about", async (req, res) => {
let memory = await os.mem();
let cpu = await os.cpu();
let options = {
guildsCount: client.guilds.cache.size,
usersCount: client.users.cache.size,
channelsCount: client.channels.cache.size,
uptime: msToDuration(client.uptime),
DJSVersion: `v${version}`,
NodeVersion: `${process.version}`,
ping: `${client.ws.ping}ms`,
cpu: cpu.brand,
ram: {
total: formatBytes(memory.total),
usage: formatBytes(memory.used),
},
};
res.send(options);
});
app.get("/contact", (req, res) => {
let options = {
user: client.user,
};
res.send(options);
});
app.listen(port, () => {
console.log(`Listening at http://localhost:${port}`);
});
};