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) => {
|
2022-10-23 21:40:52 +00:00
|
|
|
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) {
|
2022-10-23 21:40:52 +00:00
|
|
|
return `${style.bold(style.yellow(`${ping ? config.usernamePrefix : ''}${username}`))} with ${style.bold(`${score}`)} points`;
|
2022-10-21 03:07:32 +00:00
|
|
|
}
|
|
|
|
|
2022-10-23 21:40:52 +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;
|