JaBa/commands/Economy/rob.js

86 lines
2.5 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js");
class Rob extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "rob",
dirname: __dirname,
enabled: true,
guildOnly: true,
2021-12-26 19:29:37 +05:00
aliases: ["steal"],
2021-12-10 21:39:54 +05:00
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: 5000
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/rob:MISSING_MEMBER");
if (member.id === message.author.id) return message.error("economy/rob:YOURSELF");
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
const isInCooldown = memberData.cooldowns.rob || 0;
if (isInCooldown) {
2021-12-26 19:29:37 +05:00
if (isInCooldown > Date.now()) return message.error("economy/rob:COOLDOWN", {
username: member.user.tag
});
2021-12-10 21:39:54 +05:00
};
let amountToRob = args[1];
2021-12-26 19:29:37 +05:00
if (!amountToRob || isNaN(amountToRob) || parseInt(amountToRob, 10) <= 0) return message.error("economy/rob:MISSING_AMOUNT", {
username: member.user.username
});
2021-12-10 21:39:54 +05:00
amountToRob = Math.floor(parseInt(amountToRob, 10));
2021-12-26 19:29:37 +05:00
if (amountToRob > memberData.money) return message.error("economy/rob:NOT_ENOUGH_MEMBER", {
username: member.user.username,
money: amountToRob
});
2021-12-10 21:39:54 +05:00
const potentiallyLose = Math.floor(amountToRob * 1.5);
2021-12-26 19:29:37 +05:00
if (potentiallyLose > data.memberData.money) return message.error("economy/rob:NOT_ENOUGH_AUTHOR", {
moneyMin: potentiallyLose,
moneyCurrent: data.memberData.money
});
2021-12-10 21:39:54 +05:00
const itsAWon = Math.floor(this.client.functions.randomNum(0, 100) < 25);
if (itsAWon) {
const toWait = Date.now() + 6 * (60 * 60000);
memberData.cooldowns.rob = toWait;
memberData.markModified("cooldowns");
await memberData.save();
const randomNum = Math.floor(this.client.functions.randomNum(1, 3));
2021-12-26 19:29:37 +05:00
message.sendT("economy/rob:ROB_WON_" + randomNum, {
money: amountToRob,
username: member.user.username
});
2021-12-10 21:39:54 +05:00
data.memberData.money += amountToRob;
memberData.money -= amountToRob, 10;
memberData.save();
data.memberData.save();
} else {
const won = Math.floor(0.9 * amountToRob);
const randomNum = Math.floor(this.client.functions.randomNum(1, 3));
2021-12-26 19:29:37 +05:00
message.sendT("economy/rob:ROB_LOSE_" + randomNum, {
fine: potentiallyLose,
offset: won,
username: member.user.username
});
2021-12-10 21:39:54 +05:00
data.memberData.money -= potentiallyLose;
memberData.money += won;
memberData.save();
data.memberData.save();
};
}
};
module.exports = Rob;