3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

debug: add debug logging to automod clean action

This commit is contained in:
Dragory 2022-01-17 21:28:00 +02:00
parent 264cf93fe2
commit feeb048855
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1

View file

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