From 50fab9718f86c26d67125135a648ab831f82a1cb Mon Sep 17 00:00:00 2001 From: metal Date: Wed, 1 Sep 2021 14:58:24 +0000 Subject: [PATCH] initial --- .../plugins/Automod/actions/setSlowmode.ts | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/backend/src/plugins/Automod/actions/setSlowmode.ts b/backend/src/plugins/Automod/actions/setSlowmode.ts index ad333e6d..de478a56 100644 --- a/backend/src/plugins/Automod/actions/setSlowmode.ts +++ b/backend/src/plugins/Automod/actions/setSlowmode.ts @@ -1,14 +1,13 @@ -import { Snowflake, TextChannel } from "discord.js"; +import { Snowflake, TextChannel, ThreadChannel } from "discord.js"; import * as t from "io-ts"; import { ChannelTypeStrings } from "src/types"; -import { LogType } from "../../../data/LogType"; import { convertDelayStringToMS, isDiscordAPIError, tDelayString, tNullable } from "../../../utils"; import { automodAction } from "../helpers"; import { LogsPlugin } from "../../Logs/LogsPlugin"; export const SetSlowmodeAction = automodAction({ configType: t.type({ - channels: t.array(t.string), + channels: tNullable(t.array(t.string)), duration: tNullable(tDelayString), }), @@ -16,18 +15,30 @@ 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 - if (!channel || !(channel.type === ChannelTypeStrings.TEXT || ChannelTypeStrings.CATEGORY)) { + if ( + !channel || + !( + channel.type === ChannelTypeStrings.TEXT || + ChannelTypeStrings.CATEGORY || + ChannelTypeStrings.PUBLIC_THREAD || + ChannelTypeStrings.NEWS_THREAD || + ChannelTypeStrings.PRIVATE_THREAD + ) + ) { continue; } - const channelsToSlowmode: TextChannel[] = []; + const channelsToSlowmode: Array = []; if (channel.type === ChannelTypeStrings.CATEGORY) { // Find all text channels within the category for (const ch of pluginData.guild.channels.cache.values()) {