Fixed leaderboard first name color.
This commit is contained in:
parent
11dd4f2c53
commit
be4ee96847
12
src/play.js
12
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 */
|
||||
|
|
|
@ -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`;
|
||||
|
|
Loading…
Reference in New Issue