-
Notifications
You must be signed in to change notification settings - Fork 66
/
_autolevelup.js
55 lines (48 loc) · 3.2 KB
/
_autolevelup.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
let handler = m => m
let levelling = require('../lib/levelling')
let fetch = require('node-fetch')
handler.before = async function (m) {
let user = global.db.data.users[m.sender]
let users = Object.entries(global.db.data.users).map(([key, value]) => {
return { ...value, jid: key }
})
let pp = './src/avatar_contact.png'
let who = m.sender
let role = global.db.data.users[m.sender].role
let exp = global.db.data.users[m.sender].exp
let discriminator = who.substring(9, 13)
let sortedLevel = users.map(toNumber('level')).sort(sort('level'))
let usersLevel = sortedLevel.map(enumGetKey)
let { min, xp, max } = levelling.xpRange(user.level, global.multiplier)
let username = conn.getName(who)
try {
pp = await this.getProfilePicture(who)
} catch (e) {
} finally {
if (!user.autolevelup) return !0
let before = user.level * 1
while (levelling.canLevelUp(user.level, user.exp, global.multiplier)) user.level++
if (before !== user.level) {
let rank = `https://telegra.ph/file/5b94da0fc1fafa4aa1be7.jpg`
{
let tag = `@${m.sender.replace(/@.+/, '')}`
let mentionedJid = [m.sender]
await this.sendButtonLoc(m.chat, await (await fetch('https://telegra.ph/file/8dfcf533fd8e65e3dfcbd.jpg')).buffer(), `╭─「 Level Up 」\n│ • Nama: *${conn.getName(m.sender)}*\n│ • Tag: *${tag}*\n│ • Role: *${role}*\n│ • Exp: *${exp} Xp*\n│ • Level sebelumnya: *${before}*\n│ • Level sekarang: *${user.level}*\n╰───────࿐`.trim(), wm, 'PROFILE', '.profile', m, { contextInfo: { mentionedJid }})
}
}
}
}
module.exports = handler
function sort(property, ascending = true) {
if (property) return (...args) => args[ascending & 1][property] - args[!ascending & 1][property]
else return (...args) => args[ascending & 1] - args[!ascending & 1]
}
function toNumber(property, _default = 0) {
if (property) return (a, i, b) => {
return { ...b[i], [property]: a[property] === undefined ? _default : a[property] }
}
else return a => a === undefined ? _default : a
}
function enumGetKey(a) {
return a.jid
}