simply-xp 1.3.5-beta-6 → 1.3.5

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/src/reset.js CHANGED
@@ -1,22 +1,22 @@
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
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;
package/src/roleSetup.js CHANGED
@@ -1,121 +1,121 @@
1
- const lrole = require('../src/models/lvlrole.js')
2
-
3
- class roleSetup {
4
- /**
5
- * @param {Discord.Client} client
6
- * @param {string} guildID
7
- * @param {import('../index').lvladdOptions} options
8
- */
9
-
10
- static async add(client, guildID, options = []) {
11
- let rol = await lrole.findOne({
12
- gid: guildID,
13
- lvlrole: {
14
- lvl: options.level,
15
- role: options.role
16
- }
17
- })
18
-
19
- let g = client.guilds.cache.get(guildID)
20
-
21
- let roll = g.roles.cache.find((r) => r.id === options.role)
22
-
23
- if (roll) {
24
- if (rol) throw new Error('Level Already Exist. Use delete')
25
- else if (!rol) {
26
- let newrol = await lrole.findOne({
27
- gid: guildID
28
- })
29
-
30
- if (!newrol) {
31
- newrol = new lrole({
32
- gid: guildID,
33
- lvlrole: []
34
- })
35
-
36
- await newrol.save()
37
- }
38
-
39
- newrol.lvlrole.push({ lvl: options.level, role: options.role })
40
-
41
- await newrol
42
- .save()
43
- .catch((e) =>
44
- console.log(`[XP] Failed to add lvlrole to database | ${e}`)
45
- )
46
-
47
- return true
48
- }
49
- } else {
50
- throw new Error(
51
- 'Role ID is invalid. | ' +
52
- `Guild ID: ${guildID} | Role ID: ${options.role}`
53
- )
54
- }
55
- }
56
-
57
- /**
58
- * @param {Discord.Client} client
59
- * @param {string} guildID
60
- * @param {import('../index').lvlremoveOptions} options
61
- */
62
-
63
- static async remove(client, guildID, options = []) {
64
- let rol = await lrole.find({
65
- gid: guildID
66
- })
67
-
68
- if (!rol || rol.length === 0)
69
- throw new Error('Level role with this level does not exist')
70
- rol = rol[0].lvlrole.find((item) => item.lvl === options.level) || undefined
71
-
72
- if (rol) {
73
- let newrol = await lrole.findOneAndUpdate(
74
- {
75
- gid: guildID
76
- },
77
- {
78
- $pull: { lvlrole: { lvl: options.level } }
79
- }
80
- )
81
-
82
- return true
83
- } else throw new Error('Level role with this level does not exist')
84
- }
85
-
86
- /**
87
- * @param {Discord.Client} client
88
- * @param {string} guildID
89
- */
90
-
91
- static async fetch(client, guildID) {
92
- let rol = await lrole.find({
93
- gid: guildID
94
- })
95
-
96
- if (!rol || rol.length === 0) return
97
-
98
- return rol[0].lvlrole
99
- }
100
-
101
- /**
102
- * @param {Discord.Client} client
103
- * @param {string} guildID
104
- * @param {string} level
105
- */
106
-
107
- static async find(client, guildID, level) {
108
- let rol = await lrole.find({
109
- gid: guildID
110
- })
111
-
112
- if (!rol || !rol.length) return
113
- rol = rol[0].lvlrole.filter((i) => i.lvl == level) || undefined
114
-
115
- if (rol) {
116
- return rol
117
- }
118
- }
119
- }
120
-
121
- module.exports = roleSetup
1
+ const lrole = require("../src/models/lvlrole.js");
2
+
3
+ class roleSetup {
4
+ /**
5
+ * @param {Discord.Client} client
6
+ * @param {string} guildID
7
+ * @param {import("../index").lvladdOptions} options
8
+ */
9
+
10
+ static async add(client, guildID, options = []) {
11
+ let rol = await lrole.findOne({
12
+ gid: guildID,
13
+ lvlrole: {
14
+ lvl: options.level,
15
+ role: options.role
16
+ }
17
+ });
18
+
19
+ let g = client.guilds.cache.get(guildID);
20
+
21
+ let roll = g.roles.cache.find((r) => r.id === options.role);
22
+
23
+ if (roll) {
24
+ if (rol) throw new Error("Level Already Exist. Use delete");
25
+ else if (!rol) {
26
+ let newrol = await lrole.findOne({
27
+ gid: guildID
28
+ });
29
+
30
+ if (!newrol) {
31
+ newrol = new lrole({
32
+ gid: guildID,
33
+ lvlrole: []
34
+ });
35
+
36
+ await newrol.save();
37
+ }
38
+
39
+ newrol.lvlrole.push({lvl: options.level, role: options.role});
40
+
41
+ await newrol
42
+ .save()
43
+ .catch((e) =>
44
+ console.log(`[XP] Failed to add lvlrole to database | ${e}`)
45
+ );
46
+
47
+ return true;
48
+ }
49
+ } else {
50
+ throw new Error(
51
+ "Role ID is invalid. | " +
52
+ `Guild ID: ${guildID} | Role ID: ${options.role}`
53
+ );
54
+ }
55
+ }
56
+
57
+ /**
58
+ * @param {Discord.Client} client
59
+ * @param {string} guildID
60
+ * @param {import("../index").lvlremoveOptions} options
61
+ */
62
+
63
+ static async remove(client, guildID, options = []) {
64
+ let rol = await lrole.find({
65
+ gid: guildID
66
+ });
67
+
68
+ if (!rol || rol.length === 0)
69
+ throw new Error("Level role with this level does not exist");
70
+ rol = rol[0].lvlrole.find((item) => item.lvl === options.level) || undefined;
71
+
72
+ if (rol) {
73
+ await lrole.findOneAndUpdate(
74
+ {
75
+ gid: guildID
76
+ },
77
+ {
78
+ $pull: {lvlrole: {lvl: options.level}}
79
+ }
80
+ );
81
+
82
+ return true;
83
+ } else throw new Error("Level role with this level does not exist");
84
+ }
85
+
86
+ /**
87
+ * @param {Discord.Client} client
88
+ * @param {string} guildID
89
+ */
90
+
91
+ static async fetch(client, guildID) {
92
+ let rol = await lrole.find({
93
+ gid: guildID
94
+ });
95
+
96
+ if (!rol || rol.length === 0) return;
97
+
98
+ return rol[0].lvlrole;
99
+ }
100
+
101
+ /**
102
+ * @param {Discord.Client} client
103
+ * @param {string} guildID
104
+ * @param {string} level
105
+ */
106
+
107
+ static async find(client, guildID, level) {
108
+ let rol = await lrole.find({
109
+ gid: guildID
110
+ });
111
+
112
+ if (!rol || !rol.length) return;
113
+ rol = rol[0].lvlrole.filter((i) => i.lvl == level) || undefined;
114
+
115
+ if (rol) {
116
+ return rol;
117
+ }
118
+ }
119
+ }
120
+
121
+ module.exports = roleSetup;
package/src/setLevel.js CHANGED
@@ -1,70 +1,42 @@
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 {string} level
9
- */
10
- async function setLevel(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
30
- .save()
31
- .catch((e) => console.log(`[XP] Failed to save new user to database`))
32
-
33
- let xp = (level * 10) ** 2
34
-
35
- return {
36
- level: level,
37
- exp: xp
38
- }
39
- }
40
- let level1 = user.level
41
-
42
- user.xp = (level * 10) ** 2
43
- user.level = Math.floor(0.1 * Math.sqrt(user.xp))
44
-
45
- await user
46
- .save()
47
- .catch((e) =>
48
- console.log(`[XP] Failed to set Level | User: ${userID} | Err: ${e}`)
49
- )
50
-
51
- if (level1 !== level) {
52
- let data = {
53
- xp: user.xp,
54
- level: user.level,
55
- userID,
56
- guildID
57
- }
58
-
59
- let role = await roleSetup.find(client, guildID, level)
60
-
61
- client.emit('levelUp', message, data, role)
62
- }
63
-
64
- return {
65
- level: user.level,
66
- xp: user.xp
67
- }
68
- }
69
-
70
- module.exports = setLevel
1
+ const levels = require("../src/models/level.js");
2
+ const {roleSetup} = require("../simplyxp");
3
+
4
+ /**
5
+ * @param {Discord.Message} message
6
+ * @param {string} userID
7
+ * @param {string} guildID
8
+ * @param {string} level
9
+ */
10
+ async function setLevel(message, userID, guildID, level) {
11
+ if (!userID) throw new Error("[XP] User ID was not provided.");
12
+ if (!guildID) throw new Error("[XP] Guild ID was not provided.");
13
+ if (!level || isNaN(Number(level))) throw new Error("[XP] Invalid level amount.");
14
+
15
+ const {client} = message;
16
+
17
+ const user = await levels.findOneAndUpdate(
18
+ {user: userID, guild: guildID},
19
+ {xp: (level * 10) ** 2, level: Math.floor(0.1 * Math.sqrt((level * 10) ** 2))},
20
+ {upsert: true, new: true}
21
+ );
22
+
23
+ if (user.level !== level) {
24
+ let data = {
25
+ xp: user.xp,
26
+ level: user.level,
27
+ userID,
28
+ guildID
29
+ };
30
+
31
+ let role = await roleSetup.find(client, guildID, level);
32
+
33
+ client.emit("levelUp", message, data, role);
34
+ }
35
+
36
+ return {
37
+ level: user.level,
38
+ xp: user.xp
39
+ };
40
+ }
41
+
42
+ module.exports = setLevel;
package/src/setXP.js CHANGED
@@ -1,51 +1,23 @@
1
- const levels = require('../src/models/level.js')
2
-
3
- /**
4
- * @param {string} userID
5
- * @param {string} guildID
6
- * @param {string} xp
7
- */
8
-
9
- async function setXP(userID, guildID, xp) {
10
- if (!userID) throw new Error('[XP] User ID was not provided.')
11
-
12
- if (!guildID) throw new Error('[XP] Guild ID was not provided.')
13
-
14
- if (!xp) throw new Error('[XP] XP amount is not provided.')
15
-
16
- if (Number(xp).toString() === 'NaN')
17
- throw new Error('[XP] XP amount is not a number.')
18
-
19
- const user = await levels.findOne({ user: userID, guild: guildID })
20
-
21
- let lvl = Math.floor(0.1 * Math.sqrt(xp))
22
-
23
- if (!user) {
24
- const newUser = new levels({
25
- user: userID,
26
- guild: guildID,
27
- xp: xp,
28
- level: lvl
29
- })
30
-
31
- await newUser
32
- .save()
33
- .catch((e) => console.log(`[XP] Failed to save new use to database`))
34
-
35
- return {
36
- xp: 0
37
- }
38
- }
39
- user.xp = xp
40
- user.level = Math.floor(0.1 * Math.sqrt(user.xp))
41
-
42
- await user
43
- .save()
44
- .catch((e) =>
45
- console.log(`[XP] Failed to set XP | User: ${userID} | Err: ${e}`)
46
- )
47
-
48
- return { xp }
49
- }
50
-
51
- module.exports = setXP
1
+ const levels = require("../src/models/level.js");
2
+
3
+ async function setXP(userID, guildID, xp) {
4
+ if (!userID) throw new Error("[XP] User ID was not provided.");
5
+ if (!guildID) throw new Error("[XP] Guild ID was not provided.");
6
+ if (!xp || isNaN(Number(xp))) throw new Error("[XP] Invalid XP amount.");
7
+
8
+ const user = await levels.findOneAndUpdate(
9
+ {user: userID, guild: guildID},
10
+ {xp: xp},
11
+ {upsert: true}
12
+ );
13
+
14
+ const lvl = Math.floor(0.1 * Math.sqrt(xp));
15
+ if (user.level !== lvl) {
16
+ user.level = lvl;
17
+ await user.save().catch((e) => console.log(`[XP] Failed to set XP | User: ${userID} | Err: ${e}`));
18
+ }
19
+
20
+ return {xp};
21
+ }
22
+
23
+ module.exports = setXP;
@@ -1,128 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our
6
- community a harassment-free experience for everyone, regardless of age, body
7
- size, visible or invisible disability, ethnicity, sex characteristics, gender
8
- identity and expression, level of experience, education, socio-economic status,
9
- nationality, personal appearance, race, religion, or sexual identity
10
- and orientation.
11
-
12
- We pledge to act and interact in ways that contribute to an open, welcoming,
13
- diverse, inclusive, and healthy community.
14
-
15
- ## Our Standards
16
-
17
- Examples of behavior that contributes to a positive environment for our
18
- community include:
19
-
20
- * Demonstrating empathy and kindness toward other people
21
- * Being respectful of differing opinions, viewpoints, and experiences
22
- * Giving and gracefully accepting constructive feedback
23
- * Accepting responsibility and apologizing to those affected by our mistakes,
24
- and learning from the experience
25
- * Focusing on what is best not just for us as individuals, but for the
26
- overall community
27
-
28
- Examples of unacceptable behavior include:
29
-
30
- * The use of sexualized language or imagery, and sexual attention or
31
- advances of any kind
32
- * Trolling, insulting or derogatory comments, and personal or political attacks
33
- * Public or private harassment
34
- * Publishing others' private information, such as a physical or email
35
- address, without their explicit permission
36
- * Other conduct which could reasonably be considered inappropriate in a
37
- professional setting
38
-
39
- ## Enforcement Responsibilities
40
-
41
- Community leaders are responsible for clarifying and enforcing our standards of
42
- acceptable behavior and will take appropriate and fair corrective action in
43
- response to any behavior that they deem inappropriate, threatening, offensive,
44
- or harmful.
45
-
46
- Community leaders have the right and responsibility to remove, edit, or reject
47
- comments, commits, code, wiki edits, issues, and other contributions that are
48
- not aligned to this Code of Conduct, and will communicate reasons for moderation
49
- decisions when appropriate.
50
-
51
- ## Scope
52
-
53
- This Code of Conduct applies within all community spaces, and also applies when
54
- an individual is officially representing the community in public spaces.
55
- Examples of representing our community include using an official e-mail address,
56
- posting via an official social media account, or acting as an appointed
57
- representative at an online or offline event.
58
-
59
- ## Enforcement
60
-
61
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
- reported to the community leaders responsible for enforcement at
63
- Email.
64
- All complaints will be reviewed and investigated promptly and fairly.
65
-
66
- All community leaders are obligated to respect the privacy and security of the
67
- reporter of any incident.
68
-
69
- ## Enforcement Guidelines
70
-
71
- Community leaders will follow these Community Impact Guidelines in determining
72
- the consequences for any action they deem in violation of this Code of Conduct:
73
-
74
- ### 1. Correction
75
-
76
- **Community Impact**: Use of inappropriate language or other behavior deemed
77
- unprofessional or unwelcome in the community.
78
-
79
- **Consequence**: A private, written warning from community leaders, providing
80
- clarity around the nature of the violation and an explanation of why the
81
- behavior was inappropriate. A public apology may be requested.
82
-
83
- ### 2. Warning
84
-
85
- **Community Impact**: A violation through a single incident or series
86
- of actions.
87
-
88
- **Consequence**: A warning with consequences for continued behavior. No
89
- interaction with the people involved, including unsolicited interaction with
90
- those enforcing the Code of Conduct, for a specified period of time. This
91
- includes avoiding interactions in community spaces as well as external channels
92
- like social media. Violating these terms may lead to a temporary or
93
- permanent ban.
94
-
95
- ### 3. Temporary Ban
96
-
97
- **Community Impact**: A serious violation of community standards, including
98
- sustained inappropriate behavior.
99
-
100
- **Consequence**: A temporary ban from any sort of interaction or public
101
- communication with the community for a specified period of time. No public or
102
- private interaction with the people involved, including unsolicited interaction
103
- with those enforcing the Code of Conduct, is allowed during this period.
104
- Violating these terms may lead to a permanent ban.
105
-
106
- ### 4. Permanent Ban
107
-
108
- **Community Impact**: Demonstrating a pattern of violation of community
109
- standards, including sustained inappropriate behavior, harassment of an
110
- individual, or aggression toward or disparagement of classes of individuals.
111
-
112
- **Consequence**: A permanent ban from any sort of public interaction within
113
- the community.
114
-
115
- ## Attribution
116
-
117
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
- version 2.0, available at
119
- https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
-
121
- Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
- enforcement ladder](https://github.com/mozilla/diversity).
123
-
124
- [homepage]: https://www.contributor-covenant.org
125
-
126
- For answers to common questions about this code of conduct, see the FAQ at
127
- https://www.contributor-covenant.org/faq. Translations are available at
128
- https://www.contributor-covenant.org/translations.
@@ -1,31 +0,0 @@
1
- ---
2
- name: Bug report
3
- about: Create a report to help us improve
4
- title: ''
5
- labels: 'bug'
6
- assignees: ''
7
- ---
8
-
9
- **Describe the bug**
10
- A clear and concise description of what the bug is.
11
-
12
- **To Reproduce**
13
- Steps to reproduce the behavior:
14
-
15
- 1. Run the bot
16
- 2. Try the function
17
- 3. See error
18
-
19
- **Expected behavior**
20
- A clear and concise description of what you expected to happen.
21
-
22
- **Screenshots**
23
- If applicable, add screenshots to help explain your problem.
24
-
25
- **Versions (please complete the following information):**
26
-
27
- - Discord.js Version [e.g. v13]
28
- - simply-xp Version [e.g. v2.0.0]
29
-
30
- **Additional context**
31
- Add any other context about the problem here.
@@ -1,20 +0,0 @@
1
- ---
2
- name: Feature request
3
- about: Suggest an idea for this project
4
- title: ''
5
- labels: 'feature'
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Is your feature request related to a problem? Please describe.**
11
- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
-
13
- **Describe the solution you'd like**
14
- A clear and concise description of what you want to happen.
15
-
16
- **Describe alternatives you've considered**
17
- A clear and concise description of any alternative solutions or features you've considered.
18
-
19
- **Additional context**
20
- Add any other context or screenshots about the feature request here.