ignoring channels for xp gain

master
Kit Kasune 3 years ago
parent 1ca256cd1f
commit 22cf92fe0c
  1. 3
      bot.js
  2. 26
      events/messageCreate.js
  3. 4
      models/localxp.js
  4. 2
      util/cache/lxp.js

@ -31,7 +31,8 @@ client.misc = {
lxp: { lxp: {
enabled: [], enabled: [],
xp: {}, xp: {},
hasLevelRoles: [] hasLevelRoles: [],
disabledChannels: new Map()
}, },
monit: {}, monit: {},
monitEnabled: [], monitEnabled: [],

@ -60,18 +60,20 @@ module.exports = async (client, message) => {
} }
if (message.guild && client.misc.cache.lxp.enabled.includes(message.guild.id)) { if (message.guild && client.misc.cache.lxp.enabled.includes(message.guild.id)) {
if (!client.misc.cache.lxp.xp[message.guild.id]) {client.misc.cache.lxp.xp[message.guild.id] = {};} if (!client.misc.cache.lxp.disabledMessages.has(message.guild.id) || !client.misc.cache.lxp.disabledMessage.get(message.guild.id).includes(message.channel.id)) {
if (!client.misc.cache.lxp.xp[message.guild.id][message.author.id]) { if (!client.misc.cache.lxp.xp[message.guild.id]) {client.misc.cache.lxp.xp[message.guild.id] = {};}
LXP.findOne({gid: message.guild.id}).then(xp => { if (!client.misc.cache.lxp.xp[message.guild.id][message.author.id]) {
client.misc.cache.lxp.xp[message.guild.id][message.author.id] = { LXP.findOne({gid: message.guild.id}).then(xp => {
xp: xp.xp[message.author.id] ? xp.xp[message.author.id][0] : 0, client.misc.cache.lxp.xp[message.guild.id][message.author.id] = {
level: xp.xp[message.author.id] ? xp.xp[message.author.id][1] : 1, xp: xp.xp[message.author.id] ? xp.xp[message.author.id][0] : 0,
lastXP: new Date().getTime() - 60000 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); 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);
}
} }
} }

@ -4,7 +4,9 @@ const lxp = new mongoose.Schema({
gid: {type: String, unique: true}, gid: {type: String, unique: true},
msg: {type: Boolean, default: true}, msg: {type: Boolean, default: true},
xp: {type: Object, default: {}}, xp: {type: Object, default: {}},
lvch: {type: String, default: ''} lvch: {type: String, default: ''},
chests: {type: Object},
noGains: {type: [String]}
}); });
module.exports = mongoose.model('localxp', lxp); module.exports = mongoose.model('localxp', lxp);

2
util/cache/lxp.js vendored

@ -2,8 +2,10 @@ const LXP = require('../../models/localxp');
module.exports = async client => { module.exports = async client => {
client.misc.cache.lxp.enabled = []; client.misc.cache.lxp.enabled = [];
client.misc.cache.lxp.disabledChannels = new Map();
for await (const xp of LXP.find()) { for await (const xp of LXP.find()) {
client.misc.cache.lxp.enabled.push(xp.gid); client.misc.cache.lxp.enabled.push(xp.gid);
if (xp.noGains && xp.noGains.length) {client.misc.cache.lxp.disabledChannels.set(xp.gid, xp.noGains);}
} }
}; };
Loading…
Cancel
Save