JaBa/commands/Economy/money.js

92 lines
3 KiB
JavaScript
Raw Normal View History

2022-08-09 23:48:33 +05:00
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
2022-08-09 23:48:33 +05:00
class Money extends BaseCommand {
/**
*
* @param {import("../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("money")
.setDescription(client.translate("economy/money:DESCRIPTION"))
.setDescriptionLocalizations({ "uk": client.translate("economy/money:DESCRIPTION", null, "uk-UA") })
.setDMPermission(false)
2022-08-09 23:48:33 +05:00
.addUserOption(option => option.setName("user")
.setDescription(client.translate("common:USER"))
.setDescriptionLocalizations({ "uk": client.translate("common:USER", null, "uk-UA") })),
2022-08-09 23:48:33 +05:00
aliases: [],
dirname: __dirname,
ownerOnly: false,
2022-08-09 23:48:33 +05:00
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @param {Object} data
*/
async execute(client, interaction, data) {
await interaction.deferReply();
2022-08-09 23:48:33 +05:00
const member = interaction.options.getMember("user") || interaction.member;
if (member.user.bot) return interaction.error("economy/money:BOT_USER");
const memberData = member.id === interaction.user.id ? data.memberData : await client.findOrCreateMember({
2022-08-09 23:48:33 +05:00
id: member.id,
guildId: interaction.guildId,
2022-08-09 23:48:33 +05:00
});
const guilds = client.guilds.cache.filter(g => g.members.cache.find(m => m.id === member.id));
let globalMoney = 0;
await client.functions.asyncForEach(guilds, async guild => {
2022-08-09 23:48:33 +05:00
const data = await client.findOrCreateMember({
id: member.id,
guildId: guild.id,
2022-08-09 23:48:33 +05:00
});
globalMoney += data.money + data.bankSold;
});
const embed = new EmbedBuilder()
.setAuthor({
name: interaction.translate("economy/money:TITLE", {
user: member.user.tag,
2022-08-09 23:48:33 +05:00
}),
iconURL: member.user.displayAvatarURL(),
2022-08-09 23:48:33 +05:00
})
.addFields([
{
name: interaction.translate("economy/profile:CASH"),
value: `**${memberData.money}** ${client.getNoun(memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:BANK"),
value: `**${memberData.bankSold}** ${client.getNoun(memberData.bankSold, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:GLOBAL"),
value: `**${globalMoney}** ${client.getNoun(globalMoney, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
inline: true,
},
2022-08-09 23:48:33 +05:00
])
.setColor(client.config.embed.color)
.setFooter({
text: client.config.embed.footer,
2022-08-09 23:48:33 +05:00
});
interaction.editReply({
embeds: [embed],
2022-08-09 23:48:33 +05:00
});
}
}
module.exports = Money;