mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 05:04:58 +05:00
Фиксы и таблицы лидеров в эмбедах
This commit is contained in:
parent
b0deb2e447
commit
a5456a11d6
9 changed files with 130 additions and 54 deletions
|
@ -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({
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
module.exports = Leaderboard;
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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: [{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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": "Репутация"
|
||||
}
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue