2022-08-09 23:48:33 +05:00
|
|
|
const { SlashCommandBuilder } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Rob extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
|
|
|
constructor(client) {
|
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("rob")
|
|
|
|
.setDescription(client.translate("economy/rob:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.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"),
|
2023-06-15 19:46:27 +05:00
|
|
|
})
|
2022-10-13 00:05:36 +05:00
|
|
|
.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
|
|
|
aliases: [],
|
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @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/rob:YOURSELF");
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
const amount = interaction.options.getInteger("amount");
|
|
|
|
if (amount <= 0) return interaction.error("misc:MORE_THAN_ZERO");
|
|
|
|
|
|
|
|
const memberData = await client.findOrCreateMember({
|
|
|
|
id: member.id,
|
2022-12-15 21:02:38 +05:00
|
|
|
guildId: interaction.guildId,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
if (amount > memberData.money) return interaction.error("economy/rob:NOT_ENOUGH_MEMBER", { user: member.toString() });
|
2022-10-09 14:26:22 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
const isInCooldown = memberData.cooldowns.rob || 0;
|
|
|
|
if (isInCooldown) {
|
|
|
|
if (isInCooldown > Date.now()) return interaction.error("economy/rob:COOLDOWN", { user: member.toString() });
|
|
|
|
}
|
|
|
|
|
|
|
|
const potentiallyLose = Math.floor(amount * 1.5);
|
2023-07-05 00:58:06 +05:00
|
|
|
if (potentiallyLose > data.memberData.money)
|
|
|
|
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"))}`,
|
|
|
|
moneyCurrent: `**${data.memberData.money}** ${client.functions.getNoun(data.memberData.money, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
|
|
});
|
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,
|
2023-01-09 01:39:13 +05:00
|
|
|
randomNum = client.functions.randomNum(1, 2);
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
memberData.cooldowns.rob = toWait;
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2023-10-30 21:45:10 +05:00
|
|
|
memberData.markModified();
|
2022-08-09 23:48:33 +05:00
|
|
|
await memberData.save();
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
interaction.replyT("economy/rob:ROB_WON_" + randomNum, {
|
2023-04-20 11:47:47 +05:00
|
|
|
money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
2022-12-15 21:02:38 +05:00
|
|
|
user: member.toString(),
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
data.memberData.money += amount;
|
|
|
|
memberData.money -= amount;
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2023-10-30 21:45:10 +05:00
|
|
|
data.memberData.markModified();
|
|
|
|
memberData.markModified();
|
2022-08-09 23:48:33 +05:00
|
|
|
await data.memberData.save();
|
2023-07-03 19:30:47 +05:00
|
|
|
await memberData.save();
|
2022-08-09 23:48:33 +05:00
|
|
|
} else {
|
2023-01-09 01:39:13 +05:00
|
|
|
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, {
|
2023-04-20 11:47:47 +05:00
|
|
|
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"))}`,
|
2022-12-15 21:02:38 +05:00
|
|
|
user: member.toString(),
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
data.memberData.money -= potentiallyLose;
|
|
|
|
memberData.money += won;
|
2023-01-09 01:39:13 +05:00
|
|
|
|
2023-10-30 21:45:10 +05:00
|
|
|
data.memberData.markModified();
|
|
|
|
memberData.markModified();
|
2022-08-09 23:48:33 +05:00
|
|
|
await data.memberData.save();
|
2023-07-03 19:30:47 +05:00
|
|
|
await memberData.save();
|
2022-08-09 23:48:33 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Rob;
|