You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Luno/util/lxp/gainxp.js

48 lines
3.3 KiB

4 years ago
const LXP = require('../../models/localxp');
const LR = require('../../models/levelroles');
module.exports = async (client, member, channel) => {
client.misc.cache.lxp.xp[channel.guild.id][member].lastXP = new Date().getTime();
client.misc.cache.lxp.xp[channel.guild.id][member].xp += 10;
3 years ago
//console.log(`\nGAIN/PSV || Giving ${(Math.floor(client.misc.cache.lxp.xp[channel.guild.id][member].level / 35) + 1)} monners to ${client.guilds.cache.get(client.misc.neptune).members.cache.get(member).displayName} who is level ${client.misc.cache.lxp.xp[channel.guild.id][member].level}.`);
//console.log(`GAIN/PSV || Currently has ${client.misc.cache.monners[member]}`);
3 years ago
client.misc.cache.monners[member] += (Math.floor(client.misc.cache.lxp.xp[channel.guild.id][member].level / 35) + 1);
3 years ago
//console.log(`GAIN/PSV || Now has ${client.misc.cache.monners[member]}`);
4 years ago
let x = client.misc.cache.lxp.xp[channel.guild.id][member].level;
4 years ago
let max = Math.ceil(100 + (((x / 2.85) ** 2.2) * 2.5));
4 years ago
if (client.misc.cache.lxp.xp[channel.guild.id][member].xp > max) {
client.misc.cache.lxp.xp[channel.guild.id][member].xp -= max;
client.misc.cache.lxp.xp[channel.guild.id][member].level += 1;
LXP.findOne({gid: channel.guild.id}).then(async xp => {
3 years ago
4 years ago
if (!xp || !xp.msg) {return;}
try {
let ch = xp.lvch.length ? channel.guild.channels.cache.get(xp.lvch) : channel;
if (ch.partial) {await ch.fetch().catch(() => {});}
3 years ago
//console.log(`\nGAIN/BONUS || Level ${x + 1} user ${client.guilds.cache.get(client.misc.neptune).members.cache.get(member).displayName} getting ${((Math.floor((x + 1) / 10) + 1) * 5)} bonus`);
3 years ago
let cur = ((Math.floor((x + 1) / 10) + 1) * 5);
client.misc.cache.monners[member] += cur;
3 years ago
//console.log(`GAIN/BONUS || Now has ${client.misc.cache.monners[member]}`);
3 years ago
if (ch && ch.permissionsFor(ch.guild.me.id).has('SEND_MESSAGES')) {ch.send(`<a:CF_moonheart:868653516913246208> <@${member}> has reached **Level ${x + 1}**, and gained **${cur}** bonus Mooners<a:CF_mooners:868652679717589012>!`).catch((e) => {/*console.error(e)*/});}
4 years ago
if (client.misc.cache.lxp.hasLevelRoles.includes(channel.guild.id)) {
LR.findOne({gid: channel.guild.id}).then(async lr => {
if (!lr) {return;}
if (Object.keys(lr.roles).includes(`${client.misc.cache.lxp.xp[channel.guild.id][member].level}`)) {
try {
let role = channel.guild.roles.cache.get(`${lr.roles[client.misc.cache.lxp.xp[channel.guild.id][member].level]}`);
if (!role) {return;}
if (!channel.guild.me.permissions.has("MANAGE_ROLES")) {return;}
let m = channel.guild.members.cache.get(member);
if (!m) {return;}
m.roles.add(role).catch((e) => {/*console.error(e);*/});
} catch (e) {/*console.error(e);*/}
}
});
}
} catch (e) {/*console.error(e);*/}
}).catch((e) => {/*console.error(e);*/})
}
};