-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathleaderboard.js
46 lines (42 loc) · 1.83 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
let handler = async (m, { conn, args }) => {
let name = m.fromMe ? conn.user : conn.contacts[m.sender]
let sortedExp = Object.entries(global.DATABASE.data.users).sort((a, b) => b[1].exp - a[1].exp)
let sortedLim = Object.entries(global.DATABASE.data.users).sort((a, b) => b[1].limit - a[1].limit)
let sortedmoney = Object.entries(global.DATABASE.data.users).sort((a, b) => b[1].money - a[1].money)
let sortedlevel = Object.entries(global.DATABASE.data.users).sort((a, b) => b[1].level - a[1].level)
let usersExp = sortedExp.map(v => v[0])
let usersLim = sortedLim.map(v => v[0])
let usersmoney = sortedmoney.map(v => v[0])
let userslevel = sortedlevel.map(v => v[0])
let len = args[0] && args[0].length > 0 ? Math.min(100, Math.max(parseInt(args[0]), 5)) : Math.min(20, sortedExp.length)
let text = `
┌〔 *Level Leaderboard Top ${len}* 〕
├Kamu: *${userslevel.indexOf(m.sender) + 1}* dari *${userslevel.length}*
│
├${sortedlevel.slice(0, len).map(([user, data], i) => (i + 1) + '. @' + user.split`@`[0] + ': *' + data.level + ' Lvl*').join`\n├`}
└────
┌〔 *Money Leaderboard Top ${len}* 〕
├Kamu: *${usersmoney.indexOf(m.sender) + 1}* dari *${usersmoney.length}*
│
├${sortedmoney.slice(0, len).map(([user, data], i) => (i + 1) + '. @' + user.split`@`[0] + ': *' + data.money + ' Money*').join`\n├`}
└────
`.trim()
conn.reply(m.chat, text, m, {
contextInfo: {
mentionedJid: [...userslevel.slice(0, len), ...usersmoney.slice(0, len)]
}
})
}
handler.help = ['leaderboard [jumlah user]', 'lb [jumlah user]']
handler.tags = ['rpg']
handler.command = /^(leaderboard|lb)$/i
handler.owner = false
handler.mods = false
handler.premium = false
handler.group = false
handler.private = false
handler.admin = false
handler.botAdmin = false
handler.fail = null
handler.exp = 0
module.exports = handler