-
Notifications
You must be signed in to change notification settings - Fork 59
/
leaderboard.js
111 lines (105 loc) · 4.65 KB
/
leaderboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const {
MessageEmbed
} = require("discord.js")
const colors = require("../lib/colors.json")
exports.run = async (client, message, args) => {
const language = client.getSettings(message.guild.id).language
const lang = require("../lib/languages/" + language + ".json")
try {
function delay(delayInms) {
return new Promise(resolve => {
setTimeout(() => {
resolve(2)
}, delayInms)
})
}
if (!args[0]) return message.channel.send(lang.NoOptionSpecified)
if (args[0].toLowerCase() !== "xp" && args[0].toLowerCase() !== "money") return message.channel.send(lang.InvalidOption)
let isGlobal;
if (args[0].toLowerCase() === "xp") {
if (args[1]) {
if (args[1].toLowerCase() === "-g" || args[1].toLowerCase() === "g" || args[1].toLowerCase() === "global" || args[1].toLowerCase() === "-global") {
isGlobal = false; // Disabled global XP due to duplication issues
} else {
isGlobal = false;
}
} else {
isGlobal = false;
}
const globalName = !isGlobal ? message.guild.name + ":" : "Global";
const filtered = !isGlobal ? client.points.filter(p => p.guild === message.guild.id).array() : client.points.array();
const sorted = filtered.sort((a, b) => b.points - a.points)
const top10 = sorted.splice(0, 10);
let embed = new MessageEmbed()
.setTitle(`${globalName} ${lang.Leaderboard}`)
.setDescription(lang.TopTenXP)
.setColor(colors.default)
.setFooter(`${lang.RespondingTo} ${message.author.tag}`, message.author.avatarURL())
.setTimestamp()
let i = 0;
for (const data of top10) {
await delay(15);
try {
i++;
embed.addField(`**${i}**. ${client.users.cache.get(data.user).tag}`, `${lang.PointsUpper}: \`${Math.floor(data.points * 100) / 100}\` | ${lang.Level}: \`${data.level}\``);
} catch {
i++;
embed.addField(`**${i}**. ${client.users.cache.get(data.user)}`, `${lang.PointsUpper}: \`${Math.floor(data.points * 100) / 100}\` | ${lang.Level}: \`${data.level}\``);
}
}
message.channel.send({
embeds: [embed]
})
} else if (args[0].toLowerCase() === "money") {
if (args[1]) {
if (args[1].toLowerCase() === "-g" || args[1].toLowerCase() === "g" || args[1].toLowerCase() === "global" || args[1].toLowerCase() === "-global") {
isGlobal = true;
} else {
isGlobal = false;
}
} else {
isGlobal = false;
}
const globalName = !isGlobal ? message.guild.name + ":" : "Global";
const filtered = !isGlobal ? client.money.filter(p => p.guild === message.guild.id).array() : client.money.array();
const sorted = filtered.sort((a, b) => b.money - a.money)
const top10 = sorted.splice(0, 10);
let embed = new MessageEmbed()
.setTitle(`${globalName} ${lang.Leaderboard}`)
.setTimestamp()
.setDescription(lang.TopTenMoney)
.setColor(colors.default)
.setFooter(`${lang.RespondingTo} ${message.author.tag}`, message.author.avatarURL())
.setTimestamp()
let i = 0;
for (const data of top10) {
await delay(15);
try {
i++;
embed.addField(`**${i}**. ${client.users.cache.get(data.user).tag}`, `${lang.Money}: \`${Math.floor(data.money * 100) / 100}\``);
} catch {
i++;
embed.addField(`**${i}**. ${client.users.cache.get(data.user)}`, `${lang.Money}: \`${Math.floor(data.money * 100) / 100}\``);
message.channel.send({
embeds: [embed]
})
}
}
}
} catch (err) {
const errors = require('../modules/errors.js')
errors.embedError(err, lang, message)
}
}
exports.conf = {
enabled: true,
aliases: ['l', 'lb', 'top', 'most', 'baltop', 'leaderboards'],
guildOnly: false,
permLevel: 'User'
}
exports.help = {
name: 'leaderboard',
category: 'Economy',
description: 'Shows the top 10 players with the most XP or money.',
usage: 'leaderboard <xp/money> [-g]'
}