schat2-clive/src/utils/get-leaders.js

19 lines
661 B
JavaScript
Raw Normal View History

2022-10-21 03:07:32 +00:00
'use strict';
const config = require('config');
const style = require('./style');
2022-10-23 22:25:13 +00:00
function getLeaders(points, user, ping = true) {
2022-10-23 19:53:59 +00:00
return Object.entries(points).sort(([, scoreA], [, scoreB]) => scoreB - scoreA).map(([userKey, score], index) => {
const username = userKey.split(':')[1] || userKey; // process the points file
2022-10-23 19:53:59 +00:00
2022-10-21 03:07:32 +00:00
if (index === 0) {
return `${style.bold(style.yellow(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`;
2022-10-21 03:07:32 +00:00
}
return `${style.bold(style.cyan(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`;
2022-10-21 03:07:32 +00:00
}).join(', ');
}
module.exports = getLeaders;