From ed4ba06f82a21707d4859cc55cfe288ae5363449 Mon Sep 17 00:00:00 2001 From: almeidx Date: Mon, 13 Jun 2022 14:24:50 +0100 Subject: [PATCH] update discord.js --- backend/package-lock.json | 113 ++++++++---------- backend/package.json | 4 +- backend/src/pluginUtils.ts | 11 +- backend/src/plugins/Automod/actions/alert.ts | 2 +- backend/src/plugins/Automod/actions/reply.ts | 2 +- .../plugins/BotControl/BotControlPlugin.ts | 4 +- .../Cases/functions/postToCaseLogChannel.ts | 3 +- .../InternalPoster/functions/editMessage.ts | 13 +- .../getOrCreateWebhookClientForChannel.ts | 4 +- .../functions/getOrCreateWebhookForChannel.ts | 4 +- .../InternalPoster/functions/sendMessage.ts | 10 +- .../logFunctions/logPostedScheduledMessage.ts | 4 +- backend/src/plugins/Post/util/postMessage.ts | 4 +- backend/src/utils/resolveMessageTarget.ts | 7 +- 14 files changed, 81 insertions(+), 104 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index bae5e80a..25139c89 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -13,8 +13,8 @@ "cors": "^2.8.5", "cross-env": "^5.2.0", "deep-diff": "^1.0.2", - "discord-api-types": "^0.33.1", - "discord.js": "^13.7.0", + "discord-api-types": "^0.33.5", + "discord.js": "^13.8.0", "dotenv": "^4.0.0", "emoji-regex": "^8.0.0", "erlpack": "github:discord/erlpack", @@ -124,16 +124,16 @@ } }, "node_modules/@discordjs/builders": { - "version": "0.13.0", - "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.13.0.tgz", - "integrity": "sha512-4L9y26KRNNU8Y7J78SRUN1Uhava9D8jfit/YqEaKi8gQRc7PdqKqk2poybo6RXaiyt/BgKYPfcjxT7WvzGfYCA==", + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.14.0.tgz", + "integrity": "sha512-+fqLIqa9wN3R+kvlld8sgG0nt04BAZxdCDP4t2qZ9TJsquLWA+xMtT8Waibb3d4li4AQS+IOfjiHAznv/dhHgQ==", "dependencies": { - "@sapphire/shapeshift": "^2.0.0", + "@sapphire/shapeshift": "^3.1.0", "@sindresorhus/is": "^4.6.0", - "discord-api-types": "^0.31.1", + "discord-api-types": "^0.33.3", "fast-deep-equal": "^3.1.3", "ts-mixer": "^6.0.1", - "tslib": "^2.3.1" + "tslib": "^2.4.0" }, "engines": { "node": ">=16.9.0" @@ -150,20 +150,15 @@ "url": "https://github.com/sindresorhus/is?sponsor=1" } }, - "node_modules/@discordjs/builders/node_modules/discord-api-types": { - "version": "0.31.2", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.31.2.tgz", - "integrity": "sha512-gpzXTvFVg7AjKVVJFH0oJGC0q0tO34iJGSHZNz9u3aqLxlD6LfxEs9wWVVikJqn9gra940oUTaPFizCkRDcEiA==" - }, "node_modules/@discordjs/builders/node_modules/tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", "integrity": "sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==" }, "node_modules/@discordjs/collection": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.6.0.tgz", - "integrity": "sha512-Ieaetb36l0nmAS5X9Upqk4W7euAO6FdXPxn3I8vBAKEcoIzEZI1mcVcPfCfagGJZSgBKpENnAnKkP4GAn+MV8w==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0.tgz", + "integrity": "sha512-R5i8Wb8kIcBAFEPLLf7LVBQKBDYUL+ekb23sOgpkpyGT+V4P7V83wTxcsqmX+PbqHt4cEHn053uMWfRqh/Z/nA==", "engines": { "node": ">=16.9.0" } @@ -209,9 +204,9 @@ } }, "node_modules/@sapphire/shapeshift": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-2.2.0.tgz", - "integrity": "sha512-UEnKgMlQyI0yY/q+lCMX0VJft9y86IsesgbIQj6e62FBYSaMVr+IaMNpi4z45Q14VnuMACbK0yrbHISNqgUYcQ==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.2.0.tgz", + "integrity": "sha512-asNgE5Ooil2/oGIAj6vZMoUc2ZFED0TGYD7jwvZsjHPQZBEh9ITj94ca4bCgiCR1s2ER/UjzykH+5wE3ebVZnQ==", "engines": { "node": ">=v15.0.0", "npm": ">=7.0.0" @@ -1704,35 +1699,30 @@ } }, "node_modules/discord-api-types": { - "version": "0.33.1", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.1.tgz", - "integrity": "sha512-dc7Xzm3isROh77jdxikQnLzKDslOPORm2Q8odXrKgEy8Aqfd1r9ISVTU/xsHkH6bFo+Hjf1A1C5OnBtu8ghy4w==" + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.5.tgz", + "integrity": "sha512-dvO5M52v7m7Dy96+XUnzXNsQ/0npsYpU6dL205kAtEDueswoz3aU3bh1UMoK4cQmcGtB1YRyLKqp+DXi05lzFg==" }, "node_modules/discord.js": { - "version": "13.7.0", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.7.0.tgz", - "integrity": "sha512-iV/An3FEB/CiBGdjWHRtgskM4UuWPq5vjhjKsrQhdVU16dbKrBxA+eIV2HWA07B3tXUGM6eco1wkr42gxxV1BA==", + "version": "13.8.0", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.8.0.tgz", + "integrity": "sha512-EPAA/2VLycYN5wSzavqa4iJ6qj3UtQFtHw5TH/60Fj29ymfEsCQVn//o1mTpwDxzwb+rPIrWhkxKIGGnjfv0Iw==", "dependencies": { - "@discordjs/builders": "^0.13.0", - "@discordjs/collection": "^0.6.0", + "@discordjs/builders": "^0.14.0", + "@discordjs/collection": "^0.7.0", "@sapphire/async-queue": "^1.3.1", "@types/node-fetch": "^2.6.1", "@types/ws": "^8.5.3", - "discord-api-types": "^0.30.0", + "discord-api-types": "^0.33.3", "form-data": "^4.0.0", "node-fetch": "^2.6.1", - "ws": "^8.6.0" + "ws": "^8.7.0" }, "engines": { "node": ">=16.6.0", "npm": ">=7.0.0" } }, - "node_modules/discord.js/node_modules/discord-api-types": { - "version": "0.30.0", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.30.0.tgz", - "integrity": "sha512-wYst0jrT8EJs2tVlwUTQ2xT0oWMjUrRMpFTkNY3NMleWyQNHgWaKhqFfxdLPdC2im9IuR5EsxcEgjhf/npeftw==" - }, "node_modules/discord.js/node_modules/form-data": { "version": "4.0.0", "license": "MIT", @@ -5275,6 +5265,7 @@ }, "node_modules/zlib-sync": { "version": "0.1.7", + "hasInstallScript": true, "license": "MIT", "dependencies": { "nan": "^2.14.0" @@ -5323,16 +5314,16 @@ } }, "@discordjs/builders": { - "version": "0.13.0", - "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.13.0.tgz", - "integrity": "sha512-4L9y26KRNNU8Y7J78SRUN1Uhava9D8jfit/YqEaKi8gQRc7PdqKqk2poybo6RXaiyt/BgKYPfcjxT7WvzGfYCA==", + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/@discordjs/builders/-/builders-0.14.0.tgz", + "integrity": "sha512-+fqLIqa9wN3R+kvlld8sgG0nt04BAZxdCDP4t2qZ9TJsquLWA+xMtT8Waibb3d4li4AQS+IOfjiHAznv/dhHgQ==", "requires": { - "@sapphire/shapeshift": "^2.0.0", + "@sapphire/shapeshift": "^3.1.0", "@sindresorhus/is": "^4.6.0", - "discord-api-types": "^0.31.1", + "discord-api-types": "^0.33.3", "fast-deep-equal": "^3.1.3", "ts-mixer": "^6.0.1", - "tslib": "^2.3.1" + "tslib": "^2.4.0" }, "dependencies": { "@sindresorhus/is": { @@ -5340,11 +5331,6 @@ "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==" }, - "discord-api-types": { - "version": "0.31.2", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.31.2.tgz", - "integrity": "sha512-gpzXTvFVg7AjKVVJFH0oJGC0q0tO34iJGSHZNz9u3aqLxlD6LfxEs9wWVVikJqn9gra940oUTaPFizCkRDcEiA==" - }, "tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", @@ -5353,9 +5339,9 @@ } }, "@discordjs/collection": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.6.0.tgz", - "integrity": "sha512-Ieaetb36l0nmAS5X9Upqk4W7euAO6FdXPxn3I8vBAKEcoIzEZI1mcVcPfCfagGJZSgBKpENnAnKkP4GAn+MV8w==" + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.7.0.tgz", + "integrity": "sha512-R5i8Wb8kIcBAFEPLLf7LVBQKBDYUL+ekb23sOgpkpyGT+V4P7V83wTxcsqmX+PbqHt4cEHn053uMWfRqh/Z/nA==" }, "@nodelib/fs.scandir": { "version": "2.1.3", @@ -5381,9 +5367,9 @@ "version": "1.3.1" }, "@sapphire/shapeshift": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-2.2.0.tgz", - "integrity": "sha512-UEnKgMlQyI0yY/q+lCMX0VJft9y86IsesgbIQj6e62FBYSaMVr+IaMNpi4z45Q14VnuMACbK0yrbHISNqgUYcQ==" + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/@sapphire/shapeshift/-/shapeshift-3.2.0.tgz", + "integrity": "sha512-asNgE5Ooil2/oGIAj6vZMoUc2ZFED0TGYD7jwvZsjHPQZBEh9ITj94ca4bCgiCR1s2ER/UjzykH+5wE3ebVZnQ==" }, "@silvia-odwyer/photon-node": { "version": "0.3.1" @@ -6382,31 +6368,26 @@ } }, "discord-api-types": { - "version": "0.33.1", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.1.tgz", - "integrity": "sha512-dc7Xzm3isROh77jdxikQnLzKDslOPORm2Q8odXrKgEy8Aqfd1r9ISVTU/xsHkH6bFo+Hjf1A1C5OnBtu8ghy4w==" + "version": "0.33.5", + "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.33.5.tgz", + "integrity": "sha512-dvO5M52v7m7Dy96+XUnzXNsQ/0npsYpU6dL205kAtEDueswoz3aU3bh1UMoK4cQmcGtB1YRyLKqp+DXi05lzFg==" }, "discord.js": { - "version": "13.7.0", - "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.7.0.tgz", - "integrity": "sha512-iV/An3FEB/CiBGdjWHRtgskM4UuWPq5vjhjKsrQhdVU16dbKrBxA+eIV2HWA07B3tXUGM6eco1wkr42gxxV1BA==", + "version": "13.8.0", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-13.8.0.tgz", + "integrity": "sha512-EPAA/2VLycYN5wSzavqa4iJ6qj3UtQFtHw5TH/60Fj29ymfEsCQVn//o1mTpwDxzwb+rPIrWhkxKIGGnjfv0Iw==", "requires": { - "@discordjs/builders": "^0.13.0", - "@discordjs/collection": "^0.6.0", + "@discordjs/builders": "^0.14.0", + "@discordjs/collection": "^0.7.0", "@sapphire/async-queue": "^1.3.1", "@types/node-fetch": "^2.6.1", "@types/ws": "^8.5.3", - "discord-api-types": "^0.30.0", + "discord-api-types": "^0.33.3", "form-data": "^4.0.0", "node-fetch": "^2.6.1", - "ws": "^8.6.0" + "ws": "^8.7.0" }, "dependencies": { - "discord-api-types": { - "version": "0.30.0", - "resolved": "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.30.0.tgz", - "integrity": "sha512-wYst0jrT8EJs2tVlwUTQ2xT0oWMjUrRMpFTkNY3NMleWyQNHgWaKhqFfxdLPdC2im9IuR5EsxcEgjhf/npeftw==" - }, "form-data": { "version": "4.0.0", "requires": { diff --git a/backend/package.json b/backend/package.json index 348492c9..4043a85d 100644 --- a/backend/package.json +++ b/backend/package.json @@ -28,8 +28,8 @@ "cors": "^2.8.5", "cross-env": "^5.2.0", "deep-diff": "^1.0.2", - "discord-api-types": "^0.33.1", - "discord.js": "^13.7.0", + "discord-api-types": "^0.33.5", + "discord.js": "^13.8.0", "dotenv": "^4.0.0", "emoji-regex": "^8.0.0", "erlpack": "github:discord/erlpack", diff --git a/backend/src/pluginUtils.ts b/backend/src/pluginUtils.ts index 031d1fa7..fae36b0d 100644 --- a/backend/src/pluginUtils.ts +++ b/backend/src/pluginUtils.ts @@ -2,7 +2,14 @@ * @file Utility functions that are plugin-instance-specific (i.e. use PluginData) */ -import { GuildMember, Message, MessageMentionOptions, MessageOptions, TextChannel } from "discord.js"; +import { + GuildMember, + GuildTextBasedChannel, + Message, + MessageMentionOptions, + MessageOptions, + TextChannel, +} from "discord.js"; import * as t from "io-ts"; import { CommandContext, configUtils, ConfigValidationError, GuildPluginData, helpers, PluginOptions } from "knub"; import { PluginOverrideCriteria } from "knub/dist/config/configTypes"; @@ -187,7 +194,7 @@ export function getPluginConfigPreprocessor( export async function sendSuccessMessage( pluginData: AnyPluginData, - channel: TextChannel, + channel: GuildTextBasedChannel, body: string, allowedMentions?: MessageMentionOptions, ): Promise { diff --git a/backend/src/plugins/Automod/actions/alert.ts b/backend/src/plugins/Automod/actions/alert.ts index 7c96dea5..8bfce04d 100644 --- a/backend/src/plugins/Automod/actions/alert.ts +++ b/backend/src/plugins/Automod/actions/alert.ts @@ -38,7 +38,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?.isText()) { 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 52aa491d..865ef127 100644 --- a/backend/src/plugins/Automod/actions/reply.ts +++ b/backend/src/plugins/Automod/actions/reply.ts @@ -36,7 +36,7 @@ export const ReplyAction = automodAction({ .filter((c) => c.message?.channel_id) .filter((c) => { const channel = pluginData.guild.channels.cache.get(c.message!.channel_id as Snowflake); - return channel instanceof TextChannel || channel instanceof ThreadChannel; + return channel?.isText(); }); const contextsByChannelId = contextsWithTextChannels.reduce((map: Map, context) => { diff --git a/backend/src/plugins/BotControl/BotControlPlugin.ts b/backend/src/plugins/BotControl/BotControlPlugin.ts index 7897d837..823d6250 100644 --- a/backend/src/plugins/BotControl/BotControlPlugin.ts +++ b/backend/src/plugins/BotControl/BotControlPlugin.ts @@ -1,4 +1,4 @@ -import { Snowflake, TextChannel } from "discord.js"; +import { Snowflake } from "discord.js"; import { AllowedGuilds } from "../../data/AllowedGuilds"; import { ApiPermissionAssignments } from "../../data/ApiPermissionAssignments"; import { Configs } from "../../data/Configs"; @@ -74,7 +74,7 @@ export const BotControlPlugin = zeppelinGlobalPlugin()({ const guild = await pluginData.client.guilds.fetch(guildId as Snowflake); if (guild) { const channel = guild.channels.cache.get(channelId as Snowflake); - if (channel instanceof TextChannel) { + if (channel?.isText()) { sendSuccessMessage(pluginData, channel, "Global plugins reloaded!"); } } diff --git a/backend/src/plugins/Cases/functions/postToCaseLogChannel.ts b/backend/src/plugins/Cases/functions/postToCaseLogChannel.ts index 1d363d60..550cc1b3 100644 --- a/backend/src/plugins/Cases/functions/postToCaseLogChannel.ts +++ b/backend/src/plugins/Cases/functions/postToCaseLogChannel.ts @@ -18,8 +18,7 @@ export async function postToCaseLogChannel( if (!caseLogChannelId) return null; const caseLogChannel = pluginData.guild.channels.cache.get(caseLogChannelId as Snowflake); - // This doesn't use `!isText() || isThread()` because TypeScript had some issues inferring types from it - if (!caseLogChannel || !(caseLogChannel instanceof TextChannel || caseLogChannel instanceof NewsChannel)) return null; + if (!caseLogChannel?.isText() || caseLogChannel.isThread()) return null; let result: InternalPosterMessageResult | null = null; try { diff --git a/backend/src/plugins/InternalPoster/functions/editMessage.ts b/backend/src/plugins/InternalPoster/functions/editMessage.ts index a0fc7169..1309f598 100644 --- a/backend/src/plugins/InternalPoster/functions/editMessage.ts +++ b/backend/src/plugins/InternalPoster/functions/editMessage.ts @@ -1,11 +1,4 @@ -import { - Message, - MessageEditOptions, - NewsChannel, - TextChannel, - WebhookClient, - WebhookEditMessageOptions, -} from "discord.js"; +import { Message, MessageEditOptions, WebhookClient, WebhookEditMessageOptions } from "discord.js"; import { GuildPluginData } from "knub"; import { InternalPosterPluginType } from "../types"; import { isDiscordAPIError, noop } from "../../../utils"; @@ -18,12 +11,10 @@ export async function editMessage( message: Message, content: MessageEditOptions & WebhookEditMessageOptions, ): Promise { - if (!(message.channel instanceof TextChannel || message.channel instanceof NewsChannel)) { + if (!message.channel.isText()) { return; } - const channel = message.channel as TextChannel | NewsChannel; - await pluginData.state.queue.add(async () => { if (message.webhookId) { const webhook = await pluginData.state.webhooks.find(message.webhookId); diff --git a/backend/src/plugins/InternalPoster/functions/getOrCreateWebhookClientForChannel.ts b/backend/src/plugins/InternalPoster/functions/getOrCreateWebhookClientForChannel.ts index cc582495..1630343b 100644 --- a/backend/src/plugins/InternalPoster/functions/getOrCreateWebhookClientForChannel.ts +++ b/backend/src/plugins/InternalPoster/functions/getOrCreateWebhookClientForChannel.ts @@ -1,11 +1,11 @@ import { GuildPluginData } from "knub"; import { InternalPosterPluginType } from "../types"; -import { NewsChannel, TextChannel, WebhookClient } from "discord.js"; +import { GuildTextBasedChannel, ThreadChannel, WebhookClient } from "discord.js"; import { getOrCreateWebhookForChannel } from "./getOrCreateWebhookForChannel"; export async function getOrCreateWebhookClientForChannel( pluginData: GuildPluginData, - channel: TextChannel | NewsChannel, + channel: Exclude, ): Promise { if (!pluginData.state.webhookClientCache.has(channel.id)) { const webhookInfo = await getOrCreateWebhookForChannel(pluginData, channel); diff --git a/backend/src/plugins/InternalPoster/functions/getOrCreateWebhookForChannel.ts b/backend/src/plugins/InternalPoster/functions/getOrCreateWebhookForChannel.ts index 8acd2887..2bb4a221 100644 --- a/backend/src/plugins/InternalPoster/functions/getOrCreateWebhookForChannel.ts +++ b/backend/src/plugins/InternalPoster/functions/getOrCreateWebhookForChannel.ts @@ -1,13 +1,13 @@ import { GuildPluginData } from "knub"; import { InternalPosterPluginType } from "../types"; -import { NewsChannel, Permissions, TextChannel } from "discord.js"; +import { GuildTextBasedChannel, Permissions, ThreadChannel } from "discord.js"; import { isDiscordAPIError } from "../../../utils"; type WebhookInfo = [id: string, token: string]; export async function getOrCreateWebhookForChannel( pluginData: GuildPluginData, - channel: TextChannel | NewsChannel, + channel: Exclude, ): Promise { // tslint:disable-next-line:no-console FIXME: Here for debugging purposes console.log(`getOrCreateWebhookForChannel(${channel.id})`); diff --git a/backend/src/plugins/InternalPoster/functions/sendMessage.ts b/backend/src/plugins/InternalPoster/functions/sendMessage.ts index bc52ac05..b33f2ea9 100644 --- a/backend/src/plugins/InternalPoster/functions/sendMessage.ts +++ b/backend/src/plugins/InternalPoster/functions/sendMessage.ts @@ -1,8 +1,6 @@ -import { Message, MessageOptions, NewsChannel, TextChannel, WebhookClient } from "discord.js"; +import { GuildTextBasedChannel, MessageOptions } from "discord.js"; import { GuildPluginData } from "knub"; import { InternalPosterPluginType } from "../types"; -import { getOrCreateWebhookForChannel } from "./getOrCreateWebhookForChannel"; -import { APIMessage } from "discord-api-types"; import { isDiscordAPIError } from "../../../utils"; import { getOrCreateWebhookClientForChannel } from "./getOrCreateWebhookClientForChannel"; @@ -12,7 +10,7 @@ export type InternalPosterMessageResult = { }; async function sendDirectly( - channel: TextChannel | NewsChannel, + channel: GuildTextBasedChannel, content: MessageOptions, ): Promise { return channel.send(content).then((message) => ({ @@ -26,11 +24,11 @@ async function sendDirectly( */ export async function sendMessage( pluginData: GuildPluginData, - channel: TextChannel | NewsChannel, + channel: GuildTextBasedChannel, content: MessageOptions, ): Promise { return pluginData.state.queue.add(async () => { - const webhookClient = await getOrCreateWebhookClientForChannel(pluginData, channel); + const webhookClient = !channel.isThread() ? await getOrCreateWebhookClientForChannel(pluginData, channel) : null; if (!webhookClient) { return sendDirectly(channel, content); } diff --git a/backend/src/plugins/Logs/logFunctions/logPostedScheduledMessage.ts b/backend/src/plugins/Logs/logFunctions/logPostedScheduledMessage.ts index 52aa83ca..7603a17c 100644 --- a/backend/src/plugins/Logs/logFunctions/logPostedScheduledMessage.ts +++ b/backend/src/plugins/Logs/logFunctions/logPostedScheduledMessage.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, ThreadChannel, User } from "discord.js"; +import type { GuildTextBasedChannel, User } from "discord.js"; import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; interface LogPostedScheduledMessageData { author: User; - channel: BaseGuildTextChannel | ThreadChannel; + channel: GuildTextBasedChannel; messageId: string; } diff --git a/backend/src/plugins/Post/util/postMessage.ts b/backend/src/plugins/Post/util/postMessage.ts index 0395867c..92489634 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, NewsChannel, TextChannel, ThreadChannel } from "discord.js"; +import { GuildTextBasedChannel, Message, MessageOptions, MessageAttachment } 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 | NewsChannel | ThreadChannel, + channel: GuildTextBasedChannel, content: MessageOptions, attachments: MessageAttachment[] = [], enableMentions: boolean = false, diff --git a/backend/src/utils/resolveMessageTarget.ts b/backend/src/utils/resolveMessageTarget.ts index a7c3043c..45d030e4 100644 --- a/backend/src/utils/resolveMessageTarget.ts +++ b/backend/src/utils/resolveMessageTarget.ts @@ -1,4 +1,5 @@ -import { Snowflake, TextChannel } from "discord.js"; +import { ChannelFlags } from "discord-api-types/v10.js"; +import { GuildTextBasedChannel, Snowflake, TextChannel, ThreadChannel } from "discord.js"; import { GuildPluginData } from "knub"; import { getChannelIdFromMessageId } from "../data/getChannelIdFromMessageId"; import { isSnowflake } from "../utils"; @@ -7,7 +8,7 @@ const channelAndMessageIdRegex = /^(\d+)[\-\/](\d+)$/; const messageLinkRegex = /^https:\/\/(?:\w+\.)?discord(?:app)?\.com\/channels\/\d+\/(\d+)\/(\d+)$/i; export interface MessageTarget { - channel: TextChannel; + channel: Exclude; messageId: string; } @@ -47,7 +48,7 @@ export async function resolveMessageTarget(pluginData: GuildPluginData, val } const channel = pluginData.guild.channels.resolve(result.channelId as Snowflake); - if (!channel || !(channel instanceof TextChannel)) { + if (!channel?.isText() || channel instanceof ThreadChannel) { return null; }