JaBa/commands/Economy/rob.js

121 lines
4.5 KiB
JavaScript
Raw Permalink Normal View History

2022-08-09 23:48:33 +05:00
const { SlashCommandBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
class Rob 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("rob")
.setDescription(client.translate("economy/rob:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("economy/rob:DESCRIPTION", null, "uk-UA"),
ru: client.translate("economy/rob:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(false)
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,
ownerOnly: false,
2022-08-09 23:48:33 +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");
if (otherMember.id === interaction.member.id) return interaction.error("economy/rob:YOURSELF");
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
const otherMemberData = await client.findOrCreateMember({
id: otherMember.id,
guildId: interaction.guildId,
2022-08-09 23:48:33 +05:00
});
2024-02-09 23:26:57 +05:00
if (amount > otherMemberData.money) return interaction.error("economy/rob:NOT_ENOUGH_MEMBER", { user: otherMember.toString() });
2022-10-09 14:26:22 +05:00
2024-02-09 23:26:57 +05:00
const isInCooldown = otherMemberData.cooldowns.rob || 0;
2022-08-09 23:48:33 +05:00
if (isInCooldown) {
2024-02-09 23:26:57 +05:00
if (isInCooldown > Date.now()) return interaction.error("economy/rob:COOLDOWN", { user: otherMember.toString() });
2022-08-09 23:48:33 +05:00
}
const potentiallyLose = Math.floor(amount * 1.5);
2024-02-09 23:26:57 +05:00
if (potentiallyLose > memberData.money)
2023-07-05 00:58:06 +05:00
return interaction.error("economy/rob:NOT_ENOUGH_AUTHOR", {
moneyMin: `**${potentiallyLose}** ${client.functions.getNoun(potentiallyLose, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
2024-02-09 23:26:57 +05:00
moneyCurrent: `**${memberData.money}** ${client.functions.getNoun(memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
2023-07-05 00:58:06 +05:00
});
2022-08-09 23:48:33 +05:00
const itsAWon = Math.floor(client.functions.randomNum(0, 100) < 25);
if (itsAWon) {
2023-07-05 00:58:06 +05:00
const toWait = Date.now() + 6 * 60 * 60 * 1000,
randomNum = client.functions.randomNum(1, 2);
2024-02-09 23:26:57 +05:00
otherMemberData.cooldowns.rob = toWait;
2024-02-09 23:26:57 +05:00
otherMemberData.markModified("cooldowns");
await otherMemberData.save();
2022-08-09 23:48:33 +05:00
interaction.replyT("economy/rob:ROB_WON_" + randomNum, {
money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
2024-02-09 23:26:57 +05:00
user: otherMember.toString(),
2022-08-09 23:48:33 +05:00
});
2024-02-09 23:26:57 +05:00
memberData.money += amount;
otherMemberData.money -= amount;
memberData.markModified("money");
2024-02-09 23:26:57 +05:00
otherMemberData.markModified("money");
2023-07-03 19:30:47 +05:00
await memberData.save();
2024-02-09 23:26:57 +05:00
await otherMemberData.save();
2022-08-09 23:48:33 +05:00
} else {
const won = Math.floor(amount * 0.9),
randomNum = client.functions.randomNum(1, 2);
2022-08-09 23:48:33 +05:00
interaction.replyT("economy/rob:ROB_LOSE_" + randomNum, {
fine: `**${potentiallyLose}** ${client.functions.getNoun(potentiallyLose, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
offset: `**${won}** ${client.functions.getNoun(won, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
2024-02-09 23:26:57 +05:00
user: otherMember.toString(),
2022-08-09 23:48:33 +05:00
});
2024-02-09 23:26:57 +05:00
memberData.money -= potentiallyLose;
otherMemberData.money += won;
memberData.markModified("money");
2024-02-09 23:26:57 +05:00
otherMemberData.markModified("money");
2023-07-03 19:30:47 +05:00
await memberData.save();
2024-02-09 23:26:57 +05:00
await otherMemberData.save();
2022-08-09 23:48:33 +05:00
}
}
}
2023-07-05 00:58:06 +05:00
module.exports = Rob;