diff --git a/commands/casino/pay.js b/commands/casino/pay.js index a87eed3..178fb4c 100644 --- a/commands/casino/pay.js +++ b/commands/casino/pay.js @@ -12,73 +12,80 @@ module.exports = { async execute(message, args, client) { let amount; const member = message.mentions.members.first(); + const color = await embedColor(message.author.id, message.guild.id) + const footer = { text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() } - const user = await new Promise((resolve, reject) => { + const pocket = await new Promise((resolve, reject) => { db.get(`SELECT * FROM users WHERE guildId = ? AND userId = ?`, [message.guild.id, message.author.id], (err, row) => { if (err) reject(err); - resolve(row); + resolve(row.pocket); }); }); - const pocket = user.pocket; if (!member) { - const embed = new EmbedBuilder() - .setTitle('Erreur') - .setDescription('❌ Veuillez mentionner un membre du serveur.') - .setColor(await embedColor(message.author.id, message.guild.id)) - .setTimestamp() - .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() }); - - return message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } }); + return message.reply({ embeds: [ + new EmbedBuilder() + .setTitle('Erreur') + .setDescription('❌ Veuillez mentionner un membre du serveur.') + .setColor(color) + .setTimestamp() + .setFooter(footer) + ], allowedMentions: { repliedUser: false } }); } if (!args[0]) { - const embed = new EmbedBuilder() - .setTitle('Erreur') - .setDescription('❌ Veuillez spécifier un montant à payer.') - .setColor(await embedColor(message.author.id, message.guild.id)) - .setTimestamp() - .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() }); + return message.reply({ embeds: [ + new EmbedBuilder() + .setTitle('Erreur') + .setDescription('❌ Veuillez spécifier un montant à payer.') + .setColor(color) + .setTimestamp() + .setFooter(footer) + ], allowedMentions: { repliedUser: false } }); - return message.reply({ embeds: [embed] }); } else if (args[0] === 'all') { amount = pocket; + } else if (isNaN(args[0])) { - const embed = new EmbedBuilder() - .setTitle('Erreur') - .setDescription('❌ Veuillez spécifier un montant valide.') - .setColor(await embedColor(message.author.id, message.guild.id)) - .setTimestamp() - .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() }); + return message.reply({ embeds: [ + new EmbedBuilder() + .setTitle('Erreur') + .setDescription('❌ Veuillez spécifier un montant valide.') + .setColor(color) + .setTimestamp() + .setFooter(footer) + ], allowedMentions: { repliedUser: false } }); - return message.reply({ embeds: [embed] }); } else if (args[0] <= 0) { - const embed = new EmbedBuilder() - .setTitle('Erreur') - .setDescription('❌ Veuillez spécifier un montant supérieur à 0.') - .setColor(await embedColor(message.author.id, message.guild.id)) - .setTimestamp() - .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() }); + return message.reply({ embeds: [ + new EmbedBuilder() + .setTitle('Erreur') + .setDescription('❌ Veuillez spécifier un montant supérieur à 0.') + .setColor(color) + .setTimestamp() + .setFooter(footer) + ], allowedMentions: { repliedUser: false } }); - return message.reply({ embeds: [embed] }); } else if (args[0] > pocket) { - const embed = new EmbedBuilder() - .setTitle('Erreur') - .setDescription('❌ Vous n\'avez pas assez d\'argent pour effectuer cette transaction.') - .setColor(await embedColor(message.author.id, message.guild.id)) - .setTimestamp() - .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() }); + return message.reply({ embeds: [ + new EmbedBuilder() + .setTitle('Erreur') + .setDescription('❌ Vous n\'avez pas assez d\'argent pour effectuer cette transaction.') + .setColor(color) + .setTimestamp() + .setFooter(footer) + ], allowedMentions: { repliedUser: false } }); - return message.reply({ embeds: [embed] }); } else if (!Number.isInteger(Number(args[0]))) { - const embed = new EmbedBuilder() - .setTitle('Erreur') - .setDescription('❌ Veuillez spécifier un montant entier.') - .setColor(await embedColor(message.author.id, message.guild.id)) - .setTimestamp() - .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() }); + return message.reply({ embeds: [ + new EmbedBuilder() + .setTitle('Erreur') + .setDescription('❌ Veuillez spécifier un montant entier.') + .setColor(color) + .setTimestamp() + .setFooter(footer) + ], allowedMentions: { repliedUser: false } }); - return message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } }); } else { amount = args[0]; } @@ -86,13 +93,13 @@ module.exports = { db.run(`UPDATE users SET pocket = pocket - ? WHERE guildId = ? AND userId = ?`, [amount, message.guild.id, message.author.id]); db.run(`UPDATE users SET pocket = pocket + ? WHERE guildId = ? AND userId = ?`, [amount, message.guild.id, member.id]); - const embed = new EmbedBuilder() - .setTitle('Paiement') - .setDescription(`💰 Vous avez payé ${amount} à ${member.user.tag}.`) - .setColor(await embedColor(message.author.id, message.guild.id)) - .setTimestamp() - .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() }); - - message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } }); + message.reply({ embeds: [ + new EmbedBuilder() + .setTitle('Paiement') + .setDescription(`💰 Vous avez payé ${amount} à ${member.user.tag}.`) + .setColor(color) + .setTimestamp() + .setFooter(footer) + ], allowedMentions: { repliedUser: false } }); }, };