diff --git a/Main.js b/Main.js index 9405cf4..29d0619 100644 --- a/Main.js +++ b/Main.js @@ -117,7 +117,7 @@ client.on("guildUpdate", async (oldGuild, newGuild) => { }); client.on("channelUpdate", async (oldChannel, newChannel) => { - lgr.channelUpdate(oldChannel, newChannel); + lgr.channelUpdate.run(oldChannel, newChannel); }); client.on("messageDelete", async (msg) => { diff --git a/cmds/moderation/src/configureMuteRole.js b/cmds/moderation/src/configureMuteRole.js index d5a2a14..609c26a 100644 --- a/cmds/moderation/src/configureMuteRole.js +++ b/cmds/moderation/src/configureMuteRole.js @@ -1,6 +1,7 @@ 'use strict'; const { Message } = require("discord.js"); +const { blockChannelUpdateEvents, unblockChannelUpdateEvents } = require("../../../resources/eventsLogger/channelUpdate"); const { trySend, parseDash, defaultImageEmbed, defaultSplitMessage } = require("../../../resources/functions"); const getColor = require("../../../resources/getColor"); @@ -34,9 +35,11 @@ async function detonate(msg, data) { msg.guild.DB.settings.mute.role = ROLE.id; let cant = []; if (ROLE) { + blockChannelUpdateEvents(); for (const U of map) { await U.updateOverwrite(ROLE, { SEND_MESSAGES: false, CONNECT: false }, "Create Mute Role").catch(() => cant.push(U.id)); - } + }; + setTimeout(unblockChannelUpdateEvents, 5000); } else return pleaseWait.edit("Create Mute Role: Can't create role. Operation cancelled"); if (cant.length > 0) { const split = defaultSplitMessage, diff --git a/resources/eventsLogger/channelUpdate.js b/resources/eventsLogger/channelUpdate.js index 1bff680..45aa1fb 100644 --- a/resources/eventsLogger/channelUpdate.js +++ b/resources/eventsLogger/channelUpdate.js @@ -3,13 +3,14 @@ const { GuildChannel, Guild, GuildAuditLogsEntry } = require("discord.js"); const { defaultEventLogEmbed, changed, trySend, wait } = require("../functions"); const getColor = require("../getColor"); +let blockChannelUpdate = false; /** * @param {GuildChannel} oldChannel * @param {GuildChannel} newChannel */ -module.exports = async (oldChannel, newChannel) => { - await wait(2000); +async function run(oldChannel, newChannel) { + await wait(4000); const dateNow = new Date(); if (!newChannel.guild.DB) await newChannel.guild.dbLoad(); if (!newChannel.guild.DB.eventChannels?.guild) return; @@ -76,6 +77,7 @@ module.exports = async (oldChannel, newChannel) => { const added = newChannel.permissionOverwrites.get(key); if (!newChannel.guild.roles.cache.get((removed || added).id)) continue; if (removed) { + if (blockChannelUpdate && removed.id === newChannel.guild.DB.settings.mute.role) return; if (!fetchAR) fetchAR = "R"; const allow = removed.allow.serialize(), deny = removed.deny.serialize(); let all = [], den = []; @@ -93,6 +95,7 @@ module.exports = async (oldChannel, newChannel) => { "**Denied:**```js\n" + (den.join(", ") || "NONE") + "```"); console.log; // BREAKPOINT } else if (added) { + if (blockChannelUpdate && added.id === newChannel.guild.DB.settings.mute.role) return; if (!fetchAR) fetchAR = "A"; const allow = added.allow.serialize(), deny = added.deny.serialize(); let all = [], den = []; @@ -158,4 +161,16 @@ async function getAudit(guild, dateNow, id, option, filter = (value, key, collec const col = await guild.fetchAuditLogs(option); const fil = col.entries.filter(filter); return fil.first(); -}; \ No newline at end of file +}; + +function blockChannelUpdateEvents() { + blockChannelUpdate = true; + console.log("CHANNEL UPDATE EVENTS BLOCKED. STATE:", blockChannelUpdate); +}; + +function unblockChannelUpdateEvents() { + blockChannelUpdate = false; + console.log("CHANNEL UPDATE EVENTS UNBLOCKED. STATE:", blockChannelUpdate); +}; + +module.exports = { run, blockChannelUpdateEvents, unblockChannelUpdateEvents } \ No newline at end of file