simply-xp 1.3.5-beta-7 → 2.0.0-dev.1
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/FUNDING.yml +2 -2
- package/README.md +69 -57
- package/lib/src/add.d.ts +28 -0
- package/lib/src/add.js +23 -0
- package/lib/src/cards.d.ts +91 -0
- package/lib/src/cards.js +23 -0
- package/lib/src/charts.d.ts +17 -0
- package/lib/src/charts.js +10 -0
- package/lib/src/connect.d.ts +26 -0
- package/lib/src/connect.js +47 -0
- package/lib/src/create.d.ts +12 -0
- package/lib/src/create.js +11 -0
- package/lib/src/deprecated/rank.d.ts +18 -0
- package/lib/src/deprecated/rank.js +12 -0
- package/lib/src/fetch.d.ts +12 -0
- package/lib/src/fetch.js +11 -0
- package/lib/src/functions/database.d.ts +111 -0
- package/lib/src/functions/database.js +56 -0
- package/lib/src/functions/utilities.d.ts +41 -0
- package/lib/src/functions/utilities.js +17 -0
- package/lib/src/functions/xplogs.d.ts +59 -0
- package/lib/src/functions/xplogs.js +1 -0
- package/lib/src/leaderboard.d.ts +27 -0
- package/lib/src/leaderboard.js +10 -0
- package/lib/src/migrate.d.ts +25 -0
- package/lib/src/migrate.js +19 -0
- package/lib/src/reset.d.ts +12 -0
- package/lib/src/reset.js +12 -0
- package/lib/src/roleSetup.d.ts +47 -0
- package/lib/src/roleSetup.js +29 -0
- package/lib/src/set.d.ts +25 -0
- package/lib/src/set.js +23 -0
- package/lib/xp.d.ts +25 -0
- package/lib/xp.js +45 -0
- package/package.json +70 -53
- package/.eslintrc.json +0 -29
- package/.github/CODE_OF_CONDUCT.md +0 -128
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -31
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.github/SECURITY.md +0 -25
- package/.github/pull_request_template.md +0 -8
- package/.github/workflows/codeql-analysis.yml +0 -71
- package/.idea/discord.xml +0 -7
- package/.idea/misc.xml +0 -6
- package/.idea/modules.xml +0 -8
- package/.idea/simply-xp.iml +0 -9
- package/.idea/vcs.xml +0 -6
- package/index.d.ts +0 -107
- package/simplyxp.js +0 -31
- package/src/addLevel.js +0 -66
- package/src/addXP.js +0 -104
- package/src/charts.js +0 -92
- package/src/connect.js +0 -22
- package/src/create.js +0 -28
- package/src/fetch.js +0 -74
- package/src/leaderboard.js +0 -52
- package/src/lvlRole.js +0 -53
- package/src/models/level.js +0 -10
- package/src/models/lvlrole.js +0 -8
- package/src/rank.js +0 -295
- package/src/reset.js +0 -22
- package/src/roleSetup.js +0 -121
- package/src/setLevel.js +0 -70
- package/src/setXP.js +0 -51
- /package/{src → lib/src}/Fonts/Baloo-Regular.ttf +0 -0
package/src/addLevel.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js');
|
|
2
|
-
let {roleSetup} = require('../simplyxp');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {Discord.Message} message
|
|
6
|
-
* @param {string} userID
|
|
7
|
-
* @param {string} guildID
|
|
8
|
-
* @param {number} level
|
|
9
|
-
*/
|
|
10
|
-
async function addLevel(message, userID, guildID, level) {
|
|
11
|
-
if (!userID) throw new Error('[XP] User ID was not provided.');
|
|
12
|
-
|
|
13
|
-
if (!guildID) throw new Error('[XP] Guild ID was not provided.');
|
|
14
|
-
|
|
15
|
-
if (!level) throw new Error('[XP] Level amount is not provided.');
|
|
16
|
-
|
|
17
|
-
let {client} = message;
|
|
18
|
-
|
|
19
|
-
const user = await levels.findOne({user: userID, guild: guildID});
|
|
20
|
-
|
|
21
|
-
if (!user) {
|
|
22
|
-
const newUser = new levels({
|
|
23
|
-
user: userID,
|
|
24
|
-
guild: guildID,
|
|
25
|
-
xp: 0,
|
|
26
|
-
level: 0
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
await newUser.save().catch(() => console.log('[XP] Failed to save new user to database'));
|
|
30
|
-
|
|
31
|
-
let xp = (level * 10) ** 2;
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
level: level,
|
|
35
|
-
exp: xp
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
let level1 = user.level;
|
|
39
|
-
|
|
40
|
-
user.level += parseFloat(level);
|
|
41
|
-
user.xp = (user.level * 10) ** 2;
|
|
42
|
-
|
|
43
|
-
await user.save().catch((e) =>
|
|
44
|
-
console.log(`[XP] Failed to add Level | User: ${userID} | Err: ${e}`)
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
if (level1 !== level) {
|
|
48
|
-
let data = {
|
|
49
|
-
xp: user.xp,
|
|
50
|
-
level: user.level,
|
|
51
|
-
userID,
|
|
52
|
-
guildID
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
let role = await roleSetup.find(client, guildID, level);
|
|
56
|
-
|
|
57
|
-
client.emit('levelUp', message, data, role);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return {
|
|
61
|
-
level: user.level,
|
|
62
|
-
xp: user.xp
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
module.exports = addLevel;
|
package/src/addXP.js
DELETED
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js');
|
|
2
|
-
let {roleSetup} = require('../simplyxp');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {Discord.Message} message
|
|
6
|
-
* @param {string} userID
|
|
7
|
-
* @param {string} guildID
|
|
8
|
-
* @param {number} xp
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
async function addXP(message, userID, guildID, xp) {
|
|
12
|
-
if (!userID) throw new Error('[XP] User ID was not provided.');
|
|
13
|
-
|
|
14
|
-
if (!guildID) throw new Error('[XP] Guild ID was not provided.');
|
|
15
|
-
|
|
16
|
-
if (!xp) throw new Error('[XP] XP amount is not provided.');
|
|
17
|
-
|
|
18
|
-
let {client} = message;
|
|
19
|
-
|
|
20
|
-
let min;
|
|
21
|
-
let max;
|
|
22
|
-
if (xp.min) {
|
|
23
|
-
if (!xp.max)
|
|
24
|
-
throw new Error(
|
|
25
|
-
'[XP] XP min amount is provided but max amount is not provided.'
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
min = Number(xp.min);
|
|
29
|
-
|
|
30
|
-
if (Number(xp.min).toString() === 'NaN')
|
|
31
|
-
throw new Error('[XP] XP amount (min) is not a number.');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (xp.max) {
|
|
35
|
-
if (!xp.min)
|
|
36
|
-
throw new Error(
|
|
37
|
-
'[XP] XP max amount is provided but min amount is not provided.'
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
max = Number(xp.max);
|
|
41
|
-
|
|
42
|
-
if (Number(xp.max).toString() === 'NaN')
|
|
43
|
-
throw new Error('[XP] XP amount (max) is not a number.');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (xp.min && xp.max) {
|
|
47
|
-
xp = Math.floor(Math.random() * (max - min) + min);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const user = await levels.findOne({user: userID, guild: guildID});
|
|
51
|
-
|
|
52
|
-
let lvl = Math.floor(0.1 * Math.sqrt(xp));
|
|
53
|
-
|
|
54
|
-
// TODO: FIX THIS xp = xp & level = lvl
|
|
55
|
-
if (!user) {
|
|
56
|
-
const newUser = new levels({
|
|
57
|
-
user: userID,
|
|
58
|
-
guild: guildID,
|
|
59
|
-
xp: xp,
|
|
60
|
-
level: lvl
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
await newUser.save().catch(() => console.log('[XP] Failed to save new user to database'));
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
level: 0,
|
|
67
|
-
exp: 0
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
let level1 = user.level;
|
|
71
|
-
|
|
72
|
-
user.xp += parseInt(xp, 10);
|
|
73
|
-
user.level = Math.floor(0.1 * Math.sqrt(user.xp));
|
|
74
|
-
|
|
75
|
-
await user.save().catch((e) => console.log(`[XP] Failed to add XP | User: ${userID} | Err: ${e}`));
|
|
76
|
-
|
|
77
|
-
let level = user.level;
|
|
78
|
-
|
|
79
|
-
xp = user.xp;
|
|
80
|
-
|
|
81
|
-
if (user.xp === 0 || Math.sign(user.xp) === -1) {
|
|
82
|
-
xp = 0;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (level1 !== level) {
|
|
86
|
-
let data = {
|
|
87
|
-
xp,
|
|
88
|
-
level,
|
|
89
|
-
userID,
|
|
90
|
-
guildID
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
let role = await roleSetup.find(client, guildID, level);
|
|
94
|
-
|
|
95
|
-
client.emit('levelUp', message, data, role);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
level,
|
|
100
|
-
xp
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
module.exports = addXP;
|
package/src/charts.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
let leaderboard = require('./leaderboard');
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {Discord.Message} message
|
|
5
|
-
* @param {import('../index').chartsOptions} options
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
async function charts(message, options) {
|
|
9
|
-
try {
|
|
10
|
-
require('canvas');
|
|
11
|
-
} catch {
|
|
12
|
-
throw '[XP] This requires canvas to be installed. \n"npm install canvas"';
|
|
13
|
-
}
|
|
14
|
-
const ChartJS = require('chart.js');
|
|
15
|
-
const Canvas = require('canvas');
|
|
16
|
-
let {client} = message;
|
|
17
|
-
|
|
18
|
-
let data = [];
|
|
19
|
-
let pos = options?.position || 5;
|
|
20
|
-
let uzern = [];
|
|
21
|
-
|
|
22
|
-
let ctx = Canvas.createCanvas(950, 526);
|
|
23
|
-
await leaderboard(client, message.guild.id).then((e) => {
|
|
24
|
-
e.forEach((m) => {
|
|
25
|
-
if (m.position <= pos) {
|
|
26
|
-
data.push(m.xp);
|
|
27
|
-
uzern.push(m.tag);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
new ChartJS(ctx, {
|
|
33
|
-
type: options.type || 'bar',
|
|
34
|
-
data: {
|
|
35
|
-
labels: uzern,
|
|
36
|
-
datasets: [
|
|
37
|
-
{
|
|
38
|
-
label: 'Leaderboards',
|
|
39
|
-
data: data,
|
|
40
|
-
backgroundColor: [
|
|
41
|
-
'rgba(255, 99, 132, 0.5)',
|
|
42
|
-
'rgba(255, 159, 64, 0.5)',
|
|
43
|
-
'rgba(255, 205, 86, 0.5)',
|
|
44
|
-
'rgba(75, 192, 192, 0.5)',
|
|
45
|
-
'rgba(54, 162, 235, 0.5)',
|
|
46
|
-
'rgba(153, 102, 255, 0.5)',
|
|
47
|
-
'rgb(201, 203, 207, 0.5)'
|
|
48
|
-
],
|
|
49
|
-
borderColor: [
|
|
50
|
-
'rgb(255, 99, 132)',
|
|
51
|
-
'rgb(255, 159, 64)',
|
|
52
|
-
'rgb(255, 205, 86)',
|
|
53
|
-
'rgb(75, 192, 192)',
|
|
54
|
-
'rgb(54, 162, 235)',
|
|
55
|
-
'rgb(153, 102, 255)',
|
|
56
|
-
'rgb(201, 203, 207)'
|
|
57
|
-
],
|
|
58
|
-
borderWidth: 2
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
},
|
|
62
|
-
options: {
|
|
63
|
-
animation: false,
|
|
64
|
-
plugins: {
|
|
65
|
-
title: {
|
|
66
|
-
display: true,
|
|
67
|
-
text: 'XP Datasheet'
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
},
|
|
71
|
-
plugins: [
|
|
72
|
-
{
|
|
73
|
-
id: 'simply-xp',
|
|
74
|
-
beforeDraw: (chart) => {
|
|
75
|
-
const ctx = chart.canvas.getContext('2d');
|
|
76
|
-
ctx.save();
|
|
77
|
-
ctx.globalCompositeOperation = 'destination-over';
|
|
78
|
-
ctx.fillStyle = options.background || '#2F3136';
|
|
79
|
-
ctx.fillRect(0, 0, chart.width, chart.height);
|
|
80
|
-
ctx.restore();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
]
|
|
84
|
-
}).update();
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
attachment: ctx.toBuffer('image/png'),
|
|
88
|
-
name: 'chart.png'
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
module.exports = charts;
|
package/src/connect.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
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);
|