From 493d61eb1f20d090541fba9644398d0266e8b6e2 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Tue, 27 Apr 2021 21:36:03 -0600 Subject: [PATCH] monitor setup and model --- commands/utility/monitor.js | 39 +++++++++++++++++++++++++++++++++++++ models/monitor.js | 9 +++++++++ 2 files changed, 48 insertions(+) create mode 100644 commands/utility/monitor.js create mode 100644 models/monitor.js diff --git a/commands/utility/monitor.js b/commands/utility/monitor.js new file mode 100644 index 0000000..4575b34 --- /dev/null +++ b/commands/utility/monitor.js @@ -0,0 +1,39 @@ +const Discord = require('discord.js'); + +const GuildData = require('../../models/guild'); +const Monitors = require('../../models/monitor'); + +module.exports = { + name: "monitor", + aliases: ['serverstats', 'monit'], + meta: { + category: 'Utility', + description: "Monitors your server's messaging and voice activity", + syntax: '`monitor `', + extra: null, + guildOnly: true + }, + help: new Discord.MessageEmbed() + .setTitle("Help -> Server Stats Monitoring") + .setDescription("Monitor and track your members' activity such as their message counts and voice hours.") + .addField("Syntax", "`monitor `"), + async execute(message, msg, args, cmd, prefix, mention, client) { + let tm = await Monitors.findOne({gid: message.guild.id}); + + if (!args.length || (args.length && ['v', 'view', 'stats'].includes(args[0].toLowerCase()))) { + + } + + if (['s', 'setup', 'config', 'configure'].includes(args[0].toLowerCase())) { + let tg = await GuildData.findOne({gid: message.guild.id}); + if ((tg && tg.staffrole && tg.staffrole.length && !message.member.roles.cache.has(tg.staffrole)) && !message.member.permissions.has("ADMINISTRATOR")) {return message.channel.send("You must be an administrator or have the staff role in your server in order to use this command!");} + if (tm) {return message.channel.send("You already have an activity monitor set up!");} + tm = new Monitors({gid: message.guild.id}); + tm.save(); + client.misc.cache.monit[message.guild.id] = {messages: {channels: {}, members: {}}, voice: {channels: {}, members: {}}}; + return message.channel.send("Your server activity monitor has been set up successfully!"); + } + + else {return message.channel.send(`Syntax: \`${prefix}monitor \``);} + } +}; \ No newline at end of file diff --git a/models/monitor.js b/models/monitor.js new file mode 100644 index 0000000..6ac9a8a --- /dev/null +++ b/models/monitor.js @@ -0,0 +1,9 @@ +const mongoose = require('mongoose'); + +const Monitor = new mongoose.Schema({ + gid: {type: String, unique: true}, + messages: {type: Object, default: {}}, + voice: {type: Object, default: {}} +}); + +module.exports = mongoose.model("monitor", Monitor); \ No newline at end of file