From d8c1a5791b649584ccbfe138e2c6f96a3414fd2a Mon Sep 17 00:00:00 2001 From: Tiago R Date: Thu, 28 Dec 2023 20:14:26 +0000 Subject: [PATCH] Reworked automod "set_slowmode" action (#441) * initial * fixes Signed-off-by: GitHub --------- Signed-off-by: GitHub Co-authored-by: Almeida --- .../src/plugins/Automod/actions/setSlowmode.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/src/plugins/Automod/actions/setSlowmode.ts b/backend/src/plugins/Automod/actions/setSlowmode.ts index 7b527f10..abd27f8a 100644 --- a/backend/src/plugins/Automod/actions/setSlowmode.ts +++ b/backend/src/plugins/Automod/actions/setSlowmode.ts @@ -6,7 +6,7 @@ import { automodAction } from "../helpers"; export const SetSlowmodeAction = automodAction({ configType: t.type({ - channels: t.array(t.string), + channels: tNullable(t.array(t.string)), duration: tNullable(tDelayString), }), @@ -14,14 +14,17 @@ export const SetSlowmodeAction = automodAction({ duration: "10s", }, - async apply({ pluginData, actionConfig }) { + async apply({ pluginData, actionConfig, contexts }) { const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0); - - for (const channelId of actionConfig.channels) { + const channels: Snowflake[] = actionConfig.channels ?? []; + if (channels.length === 0) { + channels.push(...contexts.filter((c) => c.message?.channel_id).map((c) => c.message!.channel_id)); + } + for (const channelId of channels) { const channel = pluginData.guild.channels.cache.get(channelId as Snowflake); - // Only text channels and text channels within categories support slowmodes - if (!channel || (!channel.isTextBased() && channel.type !== ChannelType.GuildCategory)) { + + if (!channel?.isTextBased() && channel?.type !== ChannelType.GuildCategory) { continue; }