JaBa/commands/Economy/profile.js

140 lines
4.9 KiB
JavaScript
Raw Permalink Normal View History

const { SlashCommandBuilder } = require("discord.js");
2022-08-09 23:48:33 +05:00
const BaseCommand = require("../../base/BaseCommand");
2022-08-09 23:48:33 +05:00
class Profile extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
2022-08-09 23:48:33 +05:00
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("profile")
.setDescription(client.translate("economy/profile:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("economy/profile:DESCRIPTION", null, "uk-UA"),
ru: client.translate("economy/profile:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
2023-07-05 00:58:06 +05:00
.addUserOption(option =>
option
.setName("user")
.setDescription(client.translate("common:USER"))
.setDescriptionLocalizations({
uk: client.translate("common:USER", null, "uk-UA"),
ru: client.translate("common:USER", null, "ru-RU"),
}),
),
2022-08-09 23:48:33 +05:00
dirname: __dirname,
ownerOnly: false,
2022-08-09 23:48:33 +05:00
});
}
2022-08-09 23:48:33 +05:00
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
2022-08-09 23:48:33 +05:00
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
2024-02-09 23:26:57 +05:00
async execute(client, interaction) {
2022-08-09 23:48:33 +05:00
await interaction.deferReply();
2022-08-30 14:26:56 +05:00
2022-08-09 23:48:33 +05:00
const member = interaction.options.getMember("user") || interaction.member;
if (member.user.bot) return interaction.error("economy/profile:BOT_USER");
2024-02-09 23:26:57 +05:00
const memberData = member.id === interaction.user.id ? interaction.data.member : await client.findOrCreateMember({ id: member.id, guildId: interaction.guildId });
const userData = member.id === interaction.user.id ? interaction.data.user : await client.findOrCreateUser(member.id);
2022-08-09 23:48:33 +05:00
if (userData.lover && !client.users.cache.find(u => u.id === userData.lover)) await client.users.fetch(userData.lover, true);
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;
});
2023-06-07 23:59:38 +05:00
const lover = client.users.cache.get(userData.lover);
const embed = client.embed({
author: {
2022-08-09 23:48:33 +05:00
name: interaction.translate("economy/profile:TITLE", {
2023-09-01 17:39:52 +05:00
user: member.user.getUsername(),
2022-08-09 23:48:33 +05:00
}),
iconURL: member.displayAvatarURL(),
},
image: "attachment://achievements.png",
fields: [
2022-08-09 23:48:33 +05:00
{
name: interaction.translate("economy/profile:BIO"),
value: userData.bio ? userData.bio : interaction.translate("common:UNKNOWN"),
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:CASH"),
value: `**${memberData.money}** ${client.functions.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.functions.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.functions.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
},
{
name: interaction.translate("economy/profile:REPUTATION"),
value: `**${userData.rep}** ${client.functions.getNoun(userData.rep, interaction.translate("misc:NOUNS:POINTS:1"), interaction.translate("misc:NOUNS:POINTS:2"), interaction.translate("misc:NOUNS:POINTS:5"))}`,
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:LEVEL"),
2023-07-05 00:58:06 +05:00
value: `**${memberData.level}**`,
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:XP"),
value: `**${memberData.exp}/${5 * (memberData.level * memberData.level) + 80 * memberData.level + 100}** xp`,
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:REGISTERED"),
value: `<t:${Math.floor(memberData.registeredAt / 1000)}:f>`,
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:BIRTHDATE"),
value: !userData.birthdate ? interaction.translate("common:NOT_DEFINED") : `<t:${userData.birthdate}:D>`,
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:LOVER"),
2023-07-05 00:58:06 +05:00
value: !userData.lover ? interaction.translate("common:NOT_DEFINED") : lover.getUsername(),
inline: true,
2022-08-09 23:48:33 +05:00
},
{
name: interaction.translate("economy/profile:ACHIEVEMENTS"),
value: interaction.translate("economy/profile:ACHIEVEMENTS_CONTENT"),
},
],
});
2022-08-09 23:48:33 +05:00
2024-02-09 23:26:57 +05:00
const achievements = await userData.getAchievements();
2022-08-09 23:48:33 +05:00
interaction.editReply({
embeds: [embed],
2023-07-05 00:58:06 +05:00
files: [
{
name: "achievements.png",
2024-02-09 23:26:57 +05:00
attachment: achievements,
2023-07-05 00:58:06 +05:00
},
],
2022-08-09 23:48:33 +05:00
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Profile;