Fixed leaderboard first name color.

This commit is contained in:
ThePendulum 2022-10-23 21:53:59 +02:00
parent 11dd4f2c53
commit be4ee96847
2 changed files with 7 additions and 13 deletions

View File

@ -6,6 +6,7 @@ const logger = require('simple-node-logger').createSimpleLogger();
const { argv } = require('yargs'); const { argv } = require('yargs');
// const timers = require('timers/promises'); // const timers = require('timers/promises');
const getLeaders = require('./utils/get-leaders');
const style = require('./utils/style'); const style = require('./utils/style');
logger.setLevel(argv.level || 'info'); logger.setLevel(argv.level || 'info');
@ -72,16 +73,7 @@ function getLeaderboard(game, { user, room, command }) {
return; return;
} }
const curatedLeaderboard = Object.entries(leaderboard) game.sendMessage(`The top ${Math.min(Object.keys(leaderboard).length, 10)} ${style.italic(game.name)} players are: ${getLeaders(leaderboard, user)}`, room.id);
.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);
} }
/* eslint-disable no-irregular-whitespace */ /* eslint-disable no-irregular-whitespace */

View File

@ -3,10 +3,12 @@
const config = require('config'); const config = require('config');
const style = require('./style'); const style = require('./style');
function getLeaders(points) { function getLeaders(points, _user) {
return Object.entries(points).sort(([, scoreA], [, scoreB]) => scoreB - scoreA).map(([username, score], index) => { 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) { 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`; return `${style.bold(style.cyan(`${config.usernamePrefix}${username}`))} with ${style.bold(`${score}`)} points`;