From be4ee9684772a6a8ec01e9caa40e6008015206fe Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Sun, 23 Oct 2022 21:53:59 +0200 Subject: [PATCH] Fixed leaderboard first name color. --- src/play.js | 12 ++---------- src/utils/get-leaders.js | 8 +++++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/play.js b/src/play.js index 3039c91..29f78e5 100644 --- a/src/play.js +++ b/src/play.js @@ -6,6 +6,7 @@ const logger = require('simple-node-logger').createSimpleLogger(); const { argv } = require('yargs'); // const timers = require('timers/promises'); +const getLeaders = require('./utils/get-leaders'); const style = require('./utils/style'); logger.setLevel(argv.level || 'info'); @@ -72,16 +73,7 @@ function getLeaderboard(game, { user, room, command }) { return; } - const curatedLeaderboard = Object.entries(leaderboard) - .sort(([, scoreA], [, scoreB]) => scoreB - scoreA) - .map(([userKey, score]) => { - const username = userKey.split(':')[1]; - return `${style.bold(`${username === user.username ? config.usernamePrefix : ''}${username}`)} at ${style.bold(score)} points`; - }) - .slice(0, 10) - .join(', '); - - game.sendMessage(`The top ${Math.min(Object.keys(leaderboard).length, 10)} ${style.italic(game.name)} players are: ${curatedLeaderboard}`, room.id); + game.sendMessage(`The top ${Math.min(Object.keys(leaderboard).length, 10)} ${style.italic(game.name)} players are: ${getLeaders(leaderboard, user)}`, room.id); } /* eslint-disable no-irregular-whitespace */ diff --git a/src/utils/get-leaders.js b/src/utils/get-leaders.js index bcea75a..4955bfc 100644 --- a/src/utils/get-leaders.js +++ b/src/utils/get-leaders.js @@ -3,10 +3,12 @@ const config = require('config'); const style = require('./style'); -function getLeaders(points) { - return Object.entries(points).sort(([, scoreA], [, scoreB]) => scoreB - scoreA).map(([username, score], index) => { +function getLeaders(points, _user) { + return Object.entries(points).sort(([, scoreA], [, scoreB]) => scoreB - scoreA).map(([userKey, score], index) => { + const username = userKey.split(':')[1]; // process the points file + if (index === 0) { - return `${style.bold(`${config.usernamePrefix}${username}`)} with ${style.bold(`${score}`)} points`; + return `${style.bold(style.yellow(`${config.usernamePrefix}${username}`))} with ${style.bold(`${score}`)} points`; } return `${style.bold(style.cyan(`${config.usernamePrefix}${username}`))} with ${style.bold(`${score}`)} points`;