From 507b5baa1b085880e1b5e6e40625073eb3f7cd94 Mon Sep 17 00:00:00 2001 From: WubzyGD Date: Fri, 21 May 2021 02:51:40 -0600 Subject: [PATCH] fix logs and vc logs --- commands/moderation/logs.js | 22 ++++++++++++++++------ events/voiceStateUpdate.js | 21 +++++++++++++++++++++ models/log.js | 24 +----------------------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/commands/moderation/logs.js b/commands/moderation/logs.js index 7e84e66..864944b 100644 --- a/commands/moderation/logs.js +++ b/commands/moderation/logs.js @@ -10,8 +10,7 @@ const ObjLogTypes = { chnew: ['chn', 'chc', 'newch', 'newchannel', 'chcreate', 'channelcreate'], //chedit: ['channeledit'], chdelete: ['chd', 'channeldelete', 'deletechannel', 'deletech', 'chdelete'], - //vcjoin: [], - //vcleave: [], + vc: ['voice', 'vc'], //servervcmute: [], //servervcdeafen: [], //kick: [], @@ -62,15 +61,16 @@ module.exports = { if (!ch) {return message.channel.send("I can't find that channel! Make sure that you've mentioned one, or that the ID you provided is correct, and that I can see it.");} if (!ch.permissionsFor(client.user.id).has("SEND_MESSAGES")) {return message.reply("I don't have permissions to send messages in that channel. Please give me access and try again.");} let tl = await LogData.findOne({gid: message.guild.id}) || new LogData({gid: message.guild.id}); - tl[lt] = ch.id; + tl.logs[lt] = ch.id; + tl.markModified(`logs.${lt}`); tl.save(); if (!client.guildconfig.logs.has(message.guild.id)) {client.guildconfig.logs.set(message.guild.id, new Map());} client.guildconfig.logs.get(message.guild.id).set(lt, ch.id); - return message.channel.send("Log settings updated!") + return message.channel.send("Log settings updated!"); } if (['l', 'list'].includes(args[0].toLowerCase())) { - return message.channel.send("Valid log types:\n\n-`msgdelete` - Shows the content of a message that was deleted, in any channel.\n-`msgedit` - Shows both the old and new versions of a message when it is edited."); + return message.channel.send("Valid log types:\n\n-`msgdelete` - Shows the content of a message that was deleted, in any channel.\n-`msgedit` - Shows both the old and new versions of a message when it is edited.\n-`vc` - Logs when members join and leave VCs."); } if (['v', 'view'].includes(args[0].toLowerCase())) { @@ -79,7 +79,17 @@ module.exports = { } if (['c', 'clear'].includes(args[0].toLowerCase())) { - + let tl = await LogData.findOne({gid: message.guild.id}); + if (!tl) {return message.channel.send("Your server doesn't have any logs set up!");} + const conf = await require('../../util/ask')(message, "Are you sure you want to clear all your server's logs settings? This cannot be undone.", 60000); + if (!conf) {return;} + if (!['y', 'yes', 'sure'].includes(`${conf}`.toLowerCase())) {return message.channel.send("Okay, I won't clear your logs settings.");} + return LogData.deleteOne({gid: message.guild.id}) + .then(() => { + client.guildconfig.logs.delete(message.guild.id); + return message.channel.send("Logs settings wiped!") + }) + .catch(() => message.channel.send("An error occurred, and your logs data wasn't deleted. Please contact my devs if the problem persists.")); } } }; \ No newline at end of file diff --git a/events/voiceStateUpdate.js b/events/voiceStateUpdate.js index c1ef903..640d04d 100644 --- a/events/voiceStateUpdate.js +++ b/events/voiceStateUpdate.js @@ -1,6 +1,27 @@ +const Discord = require("discord.js"); + const Monitor = require('../models/monitor'); module.exports = async (client, oldState, voice) => { + let ts = client.guildconfig.logs.has(voice.guild.id) && client.guildconfig.logs.get(voice.guild.id).has('vc') ? client.guildconfig.logs.get(voice.guild.id).get('vc') : null; + if (ts) {if (voice.guild.channels.cache.has(ts) && voice.guild.channels.cache.get(ts).permissionsFor(client.user.id).has("SEND_MESSAGES")) { + if (oldState.channelID && voice.channelID) { + voice.guild.channels.cache.get(ts).send(new Discord.MessageEmbed() + .setTitle(`Member Switched VCs`) + .setThumbnail(client.users.cache.get(oldState.member.id).avatarURL({size: 2048, dynamic: true})) + .setDescription(`Old Channel: **${oldState.channel.name}**\nNew Channel: **${voice.channel.name}**`) + .setColor('e86b8f').setFooter("Natsuki", client.user.avatarURL()).setTimestamp() + ).catch(() => {}); + } else { + voice.guild.channels.cache.get(ts).send(new Discord.MessageEmbed() + .setTitle(`Member ${voice.channelID ? 'Joined' : 'Left'} VC`) + .setThumbnail(client.users.cache.get(oldState.member.id).avatarURL({size: 2048, dynamic: true})) + .setDescription(`Channel: **${voice.channelID ? voice.channel.name : oldState.channel.name}**`) + .setColor('e86b8f').setFooter("Natsuki", client.user.avatarURL()).setTimestamp() + ).catch(() => {}); + } + }} + if (client.users.cache.get(voice.member.id).bot) {return;} if (voice.guild && client.misc.cache.monitEnabled.includes(voice.guild.id)) { if (voice.channelID) { diff --git a/models/log.js b/models/log.js index 6afb660..4f021b3 100644 --- a/models/log.js +++ b/models/log.js @@ -2,29 +2,7 @@ const mongoose = require('mongoose'); const logSchema = new mongoose.Schema({ gid: {type: String, unique: true}, - mdelete: {type: String, default: ''}, - medit: {type: String, default: ''}, - chnew: {type: String, default: ''}, - chedit: {type: String, default: ''}, - chdelete: {type: String, default: ''}, - vcjoin: {type: String, default: ''}, - vcleave: {type: String, default: ''}, - servervcmute: {type: String, default: ''}, - servervcdeafen: {type: String, default: ''}, - kick: {type: String, default: ''}, - ban: {type: String, default: ''}, - mute: {type: String, default: ''}, - warn: {type: String, default: ''}, - giverole: {type: String, default: ''}, - takerole: {type: String, default: ''}, - addrole: {type: String, default: ''}, - editrole: {type: String, default: ''}, - deleterole: {type: String, default: ''}, - serverjoin: {type: String, default: ''}, - serverleave: {type: String, default: ''}, - nickname: {type: String, default: ''}, - username: {type: String, default: ''}, - avatar: {type: String, default: ''} + logs: {type: Object, default: {}} }); module.exports = mongoose.model('log', logSchema); \ No newline at end of file