Fixed leaderboard dumping every single player.

This commit is contained in:
2022-10-24 00:53:32 +02:00
parent 4d324993fd
commit 4ef8b55021
2 changed files with 13 additions and 9 deletions

View File

@@ -3,16 +3,20 @@
const config = require('config');
const style = require('./style');
function getLeaders(points, user, ping = true) {
return Object.entries(points).sort(([, scoreA], [, scoreB]) => scoreB - scoreA).map(([userKey, score], index) => {
const username = userKey.split(':')[1] || userKey; // process the points file
function getLeaders(points, user, ping = true, limit = Infinity) {
return Object.entries(points)
.sort(([, scoreA], [, scoreB]) => scoreB - scoreA)
.slice(0, limit)
.map(([userKey, score], index) => {
const username = userKey.split(':')[1] || userKey; // process the points file
if (index === 0) {
return `${style.bold(style.yellow(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`;
}
if (index === 0) {
return `${style.bold(style.yellow(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`;
}
return `${style.bold(style.cyan(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`;
}).join(', ');
return `${style.bold(style.cyan(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`;
})
.join(', ');
}
module.exports = getLeaders;