From a5456a11d6ed6c1514ef7c4a78e535978c9b1f58 Mon Sep 17 00:00:00 2001 From: JonnyBro Date: Thu, 13 Jan 2022 19:49:12 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=D1=8B=20=D0=B8=20?= =?UTF-8?q?=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D1=8B=20=D0=BB=D0=B8=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=BE=D0=B2=20=D0=B2=20=D1=8D=D0=BC=D0=B1=D0=B5?= =?UTF-8?q?=D0=B4=D0=B0=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/Administration/configuration.js | 4 +- commands/Economy/leaderboard.js | 150 ++++++++++++++++------- dashboard/public/docs/updates.md | 3 +- dashboard/utils.js | 8 +- dashboard/views/stats/guild.ejs | 2 +- events/guildCreate.js | 4 +- events/guildDelete.js | 4 +- languages/ru-RU/economy/leaderboard.json | 8 +- package.json | 1 - 9 files changed, 130 insertions(+), 54 deletions(-) diff --git a/commands/Administration/configuration.js b/commands/Administration/configuration.js index db077647..90cd16dd 100644 --- a/commands/Administration/configuration.js +++ b/commands/Administration/configuration.js @@ -23,7 +23,9 @@ class Configuration extends Command { const embed = new Discord.MessageEmbed() .setAuthor({ name: message.guild.name, - iconURL: message.guild.iconURL() + iconURL: message.guild.iconURL({ + dynamic: true + }) }) .setColor(data.config.embed.color) .setFooter({ diff --git a/commands/Economy/leaderboard.js b/commands/Economy/leaderboard.js index c0bcafcf..b0f2197d 100644 --- a/commands/Economy/leaderboard.js +++ b/commands/Economy/leaderboard.js @@ -1,5 +1,5 @@ const Command = require("../../base/Command"), - AsciiTable = require("ascii-table"); + Discord = require("discord.js"); class Leaderboard extends Command { constructor(client) { @@ -30,18 +30,43 @@ class Leaderboard extends Command { membersLeaderboard = members.map((m) => { return { id: m.id, - value: m.money + m.bankSold + money: 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")); - + }).sort((a, b) => b.money - a.money); if (membersLeaderboard.length > 20) membersLeaderboard.length = 20; - const newTable = await fetchUsers(membersLeaderboard, table, this.client); + let userNames = ""; + let money = ""; + for (let i = 0; i < membersLeaderboard.length; i++) { + const data = membersLeaderboard[i]; + const user = (await this.client.users.fetch(data.id)).tag; + + userNames += `**${i + 1}**. ${user}\n`; + money += `**${data.money}**\n`; + } + + const embed = new Discord.MessageEmbed() + .setAuthor({ + name: message.translate("economy/leaderboard:TABLE", { + name: message.guild.name + }), + iconURL: message.guild.iconURL({ + dynamic: true + }) + }) + .setColor(this.client.config.embed.color) + .addFields({ + name: message.translate("economy/leaderboard:TOP"), + value: userNames, + inline: true + }, { + name: message.translate("economy/leaderboard:LEVEL"), + value: money, + inline: true + }); + message.channel.send({ - content: "```\n" + newTable.toString() + "```" + embeds: [embed] }); } else if (type === "level") { const members = await this.client.membersData.find({ @@ -50,18 +75,50 @@ class Leaderboard extends Command { membersLeaderboard = members.map((m) => { return { id: m.id, - value: m.level + level: m.level, + xp: m.exp }; - }).sort((a, b) => b.value - a.value); - - const table = new AsciiTable("Таблица лидеров"); - table.setHeading("#", message.translate("common:USER"), message.translate("common:LEVEL")); - + }).sort((a, b) => b.level - a.level); if (membersLeaderboard.length > 20) membersLeaderboard.length = 20; - const newTable = await fetchUsers(membersLeaderboard, table, this.client); + let userNames = ""; + let level = ""; + let xp = ""; + for (let i = 0; i < membersLeaderboard.length; i++) { + const data = membersLeaderboard[i]; + const user = (await this.client.users.fetch(data.id)).tag; + + userNames += `**${i + 1}**. ${user}\n`; + level += `**${data.level}**\n`; + xp += `**${data.xp}** / **${5 * (data.level * data.level) + 80 * data.level + 100}**\n`; + } + + const embed = new Discord.MessageEmbed() + .setAuthor({ + name: message.translate("economy/leaderboard:TABLE", { + name: message.guild.name + }), + iconURL: message.guild.iconURL({ + dynamic: true + }) + }) + .setColor(this.client.config.embed.color) + .addFields({ + name: message.translate("economy/leaderboard:TOP"), + value: userNames, + inline: true + }, { + name: message.translate("economy/leaderboard:LEVEL"), + value: level, + inline: true + }, { + name: message.translate("economy/leaderboard:XP"), + value: xp, + inline: true + }); + message.channel.send({ - content: "```\n" + newTable.toString() + "```" + embeds: [embed] }); } else if (type === "rep") { const users = await this.client.usersData.find({ @@ -70,18 +127,43 @@ class Leaderboard extends Command { usersLeaderboard = users.map((u) => { return { id: u.id, - value: u.rep + rep: u.rep }; - }).sort((a, b) => b.value - a.value); - - const table = new AsciiTable("Таблица лидеров"); - table.setHeading("#", message.translate("common:USER"), message.translate("common:POINTS")); - + }).sort((a, b) => b.rep - a.rep); if (usersLeaderboard.length > 20) usersLeaderboard.length = 20; - const newTable = await fetchUsers(usersLeaderboard, table, this.client); + let userNames = ""; + let rep = ""; + for (let i = 0; i < usersLeaderboard.length; i++) { + const data = usersLeaderboard[i]; + const user = (await this.client.users.fetch(data.id)).tag; + + userNames += `**${i + 1}**. ${user}\n`; + rep += `**${data.rep}**\n`; + } + + const embed = new Discord.MessageEmbed() + .setAuthor({ + name: message.translate("economy/leaderboard:TABLE", { + name: message.guild.name + }), + iconURL: message.guild.iconURL({ + dynamic: true + }) + }) + .setColor(this.client.config.embed.color) + .addFields({ + name: message.translate("economy/leaderboard:TOP"), + value: userNames, + inline: true + }, { + name: message.translate("economy/leaderboard:REP"), + value: rep, + inline: true + }); + message.channel.send({ - content: "```\n" + newTable.toString() + "```" + embeds: [embed] }); } @@ -89,20 +171,4 @@ class Leaderboard extends Command { } } -module.exports = Leaderboard; - -async function fetchUsers(array, table, client) { - return new Promise((resolve) => { - let index = 1; - array.forEach((element) => { - client.users.fetch(element.id).then((user) => { - const regEx = /(?:[\u2700-\u27bf]|(?:\ud83c[\udde6-\uddff]){2}|[\ud800-\udbff][\udc00-\udfff]|[\u0023-\u0039]\ufe0f?\u20e3|\u3299|\u3297|\u303d|\u3030|\u24c2|\ud83c[\udd70-\udd71]|\ud83c[\udd7e-\udd7f]|\ud83c\udd8e|\ud83c[\udd91-\udd9a]|\ud83c[\udde6-\uddff]|\ud83c[\ude01-\ude02]|\ud83c\ude1a|\ud83c\ude2f|\ud83c[\ude32-\ude3a]|\ud83c[\ude50-\ude51]|\u203c|\u2049|[\u25aa-\u25ab]|\u25b6|\u25c0|[\u25fb-\u25fe]|\u00a9|\u00ae|\u2122|\u2139|\ud83c\udc04|[\u2600-\u26FF]|\u2b05|\u2b06|\u2b07|\u2b1b|\u2b1c|\u2b50|\u2b55|\u231a|\u231b|\u2328|\u23cf|[\u23e9-\u23f3]|[\u23f8-\u23fa]|\ud83c\udccf|\u2934|\u2935|[\u2190-\u21ff])/g; - let username = user.username.replace(regEx, ""); - if (username.length > 20) username = username.substr(0, 20); - - table.addRow(index++, username, element.value); - }); - }); - resolve(table); - }); -} \ No newline at end of file +module.exports = Leaderboard; \ No newline at end of file diff --git a/dashboard/public/docs/updates.md b/dashboard/public/docs/updates.md index 6369d0a4..4a446a8e 100644 --- a/dashboard/public/docs/updates.md +++ b/dashboard/public/docs/updates.md @@ -1,10 +1,11 @@ -### JaBa v3.2.7 +### JaBa v3.2.8 * Добавлено * Статистика сервера на сайте ([пример](https://jaba.pp.ua/stats/651412418202959872)). * Профиль пользователя определённого сервера на сайте ([пример](https://jaba.pp.ua/user/281361531411890186/651412418202959872)) Ссылки на статистику сервера и профиль пользователя можно найти в *serverinfo* и *profile (@пользователь)* соответственно. * Изменения + * Таблицы лидеров теперь показываются в эмбедах. * Отключены команда *someone* и тэг *@someone*. ### JaBa v3.2.7 diff --git a/dashboard/utils.js b/dashboard/utils.js index 1ce1ec31..66b502d9 100644 --- a/dashboard/utils.js +++ b/dashboard/utils.js @@ -46,11 +46,9 @@ async function fetchUsers(array, client) { return new Promise((resolve) => { const users = []; array.filter((e) => e.id).forEach((element) => { - client.users.fetch(element.id).then((user) => { - user.username = user.username.replace(/[\W_]+/g, " "); - if (user.username.length > 13) { - user.username = user.username.substr(0, 10) + "..."; - } + client.users.fetch(element.id).then(user => { + if (user.username.length > 15) user.username = user.username.substr(0, 12) + "..."; + users.push({ ...{ money: element.money, diff --git a/dashboard/views/stats/guild.ejs b/dashboard/views/stats/guild.ejs index 12c8f876..960f4e4f 100644 --- a/dashboard/views/stats/guild.ejs +++ b/dashboard/views/stats/guild.ejs @@ -114,7 +114,7 @@ /* LEADERBOARD */ let values = ["money", "level"]; values.forEach((value) => { - let members = JSON.parse(`<%- JSON.stringify(stats) %>`)[value]; + let members = JSON.parse(`<%- JSON.stringify(stats) %>`)[value].sort((a, b) => a - b); let data = { labels: members.map(a => a.username), datasets: [{ diff --git a/events/guildCreate.js b/events/guildCreate.js index ee38c290..70a1cabd 100644 --- a/events/guildCreate.js +++ b/events/guildCreate.js @@ -48,7 +48,9 @@ module.exports = class { const logsEmbed = new Discord.MessageEmbed() .setAuthor({ name: guild.name, - iconURL: guild.iconURL() + iconURL: guild.iconURL({ + dynamic: true + }) }) .setColor("#32CD32") .setDescription(text); diff --git a/events/guildDelete.js b/events/guildDelete.js index d0bd396f..3c511dbc 100644 --- a/events/guildDelete.js +++ b/events/guildDelete.js @@ -12,7 +12,9 @@ module.exports = class { const embed = new Discord.MessageEmbed() .setAuthor({ name: guild.name, - iconURL: guild.iconURL() + iconURL: guild.iconURL({ + dynamic: true + }) }) .setColor("#B22222") .setDescription(text); diff --git a/languages/ru-RU/economy/leaderboard.json b/languages/ru-RU/economy/leaderboard.json index b620fb93..cdf3fc81 100644 --- a/languages/ru-RU/economy/leaderboard.json +++ b/languages/ru-RU/economy/leaderboard.json @@ -3,5 +3,11 @@ "USAGE": "{{prefix}}leaderboard [rep/level/credits]", "EXAMPLES": "{{prefix}}leaderboard credits\n{{prefix}}leaderboard level", "MISSING_TYPE": "Выберите таблицу `credits`, `level` или `rep`", - "MOBILE": ":confused: Я заметил, что вы онлайн с телефона.... Таблица лидеров может отображаться некорректно на маленьких экранах. Попробуйте переключиться на ландшафтный режим или попробуйте позже с другого устройства!" + "MOBILE": ":confused: Я заметил, что вы онлайн с телефона... Таблица лидеров может отображаться некорректно на маленьких экранах. Попробуйте переключиться на ландшафтный режим или попробуйте позже с другого устройства!", + "TABLE": "Таблица лидеров {{name}}", + "TOP": "Топ 20", + "LEVEL": "Уровень", + "XP": "Опыт", + "CREDITS": "Кредиты", + "REP": "Репутация" } \ No newline at end of file diff --git a/package.json b/package.json index 09fdc424..09d57957 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,6 @@ "@sentry/node": "6.3.6", "@sindresorhus/slugify": "^1.1.0", "amethyste-api": "github:Androz2091/amethyste-api", - "ascii-table": "0.0.9", "blague.xyz": "^2.0.4", "btoa": "^1.2.1", "canvacord": "^5.1.0",