mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 23:36:29 +02:00
155 lines
6.4 KiB
JavaScript
155 lines
6.4 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) {
|
|
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])) {
|
|
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 (args[0] < 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
|
|
}
|
|
|
|
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 {
|
|
if (row.pocket < args[0]) {
|
|
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() })
|
|
|
|
return message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } })
|
|
});
|
|
} else {
|
|
resolve(row.pocket);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
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é \`${args[0]}\` sur \`${args[1]}\`. La bille tourne...\nRésultat dans 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, 5000));
|
|
|
|
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 = args[0] * 2;
|
|
} else if ((args[1] === 'vert' || args[1] === 'green') && colorR === 'vert') {
|
|
gain = args[0] * 36;
|
|
} 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 >= 0) {
|
|
embedColor(message.author.id, message.guild.id).then(color => {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle('🎲 Roulette')
|
|
.setDescription(`Vous avez misé \`${args[0]}\` 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é \`${args[0]}\` 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
|
|
}
|
|
}
|
|
}; |