Files
bot-discord-coins/commands/teams/tcadenas.js
T
2024-06-24 00:32:05 +02:00

130 lines
3.6 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) {
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);
},
);
});
if (!team) {
const embed = new EmbedBuilder()
.setTitle("Ajout Impossible")
.setDescription(`❌ Veuillez indiquer l'id une team.`)
.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 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 },
});
}
},
};