2024-09-19 23:58:06 +05:00
|
|
|
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
|
2022-08-09 23:48:33 +05:00
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Pay 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("pay")
|
|
|
|
.setDescription(client.translate("economy/pay:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("economy/pay:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("economy/pay:DESCRIPTION", null, "ru-RU"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2024-09-19 23:58:06 +05:00
|
|
|
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall])
|
2024-09-14 19:52:56 +05:00
|
|
|
.setContexts([InteractionContextType.Guild])
|
2023-07-05 00:58:06 +05:00
|
|
|
.addUserOption(option =>
|
|
|
|
option
|
|
|
|
.setName("user")
|
|
|
|
.setDescription(client.translate("common:USER"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:USER", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:USER", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
)
|
|
|
|
.addIntegerOption(option =>
|
|
|
|
option
|
|
|
|
.setName("amount")
|
|
|
|
.setDescription(client.translate("common:INT"))
|
|
|
|
.setDescriptionLocalizations({
|
|
|
|
uk: client.translate("common:INT", null, "uk-UA"),
|
|
|
|
ru: client.translate("common:INT", null, "ru-RU"),
|
|
|
|
})
|
|
|
|
.setRequired(true),
|
|
|
|
),
|
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
|
|
|
|
*/
|
2024-02-09 23:26:57 +05:00
|
|
|
async execute(client, interaction) {
|
|
|
|
const memberData = interaction.data.member,
|
|
|
|
otherMember = interaction.options.getMember("user");
|
|
|
|
if (otherMember.user.bot) return interaction.error("economy/pay:BOT_USER");
|
2024-07-18 00:07:24 +05:00
|
|
|
if (otherMember.id === interaction.member.id) return interaction.error("misc:CANT_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");
|
2024-02-09 23:26:57 +05:00
|
|
|
if (amount > memberData.money)
|
2023-07-05 00:58:06 +05:00
|
|
|
return interaction.error("economy/pay:ENOUGH_MONEY", {
|
|
|
|
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
|
|
|
|
2024-05-24 23:11:03 +05:00
|
|
|
const otherMemberData = await client.getMemberData(otherMember.id, interaction.guildId);
|
2022-08-09 23:48:33 +05:00
|
|
|
|
2024-02-09 23:26:57 +05:00
|
|
|
memberData.money -= amount;
|
|
|
|
otherMemberData.money += amount;
|
|
|
|
|
2022-10-09 14:26:22 +05:00
|
|
|
const info1 = {
|
2024-02-09 23:26:57 +05:00
|
|
|
user: otherMember.user.getUsername(),
|
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
|
|
|
};
|
2024-02-09 23:26:57 +05:00
|
|
|
memberData.transactions.push(info1);
|
2022-08-09 23:48:33 +05:00
|
|
|
|
2022-10-09 14:26:22 +05:00
|
|
|
const info2 = {
|
2024-02-09 23:26:57 +05:00
|
|
|
user: otherMember.user.getUsername(),
|
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
|
|
|
};
|
2024-02-09 23:26:57 +05:00
|
|
|
otherMemberData.transactions.push(info2);
|
2022-08-09 23:48:33 +05:00
|
|
|
|
2024-05-24 23:02:12 +05:00
|
|
|
await memberData.save();
|
|
|
|
await otherMemberData.save();
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
interaction.success("economy/pay:SUCCESS", {
|
2024-02-09 23:26:57 +05:00
|
|
|
user: otherMember.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
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Pay;
|