mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 15:07:20 +02:00
251 lines
7.2 KiB
JavaScript
251 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: ["roulette"],
|
|
description: "Lance une roulette.",
|
|
emote: "🎲",
|
|
utilisation: "<mise> <couleur>",
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
let mise = 0;
|
|
const pocket = await new Promise((resolve, reject) => {
|
|
db.get(
|
|
`SELECT pocket FROM users WHERE userId = ? AND guildId = ?`,
|
|
[message.author.id, message.guild.id],
|
|
(err, row) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve(row.pocket);
|
|
}
|
|
},
|
|
);
|
|
});
|
|
if (args[0] == "all") {
|
|
mise = pocket;
|
|
} else {
|
|
mise = args[0];
|
|
}
|
|
|
|
if (args.length !== 2) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Roulette")
|
|
.setDescription(
|
|
`Vous devez spécifier une mise et une couleur. Exemple : \`&roulette 100 rouge\`.`,
|
|
)
|
|
.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]) && !args[0] == "all") {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Roulette")
|
|
.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 (mise < 25) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Roulette")
|
|
.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;
|
|
} else if (
|
|
args[1] !== "rouge" &&
|
|
args[1] !== "noir" &&
|
|
args[1] !== "vert" &&
|
|
args[1] !== "red" &&
|
|
args[1] !== "black" &&
|
|
args[1] !== "green"
|
|
) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Roulette")
|
|
.setDescription(
|
|
`La couleur doit être \`rouge\`, \`noir\` ou \`vert\`.`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (pocket < mise) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Roulette")
|
|
.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("🎲 Roulette")
|
|
.setImage(
|
|
"https://images-ext-1.discordapp.net/external/Zz7GmmFoFdFRB7GCjiJGaDHDjJi8noOLY8zasCmUOGQ/https/media.giphy.com/media/26uflBhaGt5lQsaCA/giphy.gif",
|
|
)
|
|
.setDescription(
|
|
`Vous avez misé \`${mise}\` sur \`${args[1]}\`. La bille tourne...\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));
|
|
|
|
const result = Math.floor(Math.random() * 37);
|
|
let colorR = "";
|
|
if (result === 0) {
|
|
colorR = "vert";
|
|
} else if (result % 2 === 0) {
|
|
colorR = "rouge";
|
|
} else {
|
|
colorR = "noir";
|
|
}
|
|
|
|
let gain = 0;
|
|
if (
|
|
((args[1] === "rouge" || args[1] === "red") && colorR === "rouge") ||
|
|
((args[1] === "noir" || args[1] === "black") && colorR === "noir")
|
|
) {
|
|
gain = Math.round(mise * 1.5);
|
|
} else if (
|
|
(args[1] === "vert" || args[1] === "green") &&
|
|
colorR === "vert"
|
|
) {
|
|
gain = mise * 36;
|
|
} else {
|
|
gain = 0 - mise;
|
|
}
|
|
|
|
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 >= 0) {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Roulette")
|
|
.setDescription(
|
|
`Vous avez misé \`${mise}\` sur \`${args[1]}\` et la bille est tombée sur \`${colorR}\`. 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 {
|
|
embedColor(message.author.id, message.guild.id).then((color) => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🎲 Roulette")
|
|
.setDescription(
|
|
`Vous avez misé \`${mise}\` sur \`${args[1]}\` et la bille est tombée sur \`${colorR}\`. Vous avez perdu \`${0 - gain}\` !`,
|
|
)
|
|
.setColor(color)
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
message.reply({
|
|
embeds: [embed],
|
|
allowedMentions: { repliedUser: false },
|
|
});
|
|
});
|
|
return;
|
|
}
|
|
},
|
|
};
|