2022-08-09 23:48:33 +05:00
|
|
|
const { SlashCommandBuilder } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Bank 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("bank")
|
|
|
|
.setDescription(client.translate("economy/bank:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("economy/bank:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("economy/bank: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
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName("option")
|
|
|
|
.setDescription(client.translate("economy/bank:OPTION"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("economy/bank:OPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("economy/bank:OPTION", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true)
|
|
|
|
.setChoices({ name: client.translate("economy/bank:DEPOSIT"), value: "deposit" }, { name: client.translate("economy/bank:WITHDRAW"), value: "withdraw" }),
|
|
|
|
)
|
|
|
|
.addStringOption(option =>
|
|
|
|
option
|
|
|
|
.setName("credits")
|
|
|
|
.setDescription(client.translate("misc:OPTION_NAN_ALL"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("misc:OPTION_NAN_ALL", null, "uk-UA"),
|
|
|
|
ru: client.translate("misc:OPTION_NAN_ALL", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
),
|
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
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-08-09 23:48:33 +05:00
|
|
|
*/
|
|
|
|
async onLoad() {
|
|
|
|
//...
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
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) {
|
|
|
|
const choice = interaction.options.getString("option");
|
|
|
|
|
|
|
|
if (choice === "deposit") {
|
2023-06-15 19:46:27 +05:00
|
|
|
const credits = interaction.options.getString("credits").toLowerCase() === "all" ? data.memberData.money : interaction.options.getString("credits");
|
2022-08-09 23:48:33 +05:00
|
|
|
if (isNaN(credits) || credits < 1) return interaction.error("misc:OPTION_NAN_ALL");
|
2023-07-05 00:58:06 +05:00
|
|
|
if (data.memberData.money < credits)
|
|
|
|
return interaction.error("economy/bank:NOT_ENOUGH_CREDIT", {
|
|
|
|
money: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
|
|
});
|
2022-08-09 23:48:33 +05:00
|
|
|
|
2022-10-09 14:26:22 +05:00
|
|
|
data.memberData.money -= credits;
|
|
|
|
data.memberData.bankSold += credits;
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
data.memberData.markModified("money");
|
|
|
|
data.memberData.markModified("bankSold");
|
2022-10-09 14:26:22 +05:00
|
|
|
await data.memberData.save();
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
const info = {
|
|
|
|
user: interaction.translate("economy/transactions:BANK"),
|
|
|
|
amount: credits,
|
|
|
|
date: Date.now(),
|
2022-12-15 21:02:38 +05:00
|
|
|
type: "send",
|
2022-08-09 23:48:33 +05:00
|
|
|
};
|
|
|
|
data.memberData.transactions.push(info);
|
|
|
|
|
|
|
|
interaction.success("economy/bank:SUCCESS_DEP", {
|
2023-04-20 11:47:47 +05:00
|
|
|
money: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const credits = interaction.options.getString("credits") === "all" ? data.memberData.bankSold : interaction.options.getString("credits");
|
|
|
|
if (isNaN(credits) || credits < 1) return interaction.error("misc:OPTION_NAN_ALL");
|
2023-07-05 00:58:06 +05:00
|
|
|
if (data.memberData.bankSold < credits)
|
|
|
|
return interaction.error("economy/bank:NOT_ENOUGH_BANK", {
|
|
|
|
money: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
|
|
});
|
2022-08-09 23:48:33 +05:00
|
|
|
|
|
|
|
const info = {
|
|
|
|
user: interaction.translate("economy/transactions:BANK"),
|
|
|
|
amount: credits,
|
|
|
|
date: Date.now(),
|
2022-12-15 21:02:38 +05:00
|
|
|
type: "got",
|
2022-08-09 23:48:33 +05:00
|
|
|
};
|
|
|
|
|
|
|
|
data.memberData.transactions.push(info);
|
|
|
|
|
|
|
|
data.memberData.money += credits;
|
|
|
|
data.memberData.bankSold -= credits;
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2023-10-31 22:24:40 +05:00
|
|
|
data.memberData.markModified("money");
|
|
|
|
data.memberData.markModified("bankSold");
|
2022-08-09 23:48:33 +05:00
|
|
|
await data.memberData.save();
|
|
|
|
|
|
|
|
interaction.success("economy/bank:SUCCESS_WD", {
|
2023-04-20 11:47:47 +05:00
|
|
|
money: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Bank;
|