mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 05:04:58 +05:00
85 lines
No EOL
2.4 KiB
JavaScript
85 lines
No EOL
2.4 KiB
JavaScript
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"))
|
|
.setDMPermission(false)
|
|
.addUserOption(option => option.setName("user")
|
|
.setDescription(client.translate("common:USER"))
|
|
.setRequired(true))
|
|
.addIntegerOption(option => option.setName("amount")
|
|
.setDescription(client.translate("common:INT"))
|
|
.setRequired(true)),
|
|
aliases: [],
|
|
dirname: __dirname,
|
|
ownerOnly: false,
|
|
});
|
|
}
|
|
/**
|
|
*
|
|
* @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");
|
|
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", {
|
|
amount: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDITS:1"), interaction.translate("misc:NOUNS:CREDITS:2"), interaction.translate("misc:NOUNS:CREDITS:5"))}`,
|
|
});
|
|
|
|
const memberData = await client.findOrCreateMember({
|
|
id: member.id,
|
|
guildId: interaction.guildId,
|
|
});
|
|
|
|
data.memberData.money -= amount;
|
|
await data.memberData.save();
|
|
|
|
memberData.money += amount;
|
|
memberData.save();
|
|
|
|
const info1 = {
|
|
user: member.user.tag,
|
|
amount: amount,
|
|
date: Date.now(),
|
|
type: "send",
|
|
};
|
|
data.memberData.transactions.push(info1);
|
|
|
|
const info2 = {
|
|
user: member.user.tag,
|
|
amount: amount,
|
|
date: Date.now(),
|
|
type: "got",
|
|
};
|
|
data.memberData.transactions.push(info2);
|
|
|
|
interaction.success("economy/pay:SUCCESS", {
|
|
user: member.toString(),
|
|
amount: `**${amount}** ${client.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = Pay; |