Files
bot-discord-coins/commands/teams/trep.js
T
2024-05-27 11:14:38 +02:00

64 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { EmbedBuilder } = require('discord.js');
const db = require('../../fonctions/database.js');
const embedColor = require('../../fonctions/embedColor.js');
module.exports = {
aliases: ['teamrep'],
description: 'Ajoute un point de reputation a une team.',
emote: '',
utilisation: '<team-id>',
permission: 0,
async execute(message, args, client) {
if (args.length > 0) {
const teamID = args[0].toLowerCase();
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);
});
});
const lastTrep = user.lastTrep
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 (lastTrep > Date.now() - 5400000) {
const embed = new EmbedBuilder()
.setTitle('Ajout Impossible')
.setDescription(`❌ Vous avez déjà ajouter une reputation récemment. Veuillez attendre ${Math.floor((lastTrep + 5400000 - Date.now()) / 60000)} minutes avant de pouvoir ajouter une reputation à 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 } });
}
db.run(`UPDATE users SET lastTrep =? WHERE guildId =? AND userId =?`, [Date.now(), message.guild.id, message.author.id], (err) => {
if (err) {
console.log(`${err}`.red)
}
});
db.run(`UPDATE teams SET reputation = reputation + 1 WHERE guildId =? AND id =?`, [message.guild.id, teamID], (err) => {
if (err) {
console.log(`${err}`.red)
}
});
const embed = new EmbedBuilder()
.setTitle('Reputation ajouté !')
.setDescription('Vous avez ajouter une reputation a la team `' + team.name + '`, qui a maintement `' + team.reputation + 1 + '` reputation !')
.setColor(await embedColor(message.author.id, message.guild.id))
.setTimestamp()
.setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() });
message.reply({ embeds: [embed], allowedMentions: { repliedUser: false } });
}
},
};