From feeb0488556f10f6b02311476b32797dba314fa5 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Mon, 17 Jan 2022 21:28:00 +0200 Subject: [PATCH] debug: add debug logging to automod clean action --- backend/src/plugins/Automod/actions/clean.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/backend/src/plugins/Automod/actions/clean.ts b/backend/src/plugins/Automod/actions/clean.ts index 27ee1cb63..56452d79c 100644 --- a/backend/src/plugins/Automod/actions/clean.ts +++ b/backend/src/plugins/Automod/actions/clean.ts @@ -4,6 +4,8 @@ import { LogType } from "../../../data/LogType"; import { noop } from "../../../utils"; import { automodAction } from "../helpers"; +const cleanDebugServer = process.env.TEMP_CLEAN_DEBUG_SERVER; + export const CleanAction = automodAction({ configType: t.boolean, defaultConfig: false, @@ -27,13 +29,26 @@ export const CleanAction = automodAction({ } } + if (pluginData.guild.id === cleanDebugServer) { + const toDeleteFormatted = Array.from(messageIdsToDeleteByChannelId.entries()) + .map(([channelId, messageIds]) => `- ${channelId}: ${messageIds.join(", ")}`) + .join("\n"); + // tslint:disable-next-line:no-console + console.log(`[DEBUG] Cleaning messages (${ruleName}):\n${toDeleteFormatted}`); + } + for (const [channelId, messageIds] of messageIdsToDeleteByChannelId.entries()) { for (const id of messageIds) { pluginData.state.logs.ignoreLog(LogType.MESSAGE_DELETE, id); } const channel = pluginData.guild.channels.cache.get(channelId as Snowflake) as TextChannel; - await channel.bulkDelete(messageIds as Snowflake[]).catch(noop); + await channel.bulkDelete(messageIds as Snowflake[]).catch((err) => { + if (pluginData.guild.id === cleanDebugServer) { + // tslint:disable-next-line:no-console + console.error(`[DEBUG] Failed to bulk delete messages (${ruleName}): ${err}`); + } + }); } }, });