2022-08-09 23:48:33 +05:00
|
|
|
const { SlashCommandBuilder } = require("discord.js");
|
|
|
|
const BaseCommand = require("../../base/BaseCommand");
|
|
|
|
|
|
|
|
class Slots extends BaseCommand {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
2022-07-29 23:31:08 +05:00
|
|
|
constructor(client) {
|
2022-08-09 23:48:33 +05:00
|
|
|
super({
|
|
|
|
command: new SlashCommandBuilder()
|
|
|
|
.setName("slots")
|
|
|
|
.setDescription(client.translate("economy/slots:DESCRIPTION"))
|
2023-06-15 19:46:27 +05:00
|
|
|
.setDescriptionLocalizations({
|
2023-07-05 00:58:06 +05:00
|
|
|
uk: client.translate("economy/slots:DESCRIPTION", null, "uk-UA"),
|
|
|
|
ru: client.translate("economy/slots: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
|
|
|
.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: [],
|
2022-07-29 23:31:08 +05:00
|
|
|
dirname: __dirname,
|
2022-12-15 21:02:38 +05:00
|
|
|
ownerOnly: false,
|
2022-07-29 23:31:08 +05:00
|
|
|
});
|
|
|
|
}
|
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) {
|
|
|
|
await interaction.deferReply();
|
2022-09-25 12:11:20 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
const amount = interaction.options.getInteger("amount");
|
2023-07-05 00:58:06 +05:00
|
|
|
if (amount > data.memberData.money)
|
|
|
|
return interaction.error("economy/slots:NOT_ENOUGH", {
|
|
|
|
money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
|
|
}, { edit: true });
|
2022-07-29 23:31:08 +05:00
|
|
|
|
|
|
|
const fruits = ["🍎", "🍐", "🍌", "🍇", "🍉", "🍒", "🍓"];
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
let i1 = 0,
|
|
|
|
j1 = 0,
|
|
|
|
k1 = 0,
|
|
|
|
i2 = 1,
|
|
|
|
j2 = 1,
|
|
|
|
k2 = 1,
|
|
|
|
i3 = 2,
|
|
|
|
j3 = 2,
|
|
|
|
k3 = 2;
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
const colonnes = [client.functions.shuffle(fruits), client.functions.shuffle(fruits), client.functions.shuffle(fruits)];
|
2022-07-29 23:31:08 +05:00
|
|
|
|
|
|
|
function getCredits(number, isJackpot) {
|
|
|
|
if (!isJackpot) number = number * 1.5;
|
|
|
|
else if (isJackpot) number = number * 5;
|
|
|
|
|
|
|
|
return Math.round(number);
|
|
|
|
}
|
|
|
|
|
|
|
|
editMsg();
|
|
|
|
|
|
|
|
const interval = setInterval(editMsg, 1000);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
clearInterval(interval);
|
2022-08-09 23:48:33 +05:00
|
|
|
end();
|
2022-07-29 23:31:08 +05:00
|
|
|
}, 4000);
|
|
|
|
|
|
|
|
async function end() {
|
2023-09-08 19:26:36 +05:00
|
|
|
let msg = "[ :slot_machine: | **SLOTS** ]\n------------------\n";
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
i1 = i1 < fruits.length - 1 ? i1 + 1 : 0;
|
|
|
|
i2 = i2 < fruits.length - 1 ? i2 + 1 : 0;
|
|
|
|
i3 = i3 < fruits.length - 1 ? i3 + 1 : 0;
|
|
|
|
j1 = j1 < fruits.length - 1 ? j1 + 1 : 0;
|
|
|
|
j2 = j2 < fruits.length - 1 ? j2 + 1 : 0;
|
|
|
|
j3 = j3 < fruits.length - 1 ? j3 + 1 : 0;
|
|
|
|
k1 = k1 < fruits.length - 1 ? k1 + 1 : 0;
|
|
|
|
k2 = k2 < fruits.length - 1 ? k2 + 1 : 0;
|
|
|
|
k3 = k3 < fruits.length - 1 ? k3 + 1 : 0;
|
2022-07-29 23:31:08 +05:00
|
|
|
|
|
|
|
msg += colonnes[0][i1] + " : " + colonnes[1][j1] + " : " + colonnes[2][k1] + "\n";
|
|
|
|
msg += colonnes[0][i2] + " : " + colonnes[1][j2] + " : " + colonnes[2][k2] + " **<**\n";
|
|
|
|
msg += colonnes[0][i3] + " : " + colonnes[1][j3] + " : " + colonnes[2][k3] + "\n------------------\n";
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
if (colonnes[0][i2] == colonnes[1][j2] && colonnes[1][j2] == colonnes[2][k2]) {
|
|
|
|
msg += "| : : : **" + interaction.translate("common:VICTORY").toUpperCase() + "** : : : |";
|
2022-08-09 23:48:33 +05:00
|
|
|
await interaction.editReply({
|
2022-12-15 21:02:38 +05:00
|
|
|
content: msg,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
2022-07-29 23:31:08 +05:00
|
|
|
const credits = getCredits(amount, true);
|
2022-08-09 23:48:33 +05:00
|
|
|
interaction.followUp({
|
2023-07-05 00:58:06 +05:00
|
|
|
content:
|
|
|
|
"**!! ДЖЕКПОТ !!**\n" +
|
|
|
|
interaction.translate("economy/slots:VICTORY", {
|
|
|
|
money: `**${amount}** ${client.functions.getNoun(amount, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
|
|
won: `**${credits}** ${client.functions.getNoun(credits, interaction.translate("misc:NOUNS:CREDIT:1"), interaction.translate("misc:NOUNS:CREDIT:2"), interaction.translate("misc:NOUNS:CREDIT:5"))}`,
|
|
|
|
user: interaction.member.toString(),
|
|
|
|
}),
|
2022-07-29 23:31:08 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
const toAdd = credits - amount;
|
|
|
|
|
|
|
|
const info = {
|
2022-08-09 23:48:33 +05:00
|
|
|
user: interaction.translate("economy/slots:DESCRIPTION"),
|
2022-07-29 23:31:08 +05:00
|
|
|
amount: toAdd,
|
|
|
|
date: Date.now(),
|
2022-12-15 21:02:38 +05:00
|
|
|
type: "got",
|
2022-07-29 23:31:08 +05:00
|
|
|
};
|
2023-07-03 19:30:47 +05:00
|
|
|
|
|
|
|
data.memberData.money += toAdd;
|
2022-07-29 23:31:08 +05:00
|
|
|
data.memberData.transactions.push(info);
|
|
|
|
|
2023-07-03 19:30:47 +05:00
|
|
|
data.memberData.markModified("money");
|
|
|
|
data.memberData.markModified("transactions");
|
|
|
|
|
2022-07-29 23:31:08 +05:00
|
|
|
if (!data.userData.achievements.slots.achieved) {
|
|
|
|
data.userData.achievements.slots.progress.now += 1;
|
|
|
|
if (data.userData.achievements.slots.progress.now === data.userData.achievements.slots.progress.total) {
|
|
|
|
data.userData.achievements.slots.achieved = true;
|
2022-08-09 23:48:33 +05:00
|
|
|
interaction.followUp({
|
2023-07-05 00:58:06 +05:00
|
|
|
files: [
|
|
|
|
{
|
|
|
|
name: "achievement_unlocked4.png",
|
|
|
|
attachment: "./assets/img/achievements/achievement_unlocked4.png",
|
|
|
|
},
|
|
|
|
],
|
2022-07-29 23:31:08 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
data.userData.markModified("achievements.slots");
|
|
|
|
await data.userData.save();
|
|
|
|
}
|
|
|
|
await data.memberData.save();
|
2023-07-03 19:30:47 +05:00
|
|
|
|
2022-07-29 23:31:08 +05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (colonnes[0][i2] == colonnes[1][j2] || colonnes[1][j2] == colonnes[2][k2] || colonnes[0][i2] == colonnes[2][k2]) {
|
2023-07-05 00:58:06 +05:00
|
|
|
msg += "| : : : **" + interaction.translate("common:VICTORY").toUpperCase() + "** : : : |";
|
2022-08-09 23:48:33 +05:00
|
|
|
await interaction.editReply({
|
2022-12-15 21:02:38 +05:00
|
|
|
content: msg,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
|
|
|
|
2022-07-29 23:31:08 +05:00
|
|
|
const credits = getCredits(amount, false);
|
2022-08-09 23:48:33 +05:00
|
|
|
interaction.followUp({
|
|
|
|
content: interaction.translate("economy/slots:VICTORY", {
|
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"))}`,
|
|
|
|
won: `**${credits}** ${client.functions.getNoun(credits, 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: interaction.member.toString(),
|
|
|
|
}),
|
2022-07-29 23:31:08 +05:00
|
|
|
});
|
|
|
|
const toAdd = credits - amount;
|
|
|
|
|
|
|
|
const info = {
|
2022-08-09 23:48:33 +05:00
|
|
|
user: interaction.translate("economy/slots:DESCRIPTION"),
|
2022-07-29 23:31:08 +05:00
|
|
|
amount: toAdd,
|
|
|
|
date: Date.now(),
|
2022-12-15 21:02:38 +05:00
|
|
|
type: "got",
|
2022-07-29 23:31:08 +05:00
|
|
|
};
|
2023-07-03 19:30:47 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
data.memberData.money += toAdd;
|
2023-07-03 19:30:47 +05:00
|
|
|
data.memberData.transactions.push(info);
|
|
|
|
|
|
|
|
data.memberData.markModified("money");
|
|
|
|
data.memberData.markModified("transactions");
|
2022-07-29 23:31:08 +05:00
|
|
|
|
|
|
|
if (!data.userData.achievements.slots.achieved) {
|
|
|
|
data.userData.achievements.slots.progress.now += 1;
|
|
|
|
if (data.userData.achievements.slots.progress.now === data.userData.achievements.slots.progress.total) {
|
|
|
|
data.userData.achievements.slots.achieved = true;
|
2022-08-09 23:48:33 +05:00
|
|
|
interaction.followUp({
|
2023-07-05 00:58:06 +05:00
|
|
|
files: [
|
|
|
|
{
|
|
|
|
name: "achievement_unlocked4.png",
|
|
|
|
attachment: "./assets/img/achievements/achievement_unlocked4.png",
|
|
|
|
},
|
|
|
|
],
|
2022-07-29 23:31:08 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
data.userData.markModified("achievements.slots");
|
|
|
|
await data.userData.save();
|
|
|
|
}
|
|
|
|
await data.memberData.save();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
msg += "| : : : **" + interaction.translate("common:DEFEAT").toUpperCase() + "** : : : |";
|
2022-08-09 23:48:33 +05:00
|
|
|
interaction.followUp({
|
|
|
|
content: interaction.translate("economy/slots:DEFEAT", {
|
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: interaction.member.toString(),
|
|
|
|
}),
|
2022-07-29 23:31:08 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
const info = {
|
2022-08-09 23:48:33 +05:00
|
|
|
user: interaction.translate("economy/slots:DESCRIPTION"),
|
2022-07-29 23:31:08 +05:00
|
|
|
amount: amount,
|
|
|
|
date: Date.now(),
|
2022-12-15 21:02:38 +05:00
|
|
|
type: "send",
|
2022-07-29 23:31:08 +05:00
|
|
|
};
|
2023-07-03 19:30:47 +05:00
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
data.memberData.money -= amount;
|
2023-07-03 19:30:47 +05:00
|
|
|
data.memberData.transactions.push(info);
|
|
|
|
|
|
|
|
data.memberData.markModified("money");
|
|
|
|
data.memberData.markModified("transactions");
|
2022-07-29 23:31:08 +05:00
|
|
|
|
|
|
|
if (!data.userData.achievements.slots.achieved) {
|
|
|
|
data.userData.achievements.slots.progress.now = 0;
|
|
|
|
data.userData.markModified("achievements.slots");
|
|
|
|
await data.userData.save();
|
|
|
|
}
|
|
|
|
await data.memberData.save();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
async function editMsg() {
|
2023-09-08 19:26:36 +05:00
|
|
|
let msg = "[ :slot_machine: | **SLOTS** ]\n------------------\n";
|
2022-07-29 23:31:08 +05:00
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
i1 = i1 < fruits.length - 1 ? i1 + 1 : 0;
|
|
|
|
i2 = i2 < fruits.length - 1 ? i2 + 1 : 0;
|
|
|
|
i3 = i3 < fruits.length - 1 ? i3 + 1 : 0;
|
|
|
|
j1 = j1 < fruits.length - 1 ? j1 + 1 : 0;
|
|
|
|
j2 = j2 < fruits.length - 1 ? j2 + 1 : 0;
|
|
|
|
j3 = j3 < fruits.length - 1 ? j3 + 1 : 0;
|
|
|
|
k1 = k1 < fruits.length - 1 ? k1 + 1 : 0;
|
|
|
|
k2 = k2 < fruits.length - 1 ? k2 + 1 : 0;
|
|
|
|
k3 = k3 < fruits.length - 1 ? k3 + 1 : 0;
|
2022-07-29 23:31:08 +05:00
|
|
|
|
|
|
|
msg += colonnes[0][i1] + " : " + colonnes[1][j1] + " : " + colonnes[2][k1] + "\n";
|
|
|
|
msg += colonnes[0][i2] + " : " + colonnes[1][j2] + " : " + colonnes[2][k2] + " **<**\n";
|
|
|
|
msg += colonnes[0][i3] + " : " + colonnes[1][j3] + " : " + colonnes[2][k3] + "\n";
|
|
|
|
|
2022-08-09 23:48:33 +05:00
|
|
|
await interaction.editReply({
|
2022-12-15 21:02:38 +05:00
|
|
|
content: msg,
|
2022-08-09 23:48:33 +05:00
|
|
|
});
|
2022-07-29 23:31:08 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = Slots;
|