make working leaderboard command

This commit is contained in:
Santiago Forero 2021-09-16 15:33:03 -05:00
parent dd95984723
commit 4a55c2ebe3
1 changed files with 25 additions and 0 deletions

25
commands/leaderboard.js Normal file
View File

@ -0,0 +1,25 @@
const db = require('quick.db')
module.exports = {
name: 'leaderboard',
description: 'List of tallests cactuses.',
execute(event, args, bot) {
data = db.all()
data.map(score => {
score.ID = score.ID.replace('_score','')
score.data = parseFloat(parseFloat(score.data).toFixed(3))
})
data.sort(function (a, b) {
return b.data - a.data
});
console.log(data)
let text = ""
for(let i = 0; i < 5; i++) {
text += `${i + 1}. ${data[i].ID} (${data[i].data} cm) `
}
bot.say(event.target, 'Cactus Leaderboard: ' + text)
},
};