mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 23:36:29 +02:00
224 lines
7.3 KiB
JavaScript
224 lines
7.3 KiB
JavaScript
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: "<rep|coins> <montant|all>",
|
|
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 <rep|coins> <nombre>`)",
|
|
)
|
|
.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 },
|
|
});
|
|
}
|
|
},
|
|
};
|