JaBa/commands/Economy/slots.js

183 lines
6.8 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js");
class Slots extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "slots",
dirname: __dirname,
enabled: true,
guildOnly: true,
2021-12-26 19:29:37 +05:00
aliases: ["casino", "slot"],
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: 2000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
const fruits = ["🍎", "🍐", "🍌", "🍇", "🍉", "🍒", "🍓"];
2021-12-10 21:39:54 +05:00
2022-01-03 23:20:33 +05:00
let i1 = 0,
j1 = 0,
k1 = 0,
i2 = 1,
j2 = 1,
k2 = 1,
i3 = 2,
j3 = 2,
k3 = 2;
2021-12-10 21:39:54 +05:00
// Gets three random fruits array
const colonnes = [
this.client.functions.shuffle(fruits),
this.client.functions.shuffle(fruits),
this.client.functions.shuffle(fruits)
];
// Gets the amount provided
let amount = args[0];
2021-12-30 20:03:36 +05:00
if (!amount || isNaN(amount) || amount < 1) amount = 50;
if (amount > data.memberData.money) return message.error("economy/slots:NOT_ENOUGH", {
2021-12-31 11:44:43 +05:00
money: `${amount} ${message.getNoun(amount, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`
2021-12-30 20:03:36 +05:00
});
2021-12-10 21:39:54 +05:00
amount = Math.round(amount);
2021-12-11 21:08:37 +05:00
function getCredits(number, isJackpot) {
2021-12-31 11:39:05 +05:00
if (!isJackpot) number = number * 1.5;
else if (isJackpot) number = number * 4;
2021-12-10 21:39:54 +05:00
return Math.round(number);
};
2022-01-01 14:36:16 +05:00
const tmsg = await message.sendT("misc:PLEASE_WAIT", null, {
2021-12-26 19:29:37 +05:00
prefixEmoji: "loading"
});
2021-12-10 21:39:54 +05:00
editMsg();
const interval = setInterval(editMsg, 1000);
setTimeout(() => {
clearInterval(interval);
end(tmsg);
}, 4000);
async function end() {
2021-12-26 19:29:37 +05:00
let msg = "[ :slot_machine: | **СЛОТЫ** ]\n------------------\n";
2021-12-10 21:39:54 +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;
2021-12-24 20:52:27 +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";
2021-12-10 21:39:54 +05:00
if ((colonnes[0][i2] == colonnes[1][j2]) && (colonnes[1][j2] == colonnes[2][k2])) {
2021-12-24 20:52:27 +05:00
msg += "| : : : **" + (message.translate("common:VICTORY").toUpperCase()) + "** : : : |";
2021-12-10 21:39:54 +05:00
tmsg.edit(msg);
const credits = getCredits(amount, true);
2022-01-03 23:20:33 +05:00
message.channel.send({
content: "**!! ДЖЕКПОТ !!**\n" + message.translate("economy/slots:VICTORY", {
money: `${amount} ${message.getNoun(amount, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`,
won: `${credits} ${message.getNoun(credits, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`,
username: message.author.username
})
});
2021-12-10 21:39:54 +05:00
const toAdd = credits - amount;
data.memberData.money = data.memberData.money + toAdd;
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;
2021-12-26 19:29:37 +05:00
message.channel.send({
files: [{
name: "unlocked.png",
attachment: "./assets/img/achievements/achievement_unlocked4.png"
}]
});
2021-12-10 21:39:54 +05:00
};
data.userData.markModified("achievements.slots");
await data.userData.save();
};
await data.memberData.save();
return;
};
if (colonnes[0][i2] == colonnes[1][j2] || colonnes[1][j2] == colonnes[2][k2] || colonnes[0][i2] == colonnes[2][k2]) {
2021-12-24 20:52:27 +05:00
msg += "| : : : **" + (message.translate("common:VICTORY").toUpperCase()) + "** : : : |";
2021-12-10 21:39:54 +05:00
tmsg.edit(msg);
const credits = getCredits(amount, false);
2022-01-03 23:20:33 +05:00
message.channel.send({
content: message.translate("economy/slots:VICTORY", {
money: `${amount} ${message.getNoun(amount, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`,
won: `${credits} ${message.getNoun(credits, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`,
username: message.author.username
})
});
2021-12-10 21:39:54 +05:00
const toAdd = credits - amount;
data.memberData.money = data.memberData.money + toAdd;
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;
2021-12-26 19:29:37 +05:00
message.channel.send({
files: [{
name: "unlocked.png",
attachment: "./assets/img/achievements/achievement_unlocked4.png"
}]
});
2021-12-10 21:39:54 +05:00
};
data.userData.markModified("achievements.slots");
await data.userData.save();
};
await data.memberData.save();
return;
};
2021-12-24 20:52:27 +05:00
msg += "| : : : **" + (message.translate("common:DEFEAT").toUpperCase()) + "** : : : |";
2022-01-03 23:20:33 +05:00
message.channel.send({
content: message.translate("economy/slots:DEFEAT", {
money: `${amount} ${message.getNoun(amount, message.translate("misc:NOUNS:CREDIT:1"), message.translate("misc:NOUNS:CREDIT:2"), message.translate("misc:NOUNS:CREDIT:5"))}`,
username: message.author.username
})
});
2021-12-10 21:39:54 +05:00
data.memberData.money = data.memberData.money - amount;
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;
};
function editMsg() {
2022-01-01 14:36:16 +05:00
let msg = "[ :slot_machine: | **СЛОТЫ** ]\n------------------\n";
2021-12-10 21:39:54 +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;
2021-12-26 19:29:37 +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";
2021-12-10 21:39:54 +05:00
tmsg.edit(msg);
};
}
};
module.exports = Slots;