You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Natsuki/commands/leveling/leaderboard.js

45 lines
2.2 KiB

3 years ago
const Discord = require('discord.js');
const XP = require('../../models/localxp');
module.exports = {
name: "leaderboard",
aliases: ['lb', 'rank'],
meta: {
category: 'Leveling',
description: "Find your place in the server's ranks and see the top-ranking members in the server.",
syntax: '`leaderboard`',
extra: null,
guildOnly: true
},
help: "Find your place in the server's ranks and see the top-ranking members in the server.",
async execute(message, msg, args, cmd, prefix, mention, client) {
let cfmh = '<a:xp:870418598047387668>';
let gxp = await XP.findOne({gid: message.guild.id});
3 years ago
if (!gxp) {return message.channel.send("Your server doesn't have XP enabled! If it's something you want to use, you can enable it with the `setupleveling` command");}
3 years ago
let xp = gxp.xp;
let lvlp = Object.keys(xp).sort((a, b) => {return xp[a][1] - xp[b][1];}).reverse();
let lvl = lvlp.slice(0, Object.keys(xp).length >= 10 ? 10 : Object.keys(xp).length);
3 years ago
let lvls = ``;
let i; for (i=0; i<lvl.length; i++) {lvls += `${i+1}. <@${lvl[i]}> -> **Level ${xp[lvl[i]][1]}**\n`;}
3 years ago
lvls += `\n${cfmh} *You are ranked **#${lvlp.indexOf(message.author.id) + 1}** at Level ${xp[lvlp[lvlp.indexOf(message.author.id)]][1]}.*`;
3 years ago
3 years ago
return message.channel.send({embeds: [new Discord.MessageEmbed()
3 years ago
.setTitle("Server Leaderboard")
.setThumbnail(message.guild.iconURL({size: 2048, dynamic: true}))
.addField("Level", lvls)
.setColor('c375f0')
.setFooter({text: "Natsuki | Stats may be up to 2 minutes out of sync"})
3 years ago
.setTimestamp()
3 years ago
]});
3 years ago
/*u = Object.keys(tm.messages.members).sort((a, b) => {return tm.messages.members[a] - tm.messages.members[b];}).reverse().slice(0, Object.keys(tm.messages.members).length >= 5 ? 5 : Object.keys(tm.messages.members).length);
us = ``;
let i2; for (i2=0; i2<u.length; i2++) {us += `${i2+1}. <@${u[i2]}> -> **${tm.messages.members[u[i2]]} Messages**\n`;}*/
//if (args[0] && ['mooners', 'currency', 'balance', 'bal'].includes(args[0].toLowerCase())) {}
//else {}
}
};