37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
const Revolt = require('revolt.js');
|
|
const { client, logger, config } = require('..');
|
|
const { levels, levelups } = require('../util/levels');
|
|
|
|
module.exports.meta = {
|
|
name: 'leaderboard',
|
|
aliases: [ 'top' ],
|
|
description: 'View leaderboards for XP and tic tac toe.'
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param { Revolt.Message } message
|
|
* @param { string[] } args
|
|
*/
|
|
module.exports.run = async (message, args) => new Promise(async (resolve, reject) => {
|
|
let xp = Array.from(levels)
|
|
.sort((a, b) => b[1].xp - a[1].xp);
|
|
|
|
let top = xp.slice(0, 5);
|
|
let out = `># Top 5 - XP\n>\u200b\n`;
|
|
|
|
let p = [];
|
|
top.forEach(item => p.push(client.users.fetch(item[0])));
|
|
p = await Promise.allSettled(p);
|
|
|
|
p.forEach((pr, i) => top[i].push(pr?.value));
|
|
|
|
top.forEach((item, i) => out += `><@${item[0]}>: `
|
|
+ `${item[1]?.xp} XP, Level ${item[1]?.level}}\n`);
|
|
|
|
let combinedXP = xp.reduce((total, cur) => total + cur[1]?.xp, 0);
|
|
|
|
out += `\n#### Combined XP of all users: \`${combinedXP}\``
|
|
|
|
await client.channels.sendMessage(message.channel, out);
|
|
}); |