simply-xp 1.3.5-beta-6 → 1.3.5-beta-7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +29 -0
- package/.idea/vcs.xml +6 -0
- package/package.json +7 -4
- package/simplyxp.js +31 -31
- package/src/addLevel.js +66 -66
- package/src/addXP.js +104 -103
- package/src/charts.js +92 -92
- package/src/connect.js +22 -22
- package/src/create.js +28 -28
- package/src/fetch.js +74 -74
- package/src/leaderboard.js +52 -52
- package/src/lvlRole.js +53 -53
- package/src/models/level.js +10 -10
- package/src/models/lvlrole.js +8 -8
- package/src/rank.js +295 -294
- package/src/reset.js +22 -22
- package/src/roleSetup.js +121 -121
- package/src/setLevel.js +70 -70
- package/src/setXP.js +51 -51
- package/.idea/jsLibraryMappings.xml +0 -6
- package/.idea/workspace.xml +0 -55
package/src/connect.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
const mongoose = require('mongoose')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} db
|
|
5
|
-
* @param {import('../index').connectOptions} options
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
async function connect(db, options = []) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = connect
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} db
|
|
5
|
+
* @param {import('../index').connectOptions} options
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
async function connect(db, options = []) {
|
|
9
|
+
if (!db) throw new Error('[XP] Database URL was not provided');
|
|
10
|
+
mongoose.set('strictQuery', true);
|
|
11
|
+
|
|
12
|
+
mongoose.connect(db, {
|
|
13
|
+
useNewUrlParser: true,
|
|
14
|
+
useUnifiedTopology: true
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
if (options.notify === false) return;
|
|
19
|
+
else return console.log('{ XP } Database Connected');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = connect;
|
package/src/create.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} userID
|
|
5
|
-
* @param {string} guildID
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
async function create(userID, guildID) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
module.exports = create
|
|
1
|
+
const levels = require('../src/models/level.js');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} userID
|
|
5
|
+
* @param {string} guildID
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
async function create(userID, guildID) {
|
|
9
|
+
if (!userID) throw new Error('[XP] User ID was not provided.');
|
|
10
|
+
|
|
11
|
+
if (!guildID) throw new Error('[XP] User ID was not provided.');
|
|
12
|
+
|
|
13
|
+
let uzer = await levels.findOne({ user: userID, guild: guildID });
|
|
14
|
+
|
|
15
|
+
if (uzer) return;
|
|
16
|
+
|
|
17
|
+
const newuser = new levels({
|
|
18
|
+
user: userID,
|
|
19
|
+
guild: guildID
|
|
20
|
+
});
|
|
21
|
+
await newuser
|
|
22
|
+
.save()
|
|
23
|
+
.catch(() => console.log('[XP] Failed to save new use to database'));
|
|
24
|
+
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = create;
|
package/src/fetch.js
CHANGED
|
@@ -1,74 +1,74 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {string} userID
|
|
5
|
-
* @param {string} guildID
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
async function fetch(userID, guildID) {
|
|
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
|
-
module.exports = fetch
|
|
1
|
+
const levels = require('../src/models/level.js');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} userID
|
|
5
|
+
* @param {string} guildID
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
async function fetch(userID, guildID) {
|
|
9
|
+
if (!userID) throw new Error('[XP] User ID was not provided.');
|
|
10
|
+
|
|
11
|
+
if (!guildID) throw new Error('[XP] Guild ID was not provided.');
|
|
12
|
+
|
|
13
|
+
let user = await levels.findOne({
|
|
14
|
+
user: userID,
|
|
15
|
+
guild: guildID
|
|
16
|
+
});
|
|
17
|
+
if (!user) {
|
|
18
|
+
user = new levels({
|
|
19
|
+
user: userID,
|
|
20
|
+
guild: guildID,
|
|
21
|
+
xp: 0,
|
|
22
|
+
level: 0
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await user.save();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const leaderboard = await levels
|
|
29
|
+
.find({
|
|
30
|
+
guild: guildID
|
|
31
|
+
})
|
|
32
|
+
.sort([['xp', 'descending']])
|
|
33
|
+
.exec();
|
|
34
|
+
|
|
35
|
+
if (user === null)
|
|
36
|
+
return {
|
|
37
|
+
level: 0,
|
|
38
|
+
xp: 0,
|
|
39
|
+
reqxp: 100,
|
|
40
|
+
rank: leaderboard.findIndex((i) => i.user === userID) + 1,
|
|
41
|
+
shortxp: 0,
|
|
42
|
+
shortreq: 100
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
user.position = leaderboard.findIndex((i) => i.user === userID) + 1;
|
|
46
|
+
|
|
47
|
+
let targetxp = user.level + 1;
|
|
48
|
+
|
|
49
|
+
let target = targetxp * targetxp * 100;
|
|
50
|
+
|
|
51
|
+
function shortener(count) {
|
|
52
|
+
const COUNT_ABBRS = ['', 'k', 'M', 'T'];
|
|
53
|
+
|
|
54
|
+
const i = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000));
|
|
55
|
+
let result = parseFloat((count / Math.pow(1000, i)).toFixed(2));
|
|
56
|
+
result += `${COUNT_ABBRS[i]}`;
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let shortXP = shortener(user.xp);
|
|
61
|
+
|
|
62
|
+
let shortReqXP = shortener(target);
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
level: user.level,
|
|
66
|
+
xp: user.xp,
|
|
67
|
+
reqxp: target,
|
|
68
|
+
rank: user.position,
|
|
69
|
+
shortxp: shortXP,
|
|
70
|
+
shortreq: shortReqXP
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = fetch;
|
package/src/leaderboard.js
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js')
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {Discord.Client} client
|
|
5
|
-
* @param {string} guildID
|
|
6
|
-
* @param {number?} limit
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
async function leaderboard(client, guildID, limit) {
|
|
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
|
-
module.exports = leaderboard
|
|
1
|
+
const levels = require('../src/models/level.js');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Discord.Client} client
|
|
5
|
+
* @param {string} guildID
|
|
6
|
+
* @param {number?} limit
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
async function leaderboard(client, guildID, limit) {
|
|
10
|
+
if (!guildID) throw new Error('[XP] Guild ID was not provided.');
|
|
11
|
+
|
|
12
|
+
let g = client.guilds.cache.get(guildID);
|
|
13
|
+
if (!g) throw new Error('[XP] Guild was not found.');
|
|
14
|
+
|
|
15
|
+
let leaderboard = await levels.find({guild: guildID}).sort([['xp', 'descending']]);
|
|
16
|
+
|
|
17
|
+
let led = [];
|
|
18
|
+
|
|
19
|
+
function shortener(count) {
|
|
20
|
+
const COUNT_ABBRS = ['', 'k', 'M', 'T'];
|
|
21
|
+
|
|
22
|
+
const i = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000));
|
|
23
|
+
let result = parseFloat((count / Math.pow(1000, i)).toFixed(2));
|
|
24
|
+
result += `${COUNT_ABBRS[i]}`;
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const led2 = leaderboard.map(async (key) => {
|
|
29
|
+
const user = await g.members.fetch(key.user).catch(() => null);
|
|
30
|
+
if (!user) return levels.deleteOne({user: key.user, guild: guildID});
|
|
31
|
+
if (key.xp === 0) return;
|
|
32
|
+
let pos = leaderboard.indexOf(key) + 1;
|
|
33
|
+
|
|
34
|
+
if (limit) {
|
|
35
|
+
if (pos > Number(limit)) return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
led.push({
|
|
39
|
+
guildID: key.guild,
|
|
40
|
+
userID: key.user,
|
|
41
|
+
xp: key.xp,
|
|
42
|
+
shortxp: shortener(key.xp),
|
|
43
|
+
level: key.level,
|
|
44
|
+
position: pos,
|
|
45
|
+
username: user.user.username,
|
|
46
|
+
tag: user.user.tag
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
return Promise.all(led2).then(() => led);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = leaderboard;
|
package/src/lvlRole.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js')
|
|
2
|
-
const lrole = require('../src/models/lvlrole.js')
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {Discord.Message} message
|
|
6
|
-
* @param {string} userID
|
|
7
|
-
* @param {string} guildID
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
async function lvlRole(message, userID, guildID) {
|
|
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
|
-
module.exports = lvlRole
|
|
1
|
+
const levels = require('../src/models/level.js');
|
|
2
|
+
const lrole = require('../src/models/lvlrole.js');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @param {Discord.Message} message
|
|
6
|
+
* @param {string} userID
|
|
7
|
+
* @param {string} guildID
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
async function lvlRole(message, userID, guildID) {
|
|
11
|
+
let e = await lrole.find({
|
|
12
|
+
gid: guildID
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
if (!e) return;
|
|
16
|
+
|
|
17
|
+
let user = await levels.findOne({
|
|
18
|
+
user: userID,
|
|
19
|
+
guild: guildID
|
|
20
|
+
});
|
|
21
|
+
if (!user) {
|
|
22
|
+
const newuser = new levels({
|
|
23
|
+
user: userID,
|
|
24
|
+
guild: guildID
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
await newuser
|
|
28
|
+
.save()
|
|
29
|
+
.catch(() => console.log('[XP] Failed to save new user to database'));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
e.forEach((ee) => {
|
|
33
|
+
ee = ee.lvlrole;
|
|
34
|
+
|
|
35
|
+
ee.forEach((xd) => {
|
|
36
|
+
if (user && user.level >= Number(xd.lvl)) {
|
|
37
|
+
let u = message.guild.members.cache.get(userID);
|
|
38
|
+
|
|
39
|
+
let real = message.guild.roles.cache.find((r) => r.id === xd.role);
|
|
40
|
+
if (!real) return;
|
|
41
|
+
else {
|
|
42
|
+
u.roles.add(real).catch(() => {
|
|
43
|
+
message.channel.send(
|
|
44
|
+
'[XP] ERROR: Role is higher than me. `MISSING_PERMISSIONS`'
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = lvlRole;
|
package/src/models/level.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const mongoose = require('mongoose')
|
|
2
|
-
|
|
3
|
-
const Levelz = new mongoose.Schema({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
module.exports = mongoose.model('Simply-XP', Levelz)
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const Levelz = new mongoose.Schema({
|
|
4
|
+
user: { type: String, unique: true },
|
|
5
|
+
guild: { type: String },
|
|
6
|
+
xp: { type: Number, default: 0 },
|
|
7
|
+
level: { type: Number, default: 0 }
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
module.exports = mongoose.model('Simply-XP', Levelz);
|
package/src/models/lvlrole.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const mongoose = require('mongoose')
|
|
2
|
-
|
|
3
|
-
const rol = new mongoose.Schema({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
module.exports = mongoose.model('Simply-XP-LevelRole', rol)
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const rol = new mongoose.Schema({
|
|
4
|
+
gid: { type: String },
|
|
5
|
+
lvlrole: { type: Array }
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
module.exports = mongoose.model('Simply-XP-LevelRole', rol);
|