From 9956af7c69f8da4e1159fc8e77582014f3d1e6b8 Mon Sep 17 00:00:00 2001 From: metal Date: Sun, 12 Mar 2023 16:51:26 +0000 Subject: [PATCH] more minor typings fixes - 23 err left Signed-off-by: GitHub --- backend/src/plugins/Automod/AutomodPlugin.ts | 1 - backend/src/plugins/Automod/actions/reply.ts | 2 +- backend/src/plugins/Automod/actions/startThread.ts | 1 + backend/src/plugins/CustomEvents/CustomEventsPlugin.ts | 2 +- .../src/plugins/Logs/logFunctions/logMessageDeleteAuto.ts | 4 ++-- backend/src/plugins/Logs/util/log.ts | 4 ++-- .../ModActions/events/CreateKickCaseOnManualKickEvt.ts | 2 +- backend/src/plugins/Post/commands/PostEmbedCmd.ts | 4 ++-- backend/src/plugins/Post/util/postScheduledPost.ts | 1 - .../src/plugins/Slowmode/util/applyBotSlowmodeToUserId.ts | 7 +++++-- backend/src/plugins/Slowmode/util/onMessageCreate.ts | 6 +++--- backend/src/plugins/Spam/util/logAndDetectMessageSpam.ts | 6 ++++-- backend/src/utils.ts | 2 +- backend/src/utils/idToTimestamp.ts | 4 ++-- backend/src/utils/templateSafeObjects.ts | 7 +++---- 15 files changed, 28 insertions(+), 25 deletions(-) diff --git a/backend/src/plugins/Automod/AutomodPlugin.ts b/backend/src/plugins/Automod/AutomodPlugin.ts index c0a7652a..15a5c7b4 100644 --- a/backend/src/plugins/Automod/AutomodPlugin.ts +++ b/backend/src/plugins/Automod/AutomodPlugin.ts @@ -1,5 +1,4 @@ import { configUtils, CooldownManager } from "knub"; -import { ConfigParserFn } from "knub/dist/config/configTypes"; import { GuildAntiraidLevels } from "../../data/GuildAntiraidLevels"; import { GuildArchives } from "../../data/GuildArchives"; import { GuildLogs } from "../../data/GuildLogs"; diff --git a/backend/src/plugins/Automod/actions/reply.ts b/backend/src/plugins/Automod/actions/reply.ts index b333614f..56312b95 100644 --- a/backend/src/plugins/Automod/actions/reply.ts +++ b/backend/src/plugins/Automod/actions/reply.ts @@ -121,7 +121,7 @@ export const ReplyAction = automodAction({ if (typeof actionConfig === "object" && actionConfig.auto_delete) { const delay = convertDelayStringToMS(String(actionConfig.auto_delete))!; - setTimeout(() => !replyMsg.deleted && replyMsg.delete().catch(noop), delay); + setTimeout(() => replyMsg.deletable && replyMsg.delete().catch(noop), delay); } } } diff --git a/backend/src/plugins/Automod/actions/startThread.ts b/backend/src/plugins/Automod/actions/startThread.ts index cb2741b7..db0c5e13 100644 --- a/backend/src/plugins/Automod/actions/startThread.ts +++ b/backend/src/plugins/Automod/actions/startThread.ts @@ -66,6 +66,7 @@ export const StartThreadAction = automodAction({ .create({ name: threadName, autoArchiveDuration: autoArchive, + // @ts-expect-error FIXME type: actionConfig.private ? ChannelType.PrivateThread : ChannelType.PublicThread, startMessage: !actionConfig.private && guild.features.includes(GuildFeature.PrivateThreads) diff --git a/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts b/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts index 10c1a010..6f8873ea 100644 --- a/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts +++ b/backend/src/plugins/CustomEvents/CustomEventsPlugin.ts @@ -43,7 +43,7 @@ export const CustomEventsPlugin = zeppelinGuildPlugin()( safeArgs[argKey] = userToTemplateSafeUser(argValue); } else if (argValue instanceof GuildMember) { safeArgs[argKey] = memberToTemplateSafeMember(argValue); - } else if (argValue instanceof GuildChannel || argValue instanceof ThreadChannel) { + } else if (argValue instanceof GuildChannel && argValue.isTextBased()) { safeArgs[argKey] = channelToTemplateSafeChannel(argValue); } else if (isScalar(argValue)) { safeArgs[argKey] = argValue; diff --git a/backend/src/plugins/Logs/logFunctions/logMessageDeleteAuto.ts b/backend/src/plugins/Logs/logFunctions/logMessageDeleteAuto.ts index aa9f92ae..af43512f 100644 --- a/backend/src/plugins/Logs/logFunctions/logMessageDeleteAuto.ts +++ b/backend/src/plugins/Logs/logFunctions/logMessageDeleteAuto.ts @@ -3,7 +3,7 @@ import { LogsPluginType } from "../types"; import { LogType } from "../../../data/LogType"; import { log } from "../util/log"; import { createTypedTemplateSafeValueContainer } from "../../../templateFormatter"; -import { GuildTextBasedChannel, User } from "discord.js"; +import { GuildBasedChannel, User } from "discord.js"; import { channelToTemplateSafeChannel, savedMessageToTemplateSafeSavedMessage, @@ -16,7 +16,7 @@ import { resolveChannelIds } from "../../../utils/resolveChannelIds"; interface LogMessageDeleteAutoData { message: SavedMessage; user: User | UnknownUser; - channel: GuildTextBasedChannel; + channel: GuildBasedChannel; messageDate: string; } diff --git a/backend/src/plugins/Logs/util/log.ts b/backend/src/plugins/Logs/util/log.ts index f532b3fe..def4665b 100644 --- a/backend/src/plugins/Logs/util/log.ts +++ b/backend/src/plugins/Logs/util/log.ts @@ -1,4 +1,4 @@ -import { EmbedData, MessageMentionTypes, Snowflake } from "discord.js"; +import { APIEmbed, MessageMentionTypes, Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; import { allowTimeout } from "../../../RegExpRunner"; import { ILogTypeData, LogsPluginType, TLogChannel, TLogChannelMap } from "../types"; @@ -141,7 +141,7 @@ export async function log( const buffer = pluginData.state.buffers.get(channelId)!; buffer.push({ content: typeof message === "string" ? message : message.content || "", - embeds: typeof message === "string" ? [] : ((message.embeds || []) as EmbedData[]), + embeds: typeof message === "string" ? [] : ((message.embeds || []) as APIEmbed[]), }); } } diff --git a/backend/src/plugins/ModActions/events/CreateKickCaseOnManualKickEvt.ts b/backend/src/plugins/ModActions/events/CreateKickCaseOnManualKickEvt.ts index 73d99ccf..53eea12c 100644 --- a/backend/src/plugins/ModActions/events/CreateKickCaseOnManualKickEvt.ts +++ b/backend/src/plugins/ModActions/events/CreateKickCaseOnManualKickEvt.ts @@ -1,4 +1,4 @@ -import { User } from "discord.js"; +import { AuditLogEvent, User } from "discord.js"; import { CaseTypes } from "../../../data/CaseTypes"; import { Case } from "../../../data/entities/Case"; import { logger } from "../../../logger"; diff --git a/backend/src/plugins/Post/commands/PostEmbedCmd.ts b/backend/src/plugins/Post/commands/PostEmbedCmd.ts index ee115a90..e605402b 100644 --- a/backend/src/plugins/Post/commands/PostEmbedCmd.ts +++ b/backend/src/plugins/Post/commands/PostEmbedCmd.ts @@ -1,4 +1,4 @@ -import { EmbedData } from "discord.js"; +import { APIEmbed } from "discord.js"; import { commandTypeHelpers as ct } from "../../../commandTypes"; import { sendErrorMessage } from "../../../pluginUtils"; import { isValidEmbed, trimLines } from "../../../utils"; @@ -46,7 +46,7 @@ export const PostEmbedCmd = postCmd({ } } - let embed: EmbedData = {}; + let embed: APIEmbed = {}; if (args.title) embed.title = args.title; if (color) embed.color = color; diff --git a/backend/src/plugins/Post/util/postScheduledPost.ts b/backend/src/plugins/Post/util/postScheduledPost.ts index 4b8d244d..cc9c8a22 100644 --- a/backend/src/plugins/Post/util/postScheduledPost.ts +++ b/backend/src/plugins/Post/util/postScheduledPost.ts @@ -57,7 +57,6 @@ export async function postScheduledPost(pluginData: GuildPluginData, - channel: GuildChannel & TextChannel, + channel: GuildTextBasedChannel, userId: string, ) { + // FIXME: Is there a better way to do this? + if (channel.isThread()) return; + // Deny sendMessage permission from the user. If there are existing permission overwrites, take those into account. const existingOverride = channel.permissionOverwrites?.resolve(userId as Snowflake); try { diff --git a/backend/src/plugins/Slowmode/util/onMessageCreate.ts b/backend/src/plugins/Slowmode/util/onMessageCreate.ts index b2721ab5..7fc56016 100644 --- a/backend/src/plugins/Slowmode/util/onMessageCreate.ts +++ b/backend/src/plugins/Slowmode/util/onMessageCreate.ts @@ -1,4 +1,4 @@ -import { Snowflake } from "discord.js"; +import { ChannelType, GuildTextBasedChannel, Snowflake } from "discord.js"; import { GuildPluginData } from "knub"; import { SavedMessage } from "../../../data/entities/SavedMessage"; import { hasPermission } from "../../../pluginUtils"; @@ -15,8 +15,8 @@ import { SlowmodeChannel } from "../../../data/entities/SlowmodeChannel"; export async function onMessageCreate(pluginData: GuildPluginData, msg: SavedMessage) { if (msg.is_bot) return; - const channel = pluginData.guild.channels.cache.get(msg.channel_id as Snowflake); - if (!channel?.isTextBased()) return; + const channel = pluginData.guild.channels.cache.get(msg.channel_id as Snowflake) as GuildTextBasedChannel; + if (!channel?.isTextBased() || channel.type === ChannelType.GuildStageVoice) return; // Don't apply slowmode if the lock was interrupted earlier (e.g. the message was caught by word filters) const thisMsgLock = await pluginData.locks.acquire(messageLock(msg)); diff --git a/backend/src/plugins/Spam/util/logAndDetectMessageSpam.ts b/backend/src/plugins/Spam/util/logAndDetectMessageSpam.ts index 13484855..57ee49eb 100644 --- a/backend/src/plugins/Spam/util/logAndDetectMessageSpam.ts +++ b/backend/src/plugins/Spam/util/logAndDetectMessageSpam.ts @@ -1,4 +1,4 @@ -import { Snowflake, TextChannel } from "discord.js"; +import { GuildTextBasedChannel, Snowflake, TextChannel } from "discord.js"; import { GuildPluginData } from "knub"; import moment from "moment-timezone"; import { CaseTypes } from "../../../data/CaseTypes"; @@ -141,7 +141,9 @@ export async function logAndDetectMessageSpam( clearRecentUserActions(pluginData, type, savedMessage.user_id, savedMessage.channel_id); // Generate a log from the detected messages - const channel = pluginData.guild.channels.cache.get(savedMessage.channel_id as Snowflake); + const channel = pluginData.guild.channels.cache.get( + savedMessage.channel_id as Snowflake, + ) as GuildTextBasedChannel; const archiveUrl = await saveSpamArchives(pluginData, uniqueMessages); // Create a case diff --git a/backend/src/utils.ts b/backend/src/utils.ts index c621511f..dfd4b1ea 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -401,7 +401,7 @@ export type ZStrictMessageContent = z.infer; export type StrictMessageContent = { content?: string; tts?: boolean; - embeds?: EmbedData[]; + embeds?: APIEmbed[]; }; export const tStrictMessageContent = t.type({ diff --git a/backend/src/utils/idToTimestamp.ts b/backend/src/utils/idToTimestamp.ts index 10b964a5..53a1fa03 100644 --- a/backend/src/utils/idToTimestamp.ts +++ b/backend/src/utils/idToTimestamp.ts @@ -1,6 +1,6 @@ import { Snowflake, SnowflakeUtil } from "discord.js"; -export function idToTimestamp(id: string) { +export function idToTimestamp(id: string): string | null { if (typeof id === "number") return null; - return SnowflakeUtil.deconstruct(id as Snowflake).timestamp; + return SnowflakeUtil.deconstruct(id as Snowflake).timestamp.toString(); } diff --git a/backend/src/utils/templateSafeObjects.ts b/backend/src/utils/templateSafeObjects.ts index 6ce23a99..3616b154 100644 --- a/backend/src/utils/templateSafeObjects.ts +++ b/backend/src/utils/templateSafeObjects.ts @@ -1,7 +1,7 @@ import { Emoji, Guild, - GuildChannel, + GuildBasedChannel, GuildMember, Message, PartialGuildMember, @@ -10,7 +10,6 @@ import { StageInstance, Sticker, StickerFormatType, - ThreadChannel, User, } from "discord.js"; import { UnknownUser } from "src/utils"; @@ -269,7 +268,7 @@ export function memberToTemplateSafeMember(member: GuildMember | PartialGuildMem }); } -export function channelToTemplateSafeChannel(channel: GuildChannel | ThreadChannel): TemplateSafeChannel { +export function channelToTemplateSafeChannel(channel: GuildBasedChannel): TemplateSafeChannel { return new TemplateSafeChannel({ id: channel.id, name: channel.name, @@ -449,7 +448,7 @@ export function messageToTemplateSafeMessage(message: Message): TemplateSafeMess id: message.id, content: message.content, author: userToTemplateSafeUser(message.author), - channel: channelToTemplateSafeChannel(message.channel as GuildChannel | ThreadChannel), + channel: channelToTemplateSafeChannel(message.channel as GuildBasedChannel), }); }