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