mirror of
https://github.com/arthur-pbty/bot-discord-coins.git
synced 2026-06-03 15:07:20 +02:00
316 lines
9.7 KiB
JavaScript
316 lines
9.7 KiB
JavaScript
const {
|
|
EmbedBuilder,
|
|
ActionRowBuilder,
|
|
StringSelectMenuBuilder,
|
|
StringSelectMenuOptionBuilder,
|
|
} = require("discord.js");
|
|
const db = require("../../fonctions/database.js");
|
|
const embedColor = require("../../fonctions/embedColor.js");
|
|
|
|
module.exports = {
|
|
aliases: ["leaderboard", "lb", "ttop"],
|
|
description: "Affiche le top 10 des membres/teams du serveur.",
|
|
emote: "🏆",
|
|
utilisation:
|
|
"[global|pocket|bank|reputation|niveau|team|teamreputation|teamdonnateur]",
|
|
permission: 0,
|
|
|
|
async execute(message, args, client) {
|
|
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] === "team" || args[0] === "t") {
|
|
args[0] = "team";
|
|
} else if (
|
|
args[0] === "teamreputation" ||
|
|
args[0] === "treputation" ||
|
|
args[0] === "teamrep" ||
|
|
args[0] === "trep"
|
|
) {
|
|
args[0] = "team";
|
|
} else if (
|
|
args[0] === "teamdonnateur" ||
|
|
args[0] === " tdonnateur" ||
|
|
args[0] === "tdroper" ||
|
|
args[0] === " tdropper" ||
|
|
args[0] === " teamdrop" ||
|
|
args[0] === "tdrop" ||
|
|
args[0] === "teamdroper" ||
|
|
args[0] === "teamdropper"
|
|
) {
|
|
args[0] = "teamdroper";
|
|
} else if (!args[0]) {
|
|
args[0] = "coins";
|
|
} else {
|
|
args[0] = "coins";
|
|
message.reply({
|
|
embeds: [
|
|
new EmbedBuilder()
|
|
.setTitle("Argument invalide")
|
|
.setDescription(
|
|
`Vous pouvez utiliser les arguments suivants: \`coins\`, \`pocket\`, \`bank\`, \`reputation\`, \`niveau\`, \`team\`, \`teamreputation\`, \`teamdonnateur\`, 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 },
|
|
});
|
|
}
|
|
|
|
async function leaderboard(type) {
|
|
let data;
|
|
if (type === "coins") {
|
|
data = await new Promise((resolve, reject) => {
|
|
db.all(
|
|
`SELECT userId, pocket+bank AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10`,
|
|
[message.guild.id],
|
|
(err, rows) => {
|
|
if (err) reject(err);
|
|
resolve(rows);
|
|
},
|
|
);
|
|
});
|
|
} else if (type === "pocket") {
|
|
data = await new Promise((resolve, reject) => {
|
|
db.all(
|
|
`SELECT userId, pocket AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10`,
|
|
[message.guild.id],
|
|
(err, rows) => {
|
|
if (err) reject(err);
|
|
resolve(rows);
|
|
},
|
|
);
|
|
});
|
|
} else if (type === "bank") {
|
|
data = await new Promise((resolve, reject) => {
|
|
db.all(
|
|
`SELECT userId, bank AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10`,
|
|
[message.guild.id],
|
|
(err, rows) => {
|
|
if (err) reject(err);
|
|
resolve(rows);
|
|
},
|
|
);
|
|
});
|
|
} else if (type === "reputation") {
|
|
data = await new Promise((resolve, reject) => {
|
|
db.all(
|
|
`SELECT userId, reputation AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10`,
|
|
[message.guild.id],
|
|
(err, rows) => {
|
|
if (err) reject(err);
|
|
resolve(rows);
|
|
},
|
|
);
|
|
});
|
|
} else if (type === "niveau") {
|
|
data = await new Promise((resolve, reject) => {
|
|
db.all(
|
|
`SELECT userId, lvl AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10`,
|
|
[message.guild.id],
|
|
(err, rows) => {
|
|
if (err) reject(err);
|
|
resolve(rows);
|
|
},
|
|
);
|
|
});
|
|
} else if (type === "team") {
|
|
data = await new Promise((resolve, reject) => {
|
|
db.all(
|
|
`SELECT name, bank AS coins FROM teams WHERE guildId = ? ORDER BY coins DESC LIMIT 10`,
|
|
[message.guild.id],
|
|
(err, rows) => {
|
|
if (err) reject(err);
|
|
resolve(rows);
|
|
},
|
|
);
|
|
});
|
|
} else if (type === "teamreputation") {
|
|
data = await new Promise((resolve, reject) => {
|
|
db.all(
|
|
`SELECT name, reputation AS teams FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10`,
|
|
[message.guild.id],
|
|
(err, rows) => {
|
|
if (err) reject(err);
|
|
resolve(rows);
|
|
},
|
|
);
|
|
});
|
|
} else if (type === "teamdroper") {
|
|
data = await new Promise((resolve, reject) => {
|
|
db.all(
|
|
`SELECT userId, teamdroper AS coins FROM users WHERE guildId = ? ORDER BY coins DESC LIMIT 10`,
|
|
[message.guild.id],
|
|
(err, rows) => {
|
|
if (err) reject(err);
|
|
resolve(rows);
|
|
},
|
|
);
|
|
});
|
|
}
|
|
|
|
const emoji = {
|
|
coins: "🪙",
|
|
pocket: "💰",
|
|
bank: "🏦",
|
|
reputation: "🔺",
|
|
niveau: "📊",
|
|
team: "👑",
|
|
teamreputation: "🔺",
|
|
teamdroper: "🎁",
|
|
};
|
|
|
|
let leaderboard = data
|
|
.map((row, i) => {
|
|
let position;
|
|
switch (i) {
|
|
case 0:
|
|
position = ":first_place:";
|
|
break;
|
|
case 1:
|
|
position = ":second_place:";
|
|
break;
|
|
case 2:
|
|
position = ":third_place:";
|
|
break;
|
|
default:
|
|
position = `**${i + 1}.**`;
|
|
}
|
|
return `${position} <@${row.userId}> - \`${row.coins}\` ${emoji[type]}`;
|
|
})
|
|
.join("\n\n");
|
|
|
|
const embed = new EmbedBuilder()
|
|
.setTitle("🏆 Top 10 des membres du serveur")
|
|
.setDescription(
|
|
`Voici le top 10 des membres du serveur trié par ${type}:\n\n${leaderboard}`,
|
|
)
|
|
.setColor(await embedColor(message.author.id, message.guild.id))
|
|
.setTimestamp()
|
|
.setFooter({
|
|
text: `Demandé par ${message.author.tag}`,
|
|
iconURL: message.author.displayAvatarURL(),
|
|
});
|
|
|
|
return embed;
|
|
}
|
|
|
|
const embed = await leaderboard(args[0]);
|
|
|
|
const select = new StringSelectMenuBuilder()
|
|
.setCustomId("topLeaderboard")
|
|
.setPlaceholder("Choisissez un type de leaderboard")
|
|
.addOptions(
|
|
new StringSelectMenuOptionBuilder()
|
|
.setLabel("Global")
|
|
.setEmoji("🪙")
|
|
.setDescription(
|
|
"Affiche le top en fonction de la somme de l'argent en poche et en banque",
|
|
)
|
|
.setValue("coins"),
|
|
new StringSelectMenuOptionBuilder()
|
|
.setLabel("Poche")
|
|
.setEmoji("💰")
|
|
.setDescription("Affiche le top en fonction de l'argent en poche")
|
|
.setValue("pocket"),
|
|
new StringSelectMenuOptionBuilder()
|
|
.setLabel("Banque")
|
|
.setEmoji("🏦")
|
|
.setDescription("Affiche le top en fonction de l'argent en banque")
|
|
.setValue("bank"),
|
|
new StringSelectMenuOptionBuilder()
|
|
.setLabel("Réputation")
|
|
.setEmoji("🔺")
|
|
.setDescription("Affiche le top en fonction de la réputation")
|
|
.setValue("reputation"),
|
|
new StringSelectMenuOptionBuilder()
|
|
.setLabel("Niveau")
|
|
.setEmoji("📊")
|
|
.setDescription("Affiche le top en fonction du niveau")
|
|
.setValue("niveau"),
|
|
new StringSelectMenuOptionBuilder()
|
|
.setLabel("Teams bank")
|
|
.setEmoji("👑")
|
|
.setDescription("Affiche le top en fonction de l'argent des teams")
|
|
.setValue("team"),
|
|
new StringSelectMenuOptionBuilder()
|
|
.setLabel("Teams réputation")
|
|
.setEmoji("🔺")
|
|
.setDescription(
|
|
"Affiche le top en fonction de la réputation des teams",
|
|
)
|
|
.setValue("teamreputation"),
|
|
new StringSelectMenuOptionBuilder()
|
|
.setLabel("TeamDroper")
|
|
.setEmoji("🎁")
|
|
.setDescription(
|
|
"Affiche le top en fonction du nombre de coins donnés à une team",
|
|
)
|
|
.setValue("teamdroper"),
|
|
);
|
|
|
|
const row = new ActionRowBuilder().addComponents(select);
|
|
|
|
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 = await leaderboard(selected);
|
|
replyMessage.edit({ embeds: [embed] });
|
|
interaction.followUp({
|
|
content: "Leaderboard mis à jour",
|
|
ephemeral: true,
|
|
});
|
|
}
|
|
});
|
|
},
|
|
};
|