2022-01-13 00:56:24 +05:00
|
|
|
const Command = require("../../base/Command"),
|
2022-01-04 02:18:28 +05:00
|
|
|
Discord = require("discord.js");
|
|
|
|
|
2022-01-06 19:46:10 +05:00
|
|
|
const asyncForEach = async (collection, callback) => {
|
|
|
|
const allPromises = collection.map(async key => {
|
|
|
|
await callback(key);
|
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-01-06 19:46:10 +05:00
|
|
|
return await Promise.all(allPromises);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Money extends Command {
|
2022-01-04 02:18:28 +05:00
|
|
|
constructor(client) {
|
|
|
|
super(client, {
|
|
|
|
name: "money",
|
|
|
|
dirname: __dirname,
|
|
|
|
enabled: true,
|
|
|
|
guildOnly: true,
|
2022-01-06 19:46:10 +05:00
|
|
|
aliases: ["balance", "mon"],
|
2022-01-04 02:18:28 +05:00
|
|
|
memberPermissions: [],
|
|
|
|
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
|
|
|
|
nsfw: false,
|
|
|
|
ownerOnly: false,
|
|
|
|
cooldown: 1000
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async run(message, args, data) {
|
|
|
|
let member = await this.client.resolveMember(args[0], message.guild);
|
|
|
|
if (!member) member = message.member;
|
|
|
|
const user = member.user;
|
|
|
|
|
|
|
|
if (user.bot) return message.error("misc:BOT_USER");
|
|
|
|
|
|
|
|
const memberData = (message.author === user) ? data.memberData : await this.client.findOrCreateMember({
|
|
|
|
id: user.id,
|
|
|
|
guildID: message.guild.id
|
|
|
|
});
|
|
|
|
|
|
|
|
const commonsGuilds = this.client.guilds.cache.filter((g) => g.members.cache.get(user.id));
|
2022-01-06 19:46:10 +05:00
|
|
|
let globalMoney = 0;
|
|
|
|
await asyncForEach(commonsGuilds, async (guild) => {
|
|
|
|
const data = await this.client.findOrCreateMember({
|
|
|
|
id: user.id,
|
|
|
|
guildID: guild.id
|
|
|
|
});
|
|
|
|
globalMoney += data.money;
|
|
|
|
globalMoney += data.bankSold;
|
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const embed = new Discord.MessageEmbed()
|
2022-01-05 00:24:57 +05:00
|
|
|
.setAuthor({
|
|
|
|
name: message.translate("economy/money:TITLE", {
|
|
|
|
username: member.user.username
|
|
|
|
}),
|
|
|
|
iconURL: member.user.displayAvatarURL({
|
|
|
|
size: 512,
|
|
|
|
dynamic: true,
|
|
|
|
format: "png"
|
|
|
|
})
|
|
|
|
})
|
2022-01-04 02:18:28 +05:00
|
|
|
.addField(message.translate("economy/profile:CASH"), `**${memberData.money}** ${message.getNoun(memberData.money, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`, true)
|
|
|
|
.addField(message.translate("economy/profile:BANK"), `**${memberData.bankSold}** ${message.getNoun(memberData.bankSold, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`, true)
|
|
|
|
.addField(message.translate("economy/profile:GLOBAL"), `**${globalMoney}** ${message.getNoun(globalMoney, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`, true)
|
2022-01-05 00:24:57 +05:00
|
|
|
.setColor(data.config.embed.color)
|
|
|
|
.setFooter({
|
|
|
|
text: data.config.embed.footer
|
|
|
|
});
|
2022-02-13 17:26:12 +05:00
|
|
|
message.reply({
|
2022-01-05 00:24:57 +05:00
|
|
|
embeds: [embed]
|
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
}
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-01-06 19:46:10 +05:00
|
|
|
module.exports = Money;
|