2022-01-13 00:56:24 +05:00
|
|
|
const Command = require("../../base/Command"),
|
2022-01-13 19:49:12 +05:00
|
|
|
Discord = require("discord.js");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
class Leaderboard extends Command {
|
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
|
|
name: "leaderboard",
|
|
|
|
dirname: __dirname,
|
|
|
|
enabled: true,
|
|
|
|
guildOnly: true,
|
|
|
|
aliases: ["lb"],
|
|
|
|
memberPermissions: [],
|
|
|
|
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
|
|
|
|
nsfw: false,
|
|
|
|
ownerOnly: false,
|
|
|
|
cooldown: 2000
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-05 21:58:30 +05:00
|
|
|
async run(message, args, data) {
|
2022-01-05 00:24:57 +05:00
|
|
|
const isOnlyOnMobile = (message.member.presence.clientStatus ? JSON.stringify(Object.keys(message.member.presence.clientStatus)) === JSON.stringify(["mobile"]) : false);
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const type = args[0];
|
2022-01-06 20:31:57 +05:00
|
|
|
if (!type || !["credits", "level", "rep"].includes(type)) return message.error("economy/leaderboard:MISSING_TYPE");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
if (type === "credits") {
|
|
|
|
const members = await this.client.membersData.find({
|
|
|
|
guildID: message.guild.id
|
|
|
|
}).lean(),
|
|
|
|
membersLeaderboard = members.map((m) => {
|
|
|
|
return {
|
|
|
|
id: m.id,
|
2022-01-13 19:49:12 +05:00
|
|
|
money: m.money + m.bankSold
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|
2022-01-13 19:49:12 +05:00
|
|
|
}).sort((a, b) => b.money - a.money);
|
2022-01-04 02:18:28 +05:00
|
|
|
if (membersLeaderboard.length > 20) membersLeaderboard.length = 20;
|
2022-01-06 20:31:57 +05:00
|
|
|
|
2022-01-13 19:49:12 +05:00
|
|
|
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`;
|
2022-01-14 18:20:27 +05:00
|
|
|
money += `${data.money}\n`;
|
2022-01-13 19:49:12 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
const embed = new Discord.MessageEmbed()
|
|
|
|
.setAuthor({
|
|
|
|
name: message.translate("economy/leaderboard:TABLE", {
|
|
|
|
name: message.guild.name
|
|
|
|
}),
|
|
|
|
iconURL: message.guild.iconURL({
|
|
|
|
dynamic: true
|
|
|
|
})
|
|
|
|
})
|
2022-02-05 21:58:30 +05:00
|
|
|
.setColor(data.config.embed.color)
|
2022-01-13 19:49:12 +05:00
|
|
|
.addFields({
|
|
|
|
name: message.translate("economy/leaderboard:TOP"),
|
|
|
|
value: userNames,
|
|
|
|
inline: true
|
|
|
|
}, {
|
2022-01-13 20:01:39 +05:00
|
|
|
name: message.translate("economy/leaderboard:CREDITS"),
|
2022-01-13 19:49:12 +05:00
|
|
|
value: money,
|
|
|
|
inline: true
|
|
|
|
});
|
|
|
|
|
2022-02-13 17:26:12 +05:00
|
|
|
message.reply({
|
2022-01-13 19:49:12 +05:00
|
|
|
embeds: [embed]
|
2022-01-05 00:24:57 +05:00
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
} else if (type === "level") {
|
|
|
|
const members = await this.client.membersData.find({
|
|
|
|
guildID: message.guild.id
|
|
|
|
}).lean(),
|
|
|
|
membersLeaderboard = members.map((m) => {
|
|
|
|
return {
|
|
|
|
id: m.id,
|
2022-01-13 19:49:12 +05:00
|
|
|
level: m.level,
|
|
|
|
xp: m.exp
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|
2022-01-13 19:49:12 +05:00
|
|
|
}).sort((a, b) => b.level - a.level);
|
2022-01-04 02:18:28 +05:00
|
|
|
if (membersLeaderboard.length > 20) membersLeaderboard.length = 20;
|
2022-01-06 20:31:57 +05:00
|
|
|
|
2022-01-13 19:49:12 +05:00
|
|
|
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`;
|
2022-01-14 18:20:27 +05:00
|
|
|
level += `${data.level}\n`;
|
|
|
|
xp += `${data.xp} / ${5 * (data.level * data.level) + 80 * data.level + 100}\n`;
|
2022-01-13 19:49:12 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
const embed = new Discord.MessageEmbed()
|
|
|
|
.setAuthor({
|
|
|
|
name: message.translate("economy/leaderboard:TABLE", {
|
|
|
|
name: message.guild.name
|
|
|
|
}),
|
|
|
|
iconURL: message.guild.iconURL({
|
|
|
|
dynamic: true
|
|
|
|
})
|
|
|
|
})
|
2022-02-05 21:58:30 +05:00
|
|
|
.setColor(data.config.embed.color)
|
2022-01-13 19:49:12 +05:00
|
|
|
.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
|
|
|
|
});
|
|
|
|
|
2022-02-13 17:26:12 +05:00
|
|
|
message.reply({
|
2022-01-13 19:49:12 +05:00
|
|
|
embeds: [embed]
|
2022-01-05 00:24:57 +05:00
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
} else if (type === "rep") {
|
2022-01-05 00:24:57 +05:00
|
|
|
const users = await this.client.usersData.find({
|
2022-01-06 20:31:57 +05:00
|
|
|
rep: { $gt: 0 }
|
2022-01-05 00:24:57 +05:00
|
|
|
}).lean(),
|
2022-01-04 02:18:28 +05:00
|
|
|
usersLeaderboard = users.map((u) => {
|
|
|
|
return {
|
|
|
|
id: u.id,
|
2022-01-13 19:49:12 +05:00
|
|
|
rep: u.rep
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|
2022-01-13 19:49:12 +05:00
|
|
|
}).sort((a, b) => b.rep - a.rep);
|
2022-01-04 02:18:28 +05:00
|
|
|
if (usersLeaderboard.length > 20) usersLeaderboard.length = 20;
|
2022-01-06 20:31:57 +05:00
|
|
|
|
2022-01-13 19:49:12 +05:00
|
|
|
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`;
|
2022-01-14 18:20:27 +05:00
|
|
|
rep += `${data.rep}\n`;
|
2022-01-13 19:49:12 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
const embed = new Discord.MessageEmbed()
|
|
|
|
.setAuthor({
|
|
|
|
name: message.translate("economy/leaderboard:TABLE", {
|
|
|
|
name: message.guild.name
|
|
|
|
}),
|
|
|
|
iconURL: message.guild.iconURL({
|
|
|
|
dynamic: true
|
|
|
|
})
|
|
|
|
})
|
2022-02-05 21:58:30 +05:00
|
|
|
.setColor(data.config.embed.color)
|
2022-01-13 19:49:12 +05:00
|
|
|
.addFields({
|
|
|
|
name: message.translate("economy/leaderboard:TOP"),
|
|
|
|
value: userNames,
|
|
|
|
inline: true
|
|
|
|
}, {
|
|
|
|
name: message.translate("economy/leaderboard:REP"),
|
|
|
|
value: rep,
|
|
|
|
inline: true
|
|
|
|
});
|
|
|
|
|
2022-02-13 17:26:12 +05:00
|
|
|
message.reply({
|
2022-01-13 19:49:12 +05:00
|
|
|
embeds: [embed]
|
2022-01-05 00:24:57 +05:00
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
if (isOnlyOnMobile) message.sendT("economy/leaderboard:MOBILE");
|
|
|
|
}
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-01-13 19:49:12 +05:00
|
|
|
module.exports = Leaderboard;
|