From 5d58d434b81e3f5b9caf557777c2dc2b68b2df4d Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Sun, 23 Oct 2022 23:40:52 +0200 Subject: [PATCH] Fix leaderboard showing undefined and pinging everyone. --- src/play.js | 2 +- src/utils/get-leaders.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/play.js b/src/play.js index 29f78e5..2012c98 100644 --- a/src/play.js +++ b/src/play.js @@ -73,7 +73,7 @@ function getLeaderboard(game, { user, room, command }) { return; } - game.sendMessage(`The top ${Math.min(Object.keys(leaderboard).length, 10)} ${style.italic(game.name)} players are: ${getLeaders(leaderboard, user)}`, room.id); + game.sendMessage(`The top ${Math.min(Object.keys(leaderboard).length, 10)} ${style.italic(game.name)} players are: ${getLeaders(leaderboard, user, false)}`, room.id); } /* eslint-disable no-irregular-whitespace */ diff --git a/src/utils/get-leaders.js b/src/utils/get-leaders.js index 4955bfc..8441d7d 100644 --- a/src/utils/get-leaders.js +++ b/src/utils/get-leaders.js @@ -3,15 +3,15 @@ const config = require('config'); const style = require('./style'); -function getLeaders(points, _user) { +function getLeaders(points, user, ping = false) { return Object.entries(points).sort(([, scoreA], [, scoreB]) => scoreB - scoreA).map(([userKey, score], index) => { - const username = userKey.split(':')[1]; // process the points file + const username = userKey.split(':')[1] || userKey; // process the points file if (index === 0) { - return `${style.bold(style.yellow(`${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(`${config.usernamePrefix}${username}`))} with ${style.bold(`${score}`)} points`; + return `${style.bold(style.cyan(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`; }).join(', '); }