Compare commits
2 Commits
11dd4f2c53
...
64673055fc
Author | SHA1 | Date |
---|---|---|
|
64673055fc | |
|
be4ee96847 |
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "schat2-clive",
|
||||
"version": "1.14.0",
|
||||
"version": "1.14.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "schat2-clive",
|
||||
"version": "1.14.0",
|
||||
"version": "1.14.1",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"bhttp": "^1.2.8",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "schat2-clive",
|
||||
"version": "1.14.0",
|
||||
"version": "1.14.1",
|
||||
"description": "Game host for SChat 2-powered chat sites",
|
||||
"main": "src/app.js",
|
||||
"scripts": {
|
||||
|
|
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