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);
|
|
|
|
if (!guild || !req.userInfos.displayedGuilds || !req.userInfos.displayedGuilds.find((g) => g.id === req.params.serverID)) {
|
|
|
|
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({
|
|
|
|
guildID: guild.id
|
|
|
|
}).lean();
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const leaderboards = {
|
2022-01-13 18:55:13 +05:00
|
|
|
money: utils.sortArrayOfObjects("money", membersData),
|
|
|
|
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;
|