obama-bot/commands/top.js

39 lines
1.3 KiB
JavaScript

const Discord = require('discord.js');
module.exports.meta = {
name: 'top',
aliases: ['leaderboard'],
staffOnly: false
}
const karma = require('../util/karma').karma;
const coins = require('../util/karma').coins;
/**
*
* @param {Discord.Message} message
* @param {Array<string>} args
*/
module.exports.run = async (message, args) => {
const karmaID = '733339045463064607';
const karmaEmote = message.guild.emojis.cache.get(karmaID).toString();
let karmaboard = [];
karma.keyArray().forEach(uid => {
karmaboard.push({id: uid, karma: karma.get(uid)});
});
karmaboard.sort((a, b) => a.karma - b.karma);
karmaboard.reverse();
let embed = new Discord.MessageEmbed()
.setTitle('Karma Leaderboard')
.setDescription(karmaEmote + ' Karma leaderboard - Top 12 for ' + message.guild.name);
for (let x=0; x < 12; x += 1) {
if (!karmaboard[x]) break;
let u = message.guild.members.cache.get(karmaboard[x].id);
if (!u) embed.addField(`${x+1}. [Unknown user]`, `${karmaEmote} ${karmaboard[x].karma} Karma`, true); else embed.addField(`${x+1}. ${u.user.username}#${u.user.discriminator} ${u.user.bot ? '(Bot)' : ''}`, `${karmaEmote} ${karmaboard[x].karma} Karma`, true);
}
message.channel.send(embed);
}