simply-xp 1.3.5-beta-7 → 2.0.0-dev.0-fix.2
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 +68 -57
- package/lib/src/add.d.ts +35 -0
- package/lib/src/add.js +21 -0
- package/lib/src/cards.d.ts +86 -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 +17 -0
- package/lib/src/connect.js +40 -0
- package/lib/src/create.d.ts +11 -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 +17 -0
- package/lib/src/fetch.js +10 -0
- package/lib/src/functions/convert.d.ts +10 -0
- package/lib/src/functions/convert.js +10 -0
- package/lib/src/functions/database.d.ts +90 -0
- package/lib/src/functions/database.js +56 -0
- package/lib/src/functions/xplogs.d.ts +59 -0
- package/lib/src/functions/xplogs.js +1 -0
- package/lib/src/leaderboard.d.ts +18 -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 +11 -0
- package/lib/src/reset.js +11 -0
- package/lib/src/roleSetup.d.ts +41 -0
- package/lib/src/roleSetup.js +29 -0
- package/lib/src/set.d.ts +32 -0
- package/lib/src/set.js +21 -0
- package/lib/xp.d.ts +24 -0
- package/lib/xp.js +44 -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/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);
|
package/src/models/lvlrole.js
DELETED
package/src/rank.js
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
const levels = require('../src/models/level.js');
|
|
2
|
-
const {join} = require('path');
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @param {Discord.Message} message
|
|
6
|
-
* @param {string} userID
|
|
7
|
-
* @param {string} guildID
|
|
8
|
-
* @param {import('../index').rankOptions} options
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
async function rank(message, userID, guildID, options = []) {
|
|
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
|
-
const user = await levels.findOne({
|
|
17
|
-
user: userID,
|
|
18
|
-
guild: guildID
|
|
19
|
-
});
|
|
20
|
-
if (!user) throw new Error('[XP] NO_DATA | User has no XP data.');
|
|
21
|
-
|
|
22
|
-
const leaderboard = await levels
|
|
23
|
-
.find({
|
|
24
|
-
guild: guildID
|
|
25
|
-
})
|
|
26
|
-
.sort([['xp', 'descending']])
|
|
27
|
-
.exec();
|
|
28
|
-
|
|
29
|
-
user.position = leaderboard.findIndex((i) => i.user === userID) + 1;
|
|
30
|
-
|
|
31
|
-
let targetxp = user.level + 1;
|
|
32
|
-
|
|
33
|
-
let target = targetxp * targetxp * 100;
|
|
34
|
-
|
|
35
|
-
return rankCard(message, {
|
|
36
|
-
level: user.level,
|
|
37
|
-
currentXP: user.xp,
|
|
38
|
-
neededXP: target,
|
|
39
|
-
rank: user.position,
|
|
40
|
-
background: options.background,
|
|
41
|
-
color: options.color,
|
|
42
|
-
lvlbar: options.lvlbar,
|
|
43
|
-
lvlbarBg: options.lvlbarBg,
|
|
44
|
-
member: message.guild.members.cache.get(userID)?.user
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
async function rankCard(message, options = []) {
|
|
48
|
-
try {
|
|
49
|
-
const Canvas = require('@napi-rs/canvas');
|
|
50
|
-
Canvas.GlobalFonts.registerFromPath(
|
|
51
|
-
join(__dirname, 'Fonts', 'Baloo-Regular.ttf'),
|
|
52
|
-
'Sans Serif'
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const member = options.member;
|
|
56
|
-
|
|
57
|
-
const canvas = Canvas.createCanvas(1080, 400),
|
|
58
|
-
ctx = canvas.getContext('2d');
|
|
59
|
-
|
|
60
|
-
const name = member.tag;
|
|
61
|
-
const noSymbols = (string) => string.replace(/[\u007f-\uffff]/g, '');
|
|
62
|
-
|
|
63
|
-
let fsiz = '45px';
|
|
64
|
-
if (message.guild.name.length >= 23) {
|
|
65
|
-
fsiz = '38px';
|
|
66
|
-
}
|
|
67
|
-
if (message.guild.name.length >= 40) {
|
|
68
|
-
fsiz = '28px';
|
|
69
|
-
}
|
|
70
|
-
if (message.guild.name.length >= 63) {
|
|
71
|
-
fsiz = '22px';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
let BackgroundRadius = '20',
|
|
75
|
-
BackGroundImg =
|
|
76
|
-
options.background ||
|
|
77
|
-
'https://i.ibb.co/QQvMqf7/gradient.jpg',
|
|
78
|
-
AttachmentName = 'rank.png',
|
|
79
|
-
AttachmentDesc = 'Rank Card',
|
|
80
|
-
Username = noSymbols(name),
|
|
81
|
-
AvatarRoundRadius = '50',
|
|
82
|
-
DrawLayerColor = '#000000',
|
|
83
|
-
DrawLayerOpacity = 0.4,
|
|
84
|
-
BoxColor = options.color || '#096DD1',
|
|
85
|
-
LevelBarFill = options.lvlbar || '#ffffff',
|
|
86
|
-
LevelBarBackground = options.lvlbarBg || '#ffffff',
|
|
87
|
-
Rank = options.rank,
|
|
88
|
-
TextEXP = shortener(options.currentXP) + ' XP',
|
|
89
|
-
LvlText = `Level ${shortener(options.level)}`,
|
|
90
|
-
BarRadius = '20',
|
|
91
|
-
TextXpNeded = '{current}/{needed}',
|
|
92
|
-
CurrentXP = options.currentXP,
|
|
93
|
-
NeededXP = options.neededXP;
|
|
94
|
-
|
|
95
|
-
ctx.beginPath();
|
|
96
|
-
ctx.moveTo(Number(BackgroundRadius), 0);
|
|
97
|
-
ctx.lineTo(1080 - Number(BackgroundRadius), 0);
|
|
98
|
-
ctx.quadraticCurveTo(1080, 0, 1080, Number(BackgroundRadius));
|
|
99
|
-
ctx.lineTo(1080, 400 - Number(BackgroundRadius));
|
|
100
|
-
ctx.quadraticCurveTo(
|
|
101
|
-
1080,
|
|
102
|
-
400,
|
|
103
|
-
1080 - Number(BackgroundRadius),
|
|
104
|
-
400
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
ctx.lineTo(Number(BackgroundRadius), 400);
|
|
108
|
-
ctx.quadraticCurveTo(0, 400, 0, 400 - Number(BackgroundRadius));
|
|
109
|
-
ctx.lineTo(0, Number(BackgroundRadius));
|
|
110
|
-
ctx.quadraticCurveTo(0, 0, Number(BackgroundRadius), 0);
|
|
111
|
-
ctx.closePath();
|
|
112
|
-
ctx.clip();
|
|
113
|
-
ctx.fillStyle = '#000000';
|
|
114
|
-
ctx.fillRect(0, 0, 1080, 400);
|
|
115
|
-
let background = await Canvas.loadImage(BackGroundImg);
|
|
116
|
-
ctx.globalAlpha = 0.7;
|
|
117
|
-
ctx.drawImage(background, 0, 0, 1080, 400);
|
|
118
|
-
ctx.restore();
|
|
119
|
-
|
|
120
|
-
ctx.fillStyle = DrawLayerColor;
|
|
121
|
-
ctx.globalAlpha = DrawLayerOpacity;
|
|
122
|
-
ctx.fillRect(40, 0, 240, canvas.height);
|
|
123
|
-
ctx.globalAlpha = 1;
|
|
124
|
-
|
|
125
|
-
let avatar = await Canvas.loadImage(member.displayAvatarURL());
|
|
126
|
-
ctx.save();
|
|
127
|
-
RoundedBox(ctx, 70, 30, 180, 180, Number(AvatarRoundRadius));
|
|
128
|
-
ctx.strokeStyle = BoxColor;
|
|
129
|
-
ctx.lineWidth = 15;
|
|
130
|
-
ctx.stroke();
|
|
131
|
-
ctx.clip();
|
|
132
|
-
ctx.drawImage(avatar, 70, 30, 180, 180);
|
|
133
|
-
ctx.restore();
|
|
134
|
-
|
|
135
|
-
ctx.save();
|
|
136
|
-
RoundedBox(ctx, 70, 240 + 50 + 30, 180, 50, 20);
|
|
137
|
-
ctx.strokeStyle = '#BFC85A22';
|
|
138
|
-
ctx.stroke();
|
|
139
|
-
ctx.clip();
|
|
140
|
-
ctx.fillStyle = BoxColor;
|
|
141
|
-
ctx.globalAlpha = 1;
|
|
142
|
-
ctx.fillRect(70, 320, 180, 50);
|
|
143
|
-
ctx.globalAlpha = 1;
|
|
144
|
-
ctx.fillStyle = '#ffffff';
|
|
145
|
-
ctx.font = '32px "Sans Serif"';
|
|
146
|
-
ctx.textAlign = 'center';
|
|
147
|
-
ctx.fillText(TextEXP, 160, 358);
|
|
148
|
-
ctx.restore();
|
|
149
|
-
|
|
150
|
-
ctx.save();
|
|
151
|
-
RoundedBox(ctx, 70, 240, 180, 50, 20);
|
|
152
|
-
ctx.strokeStyle = '#BFC85A22';
|
|
153
|
-
ctx.stroke();
|
|
154
|
-
ctx.clip();
|
|
155
|
-
ctx.fillStyle = BoxColor;
|
|
156
|
-
ctx.globalAlpha = 1;
|
|
157
|
-
ctx.fillRect(70, 240, 180, 50, 50);
|
|
158
|
-
ctx.globalAlpha = 1;
|
|
159
|
-
ctx.fillStyle = '#ffffff';
|
|
160
|
-
ctx.font = '32px "Sans Serif"';
|
|
161
|
-
ctx.textAlign = 'center';
|
|
162
|
-
ctx.fillText(LvlText, 70 + 180 / 2, 278);
|
|
163
|
-
ctx.restore();
|
|
164
|
-
|
|
165
|
-
ctx.save();
|
|
166
|
-
ctx.textAlign = 'left';
|
|
167
|
-
ctx.fillStyle = '#ffffff';
|
|
168
|
-
ctx.shadowColor = '#000000';
|
|
169
|
-
ctx.shadowBlur = 15;
|
|
170
|
-
ctx.shadowOffsetX = 1;
|
|
171
|
-
ctx.shadowOffsetY = 1;
|
|
172
|
-
ctx.font = '39px "Sans Serif"';
|
|
173
|
-
ctx.fillText(Username, 390, 80);
|
|
174
|
-
ctx.restore();
|
|
175
|
-
|
|
176
|
-
ctx.save();
|
|
177
|
-
ctx.textAlign = 'right';
|
|
178
|
-
ctx.fillStyle = '#ffffff';
|
|
179
|
-
ctx.shadowColor = '#000000';
|
|
180
|
-
ctx.shadowBlur = 15;
|
|
181
|
-
ctx.shadowOffsetX = 1;
|
|
182
|
-
ctx.shadowOffsetY = 1;
|
|
183
|
-
ctx.font = '55px "Sans Serif"';
|
|
184
|
-
ctx.fillText('#' + Rank, canvas.width - 55, 80);
|
|
185
|
-
ctx.restore();
|
|
186
|
-
|
|
187
|
-
ctx.save();
|
|
188
|
-
RoundedBox(ctx, 390, 305, 660, 70, Number(20));
|
|
189
|
-
ctx.strokeStyle = '#BFC85A22';
|
|
190
|
-
ctx.stroke();
|
|
191
|
-
ctx.clip();
|
|
192
|
-
ctx.fillStyle = '#ffffff';
|
|
193
|
-
ctx.font = `${fsiz} "Sans Serif"`;
|
|
194
|
-
ctx.textAlign = 'center';
|
|
195
|
-
ctx.fillText(message.guild.name, 720, 355);
|
|
196
|
-
ctx.globalAlpha = 0.2;
|
|
197
|
-
ctx.fillRect(390, 305, 660, 70);
|
|
198
|
-
ctx.restore();
|
|
199
|
-
|
|
200
|
-
ctx.save();
|
|
201
|
-
RoundedBox(ctx, 390, 145, 660, 50, Number(BarRadius));
|
|
202
|
-
ctx.strokeStyle = '#BFC85A22';
|
|
203
|
-
ctx.stroke();
|
|
204
|
-
ctx.clip();
|
|
205
|
-
ctx.fillStyle = LevelBarBackground;
|
|
206
|
-
ctx.globalAlpha = 0.2;
|
|
207
|
-
ctx.fillRect(390, 145, 660, 50, 50);
|
|
208
|
-
ctx.restore();
|
|
209
|
-
|
|
210
|
-
const percent = (100 * CurrentXP) / NeededXP;
|
|
211
|
-
const progress = (percent * 660) / 100;
|
|
212
|
-
|
|
213
|
-
ctx.save();
|
|
214
|
-
RoundedBox(ctx, 390, 145, progress, 50, Number(BarRadius));
|
|
215
|
-
ctx.strokeStyle = '#BFC85A22';
|
|
216
|
-
ctx.stroke();
|
|
217
|
-
ctx.clip();
|
|
218
|
-
ctx.fillStyle = LevelBarFill;
|
|
219
|
-
ctx.globalAlpha = 0.5;
|
|
220
|
-
ctx.fillRect(390, 145, progress, 50, 50);
|
|
221
|
-
ctx.restore();
|
|
222
|
-
|
|
223
|
-
ctx.save();
|
|
224
|
-
ctx.textAlign = 'left';
|
|
225
|
-
ctx.fillStyle = '#ffffff';
|
|
226
|
-
ctx.globalAlpha = 0.8;
|
|
227
|
-
ctx.font = '30px "Sans Serif"';
|
|
228
|
-
ctx.fillText('Next Level: ' + shortener(NeededXP) + ' XP', 390, 230);
|
|
229
|
-
ctx.restore();
|
|
230
|
-
|
|
231
|
-
const latestXP = Number(CurrentXP) - Number(NeededXP);
|
|
232
|
-
const textXPEdited = TextXpNeded.replace(/{needed}/g, shortener(NeededXP).toString())
|
|
233
|
-
.replace(/{current}/g, shortener(CurrentXP).toString())
|
|
234
|
-
.replace(/{latest}/g, latestXP.toString());
|
|
235
|
-
ctx.textAlign = 'center';
|
|
236
|
-
ctx.fillStyle = '#474747';
|
|
237
|
-
ctx.globalAlpha = 1;
|
|
238
|
-
ctx.font = '30px "Sans Serif"';
|
|
239
|
-
ctx.fillText(textXPEdited, 730, 180);
|
|
240
|
-
|
|
241
|
-
return {
|
|
242
|
-
attachment: canvas.toBuffer('image/webp'),
|
|
243
|
-
description: AttachmentDesc,
|
|
244
|
-
name: AttachmentName
|
|
245
|
-
};
|
|
246
|
-
} catch (err) {
|
|
247
|
-
console.log(`[XP] Error Occured. | rankCard | Error: ${err.stack}`);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function RoundedBox(ctx, x, y, width, height, radius) {
|
|
253
|
-
ctx.beginPath();
|
|
254
|
-
ctx.moveTo(x + radius, y);
|
|
255
|
-
ctx.lineTo(x + width - radius, y);
|
|
256
|
-
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
|
|
257
|
-
ctx.lineTo(x + width, y + height - radius);
|
|
258
|
-
ctx.quadraticCurveTo(
|
|
259
|
-
x + width,
|
|
260
|
-
y + height,
|
|
261
|
-
x + width - radius,
|
|
262
|
-
y + height
|
|
263
|
-
);
|
|
264
|
-
ctx.lineTo(x + radius, y + height);
|
|
265
|
-
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
|
|
266
|
-
ctx.lineTo(x, y + radius);
|
|
267
|
-
ctx.quadraticCurveTo(x, y, x + radius, y);
|
|
268
|
-
ctx.closePath();
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
function shortener(count) {
|
|
272
|
-
const COUNT_ABBRS = [
|
|
273
|
-
'',
|
|
274
|
-
'k',
|
|
275
|
-
'M',
|
|
276
|
-
'B',
|
|
277
|
-
'T',
|
|
278
|
-
'Q',
|
|
279
|
-
'Q+',
|
|
280
|
-
'S',
|
|
281
|
-
'S+',
|
|
282
|
-
'O',
|
|
283
|
-
'N',
|
|
284
|
-
'D',
|
|
285
|
-
'U'
|
|
286
|
-
];
|
|
287
|
-
|
|
288
|
-
const i = 0 === count ? count : Math.floor(Math.log(count) / Math.log(1000));
|
|
289
|
-
let result = parseFloat((count / Math.pow(1000, i)).toFixed(2));
|
|
290
|
-
result += `${COUNT_ABBRS[i]}`;
|
|
291
|
-
return result;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
module.exports = rank;
|
|
295
|
-
|
package/src/reset.js
DELETED
|
@@ -1,22 +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 reset(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
|
-
await levels
|
|
14
|
-
.findOneAndUpdate({ user: userID, guild: guildID }, { xp: 0, level: 0 })
|
|
15
|
-
.catch((err) => {
|
|
16
|
-
throw new Error(err);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return { user: userID, guild: guildID, xp: 0, level: 0 };
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = reset;
|