JaBa/commands/Economy/pay.js

51 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js");
class Pay extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "pay",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: [],
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: false,
cooldown: 2000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2021-12-10 21:39:54 +05:00
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", { username: member.user.tag });
const amount = Math.ceil(parseInt(sentAmount, 10));
2021-12-30 20:03:36 +05:00
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"))}`
2021-12-30 20:03:36 +05:00
});
2021-12-10 21:39:54 +05:00
2021-12-26 19:29:37 +05:00
const memberData = await this.client.findOrCreateMember({
id: member.id,
guildID: message.guild.id
});
2021-12-10 21:39:54 +05:00
data.memberData.money = data.memberData.money - parseInt(amount, 10);
data.memberData.save();
memberData.money = memberData.money + parseInt(amount, 10);
memberData.save();
2021-12-26 19:29:37 +05:00
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"))}`,
2021-12-26 19:29:37 +05:00
username: member.user.tag
});
2021-12-10 21:39:54 +05:00
}
};
module.exports = Pay;