From feae7089487007e835dbe94f8899d8ede7999389 Mon Sep 17 00:00:00 2001 From: JonnyBro Date: Thu, 6 Jan 2022 20:31:57 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BA=D1=80=D0=B0=D1=81=D0=B8?= =?UTF-8?q?=D0=B2=D1=88=D0=B5=20=D1=81=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/Economy/leaderboard.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/commands/Economy/leaderboard.js b/commands/Economy/leaderboard.js index 298786d8..90f42786 100644 --- a/commands/Economy/leaderboard.js +++ b/commands/Economy/leaderboard.js @@ -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 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") { const members = await this.client.membersData.find({ @@ -33,12 +33,15 @@ class Leaderboard extends Command { value: m.money + m.bankSold }; }).sort((a, b) => b.value - a.value); + const table = new AsciiTable("Таблица лидеров"); table.setHeading("#", message.translate("common:USER"), message.translate("common:CREDITS")); + if (membersLeaderboard.length > 20) membersLeaderboard.length = 20; + const newTable = await fetchUsers(membersLeaderboard, table, this.client); message.channel.send({ - content: `\`\`\`\n${newTable.toString()}\`\`\`` + content: "```\n" + newTable.toString() + "```" }); } else if (type === "level") { const members = await this.client.membersData.find({ @@ -50,18 +53,19 @@ class Leaderboard extends Command { value: m.level }; }).sort((a, b) => b.value - a.value); + const table = new AsciiTable("Таблица лидеров"); table.setHeading("#", message.translate("common:USER"), message.translate("common:LEVEL")); + if (membersLeaderboard.length > 20) membersLeaderboard.length = 20; + const newTable = await fetchUsers(membersLeaderboard, table, this.client); message.channel.send({ - content: `\`\`\`\n${newTable.toString()}\`\`\`` + content: "```\n" + newTable.toString() + "```" }); } else if (type === "rep") { const users = await this.client.usersData.find({ - rep: { - $gt: 0 - } + rep: { $gt: 0 } }).lean(), usersLeaderboard = users.map((u) => { return { @@ -69,12 +73,15 @@ class Leaderboard extends Command { value: u.rep }; }).sort((a, b) => b.value - a.value); + const table = new AsciiTable("Таблица лидеров"); table.setHeading("#", message.translate("common:USER"), message.translate("common:POINTS")); + if (usersLeaderboard.length > 20) usersLeaderboard.length = 20; + const newTable = await fetchUsers(usersLeaderboard, table, this.client); message.channel.send({ - content: `\`\`\`\n${newTable.toString()}\`\`\`` + content: "```\n" + newTable.toString() + "```" }); };