diff --git a/backend/src/index.ts b/backend/src/index.ts index 33043b24..f5a89f0a 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,4 +1,4 @@ -import { Client, Intents, TextChannel } from "discord.js"; +import { Client, Intents, TextChannel, ThreadChannel } from "discord.js"; import yaml from "js-yaml"; import { Knub, PluginError } from "knub"; import { PluginLoadError } from "knub/dist/plugins/PluginLoadError"; @@ -239,13 +239,15 @@ connect().then(async () => { }, sendSuccessMessageFn(channel, body) { - const guildId = channel instanceof TextChannel ? channel.guild.id : undefined; + const guildId = + channel instanceof TextChannel || channel instanceof ThreadChannel ? channel.guild.id : undefined; const emoji = guildId ? bot.getLoadedGuild(guildId)!.config.success_emoji : undefined; channel.send(successMessage(body, emoji)); }, sendErrorMessageFn(channel, body) { - const guildId = channel instanceof TextChannel ? channel.guild.id : undefined; + const guildId = + channel instanceof TextChannel || channel instanceof ThreadChannel ? channel.guild.id : undefined; const emoji = guildId ? bot.getLoadedGuild(guildId)!.config.error_emoji : undefined; channel.send(errorMessage(body, emoji)); }, diff --git a/backend/src/plugins/Automod/actions/alert.ts b/backend/src/plugins/Automod/actions/alert.ts index d26a9777..6c63e5ce 100644 --- a/backend/src/plugins/Automod/actions/alert.ts +++ b/backend/src/plugins/Automod/actions/alert.ts @@ -1,4 +1,4 @@ -import { Snowflake, TextChannel } from "discord.js"; +import { Snowflake, TextChannel, ThreadChannel } from "discord.js"; import * as t from "io-ts"; import { erisAllowedMentionsToDjsMentionOptions } from "src/utils/erisAllowedMentionsToDjsMentionOptions"; import { LogType } from "../../../data/LogType"; @@ -34,7 +34,7 @@ export const AlertAction = automodAction({ const channel = pluginData.guild.channels.cache.get(actionConfig.channel as Snowflake); const logs = pluginData.getPlugin(LogsPlugin); - if (channel && channel instanceof TextChannel) { + if (channel && (channel instanceof TextChannel || channel instanceof ThreadChannel)) { const text = actionConfig.text; const theMessageLink = contexts[0].message && messageLink(pluginData.guild.id, contexts[0].message.channel_id, contexts[0].message.id); diff --git a/backend/src/plugins/Automod/actions/reply.ts b/backend/src/plugins/Automod/actions/reply.ts index c3dcded6..9c811b1d 100644 --- a/backend/src/plugins/Automod/actions/reply.ts +++ b/backend/src/plugins/Automod/actions/reply.ts @@ -1,4 +1,4 @@ -import { MessageOptions, Permissions, Snowflake, TextChannel, User } from "discord.js"; +import { MessageOptions, Permissions, Snowflake, TextChannel, ThreadChannel, User } from "discord.js"; import * as t from "io-ts"; import { userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { LogType } from "../../../data/LogType"; @@ -32,7 +32,10 @@ export const ReplyAction = automodAction({ async apply({ pluginData, contexts, actionConfig, ruleName }) { const contextsWithTextChannels = contexts .filter(c => c.message?.channel_id) - .filter(c => pluginData.guild.channels.cache.get(c.message!.channel_id as Snowflake) instanceof TextChannel); + .filter(c => { + const channel = pluginData.guild.channels.cache.get(c.message!.channel_id as Snowflake); + return channel instanceof TextChannel || channel instanceof ThreadChannel; + }); const contextsByChannelId = contextsWithTextChannels.reduce((map: Map, context) => { if (!map.has(context.message!.channel_id)) { @@ -59,6 +62,7 @@ export const ReplyAction = automodAction({ ? await renderReplyText(actionConfig) : ((await renderRecursively(actionConfig.text, renderReplyText)) as MessageOptions); + console.log("formatted:", formatted); if (formatted) { const channel = pluginData.guild.channels.cache.get(channelId as Snowflake) as TextChannel; @@ -89,6 +93,7 @@ export const ReplyAction = automodAction({ } const messageContent: MessageOptions = typeof formatted === "string" ? { content: formatted } : formatted; + console.log(`sending reply message to ${channel.id}`); const replyMsg = await channel.send({ ...messageContent, allowedMentions: { diff --git a/backend/src/plugins/Automod/functions/resolveActionContactMethods.ts b/backend/src/plugins/Automod/functions/resolveActionContactMethods.ts index 8dca9ee4..5ac49703 100644 --- a/backend/src/plugins/Automod/functions/resolveActionContactMethods.ts +++ b/backend/src/plugins/Automod/functions/resolveActionContactMethods.ts @@ -1,4 +1,4 @@ -import { Snowflake, TextChannel } from "discord.js"; +import { Snowflake, TextChannel, ThreadChannel } from "discord.js"; import { GuildPluginData } from "knub"; import { ERRORS, RecoverablePluginError } from "../../../RecoverablePluginError"; import { disableUserNotificationStrings, UserNotificationMethod } from "../../../utils"; @@ -19,7 +19,7 @@ export function resolveActionContactMethods( } const channel = pluginData.guild.channels.cache.get(actionConfig.notifyChannel as Snowflake); - if (!(channel instanceof TextChannel)) { + if (!(channel instanceof TextChannel || channel instanceof ThreadChannel)) { throw new RecoverablePluginError(ERRORS.INVALID_USER_NOTIFICATION_CHANNEL); } diff --git a/backend/src/utils.ts b/backend/src/utils.ts index 54f16c46..19fc690c 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -871,7 +871,7 @@ export function chunkMessageLines(str: string, maxChunkLength = 1990): string[] } export async function createChunkedMessage( - channel: TextChannel | User, + channel: TextChannel | ThreadChannel | User, messageText: string, allowedMentions?: MessageMentionOptions, ) { @@ -1329,7 +1329,7 @@ export function messageSummary(msg: SavedMessage) { if (richEmbed) result += "Embed:```" + Util.escapeCodeBlock(JSON.stringify(richEmbed)) + "```"; // Attachments - if (msg.data.attachments) { + if (msg.data.attachments && msg.data.attachments.length) { result += "Attachments:\n" + msg.data.attachments.map((a: ISavedMessageAttachmentData) => disableLinkPreviews(a.url)).join("\n") +