From 25a386cf1ae475883f7dec985f5836a71d440e2a Mon Sep 17 00:00:00 2001 From: powermaker450 Date: Sun, 13 Oct 2024 18:31:41 -0400 Subject: [PATCH] Proper typings(?) --- src/commands/confess.ts | 15 ++++++--------- src/commands/confessban.ts | 7 +++---- src/commands/confessdel.ts | 6 +++--- src/commands/confesspardon.ts | 7 +++---- src/main.ts | 5 ++++- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/commands/confess.ts b/src/commands/confess.ts index 7294c1a..a7f765a 100644 --- a/src/commands/confess.ts +++ b/src/commands/confess.ts @@ -20,7 +20,7 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, - CommandInteraction, + ChatInputCommandInteraction, ComponentType, EmbedBuilder, SlashCommandBuilder, @@ -50,7 +50,7 @@ export const data = new SlashCommandBuilder() .setDescription("The link to an image to attach (optional)") ); -export async function execute(interaction: CommandInteraction) { +export async function execute(interaction: ChatInputCommandInteraction) { // TODO: This all works as intended, but I'd like for it so be a reusable function // instead because all of this is reused in src/main.ts:56 try { @@ -73,12 +73,11 @@ export async function execute(interaction: CommandInteraction) { .confessChannel; const adminChannel = dt.getGuildInfo(interaction.guild?.id!)?.settings .modChannel; - // @ts-ignore - const messageContent: string = `"${interaction.options.getString("message")}"`; - // @ts-ignore - const attachment: string = interaction.options.getString("attachment"); - const isAttachment = (text: string) => + const messageContent = `"${interaction.options.getString("message")}"`; + const attachment = interaction.options.getString("attachment")!; + + const isAttachment = (text: string | null) => text && (text.startsWith("http://") || text.startsWith("https://")); const color = getRandomColor(); @@ -86,7 +85,6 @@ export async function execute(interaction: CommandInteraction) { const userConfessionEmbed = new EmbedBuilder() .setColor(color) .setTitle(`Anonymous Confession \`${messageId}\``) - // @ts-ignore .setDescription(messageContent); isAttachment(attachment) && userConfessionEmbed.setImage(attachment); @@ -94,7 +92,6 @@ export async function execute(interaction: CommandInteraction) { const adminConfessionEmbed = new EmbedBuilder() .setColor(color) .setTitle(`Anonymous Confession \`${messageId}\``) - // @ts-ignore .setDescription(messageContent) .addFields( { diff --git a/src/commands/confessban.ts b/src/commands/confessban.ts index 39e5d7e..f41d5f6 100644 --- a/src/commands/confessban.ts +++ b/src/commands/confessban.ts @@ -17,7 +17,7 @@ */ import { - CommandInteraction, + ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js"; @@ -37,11 +37,10 @@ export const data = new SlashCommandBuilder() ) .setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers); -export async function execute(interaction: CommandInteraction) { +export async function execute(interaction: ChatInputCommandInteraction) { const result = dt.addBan( interaction.guild?.id!, - // @ts-ignore - interaction.options.getString("id") + interaction.options.getString("id")! ); try { diff --git a/src/commands/confessdel.ts b/src/commands/confessdel.ts index 2a3a8b7..c3d2009 100644 --- a/src/commands/confessdel.ts +++ b/src/commands/confessdel.ts @@ -17,6 +17,7 @@ */ import { + ChatInputCommandInteraction, CommandInteraction, EmbedBuilder, SlashCommandBuilder, @@ -36,7 +37,7 @@ export const data = new SlashCommandBuilder() option.setName("id").setDescription("The confession id").setRequired(true) ); -export async function execute(interaction: CommandInteraction) { +export async function execute(interaction: ChatInputCommandInteraction) { if (!dt.getGuildInfo(interaction.guild?.id!)) { return interaction.reply({ content: @@ -45,8 +46,7 @@ export async function execute(interaction: CommandInteraction) { }); } - // @ts-ignore - const idVal = interaction.options.getString("id"); + const idVal = interaction.options.getString("id")!; const result = dt.getConfession(interaction.guild?.id!, idVal); if (result) { diff --git a/src/commands/confesspardon.ts b/src/commands/confesspardon.ts index 22e589f..2b8d1d9 100644 --- a/src/commands/confesspardon.ts +++ b/src/commands/confesspardon.ts @@ -17,7 +17,7 @@ */ import { - CommandInteraction, + ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js"; @@ -37,11 +37,10 @@ export const data = new SlashCommandBuilder() ) .setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages); -export function execute(interaction: CommandInteraction) { +export function execute(interaction: ChatInputCommandInteraction) { const result = dt.removeBan( interaction.guild?.id!, - // @ts-ignore - interaction.options.getString("id") + interaction.options.getString("id")! ); try { diff --git a/src/main.ts b/src/main.ts index 3d5e169..5dd329d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -20,6 +20,7 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, + ChatInputCommandInteraction, ComponentType, EmbedBuilder, Events, @@ -58,7 +59,9 @@ BotClient.on(Events.InteractionCreate, async interaction => { const { commandName } = interaction; if (commands[commandName as keyof typeof commands]) { - commands[commandName as keyof typeof commands].execute(interaction); + commands[commandName as keyof typeof commands].execute( + interaction as ChatInputCommandInteraction + ); } });