From 05df81ddca807fa3fdc5d372cc8407377509a462 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sat, 21 Aug 2021 00:59:51 +0300 Subject: [PATCH] Fix being unable to !post to announcement channels or threads --- .../plugins/Logs/logFunctions/logRepeatedMessage.ts | 4 ++-- .../plugins/Logs/logFunctions/logScheduledMessage.ts | 4 ++-- .../Logs/logFunctions/logScheduledRepeatedMessage.ts | 4 ++-- backend/src/plugins/Post/util/actualPostCmd.ts | 10 +++++++--- backend/src/plugins/Post/util/postMessage.ts | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/backend/src/plugins/Logs/logFunctions/logRepeatedMessage.ts b/backend/src/plugins/Logs/logFunctions/logRepeatedMessage.ts index 70fdaf00..d17b5a55 100644 --- a/backend/src/plugins/Logs/logFunctions/logRepeatedMessage.ts +++ b/backend/src/plugins/Logs/logFunctions/logRepeatedMessage.ts @@ -3,12 +3,12 @@ import { LogsPluginType } from "../types"; import { LogType } from "../../../data/LogType"; import { log } from "../util/log"; import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter"; -import { BaseGuildTextChannel, User } from "discord.js"; +import { BaseGuildTextChannel, ThreadChannel, User } from "discord.js"; import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; interface LogRepeatedMessageData { author: User; - channel: BaseGuildTextChannel; + channel: BaseGuildTextChannel | ThreadChannel; datetime: string; date: string; time: string; diff --git a/backend/src/plugins/Logs/logFunctions/logScheduledMessage.ts b/backend/src/plugins/Logs/logFunctions/logScheduledMessage.ts index 64cce036..27408798 100644 --- a/backend/src/plugins/Logs/logFunctions/logScheduledMessage.ts +++ b/backend/src/plugins/Logs/logFunctions/logScheduledMessage.ts @@ -3,12 +3,12 @@ import { LogsPluginType } from "../types"; import { LogType } from "../../../data/LogType"; import { log } from "../util/log"; import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter"; -import { BaseGuildTextChannel, User } from "discord.js"; +import { BaseGuildTextChannel, ThreadChannel, User } from "discord.js"; import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; interface LogScheduledMessageData { author: User; - channel: BaseGuildTextChannel; + channel: BaseGuildTextChannel | ThreadChannel; datetime: string; date: string; time: string; diff --git a/backend/src/plugins/Logs/logFunctions/logScheduledRepeatedMessage.ts b/backend/src/plugins/Logs/logFunctions/logScheduledRepeatedMessage.ts index d020188f..55d24df3 100644 --- a/backend/src/plugins/Logs/logFunctions/logScheduledRepeatedMessage.ts +++ b/backend/src/plugins/Logs/logFunctions/logScheduledRepeatedMessage.ts @@ -3,12 +3,12 @@ import { LogsPluginType } from "../types"; import { LogType } from "../../../data/LogType"; import { log } from "../util/log"; import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter"; -import { BaseGuildTextChannel, User } from "discord.js"; +import { BaseGuildTextChannel, ThreadChannel, User } from "discord.js"; import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; interface LogScheduledRepeatedMessageData { author: User; - channel: BaseGuildTextChannel; + channel: BaseGuildTextChannel | ThreadChannel; datetime: string; date: string; time: string; diff --git a/backend/src/plugins/Post/util/actualPostCmd.ts b/backend/src/plugins/Post/util/actualPostCmd.ts index e5e25d70..dc1d662e 100644 --- a/backend/src/plugins/Post/util/actualPostCmd.ts +++ b/backend/src/plugins/Post/util/actualPostCmd.ts @@ -1,4 +1,4 @@ -import { Channel, Message, TextChannel } from "discord.js"; +import { Channel, Message, NewsChannel, TextChannel, ThreadChannel } from "discord.js"; import humanizeDuration from "humanize-duration"; import { GuildPluginData } from "knub"; import moment from "moment-timezone"; @@ -29,8 +29,12 @@ export async function actualPostCmd( "repeat-times"?: number; } = {}, ) { - if (!(targetChannel instanceof TextChannel)) { - msg.channel.send(errorMessage("Channel is not a text channel")); + if ( + !(targetChannel instanceof TextChannel) && + !(targetChannel instanceof NewsChannel) && + !(targetChannel instanceof ThreadChannel) + ) { + msg.channel.send(errorMessage("Specified channel is not a text channel, announcement channel, or thread")); return; } diff --git a/backend/src/plugins/Post/util/postMessage.ts b/backend/src/plugins/Post/util/postMessage.ts index 5bb13095..0395867c 100644 --- a/backend/src/plugins/Post/util/postMessage.ts +++ b/backend/src/plugins/Post/util/postMessage.ts @@ -1,4 +1,4 @@ -import { Message, MessageAttachment, MessageOptions, TextChannel } from "discord.js"; +import { Message, MessageAttachment, MessageOptions, NewsChannel, TextChannel, ThreadChannel } from "discord.js"; import fs from "fs"; import { GuildPluginData } from "knub"; import { downloadFile } from "../../../utils"; @@ -9,7 +9,7 @@ const fsp = fs.promises; export async function postMessage( pluginData: GuildPluginData, - channel: TextChannel, + channel: TextChannel | NewsChannel | ThreadChannel, content: MessageOptions, attachments: MessageAttachment[] = [], enableMentions: boolean = false,