XP gaining and levelup

master
Kit Kasune 4 years ago
parent 2af7dba47f
commit 7a31a2e50a
  1. 17
      events/message.js
  2. 23
      util/lxp/gainxp.js

@ -5,6 +5,7 @@ const wait = require('../util/wait');
const UserData = require('../models/user'); const UserData = require('../models/user');
const AR = require('../models/ar'); const AR = require('../models/ar');
const LXP = require('../models/localxp');
module.exports = async (client, message) => { module.exports = async (client, message) => {
if (message.author.bot) {return undefined;} if (message.author.bot) {return undefined;}
@ -48,6 +49,22 @@ module.exports = async (client, message) => {
}); });
} }
if (message.guild && client.misc.cache.lxp.enabled.includes(message.guild.id)) {
LXP.findOne({gid: message.guild.id}).then(xp => {
if (!client.misc.cache.lxp.xp[message.guild.id]) {client.misc.cache.lxp.xp[message.guild.id] = {};}
if (!client.misc.cache.lxp.xp[message.guild.id][message.author.id]) {client.misc.cache.lxp.xp[message.guild.id][message.author.id] = {
xp: xp.xp[message.author.id] ? xp.xp[message.author.id][0] : 0,
level: xp.xp[message.author.id] ? xp.xp[message.author.id][1] : 1,
lastXP: new Date().getTime() - 60000
};}
if (new Date().getTime() - client.misc.cache.lxp.xp[message.guild.id][message.author.id].lastXP > 60000) {
require('../util/lxp/gainxp')(client, message.member.id, message.channel);
}
});
}
try { try {
if (msg.startsWith(prefix) || msg.startsWith(`<@${client.user.id}>`) || msg.startsWith(`<@!${client.user.id}>`)) { if (msg.startsWith(prefix) || msg.startsWith(`<@${client.user.id}>`) || msg.startsWith(`<@!${client.user.id}>`)) {
let command = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd)); let command = client.commands.get(cmd) || client.commands.get(client.aliases.get(cmd));

@ -0,0 +1,23 @@
const LXP = require('../../models/localxp');
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;
let x = client.misc.cache.lxp.xp[channel.guild.id][member].level;
let max = Math.ceil(100 + (((x / 3) ** 1.4) * 1.3));
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 => {
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(() => {});}
if (ch && ch.permissionsFor(ch.guild.me.id).has('SEND_MESSAGES')) {ch.send(`<:awoo:560193779764559896> <@${member}> has reached **Level ${x + 1}**!`).catch((e) => {/*console.error(e)*/});}
} catch (e) {/*console.error(e);*/}
}).catch((e) => {/*console.error(e);*/})
}
};
Loading…
Cancel
Save