JaBa/dashboard/routes/guild-stats.js
JonnyBro b0deb2e447 v3.2.8
Статистика пользователя и сервера на сайте
Удалён лишний файл
Отключена комадна someone
Фикс currentURL в переменных страниц
Обновлена локализация
2022-01-13 18:55:13 +05:00

47 lines
No EOL
1.3 KiB
JavaScript

const express = require("express"),
utils = require("../utils"),
CheckAuth = require("../auth/CheckAuth"),
router = express.Router();
router.get("/:serverID", CheckAuth, async (req, res) => {
// 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,
translate: req.translate,
currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`
});
}
// Fetch guild informations
const membersData = await req.client.membersData.find({
guildID: guild.id
}).lean();
const leaderboards = {
money: utils.sortArrayOfObjects("money", membersData),
level: utils.sortArrayOfObjects("level", membersData)
};
for (const cat in leaderboards) {
const e = leaderboards[cat];
if (e.length > 10) e.length = 10;
}
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,
stats,
bot: req.client,
guildID: guild.id,
translate: req.translate,
currentURL: `${req.client.config.dashboard.baseURL}${req.originalUrl}`,
});
});
module.exports = router;