-
Notifications
You must be signed in to change notification settings - Fork 59
/
xp.js
93 lines (75 loc) · 3.35 KB
/
xp.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
exports.run = async (client, message, args) => { // eslint-disable-line no-unused-vars
const language = client.getSettings(message.guild.id).language
const lang = require("../lib/languages/" + language + ".json")
try {
if (args[0] === 'give') {
// Limited to guild owner
if (message.author.id !== message.guild.ownerID) {
return message.reply(lang.NotOwner)
}
const user = message.mentions.users.first() || client.users.get(args[0])
if (!user) return message.reply(lang.NoUserSpecified)
const pointsToAdd = parseInt(args[2], 10)
if (!pointsToAdd) return message.reply(lang.NoAmountSpecified)
// Ensure there is a points entry for this user.
client.points.ensure(`${message.guild.id}-${user.id}`, {
user: message.author.id,
guild: message.guild.id,
points: 0,
level: 1
})
// Get their current points.
let userPoints = client.points.get(`${message.guild.id}-${user.id}`, 'points')
userPoints += pointsToAdd
// And we save it!
client.points.set(`${message.guild.id}-${user.id}`, userPoints, 'points')
message.channel.send(`${user.tag} ${lang.HasReceived} ${pointsToAdd} ${lang.NowHas} ${userPoints} ${lang.Points}`)
return
}
if (args[0] === 'take') {
// Limited to guild owner
if (message.author.id !== message.guild.ownerID) {
return message.reply(lang.NotOwner)
}
const user = message.mentions.users.first() || client.users.get(args[0])
if (!user) return message.reply(lang.NoUserSpecified)
const pointsToTake = parseInt(args[2], 10)
if (!pointsToTake) return message.reply(lang.NoArgumentSpecified)
// Ensure there is a points entry for this user.
client.points.ensure(`${message.guild.id}-${user.id}`, {
user: message.author.id,
guild: message.guild.id,
points: 0,
level: 1
})
// Get their current points.
let userPoints = client.points.get(`${message.guild.id}-${user.id}`, 'points')
userPoints -= pointsToTake
// And we save it!
client.points.set(`${message.guild.id}-${user.id}`, userPoints, 'points')
message.channel.send(`${user.tag} ${lang.HasLost} ${pointsToTake} ${lang.NowHas} ${userPoints} ${lang.Points}.`)
return
}
const key = `${message.guild.id}-${message.author.id}`
const xp = client.points.get(key, 'points')
const level = client.points.get(key, 'level')
const number = ((5 * (level + 1)) ** 2) - xp
message.channel.send(`${lang.YouCurrentlyHave} ${xp}XP, ${lang.AndAreLevel} ${level}!`)
message.channel.send(`${lang.YouNeed} ${number}XP ${lang.LevelUpTo} ${level + 1}`)
} catch (err) {
const errors = require('../modules/errors.js')
errors.embedError(err, lang, message)
}
}
exports.conf = {
enabled: true,
aliases: [],
guildOnly: true,
permLevel: 'User'
}
exports.help = {
name: 'xp',
category: 'Economy',
description: 'Shows your XP/level for this Discord.',
usage: 'xp'
}