Skip to content

Commit

Permalink
v1.3.5 (BETA-7)
Browse files Browse the repository at this point in the history
CHANGES:
- Indents, that's it lmao
  • Loading branch information
Abadima committed Jun 24, 2023
1 parent c567aa5 commit 23d42cc
Show file tree
Hide file tree
Showing 17 changed files with 795 additions and 795 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"rules": {
"indent": [
"error",
4
"tab"
],
"linebreak-style": [
"error",
Expand Down
4 changes: 2 additions & 2 deletions simplyxp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
try {
require('discord.js');
require('discord.js');
} catch (e) {
console.warn('[XP] Discord.js is recommended for this package.');
console.warn('[XP] Discord.js is recommended for this package.');
}

module.exports.roleSetup = require('./src/roleSetup');
Expand Down
78 changes: 39 additions & 39 deletions src/addLevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,59 @@ let {roleSetup} = require('../simplyxp');
* @param {number} level
*/
async function addLevel(message, userID, guildID, level) {
if (!userID) throw new Error('[XP] User ID was not provided.');
if (!userID) throw new Error('[XP] User ID was not provided.');

if (!guildID) throw new Error('[XP] Guild ID was not provided.');
if (!guildID) throw new Error('[XP] Guild ID was not provided.');

if (!level) throw new Error('[XP] Level amount is not provided.');
if (!level) throw new Error('[XP] Level amount is not provided.');

let {client} = message;
let {client} = message;

const user = await levels.findOne({user: userID, guild: guildID});
const user = await levels.findOne({user: userID, guild: guildID});

if (!user) {
const newUser = new levels({
user: userID,
guild: guildID,
xp: 0,
level: 0
});
if (!user) {
const newUser = new levels({
user: userID,
guild: guildID,
xp: 0,
level: 0
});

await newUser.save().catch(() => console.log('[XP] Failed to save new user to database'));
await newUser.save().catch(() => console.log('[XP] Failed to save new user to database'));

let xp = (level * 10) ** 2;
let xp = (level * 10) ** 2;

return {
level: level,
exp: xp
};
}
let level1 = user.level;
return {
level: level,
exp: xp
};
}
let level1 = user.level;

user.level += parseFloat(level);
user.xp = (user.level * 10) ** 2;
user.level += parseFloat(level);
user.xp = (user.level * 10) ** 2;

await user.save().catch((e) =>
console.log(`[XP] Failed to add Level | User: ${userID} | Err: ${e}`)
);
await user.save().catch((e) =>
console.log(`[XP] Failed to add Level | User: ${userID} | Err: ${e}`)
);

if (level1 !== level) {
let data = {
xp: user.xp,
level: user.level,
userID,
guildID
};
if (level1 !== level) {
let data = {
xp: user.xp,
level: user.level,
userID,
guildID
};

let role = await roleSetup.find(client, guildID, level);
let role = await roleSetup.find(client, guildID, level);

client.emit('levelUp', message, data, role);
}
client.emit('levelUp', message, data, role);
}

return {
level: user.level,
xp: user.xp
};
return {
level: user.level,
xp: user.xp
};
}

module.exports = addLevel;
132 changes: 66 additions & 66 deletions src/addXP.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,96 +9,96 @@ let {roleSetup} = require('../simplyxp');
*/

async function addXP(message, userID, guildID, xp) {
if (!userID) throw new Error('[XP] User ID was not provided.');
if (!userID) throw new Error('[XP] User ID was not provided.');

if (!guildID) throw new Error('[XP] Guild ID was not provided.');
if (!guildID) throw new Error('[XP] Guild ID was not provided.');

if (!xp) throw new Error('[XP] XP amount is not provided.');
if (!xp) throw new Error('[XP] XP amount is not provided.');

let {client} = message;
let {client} = message;

let min;
let max;
if (xp.min) {
if (!xp.max)
throw new Error(
'[XP] XP min amount is provided but max amount is not provided.'
);
let min;
let max;
if (xp.min) {
if (!xp.max)
throw new Error(
'[XP] XP min amount is provided but max amount is not provided.'
);

min = Number(xp.min);
min = Number(xp.min);

if (Number(xp.min).toString() === 'NaN')
throw new Error('[XP] XP amount (min) is not a number.');
}
if (Number(xp.min).toString() === 'NaN')
throw new Error('[XP] XP amount (min) is not a number.');
}

if (xp.max) {
if (!xp.min)
throw new Error(
'[XP] XP max amount is provided but min amount is not provided.'
);
if (xp.max) {
if (!xp.min)
throw new Error(
'[XP] XP max amount is provided but min amount is not provided.'
);

max = Number(xp.max);
max = Number(xp.max);

if (Number(xp.max).toString() === 'NaN')
throw new Error('[XP] XP amount (max) is not a number.');
}
if (Number(xp.max).toString() === 'NaN')
throw new Error('[XP] XP amount (max) is not a number.');
}

if (xp.min && xp.max) {
xp = Math.floor(Math.random() * (max - min) + min);
}
if (xp.min && xp.max) {
xp = Math.floor(Math.random() * (max - min) + min);
}

const user = await levels.findOne({user: userID, guild: guildID});
const user = await levels.findOne({user: userID, guild: guildID});

let lvl = Math.floor(0.1 * Math.sqrt(xp));
let lvl = Math.floor(0.1 * Math.sqrt(xp));

// TODO: FIX THIS xp = xp & level = lvl
if (!user) {
const newUser = new levels({
user: userID,
guild: guildID,
xp: xp,
level: lvl
});
// TODO: FIX THIS xp = xp & level = lvl
if (!user) {
const newUser = new levels({
user: userID,
guild: guildID,
xp: xp,
level: lvl
});

await newUser.save().catch(() => console.log('[XP] Failed to save new user to database'));
await newUser.save().catch(() => console.log('[XP] Failed to save new user to database'));

return {
level: 0,
exp: 0
};
}
let level1 = user.level;
return {
level: 0,
exp: 0
};
}
let level1 = user.level;

user.xp += parseInt(xp, 10);
user.level = Math.floor(0.1 * Math.sqrt(user.xp));
user.xp += parseInt(xp, 10);
user.level = Math.floor(0.1 * Math.sqrt(user.xp));

await user.save().catch((e) => console.log(`[XP] Failed to add XP | User: ${userID} | Err: ${e}`));
await user.save().catch((e) => console.log(`[XP] Failed to add XP | User: ${userID} | Err: ${e}`));

let level = user.level;
let level = user.level;

xp = user.xp;
xp = user.xp;

if (user.xp === 0 || Math.sign(user.xp) === -1) {
xp = 0;
}
if (user.xp === 0 || Math.sign(user.xp) === -1) {
xp = 0;
}

if (level1 !== level) {
let data = {
xp,
level,
userID,
guildID
};
if (level1 !== level) {
let data = {
xp,
level,
userID,
guildID
};

let role = await roleSetup.find(client, guildID, level);
let role = await roleSetup.find(client, guildID, level);

client.emit('levelUp', message, data, role);
}
client.emit('levelUp', message, data, role);
}

return {
level,
xp
};
return {
level,
xp
};
}

module.exports = addXP;
Loading

0 comments on commit 23d42cc

Please sign in to comment.