role awarding

master
Kit Kasune 4 years ago
parent dc9551c9b7
commit eba7b53472
  1. 2
      commands/stats.js
  2. 18
      util/lxp/gainxp.js

@ -31,7 +31,7 @@ module.exports = {
.setTitle(`${u.displayName}${u.displayName.toLowerCase().endsWith('s') ? "'" : "'s"} Stats`) .setTitle(`${u.displayName}${u.displayName.toLowerCase().endsWith('s') ? "'" : "'s"} Stats`)
.setDescription("Local leveling stats") .setDescription("Local leveling stats")
.addField("Level", xp.level, true) .addField("Level", xp.level, true)
.addField("XP", `**${xp.xp}** of **${Math.ceil(100 + (((xp.level / 3) ** 1.4) * 1.3))}** needed to level up`, true) .addField("XP", `**${xp.xp}** of **${Math.ceil(100 + (((xp.level / 3) ** 1.4) * 1.4))}** needed to level up`, true)
.setThumbnail(client.users.cache.get(u.id).avatarURL({size: 2048})) .setThumbnail(client.users.cache.get(u.id).avatarURL({size: 2048}))
.setColor("c375f0") .setColor("c375f0")
.setFooter("Natsuki") .setFooter("Natsuki")

@ -1,11 +1,12 @@
const LXP = require('../../models/localxp'); const LXP = require('../../models/localxp');
const LR = require('../../models/levelroles');
module.exports = async (client, member, channel) => { 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].lastXP = new Date().getTime();
client.misc.cache.lxp.xp[channel.guild.id][member].xp += 10; client.misc.cache.lxp.xp[channel.guild.id][member].xp += 10;
let x = client.misc.cache.lxp.xp[channel.guild.id][member].level; let x = client.misc.cache.lxp.xp[channel.guild.id][member].level;
let max = Math.ceil(100 + (((x / 3) ** 1.4) * 1.3)); let max = Math.ceil(100 + (((x / 3) ** 1.4) * 1.4));
if (client.misc.cache.lxp.xp[channel.guild.id][member].xp > max) { 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].xp -= max;
@ -17,6 +18,21 @@ module.exports = async (client, member, channel) => {
let ch = xp.lvch.length ? channel.guild.channels.cache.get(xp.lvch) : channel; let ch = xp.lvch.length ? channel.guild.channels.cache.get(xp.lvch) : channel;
if (ch.partial) {await ch.fetch().catch(() => {});} 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)*/});} 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)*/});}
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);*/}
}).catch((e) => {/*console.error(e);*/}) }).catch((e) => {/*console.error(e);*/})
} }

Loading…
Cancel
Save