From 2907f5c079688bad75966ad5f513c66ca8e76328 Mon Sep 17 00:00:00 2001 From: Tiago R Date: Wed, 1 Sep 2021 14:58:24 +0000 Subject: [PATCH 1/2] initial --- backend/src/plugins/Automod/actions/setSlowmode.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/src/plugins/Automod/actions/setSlowmode.ts b/backend/src/plugins/Automod/actions/setSlowmode.ts index 7b527f10d..7bbd583f8 100644 --- a/backend/src/plugins/Automod/actions/setSlowmode.ts +++ b/backend/src/plugins/Automod/actions/setSlowmode.ts @@ -1,4 +1,4 @@ -import { ChannelType, GuildTextBasedChannel, Snowflake } from "discord.js"; +import { ChannelType, GuildTextBasedChannel, Snowflake, TextChannel, ThreadChannel } from "discord.js"; import * as t from "io-ts"; import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils"; import { LogsPlugin } from "../../Logs/LogsPlugin"; @@ -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,10 +14,13 @@ 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 = actionConfig.channels ?? new Array(); + 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 From d278663af6e36feb19a46dedae827d89442c4d35 Mon Sep 17 00:00:00 2001 From: Tiago R Date: Thu, 28 Dec 2023 13:22:03 +0000 Subject: [PATCH 2/2] fixes Signed-off-by: GitHub --- backend/src/plugins/Automod/actions/setSlowmode.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/plugins/Automod/actions/setSlowmode.ts b/backend/src/plugins/Automod/actions/setSlowmode.ts index 7bbd583f8..abd27f8ac 100644 --- a/backend/src/plugins/Automod/actions/setSlowmode.ts +++ b/backend/src/plugins/Automod/actions/setSlowmode.ts @@ -1,4 +1,4 @@ -import { ChannelType, GuildTextBasedChannel, Snowflake, TextChannel, ThreadChannel } from "discord.js"; +import { ChannelType, GuildTextBasedChannel, Snowflake } from "discord.js"; import * as t from "io-ts"; import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils"; import { LogsPlugin } from "../../Logs/LogsPlugin"; @@ -16,15 +16,15 @@ export const SetSlowmodeAction = automodAction({ async apply({ pluginData, actionConfig, contexts }) { const slowmodeMs = Math.max(actionConfig.duration ? convertDelayStringToMS(actionConfig.duration)! : 0, 0); - const channels = actionConfig.channels ?? new Array(); + const channels: Snowflake[] = actionConfig.channels ?? []; if (channels.length === 0) { - channels.push(...contexts.filter(c => c.message?.channel_id).map(c => c.message!.channel_id)); + 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; }