mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-08 23:31:56 +02:00
124 lines
4.0 KiB
JavaScript
124 lines
4.0 KiB
JavaScript
const { EmbedBuilder } = require("discord.js");
|
|
const db = require("../../fonctions/database.js");
|
|
const embedColor = require("../../fonctions/embedColor.js");
|
|
|
|
module.exports = {
|
|
aliases: ["arep", "areputation", "alliancereputation", "alliancerep"],
|
|
description:
|
|
"Ajoute une reputation a une alliance. (tout le monde peux en recupéré ⚠️)",
|
|
emote: "💰",
|
|
utilisation: "<id>",
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
if (args.length == 0) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Ajout de reputation")
|
|
.setDescription("❌ Vous devez spécifier une alliance a 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 if (args[0] < 3) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Ajout de reputation")
|
|
.setDescription("❌ Vous devez mettre l'id d'une alliance.")
|
|
.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 = ?`,
|
|
[message.guild.id, args[0]],
|
|
(err, row) => {
|
|
if (err) reject(err);
|
|
resolve(row);
|
|
},
|
|
);
|
|
});
|
|
const user = await new Promise((resolve, reject) => {
|
|
db.get(
|
|
`SELECT * FROM users WHERE guildId = ? AND userId = ?`,
|
|
[message.guild.id, message.author.id],
|
|
(err, row) => {
|
|
if (err) reject(err);
|
|
resolve(row.lastRep);
|
|
},
|
|
);
|
|
});
|
|
|
|
if (!alliance) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Ajout de reputation")
|
|
.setDescription("❌ Alliance introuvable.")
|
|
.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 (user.lastArep > Date.now() - 1800000) {
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Ajout de reputation impossible")
|
|
.setDescription(
|
|
`❌ Vous avez déjà ajouté une reputation récemment. Veuillez attendre \`${Math.floor((user.lastArep + 1800000 - Date.now()) / 60000)}\` minutes avant de pouvoir travailler à nouveau.`,
|
|
)
|
|
.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 alliances SET reputation = reputation + 1 WHERE guildId = ? AND id = ?`,
|
|
[message.guild.id, args[0]],
|
|
);
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("Ajout de reputation effectué")
|
|
.setDescription(
|
|
"💰 Vous avez ajouter `1` reputation à l'alliance `" + args[0] + "`.",
|
|
)
|
|
.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 },
|
|
});
|
|
}
|
|
},
|
|
};
|