mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-09 18:39:14 +02:00
70 lines
3.2 KiB
JavaScript
70 lines
3.2 KiB
JavaScript
const { EmbedBuilder } = require('discord.js');
|
|
const db = require('../../fonctions/database.js');
|
|
const embedColor = require('../../fonctions/embedColor.js');
|
|
|
|
module.exports = {
|
|
aliases: ['tcadena'],
|
|
description: 'Ajoute un cadenas à une team. (max : 5, coût : 3reputation)',
|
|
emote: '🔓',
|
|
utilisation: '<team-id>',
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
if (args.length > 0) {
|
|
const teamID = args[0].toLowerCase();
|
|
|
|
const team = await new Promise((resolve, reject) => {
|
|
db.get(`SELECT * FROM teams WHERE guildId = ? AND id = ?`, [message.guild.id, teamID], (err, row) => {
|
|
if (err) reject(err);
|
|
resolve(row);
|
|
});
|
|
});
|
|
|
|
const teamRep = team.reputation
|
|
if (teamRep < 4) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle('Ajout de cadenas impossible')
|
|
.setDescription(`❌ Vous n'avez pas assez de reputation. Il faut \`4\` reputation mais la team n'a que \`${teamRep}\` reputation`)
|
|
.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 } });
|
|
}
|
|
|
|
db.run(`UPDATE teams SET reputation = reputation - 4 WHERE guildId =? AND Id =?`, [message.guild.id, teamID], (err) => {
|
|
if (err) {
|
|
console.log(`${err}`.red)
|
|
}
|
|
});
|
|
|
|
if (team.padlock < 5) {
|
|
db.run(`UPDATE teams SET padlock = padlock + 1 WHERE guildId =? AND Id =?`, [message.guild.id, teamID], (err) => {
|
|
if (err) {
|
|
console.log(`${err}`.red)
|
|
}
|
|
});
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setTitle('Ajout de cadenas réussi !')
|
|
.setDescription('Vous avez ajouter un cadenas à team `' + team.name + '`, cette team à maintement `' + team.padlock + 1 + '` cadenas !')
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setImage()
|
|
.setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() });
|
|
|
|
message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } });
|
|
} else {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle('Ajout de cadenas impossible')
|
|
.setDescription('`' + team.name + '` à le maximum de cadenas (`' + team.padlock + 1 + '` cadenas !)')
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setImage()
|
|
.setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() });
|
|
|
|
message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } });
|
|
}
|
|
}
|
|
},
|
|
}; |