2024-02-06 21:45:53 +05:00
|
|
|
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"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.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"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.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,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
2024-02-06 21:45:53 +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
|
|
|
|
* @param {Object} data
|
|
|
|
*/
|
|
|
|
async execute(client, interaction, data) {
|
2022-08-29 21:31:36 +05:00
|
|
|
if (interaction.options.getBoolean("clear")) {
|
|
|
|
data.memberData.transactions = [];
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2023-10-30 21:45:10 +05:00
|
|
|
data.memberData.markModified("transactions");
|
2022-08-29 21:31:36 +05:00
|
|
|
await data.memberData.save();
|
|
|
|
|
|
|
|
return interaction.success("economy/transactions:CLEARED", null, { ephemeral: true });
|
|
|
|
}
|
|
|
|
|
2024-02-06 21:45:53 +05:00
|
|
|
const embed = client.embed({
|
|
|
|
author: {
|
2022-08-09 23:48:33 +05:00
|
|
|
name: interaction.translate("economy/transactions:EMBED_TRANSACTIONS"),
|
2022-12-15 21:02:38 +05:00
|
|
|
iconURL: interaction.member.displayAvatarURL(),
|
2024-02-06 21:45:53 +05:00
|
|
|
},
|
|
|
|
});
|
2022-08-09 23:48:33 +05:00
|
|
|
const transactions = data.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",
|
2024-02-06 21:45:53 +05:00
|
|
|
)}: <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) {
|
2024-02-06 21:45:53 +05:00
|
|
|
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)
|
2024-02-06 21:45:53 +05:00
|
|
|
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)
|
2024-02-06 21:45:53 +05:00
|
|
|
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({
|
2022-12-15 21:02:38 +05:00
|
|
|
embeds: [embed],
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Transactions;
|