const { EmbedBuilder } = require("discord.js"); const db = require("../../fonctions/database.js"); const embedColor = require("../../fonctions/embedColor.js"); module.exports = { aliases: [ "awh", "awith", "alliancewh", "alliancewith", "awithdraw", "alliancewithdraw", ], description: "RĂ©cupere de l'argent/des reputation dans la banque de votre alliance.", emote: "💰", utilisation: " ", permission: 0, async execute(message, args, client) { if (args.length == 0) { const embed = new EmbedBuilder() .setTitle("RĂ©cuperation Impossible") .setDescription( "❌ Vous devez spĂ©cifier un type et un montant Ă  rĂ©cupĂ©rer (`awith coins 200`).", ) .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 }, }); } else if (args[1] !== "all" && isNaN(args[1])) { const embed = new EmbedBuilder() .setTitle("RĂ©cuperation Impossible") .setDescription( "❌ Vous devez spĂ©cifier un montant valide Ă  rĂ©cupĂ©rer.", ) .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 }, }); } else if (args[1] < 1) { const embed = new EmbedBuilder() .setTitle("RĂ©cuperation Impossible") .setDescription("❌ Vous devez rĂ©cupĂ©rer au moins 1 coin/rep.") .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 }, }); } const alliance = await new Promise((resolve, reject) => { db.get( `SELECT * FROM alliances WHERE guildId = ? AND id = (SELECT alliancesId FROM team WHERE guildId = ? AND id = (SELECT teamId FROM users WHERE guildId = ? AND userId = ?))`, [message.guild.id, message.guild.id, message.author.id], (err, row) => { if (err) reject(err); resolve(row); }, ); }); if (!alliance) { const embed = new EmbedBuilder() .setTitle("RĂ©cuperation Impossible") .setDescription("❌ Vous n'ĂȘtes pas dans une alliances.") .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 }, }); } else if (args[0] == "rep" || args[0] == "r" || args[0] == "reputation") { let amout; if (args[1] === "all") { amout = alliance.bank; } else if (args[1] > alliance.bank) { const embed = new EmbedBuilder() .setTitle("RĂ©cuperation Impossible") .setDescription( "❌ Il n'y a pas suffisament de reputation dans l'alliance pour en recupĂ©rĂ© autant.\n\n💰 Il y a actuellement `" + alliance.reputation + "`rep", ) .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 }, }); } else { amout = args[1]; } db.run( `UPDATE users SET reputation = reputation + ? WHERE guildId = ? AND userId = ?`, [amout, message.guild.id, message.author.id], ); db.run( `UPDATE alliances SET reputation = reputation - ? WHERE guildId = ? AND id = ?`, [amout, message.guild.id, alliance.id], ); const embed = new EmbedBuilder() .setTitle("RĂ©cuperation EffectuĂ©") .setDescription( "💰 Vous avez rĂ©cupĂ©rĂ© **" + amout + "** coins dans la banque de votre alliances.", ) .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 }, }); } else if (args[1] == "coin" || args[0] == "c" || args[0] == "coins") { let amout; if (args[1] === "all") { amout = alliance.bank; } else if (args[1] > alliance.bank) { const embed = new EmbedBuilder() .setTitle("RĂ©cuperation Impossible") .setDescription( "❌ Il n'y a pas suffisament de coins dans l'alliance pour rĂ©cupĂ©rer cette somme.\n\n💰 il y a actuellement `" + alliance.bank + "`coins", ) .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 }, }); } else { amout = args[1]; } db.run( `UPDATE users SET pocket = pocket + ? WHERE guildId = ? AND userId = ?`, [amout, message.guild.id, message.author.id], ); db.run( `UPDATE alliances SET bank = bank - ? WHERE guildId = ? AND id = ?`, [amout, message.guild.id, alliance.id], ); const embed = new EmbedBuilder() .setTitle("RĂ©cuperation EffectuĂ©") .setDescription( "💰 Vous avez rĂ©cupĂ©rĂ© **" + amout + "** coins dans la banque de votre alliances.", ) .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 }, }); } else { const embed = new EmbedBuilder() .setTitle("RĂ©cuperation Impossible") .setDescription( "❌ Veuillez spĂ©cifier un type valide (rep|coins) :\n(`awith `)", ) .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 }, }); } }, };