vc monitoring

master
Kit Kasune 4 years ago
parent f295a0bd05
commit 0bf836eb70
  1. 5
      bot.js
  2. 4
      events/ready.js
  3. 17
      events/voiceStateUpdate.js
  4. 46
      util/vcloop.js

@ -24,7 +24,10 @@ client.misc = {
hasLevelRoles: []
},
monit: {},
monitEnabled: []
monitEnabled: [],
inVC: [],
VCG: {},
activeVC: []
},
loggers: {}
};

@ -7,10 +7,12 @@ const ora = require('ora');
const GuildSettings = require('../models/guild');
const BotDataSchema = require('../models/bot');
const LogData = require('../models/log');
const Monitors = require('../models/monitor');
const siftStatuses = require('../util/siftstatuses');
const localXPCacheClean = require('../util/lxp/cacheloop');
const monitorCacheClean = require('../util/monitorloop');
const vcloop = require('../util/vcloop');
let prefix = 'n?';
@ -77,6 +79,8 @@ module.exports = async client => {
setInterval(() => localXPCacheClean(client), 150000);
setInterval(() => monitorCacheClean(client), 150000);
setInterval(() => vcloop(client), 60000);
let botData = await BotDataSchema.findOne({finder: 'lel'})
? await BotDataSchema.findOne({finder: 'lel'})
: new BotDataSchema({

@ -0,0 +1,17 @@
const Monitor = require('../models/monitor');
export default async (client, oldState, voice) => {
if (client.users.cache.get(voice.member.id).bot) {return;}
if (voice.guild && client.misc.cache.monitEnabled.includes(voice.guild.id)) {
if (voice.channelID) {
client.misc.cache.VCG[voice.member.id] = voice.guild.id;
if (!client.misc.cache.inVC.includes(voice.member.id)) {client.misc.cache.inVC.push(voice.member.id);}
if (!client.misc.cache.activeVC.includes(voice.channelID)) {client.misc.cache.activeVC.push(voice.channelID);}
} else {
if (!client.misc.cache.inVC.includes(voice.member.id)) {return;}
client.misc.inVC.splice(client.misc.inVC.indexOf(voice.member.id), 1);
if (!voice.channel.members.size && client.misc.activeVC.includes(voice.channelID)) {client.misc.activeVC.splice(client.misc.activeVC.indexOf(voice.channelID), 1);}
if (Object.keys(client.misc.cache.VCG).includes(voice.member.id)) {delete client.misc.cache.VCG[voice.member.id];}
}
}
};

@ -0,0 +1,46 @@
module.exports = client => {
client.misc.cache.inVC.forEach(m => {
if (client.misc.cache.monitEnabled.includes(client.misc.cache.VCG[m])) {
if (!client.misc.cache.monit[client.misc.cache.VCG[m]]) {
let tm = await Monitors.findOne({gid: client.misc.cache.VCG[m]});
client.misc.cache.monit[client.misc.cache.VCG[m]] = {
messages: tm.messages,
voice: tm.voice,
expiry: new Date()
};
if (!tm) {return;}
}
if (!client.misc.cache.monit) {client.misc.cache.monit = {};}
if (!client.misc.cache.monit[client.misc.cache.VCG[m]].voice.members[m]) {client.misc.cache.monit[client.misc.cache.VCG[m]].voice.members[m] = 0;}
client.misc.cache.monit[client.misc.cache.VCG[m]].voice.members[m] += 1;
client.misc.cache.monit[client.misc.cache.VCG[m]].voice.total += 1;
client.misc.cache.monit[client.misc.cache.VCG[m]].expiry.setTime(Date.now());
} else {
client.misc.cache.inVC.splice(client.misc.cache.inVC.indexOf(m), 1);
delete client.misc.cache.VCG[m];
}
});
client.misc.cache.activeVC.forEach(vc => {
let g = client.guilds.cache.filter(g => g.channels.cache.has(vc)).first();
if (!g) {return;}
g = g.id;
if (client.misc.cache.monitEnabled.includes(g)) {
if (!client.misc.cache.monit[g]) {
let tm = await Monitors.findOne({gid: g});
client.misc.cache.monit[g] = {
messages: tm.messages,
voice: tm.voice,
expiry: new Date()
};
if (!tm) {return;}
}
if (!client.misc.cache.monit) {client.misc.cache.monit = {};}
if (!client.misc.cache.monit[g].voice.channels[vc]) {client.misc.cache.monit[g].voice.channels[vc] = 0;}
client.misc.cache.monit[g].voice.channels[vc] += 1;
client.misc.cache.monit[g].expiry.setTime(Date.now());
} else {
client.misc.cache.activeVC.splice(client.misc.cache.activeVC.indexOf(vc), 1);
}
});
};
Loading…
Cancel
Save