avoid create mute role log spam

This commit is contained in:
Neko-Life 2021-08-09 18:58:54 +07:00
parent e4d9810899
commit a601eaa344
3 changed files with 23 additions and 5 deletions

View file

@ -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) => {

View file

@ -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,

View file

@ -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();
};
};
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 }