mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-24 22:24:58 +05:00
59 lines
No EOL
1.9 KiB
JavaScript
59 lines
No EOL
1.9 KiB
JavaScript
const Command = require("../../base/Command");
|
|
|
|
class Pay extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: "pay",
|
|
dirname: __dirname,
|
|
enabled: true,
|
|
guildOnly: true,
|
|
aliases: [],
|
|
memberPermissions: [],
|
|
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
|
|
nsfw: false,
|
|
ownerOnly: false,
|
|
cooldown: 2000
|
|
});
|
|
}
|
|
|
|
async run(message, args, data) {
|
|
const member = await this.client.resolveMember(args[0], message.guild);
|
|
if (!member) return message.error("economy/pay:INVALID_MEMBER");
|
|
if (member.user.bot) return message.error("economy/pay:BOT_USER");
|
|
if (member.id === message.author.id) return message.error("economy/pay:YOURSELF");
|
|
|
|
const sentAmount = args[1];
|
|
if (!sentAmount || isNaN(sentAmount) || parseInt(sentAmount, 10) <= 0) return message.error("economy/pay:INVALID_AMOUNT");
|
|
|
|
const amount = Math.ceil(parseInt(sentAmount, 10));
|
|
if (amount > data.memberData.money) return message.error("economy/pay:ENOUGH_MONEY", {
|
|
amount: `**${amount}** ${message.getNoun(amount, message.translate("misc:NOUNS:CREDITS:1"), message.translate("misc:NOUNS:CREDITS:2"), message.translate("misc:NOUNS:CREDITS:5"))}`
|
|
});
|
|
|
|
const memberData = await this.client.findOrCreateMember({
|
|
id: member.id,
|
|
guildID: message.guild.id
|
|
});
|
|
|
|
const info = {
|
|
user: member.user.tag,
|
|
amount: parseInt(amount, 10),
|
|
date: Date.now(),
|
|
type: "send"
|
|
};
|
|
|
|
data.memberData.transactions.push(info);
|
|
data.memberData.money = data.memberData.money - parseInt(amount, 10);
|
|
data.memberData.save();
|
|
|
|
memberData.money = memberData.money + parseInt(amount, 10);
|
|
memberData.save();
|
|
|
|
message.success("economy/pay:SUCCESS", {
|
|
amount: `**${amount}** ${message.getNoun(amount, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
username: member.user.tag
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = Pay; |