obama-bot/commands/top.js
2020-11-28 17:38:23 +01:00

34 lines
1.2 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;
module.exports.run = async (message, args) => {
const karmaID1 = '733339045463064607';
const karmaEmote1 = message.guild.emojis.cache.get(karmaID1).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(karmaEmote1 + ' 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]`, `${karmaEmote1} ${karmaboard[x].karma} Karma`, true); else embed.addField(`${x+1}. ${u.user.username}#${u.user.discriminator} ${u.user.bot ? '(Bot)' : ''}`, `${karmaEmote1} ${karmaboard[x].karma} Karma`, true);
}
message.channel.send(embed);
}