Add rank to /rank, i'm dumb

This commit is contained in:
Christopher Cookman 2023-04-20 15:03:17 -06:00
parent 6390f718fa
commit d785cf72ad
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42

View file

@ -140,10 +140,29 @@ client.on("interactionCreate", async interaction => {
if (row) {
var data = row;
let lvl = data.lvl;
let rank;
// Calculate rank
await db.all(`SELECT * FROM levels ORDER BY totalXp DESC`, async (err, rows) => {
if (err) {
console.error(err);
}
if (rows) {
let rank = 0;
for (let i = 0; i < rows.length; i++) {
if (rows[i].id === user.id) {
rank = i + 1;
break;
}
}
interaction.reply({
embeds: [{
title: `${user.tag}'s Rank`,
fields: [{
name: "Rank",
value: `#${rank}`,
inline: true
},
{
name: "Level",
value: data.lvl,
inline: true
@ -168,6 +187,8 @@ client.on("interactionCreate", async interaction => {
})
}
});
}
});
break;
case "leaderboard":
await db.all(`SELECT * FROM levels ORDER BY totalXp DESC`, async (err, rows) => {
@ -254,8 +275,7 @@ client.on("interactionCreate", async interaction => {
ephemeral: true
});
}
}
);
});
break;
};
});