JaBa/commands/Economy/transactions.js

95 lines
2.7 KiB
JavaScript
Raw Normal View History

const { SlashCommandBuilder } = require("discord.js");
2022-08-09 23:48:33 +05:00
const BaseCommand = require("../../base/BaseCommand");
class Transactions 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("transactions")
2022-08-29 21:31:36 +05:00
.setDescription(client.translate("economy/transactions:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("economy/transactions:DESCRIPTION", null, "uk-UA"),
ru: client.translate("economy/transactions:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
2023-07-05 00:58:06 +05:00
.addBooleanOption(option =>
option
.setName("clear")
.setDescription(client.translate("economy/transactions:CLEAR"))
.setDescriptionLocalizations({
uk: client.translate("economy/transactions:CLEAR", null, "uk-UA"),
ru: client.translate("economy/transactions:CLEAR", 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) {
const memberData = interaction.data.member;
2022-08-29 21:31:36 +05:00
if (interaction.options.getBoolean("clear")) {
2024-02-09 23:26:57 +05:00
memberData.transactions = [];
2024-02-09 23:26:57 +05:00
await memberData.save();
2022-08-29 21:31:36 +05:00
return interaction.success("economy/transactions:CLEARED", null, { ephemeral: true });
}
const embed = client.embed({
author: {
2022-08-09 23:48:33 +05:00
name: interaction.translate("economy/transactions:EMBED_TRANSACTIONS"),
iconURL: interaction.member.displayAvatarURL(),
},
});
2024-02-09 23:26:57 +05:00
const transactions = memberData.transactions,
2023-07-05 00:58:06 +05:00
sortedTransactions = [[], []];
2022-08-09 23:48:33 +05:00
transactions.slice(-20).forEach(t => {
const array = t.type === "got" ? sortedTransactions[0] : sortedTransactions[1];
2023-07-05 00:58:06 +05:00
array.push(
`${interaction.translate("economy/transactions:T_USER_" + t.type.toUpperCase())}: ${t.user}\n${interaction.translate("economy/transactions:T_AMOUNT")}: ${t.amount}\n${interaction.translate(
"economy/transactions:T_DATE",
)}: <t:${Math.floor(t.date / 1000)}:f>\n`,
2023-07-05 00:58:06 +05:00
);
2022-08-09 23:48:33 +05:00
});
if (transactions.length < 1) {
embed.data.description = interaction.translate("economy/transactions:NO_TRANSACTIONS");
2022-08-09 23:48:33 +05:00
} else {
2023-07-05 00:58:06 +05:00
if (sortedTransactions[0].length > 0)
embed.data.fields.push([
2023-07-05 00:58:06 +05:00
{
name: interaction.translate("economy/transactions:T_GOT"),
value: sortedTransactions[0].join("\n"),
inline: true,
},
]);
if (sortedTransactions[1].length > 0)
embed.data.fields.push([
2023-07-05 00:58:06 +05:00
{
name: interaction.translate("economy/transactions:T_SEND"),
value: sortedTransactions[1].join("\n"),
inline: true,
},
]);
2022-08-09 23:48:33 +05:00
}
interaction.reply({
embeds: [embed],
2022-08-09 23:48:33 +05:00
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Transactions;