diff --git a/backend/src/pluginUtils.ts b/backend/src/pluginUtils.ts index f0b8694d..79e2eb94 100644 --- a/backend/src/pluginUtils.ts +++ b/backend/src/pluginUtils.ts @@ -3,6 +3,7 @@ */ import { + ChannelType, GuildMember, GuildTextBasedChannel, Message, @@ -197,7 +198,7 @@ export function getPluginConfigPreprocessor( export async function sendSuccessMessage( pluginData: AnyPluginData, - channel: TextChannel, + channel: GuildTextBasedChannel, body: string, allowedMentions?: MessageMentionOptions, ): Promise { @@ -218,7 +219,7 @@ export async function sendSuccessMessage( export async function sendErrorMessage( pluginData: AnyPluginData, - channel: GuildTextBasedChannel, + channel: TextBasedChannel, body: string, allowedMentions?: MessageMentionOptions, ): Promise { diff --git a/backend/src/plugins/AutoDelete/util/deleteNextItem.ts b/backend/src/plugins/AutoDelete/util/deleteNextItem.ts index 408e100f..e6851f0b 100644 --- a/backend/src/plugins/AutoDelete/util/deleteNextItem.ts +++ b/backend/src/plugins/AutoDelete/util/deleteNextItem.ts @@ -17,7 +17,7 @@ export async function deleteNextItem(pluginData: GuildPluginData renderTemplate( str, @@ -62,7 +62,7 @@ export const StartThreadAction = automodAction({ }), ); const threadName = await renderThreadName(actionConfig.name ?? "{user.tag}s thread"); - const thread = await channel.threads + const thread = await channel!.threads .create({ name: threadName, autoArchiveDuration: autoArchive, diff --git a/backend/src/plugins/Automod/functions/getTextMatchPartialSummary.ts b/backend/src/plugins/Automod/functions/getTextMatchPartialSummary.ts index 31ece554..24965dca 100644 --- a/backend/src/plugins/Automod/functions/getTextMatchPartialSummary.ts +++ b/backend/src/plugins/Automod/functions/getTextMatchPartialSummary.ts @@ -1,4 +1,4 @@ -import { Snowflake, TextChannel } from "discord.js"; +import { ActivityType, Snowflake, TextChannel } from "discord.js"; import { GuildPluginData } from "knub"; import { messageSummary, verboseChannelMention } from "../../../utils"; import { AutomodContext, AutomodPluginType } from "../types"; @@ -11,13 +11,13 @@ export function getTextMatchPartialSummary( ) { if (type === "message") { const message = context.message!; - const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake) as TextChannel; + const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake); const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``; return `message in ${channelMention}:\n${messageSummary(message)}`; } else if (type === "embed") { const message = context.message!; - const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake) as TextChannel; + const channel = pluginData.guild.channels.cache.get(message.channel_id as Snowflake); const channelMention = channel ? verboseChannelMention(channel) : `\`#${message.channel_id}\``; return `message embed in ${channelMention}:\n${messageSummary(message)}`; @@ -29,6 +29,6 @@ export function getTextMatchPartialSummary( const visibleName = context.member?.nickname || context.user!.username; return `visible name: ${visibleName}`; } else if (type === "customstatus") { - return `custom status: ${context.member!.presence?.activities.find((a) => a.type === "CUSTOM")?.name}`; + return `custom status: ${context.member!.presence?.activities.find((a) => a.type === ActivityType.Custom)?.name}`; } } diff --git a/backend/src/plugins/Automod/functions/runAutomod.ts b/backend/src/plugins/Automod/functions/runAutomod.ts index d21818ff..a711fa09 100644 --- a/backend/src/plugins/Automod/functions/runAutomod.ts +++ b/backend/src/plugins/Automod/functions/runAutomod.ts @@ -1,4 +1,4 @@ -import { Snowflake, TextChannel, ThreadChannel } from "discord.js"; +import { GuildTextBasedChannel, Snowflake, TextChannel, ThreadChannel } from "discord.js"; import { GuildPluginData } from "knub"; import { availableActions } from "../actions/availableActions"; import { CleanAction } from "../actions/clean"; @@ -18,7 +18,7 @@ export async function runAutomod(pluginData: GuildPluginData, const channelOrThread = context.channel ?? (channelIdOrThreadId - ? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as TextChannel | ThreadChannel) + ? (pluginData.guild.channels.cache.get(channelIdOrThreadId as Snowflake) as GuildTextBasedChannel) : null); const channelId = channelOrThread?.isThread() ? channelOrThread.parent?.id : channelIdOrThreadId; const threadId = channelOrThread?.isThread() ? channelOrThread.id : null; diff --git a/backend/src/plugins/Automod/triggers/anyMessage.ts b/backend/src/plugins/Automod/triggers/anyMessage.ts index 9422f4f5..2599f9d1 100644 --- a/backend/src/plugins/Automod/triggers/anyMessage.ts +++ b/backend/src/plugins/Automod/triggers/anyMessage.ts @@ -22,7 +22,7 @@ export const AnyMessageTrigger = automodTrigger()({ }, renderMatchInformation({ pluginData, contexts, matchResult }) { - const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake) as TextChannel; + const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake); return `Matched message (\`${contexts[0].message!.id}\`) in ${ channel ? verboseChannelMention(channel) : "Unknown Channel" }`; diff --git a/backend/src/plugins/Automod/triggers/matchAttachmentType.ts b/backend/src/plugins/Automod/triggers/matchAttachmentType.ts index 80154ec9..57a7f9ff 100644 --- a/backend/src/plugins/Automod/triggers/matchAttachmentType.ts +++ b/backend/src/plugins/Automod/triggers/matchAttachmentType.ts @@ -66,7 +66,7 @@ export const MatchAttachmentTypeTrigger = automodTrigger()({ }, renderMatchInformation({ pluginData, contexts, matchResult }) { - const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake) as TextChannel; + const channel = pluginData.guild.channels.cache.get(contexts[0].message!.channel_id as Snowflake); const prettyChannel = verboseChannelMention(channel); return ( diff --git a/backend/src/plugins/Automod/types.ts b/backend/src/plugins/Automod/types.ts index ed7cf56e..130a885a 100644 --- a/backend/src/plugins/Automod/types.ts +++ b/backend/src/plugins/Automod/types.ts @@ -1,4 +1,4 @@ -import { GuildMember, PartialGuildMember, TextChannel, ThreadChannel, User } from "discord.js"; +import { GuildMember, GuildTextBasedChannel, PartialGuildMember, TextChannel, ThreadChannel, User } from "discord.js"; import * as t from "io-ts"; import { BasePluginType, CooldownManager } from "knub"; import { SavedMessage } from "../../data/entities/SavedMessage"; @@ -139,7 +139,7 @@ export interface AutomodContext { locked?: ThreadChannel; unlocked?: ThreadChannel; }; - channel?: TextChannel | ThreadChannel; + channel?: GuildTextBasedChannel; } export interface RecentAction { diff --git a/backend/src/plugins/BotControl/commands/AddDashboardUserCmd.ts b/backend/src/plugins/BotControl/commands/AddDashboardUserCmd.ts index 531016a3..b8f6d720 100644 --- a/backend/src/plugins/BotControl/commands/AddDashboardUserCmd.ts +++ b/backend/src/plugins/BotControl/commands/AddDashboardUserCmd.ts @@ -19,7 +19,7 @@ export const AddDashboardUserCmd = botControlCmd({ async run({ pluginData, message: msg, args }) { const guild = await pluginData.state.allowedGuilds.find(args.guildId); if (!guild) { - sendErrorMessage(pluginData, msg.channel as TextChannel, "Server is not using Zeppelin"); + sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin"); return; } diff --git a/backend/src/utils.ts b/backend/src/utils.ts index e1324c7a..e4a2f5b2 100644 --- a/backend/src/utils.ts +++ b/backend/src/utils.ts @@ -952,7 +952,7 @@ export function chunkMessageLines(str: string, maxChunkLength = 1990): string[] } export async function createChunkedMessage( - channel: TextChannel | ThreadChannel | User, + channel: GuildTextBasedChannel | User, messageText: string, allowedMentions?: MessageMentionOptions, ) { @@ -1402,7 +1402,11 @@ export async function resolveStickerId(bot: Client, id: Snowflake): Promise { +export async function confirm( + channel: GuildTextBasedChannel, + userId: string, + content: MessageOptions, +): Promise { return waitForButtonConfirm(channel, content, { restrictToId: userId }); } @@ -1441,7 +1445,7 @@ export function verboseUserName(user: User | UnknownUser): string { return `**${user.tag}** (\`${user.id}\`)`; } -export function verboseChannelMention(channel: GuildChannel | ThreadChannel): string { +export function verboseChannelMention(channel: GuildTextBasedChannel): string { const plainTextName = channel.type === ChannelType.GuildVoice || channel.type === ChannelType.GuildStageVoice ? channel.name diff --git a/backend/src/utils/waitForInteraction.ts b/backend/src/utils/waitForInteraction.ts index 1b9cc756..ff0c90c6 100644 --- a/backend/src/utils/waitForInteraction.ts +++ b/backend/src/utils/waitForInteraction.ts @@ -4,6 +4,7 @@ import { ButtonBuilder, ButtonComponent, ButtonStyle, + GuildTextBasedChannel, Message, MessageActionRowComponentBuilder, MessageComponentInteraction, @@ -16,7 +17,7 @@ import moment from "moment"; import uuidv4 from "uuid/v4"; export async function waitForButtonConfirm( - channel: TextChannel, + channel: GuildTextBasedChannel, toPost: MessageCreateOptions, options?: WaitForOptions, ): Promise {