2022-08-09 23:48:33 +05:00
|
|
|
const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Transactions extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
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
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
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) {
|
2022-08-29 21:31:36 +05:00
|
|
|
if (interaction.options.getBoolean("clear")) {
|
|
|
|
data.memberData.transactions = [];
|
2023-07-03 19:30:47 +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 });
|
|
|
|
}
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
const embed = new EmbedBuilder()
|
|
|
|
.setAuthor({
|
|
|
|
name: interaction.translate("economy/transactions:EMBED_TRANSACTIONS"),
|
2022-12-15 21:02:38 +05:00
|
|
|
iconURL: interaction.member.displayAvatarURL(),
|
2022-08-09 23:48:33 +05:00
|
|
|
})
|
|
|
|
.setColor(client.config.embed.color)
|
|
|
|
.setFooter({
|
2022-12-15 21:02:38 +05:00
|
|
|
text: client.config.embed.footer,
|
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",
|
|
|
|
)}: ${client.functions.printDate(client, t.date, "Do MMMM YYYY, HH:mm", data.guildData.language)}\n`,
|
|
|
|
);
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
if (transactions.length < 1) {
|
|
|
|
embed.setDescription(interaction.translate("economy/transactions:NO_TRANSACTIONS"));
|
|
|
|
} else {
|
2023-07-05 00:58:06 +05:00
|
|
|
if (sortedTransactions[0].length > 0)
|
|
|
|
embed.addFields([
|
|
|
|
{
|
|
|
|
name: interaction.translate("economy/transactions:T_GOT"),
|
|
|
|
value: sortedTransactions[0].join("\n"),
|
|
|
|
inline: true,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
if (sortedTransactions[1].length > 0)
|
|
|
|
embed.addFields([
|
|
|
|
{
|
|
|
|
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;
|