2022-01-04 02:18:28 +05:00
|
|
|
const express = require("express"),
|
|
|
|
utils = require("../utils"),
|
|
|
|
CheckAuth = require("../auth/CheckAuth"),
|
2022-01-13 18:55:13 +05:00
|
|
|
router = express.Router();
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-01-13 18:55:13 +05:00
|
|
|
router.get("/:serverID", CheckAuth, async (req, res) => {
|
2022-01-04 02:18:28 +05:00
|
|
|
// Check if the user has the permissions to edit this guild
|
|
|
|
const guild = req.client.guilds.cache.get(req.params.serverID);
|
2022-01-13 21:44:19 +05:00
|
|
|
if (!guild) {
|
2022-01-04 02:18:28 +05:00
|
|
|
return res.render("404", {
|
|
|
|
user: req.userInfos,
|
2022-01-13 18:55:13 +05:00
|
|
|
translate: req.translate,
|
|
|
|
currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
// Fetch guild informations
|
2022-01-13 18:55:13 +05:00
|
|
|
const membersData = await req.client.membersData.find({
|
2022-01-13 21:37:24 +05:00
|
|
|
guildID: guild.id
|
|
|
|
}).lean(),
|
|
|
|
members = membersData.map((m) => {
|
|
|
|
return {
|
|
|
|
id: m.id,
|
|
|
|
money: m.money + m.bankSold
|
|
|
|
};
|
|
|
|
}).sort((a, b) => b.money - a.money);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const leaderboards = {
|
2022-01-13 21:37:24 +05:00
|
|
|
money: members,
|
2022-01-13 18:55:13 +05:00
|
|
|
level: utils.sortArrayOfObjects("level", membersData)
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
for (const cat in leaderboards) {
|
|
|
|
const e = leaderboards[cat];
|
|
|
|
if (e.length > 10) e.length = 10;
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const stats = {
|
|
|
|
money: await utils.fetchUsers(leaderboards.money, req.client),
|
|
|
|
level: await utils.fetchUsers(leaderboards.level, req.client)
|
|
|
|
};
|
|
|
|
|
|
|
|
res.render("stats/guild", {
|
|
|
|
user: req.userInfos,
|
2022-01-13 18:55:13 +05:00
|
|
|
stats,
|
|
|
|
bot: req.client,
|
|
|
|
guildID: guild.id,
|
|
|
|
translate: req.translate,
|
|
|
|
currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`,
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-01-13 18:55:13 +05:00
|
|
|
module.exports = router;
|