-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b116ee6
commit 2a0f016
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const Discord = require('discord.js'); | ||
module.exports = { | ||
name: 'leaderboard', | ||
aliases: ['lb'], | ||
description: 'Check the top ranking players in honeycombs or headpats', | ||
usage: '[honeycombs/headpats]', | ||
execute(message, args) { | ||
const numbers = []; | ||
const valuesArray = []; | ||
message.client.checkId(message.author.id, userObj => { | ||
const ids = Object.keys(userObj); | ||
const amount = ids.length; | ||
if(args[0] === 'honeycombs') { | ||
for(let i = 0; i < amount; i++) { | ||
numbers.push(userObj[ids[i]].honey); | ||
} | ||
} else if(args[0] === 'headpats') { | ||
for(let i = 0; i < amount; i++) { | ||
numbers.push(userObj[ids[i]].headpats); | ||
} | ||
} else { | ||
return message.reply('Type `headpats` or `honeycombs` to see the leaderboard for that type'); | ||
} | ||
for(let c = 0; c < amount; c++) { | ||
valuesArray.push(ids[c]); | ||
valuesArray.push(numbers[c]); | ||
} | ||
numbers.sort((a, b) => b - a); | ||
let lbmsg = `**${args[0].toLowerCase()} leaderboard**`; | ||
for(let r = 0; r < amount; r++) { | ||
if(numbers[0] === 0 || r === 10) {break;} | ||
const sorted = valuesArray.indexOf(numbers.shift()) - 1; | ||
const userId = valuesArray[sorted]; | ||
valuesArray.splice(sorted, 1); | ||
const value = valuesArray[sorted]; | ||
valuesArray.splice(sorted, 1); | ||
lbmsg += `\n${r + 1}. <@!${userId}>: ${value.toLocaleString('en-US')}`; | ||
} | ||
const embed = new Discord.MessageEmbed() | ||
.setDescription(lbmsg) | ||
.setColor('#f5cc16'); | ||
message.channel.send(embed); | ||
}); | ||
}, | ||
}; |