Покрасивше сделал

This commit is contained in:
JonnyBro 2022-01-06 20:31:57 +05:00
parent e444c8bd0c
commit feae708948

View file

@ -21,7 +21,7 @@ class Leaderboard extends Command {
const isOnlyOnMobile = (message.member.presence.clientStatus ? JSON.stringify(Object.keys(message.member.presence.clientStatus)) === JSON.stringify(["mobile"]) : false); const isOnlyOnMobile = (message.member.presence.clientStatus ? JSON.stringify(Object.keys(message.member.presence.clientStatus)) === JSON.stringify(["mobile"]) : false);
const type = args[0]; const type = args[0];
if (!type || (type !== "credits" && type !== "level" && type !== "rep")) return message.error("economy/leaderboard:MISSING_TYPE"); if (!type || !["credits", "level", "rep"].includes(type)) return message.error("economy/leaderboard:MISSING_TYPE");
if (type === "credits") { if (type === "credits") {
const members = await this.client.membersData.find({ const members = await this.client.membersData.find({
@ -33,12 +33,15 @@ class Leaderboard extends Command {
value: m.money + m.bankSold value: m.money + m.bankSold
}; };
}).sort((a, b) => b.value - a.value); }).sort((a, b) => b.value - a.value);
const table = new AsciiTable("Таблица лидеров"); const table = new AsciiTable("Таблица лидеров");
table.setHeading("#", message.translate("common:USER"), message.translate("common:CREDITS")); table.setHeading("#", message.translate("common:USER"), message.translate("common:CREDITS"));
if (membersLeaderboard.length > 20) membersLeaderboard.length = 20; if (membersLeaderboard.length > 20) membersLeaderboard.length = 20;
const newTable = await fetchUsers(membersLeaderboard, table, this.client); const newTable = await fetchUsers(membersLeaderboard, table, this.client);
message.channel.send({ message.channel.send({
content: `\`\`\`\n${newTable.toString()}\`\`\`` content: "```\n" + newTable.toString() + "```"
}); });
} else if (type === "level") { } else if (type === "level") {
const members = await this.client.membersData.find({ const members = await this.client.membersData.find({
@ -50,18 +53,19 @@ class Leaderboard extends Command {
value: m.level value: m.level
}; };
}).sort((a, b) => b.value - a.value); }).sort((a, b) => b.value - a.value);
const table = new AsciiTable("Таблица лидеров"); const table = new AsciiTable("Таблица лидеров");
table.setHeading("#", message.translate("common:USER"), message.translate("common:LEVEL")); table.setHeading("#", message.translate("common:USER"), message.translate("common:LEVEL"));
if (membersLeaderboard.length > 20) membersLeaderboard.length = 20; if (membersLeaderboard.length > 20) membersLeaderboard.length = 20;
const newTable = await fetchUsers(membersLeaderboard, table, this.client); const newTable = await fetchUsers(membersLeaderboard, table, this.client);
message.channel.send({ message.channel.send({
content: `\`\`\`\n${newTable.toString()}\`\`\`` content: "```\n" + newTable.toString() + "```"
}); });
} else if (type === "rep") { } else if (type === "rep") {
const users = await this.client.usersData.find({ const users = await this.client.usersData.find({
rep: { rep: { $gt: 0 }
$gt: 0
}
}).lean(), }).lean(),
usersLeaderboard = users.map((u) => { usersLeaderboard = users.map((u) => {
return { return {
@ -69,12 +73,15 @@ class Leaderboard extends Command {
value: u.rep value: u.rep
}; };
}).sort((a, b) => b.value - a.value); }).sort((a, b) => b.value - a.value);
const table = new AsciiTable("Таблица лидеров"); const table = new AsciiTable("Таблица лидеров");
table.setHeading("#", message.translate("common:USER"), message.translate("common:POINTS")); table.setHeading("#", message.translate("common:USER"), message.translate("common:POINTS"));
if (usersLeaderboard.length > 20) usersLeaderboard.length = 20; if (usersLeaderboard.length > 20) usersLeaderboard.length = 20;
const newTable = await fetchUsers(usersLeaderboard, table, this.client); const newTable = await fetchUsers(usersLeaderboard, table, this.client);
message.channel.send({ message.channel.send({
content: `\`\`\`\n${newTable.toString()}\`\`\`` content: "```\n" + newTable.toString() + "```"
}); });
}; };