From 6888a39c1a77627cfca5372cb919b7526fcc2464 Mon Sep 17 00:00:00 2001 From: *x1 Date: Tue, 18 Jun 2024 17:54:29 +0200 Subject: [PATCH] Add alliances sys (partit 5) --- commands/Alliance/Adep.js | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 commands/Alliance/Adep.js diff --git a/commands/Alliance/Adep.js b/commands/Alliance/Adep.js new file mode 100644 index 0000000..bac34cf --- /dev/null +++ b/commands/Alliance/Adep.js @@ -0,0 +1,94 @@ +const { EmbedBuilder } = require('discord.js'); +const db = require('../../fonctions/database.js'); +const embedColor = require('../../fonctions/embedColor.js'); + +module.exports = { + aliases: ['adep', 'adepot', 'alliancedep', 'alliancedepot'], + description: 'DĂ©pose de l\'argent dans la banque de votre alliance.', + emote: '💰', + utilisation: '', + permission: 0, + + async execute(message, args, client) { + if (args.length == 0) { + const embed = new EmbedBuilder() + .setTitle('DĂ©pĂŽt Impossible') + .setDescription('❌ Vous devez spĂ©cifier un montant Ă  dĂ©poser.') + .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] !== 'all' && isNaN(args[0])) { + const embed = new EmbedBuilder() + .setTitle('DĂ©pĂŽt Impossible') + .setDescription('❌ Vous devez spĂ©cifier un montant valide Ă  dĂ©poser.') + .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] < 1) { + const embed = new EmbedBuilder() + .setTitle('DĂ©pĂŽt Impossible') + .setDescription('❌ Vous devez dĂ©poser au moins 1 coin.') + .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 pocket = await new Promise((resolve, reject) => { + db.get(`SELECT pocket FROM users WHERE guildId = ? AND userId = ?`, [message.guild.id, message.author.id], (err, row) => { + if (err) reject(err); + resolve(row.pocket); + }); + }); + + let amout; + if (args[0] === 'all') { + amout = pocket; + } else if (args[0] > pocket) { + const embed = new EmbedBuilder() + .setTitle('DĂ©pĂŽt Impossible') + .setDescription('❌ Vous n\'avez pas assez d\'argent sur vous pour dĂ©poser cette somme.\n\n💰 Vous avez actuellement **' + pocket + 'coins** sur vous.') + .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[0]; + } + + 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('DĂ©pĂŽt 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 { + 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('DĂ©pĂŽt EffectuĂ©') + .setDescription('💰 Vous avez dĂ©posĂ© **' + 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 } }); + } + }, +}; \ No newline at end of file