Fixed leaderboard dumping every single player.
This commit is contained in:
parent
4d324993fd
commit
4ef8b55021
|
@ -73,7 +73,7 @@ function getLeaderboard(game, { user, room, command }) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
game.sendMessage(`The top ${Math.min(Object.keys(leaderboard).length, 10)} ${style.italic(game.name)} players are: ${getLeaders(leaderboard, user, false)}`, room.id);
|
game.sendMessage(`The top ${Math.min(Object.keys(leaderboard).length, 10)} ${style.italic(game.name)} players are: ${getLeaders(leaderboard, user, false, 10)}`, room.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-disable no-irregular-whitespace */
|
/* eslint-disable no-irregular-whitespace */
|
||||||
|
|
|
@ -3,16 +3,20 @@
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const style = require('./style');
|
const style = require('./style');
|
||||||
|
|
||||||
function getLeaders(points, user, ping = true) {
|
function getLeaders(points, user, ping = true, limit = Infinity) {
|
||||||
return Object.entries(points).sort(([, scoreA], [, scoreB]) => scoreB - scoreA).map(([userKey, score], index) => {
|
return Object.entries(points)
|
||||||
const username = userKey.split(':')[1] || userKey; // process the points file
|
.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) {
|
if (index === 0) {
|
||||||
return `${style.bold(style.yellow(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`;
|
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`;
|
return `${style.bold(style.cyan(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`;
|
||||||
}).join(', ');
|
})
|
||||||
|
.join(', ');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = getLeaders;
|
module.exports = getLeaders;
|
||||||
|
|
Loading…
Reference in New Issue