2022-08-09 23:48:33 +05:00
|
|
|
const { SlashCommandBuilder } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Pay extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("pay")
|
|
|
|
.setDescription(client.translate("economy/pay:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
|
|
|
"uk": client.translate("economy/pay:DESCRIPTION", null, "uk-UA"),
|
|
|
|
"ru": client.translate("economy/pay:DESCRIPTION", null, "ru-RU"),
|
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.setDMPermission(false)
|
2022-08-09 23:48:33 +05:00
|
|
|
.addUserOption(option => option.setName("user")
|
|
|
|
.setDescription(client.translate("common:USER"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.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
|
|
|
.setRequired(true))
|
|
|
|
.addIntegerOption(option => option.setName("amount")
|
|
|
|
.setDescription(client.translate("common:INT"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
|
|
|
"uk": client.translate("common:INT", null, "uk-UA"),
|
|
|
|
"ru": client.translate("common:INT", null, "ru-RU"),
|
|
|
|
})
|
2022-08-09 23:48:33 +05:00
|
|
|
.setRequired(true)),
|
|
|
|
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) {
|
|
|
|
const member = interaction.options.getMember("user");
|
|
|
|
if (member.user.bot) return interaction.error("economy/pay:BOT_USER");
|
|
|
|
if (member.id === interaction.member.id) return interaction.error("economy/pay:YOURSELF");
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
const amount = interaction.options.getInteger("amount");
|
|
|
|
if (amount <= 0) return interaction.error("misc:MORE_THAN_ZERO");
|
|
|
|
if (amount > data.memberData.money) return interaction.error("economy/pay:ENOUGH_MONEY", {
|
2023-04-20 11:47:47 +05:00
|
|
|
amount: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDITS:1"), interaction.translate("misc:NOUNS:CREDITS:2"), interaction.translate("misc:NOUNS:CREDITS:5"))}`,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
const memberData = await client.findOrCreateMember({
|
|
|
|
id: member.id,
|
2022-12-15 21:02:38 +05:00
|
|
|
guildId: interaction.guildId,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
2022-10-09 14:26:22 +05:00
|
|
|
data.memberData.money -= amount;
|
|
|
|
await data.memberData.save();
|
|
|
|
|
|
|
|
memberData.money += amount;
|
2023-06-15 19:46:27 +05:00
|
|
|
await memberData.save();
|
2022-10-09 14:26:22 +05:00
|
|
|
|
|
|
|
const info1 = {
|
2023-07-02 21:02:55 +05:00
|
|
|
user: client.functions.getUsername(member.user),
|
2022-08-09 23:48:33 +05:00
|
|
|
amount: amount,
|
|
|
|
date: Date.now(),
|
2022-12-15 21:02:38 +05:00
|
|
|
type: "send",
|
2022-08-09 23:48:33 +05:00
|
|
|
};
|
2022-10-09 14:26:22 +05:00
|
|
|
data.memberData.transactions.push(info1);
|
2022-08-09 23:48:33 +05:00
|
|
|
|
2022-10-09 14:26:22 +05:00
|
|
|
const info2 = {
|
2023-07-02 21:02:55 +05:00
|
|
|
user: client.functions.getUsername(member.user),
|
2022-10-09 14:26:22 +05:00
|
|
|
amount: amount,
|
|
|
|
date: Date.now(),
|
2022-12-15 21:02:38 +05:00
|
|
|
type: "got",
|
2022-10-09 14:26:22 +05:00
|
|
|
};
|
|
|
|
data.memberData.transactions.push(info2);
|
2022-08-09 23:48:33 +05:00
|
|
|
|
|
|
|
interaction.success("economy/pay:SUCCESS", {
|
|
|
|
user: member.toString(),
|
2023-04-20 11:47:47 +05:00
|
|
|
amount: `**${amount}** ${client.functions.getNoun(amount, 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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Pay;
|