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/cacheloop.js

26 lines
1.1 KiB

4 years ago
const LXP = require('../../models/localxp');
3 years ago
const Monners = require('../../models/monners');
4 years ago
module.exports = async (client) => {
let cd = new Date().getTime();
await Object.keys(client.misc.cache.lxp.xp).forEach(gxp => {
LXP.findOne({gid: gxp}).then(xp => {
if (!xp) {return;}
Object.keys(client.misc.cache.lxp.xp[gxp]).forEach(user => {
3 years ago
Monners.findOne({uid: user}).then(m => {
if (!m) {m = new Monners({uid: user});}
m.currency = client.misc.cache.monners[user];
m.save();
});
4 years ago
xp.xp[user] = [client.misc.cache.lxp.xp[gxp][user].xp, client.misc.cache.lxp.xp[gxp][user].level];
xp.markModified(`xp.${user}`);
if (cd - client.misc.cache.lxp.xp[gxp][user].lastXP > 600000) {
delete client.misc.cache.lxp.xp[gxp][user];
3 years ago
delete client.misc.cache.monners[user];
4 years ago
if (!Object.keys(client.misc.cache.lxp.xp[gxp]).length) {delete client.misc.cache.lxp.xp[gxp];}
}
});
xp.save();
3 years ago
});
});
4 years ago
};