mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-13 08:09:31 +02:00
corrige bug et debus refonte top
This commit is contained in:
+36
-94
@@ -6,105 +6,47 @@ module.exports = {
|
||||
aliases: ['leaderboard', 'lb'],
|
||||
description: 'Affiche le top 10 des membres du serveur',
|
||||
emote: '🏆',
|
||||
utilisation: '[pocket|bank|reputation]',
|
||||
utilisation: '[coins|pocket|bank|reputation|niveau]',
|
||||
permission: 0,
|
||||
|
||||
async execute(message, args, client) {
|
||||
let type = 'bank';
|
||||
let emote = ':bank:';
|
||||
if (args[0] ==='pocket') {
|
||||
type = args[0]
|
||||
emote = ':moneybag:';
|
||||
} else if (args[0] === 'reputation') {
|
||||
type = args[0]
|
||||
emote = ':star2:';
|
||||
} else if (args[0] && args[0] !== 'bank') {
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('Erreur')
|
||||
.setDescription('❌ Veuillez spécifier un type de leaderboard valide: `pocket`, `bank` ou `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 } })
|
||||
}
|
||||
|
||||
const [embed, row] = await leaderboard(message, type);
|
||||
const replyMessage = await message.reply({ embeds: [embed], components: [row], allowedMentions: { repliedUser: false } });
|
||||
|
||||
client.on('interactionCreate', async (interaction) => {
|
||||
if (!interaction.isStringSelectMenu()) return;
|
||||
|
||||
if (interaction.customId === 'topLeaderboard') {
|
||||
const selected = interaction.values[0];
|
||||
|
||||
await interaction.deferUpdate();
|
||||
|
||||
const [embed, row] = await leaderboard(message, selected);
|
||||
replyMessage.edit({ embeds: [embed], components: [row], allowedMentions: { repliedUser: false } });
|
||||
interaction.followUp({ content: `Leaderboard mis à jour en fonction de \`${selected}\``, ephemeral: true, allowedMentions: { repliedUser: false } });
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
async function leaderboard(message, type) {
|
||||
const topUsers = await new Promise((resolve, reject) => {
|
||||
db.all(`SELECT * FROM users WHERE guildId = ? ORDER BY ${type} DESC LIMIT 10`, [message.guild.id], (err, rows) => {
|
||||
if (err) reject(err);
|
||||
resolve(rows);
|
||||
});
|
||||
});
|
||||
|
||||
let emote = ':bank:';
|
||||
if (type === 'pocket') {
|
||||
emote = ':moneybag:';
|
||||
} else if (type === 'reputation') {
|
||||
emote = ':star2:';
|
||||
}
|
||||
|
||||
const description = topUsers.map((user, index) => {
|
||||
let place;
|
||||
if (index === 0) {
|
||||
place = ':first_place:';
|
||||
} else if (index === 1) {
|
||||
place = ':second_place:';
|
||||
} else if (index === 2) {
|
||||
place = ':third_place:';
|
||||
if (args[0] === 'coins' || args[0] === 'coin' || args[0] === 'global' || args[0] === 'money') {
|
||||
args[0] = 'coins'
|
||||
} else if (args[0] === 'pocket' || args[0] === 'cash' || args[0] === 'wallet' || args[0] === 'porte-monnaie' || args[0] === 'poche') {
|
||||
args[0] = 'pocket'
|
||||
} else if (args[0] === 'bank' || args[0] === 'banque' || args[0] === 'coffre' || args[0] === 'coffre-fort' || args[0] === 'bk') {
|
||||
args[0] = 'bank'
|
||||
} else if (args[0] === 'reputation' || args[0] === 'rep' || args[0] === 'réputation' || args[0] === 'reput') {
|
||||
args[0] = 'reputation'
|
||||
} else if (args[0] === 'niveau' || args[0] === 'lvl' || args[0] === 'level' || args[0] === 'lvl') {
|
||||
args[0] = 'niveau'
|
||||
} else if (!args[0]) {
|
||||
args[0] = 'coins'
|
||||
} else {
|
||||
place = `${index + 1}.`;
|
||||
args[0] = 'coins'
|
||||
message.reply({ embeds: [
|
||||
new EmbedBuilder()
|
||||
.setTitle('Argument invalide')
|
||||
.setDescription(`Vous pouvez utiliser les arguments suivants: \`coins\`, \`pocket\`, \`bank\`, \`reputation\`, \`niveau\` ou ne rien mettre pour afficher le top 10 des membres du serveur.`)
|
||||
.setColor(await embedColor(message.author.id, message.guild.id))
|
||||
.setTimestamp()
|
||||
.setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() })
|
||||
], allowedMentions: { repliedUser: false } })
|
||||
}
|
||||
return `${place} <@${user.userId}> - \`${user[type]}\` ${emote}`;
|
||||
});
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setAuthor({ name: `Top 10 des Membres de ${message.guild.name} en ${type}`, iconURL: message.guild.iconURL() })
|
||||
.setDescription(description.join('\n\n'))
|
||||
.setColor(await embedColor(message.author.id, message.guild.id))
|
||||
.setTimestamp()
|
||||
.setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() });
|
||||
|
||||
const select = new StringSelectMenuBuilder()
|
||||
.setCustomId('topLeaderboard')
|
||||
.setPlaceholder('Choisissez un type de leaderboard')
|
||||
.addOptions(
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('Pocket')
|
||||
.setDescription('Affiche le top en fonction de leur argent de poche')
|
||||
.setValue('pocket'),
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('Bank')
|
||||
.setDescription('Affiche le top en fonction de leur argent en banque')
|
||||
.setValue('bank'),
|
||||
new StringSelectMenuOptionBuilder()
|
||||
.setLabel('Reputation')
|
||||
.setDescription('Affiche le top en fonction de leur réputation')
|
||||
.setValue('reputation')
|
||||
);
|
||||
|
||||
const row = new ActionRowBuilder()
|
||||
.addComponents(select);
|
||||
let data;
|
||||
if (args[0] === 'coins') {
|
||||
data = db.all(`SELECT userId, pocket+bank AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10`, [message.guild.id]);
|
||||
} else if (args[0] === 'pocket') {
|
||||
data = db.all(message.guild.id, 'SELECT userId, pocket AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10', [message.guild.id]);
|
||||
} else if (args[0] === 'bank') {
|
||||
data = db.all(message.guild.id, 'SELECT userId, bank AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10', [message.guild.id]);
|
||||
} else if (args[0] === 'reputation') {
|
||||
data = db.all(message.guild.id, 'SELECT userId, reputation AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10', [message.guild.id]);
|
||||
} else if (args[0] === 'niveau') {
|
||||
data = db.all(message.guild.id, 'SELECT userId, lvl AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10', [message.guild.id]);
|
||||
}
|
||||
|
||||
return [embed, row];
|
||||
console.log(data)
|
||||
},
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
const { Events } = require('discord.js');
|
||||
const db = require('../fonctions/database.js');
|
||||
const embedColor = require('../fonctions/embedColor.js');
|
||||
|
||||
module.exports = {
|
||||
name: Events.InteractionCreate,
|
||||
|
||||
@@ -7,10 +7,10 @@ module.exports = {
|
||||
if (message.author.bot) return;
|
||||
|
||||
if (message.content.length < 50) {
|
||||
db.run(`UPDATE users SET xp = xp + 1, WHERE guildId = ? AND userId = ?`, [message.guild.id, message.author.id]);
|
||||
db.run(`UPDATE users SET xp = xp + 1 WHERE guildId = ? AND userId = ?`, [message.guild.id, message.author.id]);
|
||||
}
|
||||
if (message.content.length >= 50) {
|
||||
db.run(`UPDATE users SET xp = xp + 3, WHERE guildId = ? AND userId = ?`, [message.guild.id, message.author.id]);
|
||||
db.run(`UPDATE users SET xp = xp + 3 WHERE guildId = ? AND userId = ?`, [message.guild.id, message.author.id]);
|
||||
}
|
||||
|
||||
const user = await new Promise((resolve, reject) => {
|
||||
|
||||
Reference in New Issue
Block a user