From 96228bdb24b74f36d69a9ef079a1e2ce0f84bd64 Mon Sep 17 00:00:00 2001 From: pineafan Date: Tue, 21 Feb 2023 14:22:55 +0000 Subject: [PATCH] Fixed all typescript errors --- package.json | 3 +++ src/commands/server/buttons.ts | 2 +- src/commands/settings/autopublish.ts | 2 +- src/commands/settings/logs/attachment.ts | 2 +- src/commands/settings/logs/warnings.ts | 2 +- src/context/messages/purgeto.ts | 5 +++-- src/events/guildMemberUpdate.ts | 2 +- src/utils/dualCollector.ts | 13 ++++++------- src/utils/singleNotify.ts | 21 +++++++++++---------- tsconfig.json | 3 ++- 10 files changed, 30 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 888ceaf..96c6e7a 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,9 @@ "typescript": "^4.9.4", "uuid": "^8.3.2" }, + "resolutions": { + "discord-api-types": "0.37.20" + }, "name": "nucleus", "version": "0.0.1", "description": "Nucleus: The core of your server", diff --git a/src/commands/server/buttons.ts b/src/commands/server/buttons.ts index 61db825..e4bda0d 100644 --- a/src/commands/server/buttons.ts +++ b/src/commands/server/buttons.ts @@ -134,7 +134,7 @@ export const callback = async (interaction: CommandInteraction): Promise = let i: Discord.ButtonInteraction | Discord.ChannelSelectMenuInteraction | Discord.StringSelectMenuInteraction; try { i = await interaction.channel!.awaitMessageComponent({ - filter: (i) => i.user.id === interaction.user.id, + filter: (i: Discord.Interaction) => i.user.id === interaction.user.id, time: 300000 }) as Discord.ButtonInteraction | Discord.ChannelSelectMenuInteraction | Discord.StringSelectMenuInteraction; } catch (e) { diff --git a/src/commands/settings/autopublish.ts b/src/commands/settings/autopublish.ts index f2c367f..1dc97e0 100644 --- a/src/commands/settings/autopublish.ts +++ b/src/commands/settings/autopublish.ts @@ -53,7 +53,7 @@ export const callback = async (interaction: CommandInteraction): Promise = let i: Discord.ButtonInteraction | Discord.ChannelSelectMenuInteraction; try { i = await interaction.channel!.awaitMessageComponent({ - filter: (i) => i.user.id === interaction.user.id, + filter: (i: Discord.Interaction) => i.user.id === interaction.user.id, time: 300000 }) as Discord.ButtonInteraction | Discord.ChannelSelectMenuInteraction; } catch (e) { diff --git a/src/commands/settings/logs/attachment.ts b/src/commands/settings/logs/attachment.ts index a3b24ff..8331043 100644 --- a/src/commands/settings/logs/attachment.ts +++ b/src/commands/settings/logs/attachment.ts @@ -72,7 +72,7 @@ const callback = async (interaction: CommandInteraction): Promise => { let i: Discord.ButtonInteraction | Discord.SelectMenuInteraction; try { i = (await interaction.channel!.awaitMessageComponent({ - filter: (i) => i.user.id === interaction.user.id, + filter: (i: Discord.Interaction) => i.user.id === interaction.user.id, time: 300000 })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction; } catch (e) { diff --git a/src/commands/settings/logs/warnings.ts b/src/commands/settings/logs/warnings.ts index 25f9064..24249a2 100644 --- a/src/commands/settings/logs/warnings.ts +++ b/src/commands/settings/logs/warnings.ts @@ -61,7 +61,7 @@ const callback = async (interaction: CommandInteraction): Promise => { let i: Discord.ButtonInteraction | Discord.SelectMenuInteraction; try { i = (await interaction.channel!.awaitMessageComponent({ - filter: (i) => i.user.id === interaction.user.id, + filter: (i: Discord.Interaction) => i.user.id === interaction.user.id, time: 300000 })) as Discord.ButtonInteraction | Discord.SelectMenuInteraction; } catch (e) { diff --git a/src/context/messages/purgeto.ts b/src/context/messages/purgeto.ts index b0211ec..4627bf2 100644 --- a/src/context/messages/purgeto.ts +++ b/src/context/messages/purgeto.ts @@ -1,7 +1,7 @@ import confirmationMessage from '../../utils/confirmationMessage.js'; import EmojiEmbed from '../../utils/generateEmojiEmbed.js'; import { LoadingEmbed } from '../../utils/defaults.js'; -import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, ContextMenuCommandBuilder, GuildTextBasedChannel, MessageContextMenuCommandInteraction } from "discord.js"; +import Discord, { ActionRowBuilder, ButtonBuilder, ButtonStyle, ContextMenuCommandBuilder, GuildTextBasedChannel, Message, MessageContextMenuCommandInteraction } from "discord.js"; import client from "../../utils/client.js"; import getEmojiByName from '../../utils/getEmojiByName.js'; import { JSONTranscriptFromMessageArray, JSONTranscriptToHumanReadable } from "../../utils/logTranscripts.js"; @@ -184,7 +184,8 @@ const callback = async (interaction: MessageContextMenuCommandInteraction) => { } }; log(data); - const transcript = JSONTranscriptToHumanReadable(JSONTranscriptFromMessageArray(deleted.map((m) => m as Discord.Message))!); + const messages: Message[] = deleted.map(m => m).filter(m => m instanceof Message).map(m => m as Message); + const transcript = JSONTranscriptToHumanReadable(JSONTranscriptFromMessageArray(messages)!); const attachmentObject = { attachment: Buffer.from(transcript), name: `purge-${channel.id}-${Date.now()}.txt`, diff --git a/src/events/guildMemberUpdate.ts b/src/events/guildMemberUpdate.ts index b674060..5788f61 100644 --- a/src/events/guildMemberUpdate.ts +++ b/src/events/guildMemberUpdate.ts @@ -106,7 +106,7 @@ export async function callback(client: NucleusClient, before: GuildMember, after } if ( (before.communicationDisabledUntilTimestamp ?? 0) < Date.now() && - (after.communicationDisabledUntil ?? 0) > Date.now() + new Date(after.communicationDisabledUntil ?? 0).getTime() > Date.now() ) { await client.database.history.create( "mute", diff --git a/src/utils/dualCollector.ts b/src/utils/dualCollector.ts index 072f73f..0b05779 100644 --- a/src/utils/dualCollector.ts +++ b/src/utils/dualCollector.ts @@ -10,15 +10,14 @@ export default async function ( try { out = await new Promise((resolve, _reject) => { const mes = m - .createMessageComponentCollector({ - filter: (m) => interactionFilter(m), - time: 300000 - }) - .on("collect", (m) => { + .createMessageComponentCollector({ + filter: (m) => interactionFilter(m), + time: 300000 + }) + .on("collect", (m) => { resolve(m); }); - const int = m.channel - .createMessageCollector({ + const int = m.channel.createMessageCollector({ filter: (m) => messageFilter(m), time: 300000 }) diff --git a/src/utils/singleNotify.ts b/src/utils/singleNotify.ts index 8e3aa60..6bf63e1 100644 --- a/src/utils/singleNotify.ts +++ b/src/utils/singleNotify.ts @@ -1,6 +1,7 @@ import client from "./client.js"; import EmojiEmbed from "./generateEmojiEmbed.js"; import { Record as ImmutableRecord } from "immutable"; +import type { TextChannel, ThreadChannel, NewsChannel } from "discord.js"; const severitiesType = ImmutableRecord({ Critical: "Danger", @@ -31,20 +32,20 @@ export default async function ( const channel = await client.channels.fetch(data.logging.staff.channel); if (!channel) return; if (!channel.isTextBased()) return; + const textChannel = channel as TextChannel | ThreadChannel | NewsChannel; + let messageData = {embeds: [ + new EmojiEmbed() + .setTitle(`${severity} notification`) + .setDescription(message) + .setStatus(severities.get(severity)) + .setEmoji("CONTROL.BLOCKCROSS") + ]} if (pings) { - await channel.send({ + messageData = Object.assign(messageData, { content: pings.map((ping) => `<@${ping}>`).join(" ") }); } - await channel.send({ - embeds: [ - new EmojiEmbed() - .setTitle(`${severity} notification`) - .setDescription(message) - .setStatus(severities.get(severity)) - .setEmoji("CONTROL.BLOCKCROSS") - ] - }); + await textChannel.send(messageData); } catch (err) { console.error(err); } diff --git a/tsconfig.json b/tsconfig.json index 7e6abdc..a67284d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,7 +11,8 @@ "resolveJsonModule": true, "moduleResolution": "NodeNext", "skipLibCheck": true, - "noImplicitReturns": false + "noImplicitReturns": false, + "ignoreDeprecations": "5.0" }, "include": ["src/**/*", "src/index.d.ts"], "exclude": ["src/Unfinished/**/*"]