mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 23:36:29 +02:00
231 lines
7.2 KiB
JavaScript
231 lines
7.2 KiB
JavaScript
const {
|
|
EmbedBuilder,
|
|
ButtonStyle,
|
|
ButtonBuilder,
|
|
ActionRowBuilder,
|
|
} = require("discord.js");
|
|
const embedColor = require("../../fonctions/embedColor.js");
|
|
const db = require("../../fonctions/database.js");
|
|
|
|
module.exports = {
|
|
aliases: ["slot"],
|
|
description:
|
|
"Lance la machine à sous (si 3caractère identique, tu remporte 3fois ta mise).",
|
|
emote: "🪙",
|
|
utilisation: "<mise>",
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
if (args.length !== 1) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Machine à sous")
|
|
.setDescription(
|
|
`Vous devez spécifier une mise. Exemple : \`&machine-a-sous 100\`.`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
} else if (isNaN(args[0])) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Machine à sous")
|
|
.setDescription(`La mise doit être un nombre.`)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
} else if (args[0] < 25) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Machine à sous")
|
|
.setDescription(`La mise doit être supérieure ou égale à \`25\`.`)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
|
|
const pocket = await new Promise((resolve, reject) => {
|
|
db.get(
|
|
`SELECT pocket FROM users WHERE userId = ? AND guildId = ?`,
|
|
[message.author.id, message.guild.id],
|
|
async (err, row) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(row.pocket);
|
|
}
|
|
},
|
|
);
|
|
});
|
|
|
|
if (pocket < args[0]) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Machine à sous")
|
|
.setDescription(
|
|
`Vous n'avez pas assez d'argent sur vous pour miser cette somme.`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Machine à sous")
|
|
.setImage(
|
|
"https://cdn.discordapp.com/attachments/1244326671730086049/1246142849955664093/3OkKuOYO.1245413015365488731.gif?ex=665b5077&is=6659fef7&hm=94eb9000c433e25e2e9a2355e693eb8e01b5d27fa250a8889f6098f14bf67a80&",
|
|
)
|
|
.setDescription(
|
|
`Vous avez misé \`${args[0]}\`. Les chiffres deffilent...\nRésultat dans 7.5 secondes...`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
return message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
|
|
await new Promise((resolve) => setTimeout(resolve, 7500));
|
|
|
|
let nombre1 = await Math.floor(Math.random() * 10);
|
|
let nombre2 = await Math.floor(Math.random() * (nombre1 + 1));
|
|
let nombre3 = await Math.floor(Math.random() * (nombre2 + 2));
|
|
|
|
let gain = 0;
|
|
if ((nombre1 === nombre2) === nombre3) {
|
|
gain = args[0] * 10;
|
|
} else if (
|
|
nombre1 === nombre2 ||
|
|
nombre1 === nombre3 ||
|
|
nombre2 == nombre3
|
|
) {
|
|
gain = args[0] * 2;
|
|
} else {
|
|
gain = 0 - args[0];
|
|
}
|
|
|
|
await new Promise((resolve, reject) => {
|
|
db.run(
|
|
`UPDATE users SET pocket = pocket + ? WHERE userId = ? AND guildId = ?`,
|
|
[gain, message.author.id, message.guild.id],
|
|
(err) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve();
|
|
}
|
|
},
|
|
);
|
|
});
|
|
|
|
if (gain == args[0] * 10) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Machine à sous")
|
|
.setDescription(
|
|
`Vous avez misé \`${args[0]}\` et les nombres sont : ${nombre1}, ${nombre2}, ${nombre3}. Vous avez gagné \`${gain}\` !`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
} else if (gain == args[0] * 2) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Machine à sous")
|
|
.setDescription(
|
|
`Vous avez misé \`${args[0]}\` et les nombres sont : ${nombre1}, ${nombre2}, ${nombre3}. Vous gagner deux fois votre mise (\`${gain}\`) car deux nombres sont identiques :wink: !`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
} else {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🪙 Machine à sous")
|
|
.setDescription(
|
|
`Vous avez misé \`${args[0]}\` et les nombres sont : ${nombre1}, ${nombre2}, ${nombre3}. Vous avez perdu \`${0 - gain}\` !\n\nLa probabilité de ne pas perdre à ce jeu est inferieur à 5%. La mise en cas de gain est donc mutiplier par 10`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
},
|
|
};
|