From 4a55c2ebe3e7a3309d853d5a4720e8ee8595ef39 Mon Sep 17 00:00:00 2001 From: Santiago Forero Date: Thu, 16 Sep 2021 15:33:03 -0500 Subject: [PATCH] make working leaderboard command --- commands/leaderboard.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 commands/leaderboard.js diff --git a/commands/leaderboard.js b/commands/leaderboard.js new file mode 100644 index 0000000..586c329 --- /dev/null +++ b/commands/leaderboard.js @@ -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) + }, +}; \ No newline at end of file