level role model and cache

master
Kit Kasune 4 years ago
parent 075d733e64
commit dc9551c9b7
  1. 3
      bot.js
  2. 8
      models/levelroles.js
  3. 5
      util/cache.js
  4. 9
      util/cache/lr.js

@ -20,7 +20,8 @@ client.misc = {
}, },
lxp: { lxp: {
enabled: [], enabled: [],
xp: {} xp: {},
hasLevelRoles: []
} }
} }
}; };

@ -0,0 +1,8 @@
const mongoose = require('mongoose');
const LR = new mongoose.Schema({
gid: {type: String, unique: true},
roles: {type: Object, default: {}}
});
module.exports = mongoose.model('levelroles', LR);

@ -18,4 +18,9 @@ module.exports = async (client) => {
await require('./cache/lxp')(client); await require('./cache/lxp')(client);
ora_lxpCache.stop(); ora_lxpCache.clear(); ora_lxpCache.stop(); ora_lxpCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.lxp.enabled.length}`)} ${chalk.blueBright(`guilds with XP enabled.`)}`); console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.lxp.enabled.length}`)} ${chalk.blueBright(`guilds with XP enabled.`)}`);
let ora_lrCache = ora("Caching Level Roles...").start();
await require('./cache/lr')(client);
ora_lrCache.stop(); ora_lrCache.clear();
console.log(`${chalk.gray('[PROC]')} >> ${chalk.blueBright(`Cached`)} ${chalk.white(`${client.misc.cache.lxp.enabled.length}`)} ${chalk.blueBright(`guilds with Level Roles enabled.`)}`);
}; };

9
util/cache/lr.js vendored

@ -0,0 +1,9 @@
const LR = require('../../models/levelroles');
module.exports = async client => {
client.misc.cache.lxp.hasLevelRoles = [];
for await (const lr of LR.find()) {
client.misc.cache.lxp.hasLevelRoles.push(lr.gid);
}
};
Loading…
Cancel
Save