From 7fb0d02adfd44a1e7a9bc9df282d11f61f4c7bfa Mon Sep 17 00:00:00 2001 From: Almeida Date: Sun, 26 Jun 2022 12:09:27 +0100 Subject: [PATCH] fix discord-api-types imports & usage of removed guild features (#335) --- .../plugins/Automod/actions/startThread.ts | 28 ++++++++----------- .../plugins/Automod/triggers/threadArchive.ts | 2 +- .../plugins/Automod/triggers/threadCreate.ts | 2 +- .../plugins/Automod/triggers/threadDelete.ts | 2 +- .../Automod/triggers/threadUnarchive.ts | 2 +- .../InternalPoster/functions/sendMessage.ts | 5 ++-- 6 files changed, 17 insertions(+), 24 deletions(-) diff --git a/backend/src/plugins/Automod/actions/startThread.ts b/backend/src/plugins/Automod/actions/startThread.ts index 0fead10b..943f9be6 100644 --- a/backend/src/plugins/Automod/actions/startThread.ts +++ b/backend/src/plugins/Automod/actions/startThread.ts @@ -1,4 +1,4 @@ -import { GuildFeature, ThreadAutoArchiveDuration } from "discord-api-types"; +import { GuildFeature, ThreadAutoArchiveDuration } from "discord-api-types/v9"; import { TextChannel } from "discord.js"; import * as t from "io-ts"; import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter"; @@ -7,6 +7,13 @@ import { convertDelayStringToMS, MINUTES, noop, tDelayString, tNullable } from " import { savedMessageToTemplateSafeSavedMessage, userToTemplateSafeUser } from "../../../utils/templateSafeObjects"; import { automodAction } from "../helpers"; +const validThreadAutoArchiveDurations: ThreadAutoArchiveDuration[] = [ + ThreadAutoArchiveDuration.OneHour, + ThreadAutoArchiveDuration.OneDay, + ThreadAutoArchiveDuration.ThreeDays, + ThreadAutoArchiveDuration.OneWeek, +]; + export const StartThreadAction = automodAction({ configType: t.type({ name: tNullable(t.string), @@ -41,22 +48,9 @@ export const StartThreadAction = automodAction({ const archiveSet = actionConfig.auto_archive ? Math.ceil(Math.max(convertDelayStringToMS(actionConfig.auto_archive) ?? 0, 0) / MINUTES) : ThreadAutoArchiveDuration.OneDay; - let autoArchive: ThreadAutoArchiveDuration; - if (archiveSet === ThreadAutoArchiveDuration.OneDay) { - autoArchive = ThreadAutoArchiveDuration.OneDay; - } else if ( - archiveSet === ThreadAutoArchiveDuration.ThreeDays && - guild.features.includes(GuildFeature.ThreeDayThreadArchive) - ) { - autoArchive = ThreadAutoArchiveDuration.ThreeDays; - } else if ( - archiveSet === ThreadAutoArchiveDuration.OneWeek && - guild.features.includes(GuildFeature.SevenDayThreadArchive) - ) { - autoArchive = ThreadAutoArchiveDuration.OneWeek; - } else { - autoArchive = ThreadAutoArchiveDuration.OneHour; - } + const autoArchive = validThreadAutoArchiveDurations.includes(archiveSet) + ? (archiveSet as ThreadAutoArchiveDuration) + : ThreadAutoArchiveDuration.OneHour; for (const threadContext of threads) { const channel = pluginData.guild.channels.cache.get(threadContext.message!.channel_id) as TextChannel; diff --git a/backend/src/plugins/Automod/triggers/threadArchive.ts b/backend/src/plugins/Automod/triggers/threadArchive.ts index 40cd43df..d4ed631b 100644 --- a/backend/src/plugins/Automod/triggers/threadArchive.ts +++ b/backend/src/plugins/Automod/triggers/threadArchive.ts @@ -1,4 +1,4 @@ -import { Snowflake } from "discord-api-types"; +import { Snowflake } from "discord-api-types/v9"; import { User, Util } from "discord.js"; import * as t from "io-ts"; import { tNullable } from "../../../utils"; diff --git a/backend/src/plugins/Automod/triggers/threadCreate.ts b/backend/src/plugins/Automod/triggers/threadCreate.ts index f4bc7e7a..c0ae6ad3 100644 --- a/backend/src/plugins/Automod/triggers/threadCreate.ts +++ b/backend/src/plugins/Automod/triggers/threadCreate.ts @@ -1,4 +1,4 @@ -import { Snowflake } from "discord-api-types"; +import { Snowflake } from "discord-api-types/v9"; import { User, Util } from "discord.js"; import * as t from "io-ts"; import { automodTrigger } from "../helpers"; diff --git a/backend/src/plugins/Automod/triggers/threadDelete.ts b/backend/src/plugins/Automod/triggers/threadDelete.ts index 988ee752..cecb5862 100644 --- a/backend/src/plugins/Automod/triggers/threadDelete.ts +++ b/backend/src/plugins/Automod/triggers/threadDelete.ts @@ -1,4 +1,4 @@ -import { Snowflake } from "discord-api-types"; +import { Snowflake } from "discord-api-types/v9"; import { User, Util } from "discord.js"; import * as t from "io-ts"; import { automodTrigger } from "../helpers"; diff --git a/backend/src/plugins/Automod/triggers/threadUnarchive.ts b/backend/src/plugins/Automod/triggers/threadUnarchive.ts index 05e729f1..ce3adf81 100644 --- a/backend/src/plugins/Automod/triggers/threadUnarchive.ts +++ b/backend/src/plugins/Automod/triggers/threadUnarchive.ts @@ -1,4 +1,4 @@ -import { Snowflake } from "discord-api-types"; +import { Snowflake } from "discord-api-types/v9"; import { User, Util } from "discord.js"; import * as t from "io-ts"; import { tNullable } from "../../../utils"; diff --git a/backend/src/plugins/InternalPoster/functions/sendMessage.ts b/backend/src/plugins/InternalPoster/functions/sendMessage.ts index 283cc3dc..3afa9614 100644 --- a/backend/src/plugins/InternalPoster/functions/sendMessage.ts +++ b/backend/src/plugins/InternalPoster/functions/sendMessage.ts @@ -1,8 +1,7 @@ -import { GuildTextBasedChannel, Message, MessageOptions, NewsChannel, TextChannel, WebhookClient } from "discord.js"; +import { GuildTextBasedChannel, MessageOptions, WebhookClient } from "discord.js"; import { GuildPluginData } from "knub"; import { InternalPosterPluginType } from "../types"; -import { channelIsWebhookable, getOrCreateWebhookForChannel } from "./getOrCreateWebhookForChannel"; -import { APIMessage } from "discord-api-types"; +import { channelIsWebhookable } from "./getOrCreateWebhookForChannel"; import { isDiscordAPIError } from "../../../utils"; import { getOrCreateWebhookClientForChannel } from "./getOrCreateWebhookClientForChannel";