From 497d334b15534e3ef623052eebf0d69e20bf4de2 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 5 Sep 2021 20:58:50 +0300 Subject: [PATCH] Fix channel/category/thread matching for threads in Automod overrides --- backend/src/plugins/Automod/functions/runAutomod.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/src/plugins/Automod/functions/runAutomod.ts b/backend/src/plugins/Automod/functions/runAutomod.ts index cba8f029..edc75c13 100644 --- a/backend/src/plugins/Automod/functions/runAutomod.ts +++ b/backend/src/plugins/Automod/functions/runAutomod.ts @@ -1,4 +1,4 @@ -import { Snowflake, TextChannel } from "discord.js"; +import { Snowflake, TextChannel, ThreadChannel } from "discord.js"; import { GuildPluginData } from "knub"; import { availableActions } from "../actions/availableActions"; import { CleanAction } from "../actions/clean"; @@ -11,8 +11,14 @@ export async function runAutomod(pluginData: GuildPluginData, const userId = context.user?.id || context.member?.id || context.message?.user_id; const user = context.user || (userId && pluginData.client.users!.cache.get(userId as Snowflake)); const member = context.member || (userId && pluginData.guild.members.cache.get(userId as Snowflake)) || null; - const channelId = context.message?.channel_id; - const channel = channelId ? (pluginData.guild.channels.cache.get(channelId as Snowflake) as TextChannel) : null; + + const channelIdOrThreadId = context.message?.channel_id; + const channelOrThread = channelIdOrThreadId + ? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as TextChannel | ThreadChannel) + : null; + const channelId = channelOrThread?.isThread() ? channelOrThread.parent?.id : channelIdOrThreadId; + const threadId = channelOrThread?.isThread() ? channelOrThread.id : null; + const channel = channelOrThread?.isThread() ? channelOrThread.parent : channelOrThread; const categoryId = channel?.parentId; // Don't apply Automod on Zeppelin itself @@ -23,6 +29,7 @@ export async function runAutomod(pluginData: GuildPluginData, const config = await pluginData.config.getMatchingConfig({ channelId, categoryId, + threadId, userId, member, });