From d8ebeff4812c2978117ef130f9ccd4c873978aad Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 23 Mar 2025 16:44:42 +0100 Subject: [PATCH] Updated subcommand types --- src/commands/guild.ts | 6 +++--- src/commands/guild/info.ts | 2 +- src/commands/guild/member.ts | 2 +- src/commands/guild/top.ts | 2 +- src/commands/staff.ts | 10 +++++----- src/commands/staff/beast.ts | 2 +- src/commands/staff/help.ts | 4 ++-- src/commands/staff/prune.ts | 2 +- src/commands/staff/removeguildroles.ts | 2 +- src/commands/staff/updateall.ts | 2 +- src/typings/SubCommand.ts | 13 +++++++++++-- 11 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/commands/guild.ts b/src/commands/guild.ts index 54b0db8..c5a03e5 100644 --- a/src/commands/guild.ts +++ b/src/commands/guild.ts @@ -24,17 +24,17 @@ export default { const subcommand = interaction.options.getSubcommand() if (subcommand === "member") { - await guildMember(interaction) + await guildMember({ interaction }) return } if (subcommand === "info") { - await guildInfo(interaction) + await guildInfo({ interaction }) return } if (subcommand === "top") { - await guildTop(interaction) + await guildTop({ interaction }) return } diff --git a/src/commands/guild/info.ts b/src/commands/guild/info.ts index a891d02..26787c8 100644 --- a/src/commands/guild/info.ts +++ b/src/commands/guild/info.ts @@ -24,7 +24,7 @@ export const infoSub = new SlashCommandSubcommandBuilder() ) ) -const cmd: SubCommand = async (interaction) => { +const cmd: SubCommand = async ({ interaction }) => { await interaction.deferReply() const query = interaction.options.getString("query")! diff --git a/src/commands/guild/member.ts b/src/commands/guild/member.ts index 9714c71..ff2b4fd 100644 --- a/src/commands/guild/member.ts +++ b/src/commands/guild/member.ts @@ -16,7 +16,7 @@ export const memberSub = new SlashCommandSubcommandBuilder() .setRequired(true) ) -const cmd: SubCommand = async (interaction) => { +const cmd: SubCommand = async ({ interaction }) => { await interaction.deferReply() const ign = interaction.options.getString("ign")! diff --git a/src/commands/guild/top.ts b/src/commands/guild/top.ts index a4b6117..fdf3298 100644 --- a/src/commands/guild/top.ts +++ b/src/commands/guild/top.ts @@ -30,7 +30,7 @@ export const topSub = new SlashCommandSubcommandBuilder() .setDescription("The amount of guild members to show. [Default: 10]") ) -const cmd: SubCommand = async (interaction) => { +const cmd: SubCommand = async ({ interaction }) => { await interaction.deferReply() const query = interaction.options.getString("query")! diff --git a/src/commands/staff.ts b/src/commands/staff.ts index f970f86..85a11dd 100644 --- a/src/commands/staff.ts +++ b/src/commands/staff.ts @@ -29,27 +29,27 @@ export default { const subcommand = interaction.options.getSubcommand() if (subcommand === "help") { - help(interaction, client) + help({ interaction, client }) return } if (subcommand === "beast") { - beast(interaction) + beast({ interaction }) return } if (subcommand === "prune") { - prune(interaction) + prune({ interaction }) return } if (subcommand === "removeguildroles") { - removeGuildRoles(interaction) + removeGuildRoles({ interaction }) return } if (subcommand === "updateall") { - updateAll(interaction) + updateAll({ interaction }) return } diff --git a/src/commands/staff/beast.ts b/src/commands/staff/beast.ts index 2c08f96..6bdf69c 100644 --- a/src/commands/staff/beast.ts +++ b/src/commands/staff/beast.ts @@ -14,7 +14,7 @@ export const beastSub = new SlashCommandSubcommandBuilder() .setRequired(true) ) -const cmd: SubCommand = async (interaction) => { +const cmd: SubCommand = async ({ interaction }) => { await interaction.deferReply() const ign = interaction.options.getString("ign")! diff --git a/src/commands/staff/help.ts b/src/commands/staff/help.ts index af661d4..043943c 100644 --- a/src/commands/staff/help.ts +++ b/src/commands/staff/help.ts @@ -1,12 +1,12 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ComponentType, MessageFlags, SlashCommandSubcommandBuilder } from "discord.js" import { devMessage, embedColor } from "~/config/options" -import { SubCommmndClient } from "~/typings" +import { SubCommand } from "~/typings" export const helpSub = new SlashCommandSubcommandBuilder() .setName("help") .setDescription("Get help with staff commands") -const cmd: SubCommmndClient = async (interaction, client) => { +const cmd: SubCommand = async ({ interaction, client }) => { await interaction.deferReply() type CommandList = { diff --git a/src/commands/staff/prune.ts b/src/commands/staff/prune.ts index e740f8d..e7e99b5 100644 --- a/src/commands/staff/prune.ts +++ b/src/commands/staff/prune.ts @@ -7,7 +7,7 @@ export const pruneSub = new SlashCommandSubcommandBuilder() .setName("prune") .setDescription("Update the discord roles of all guild members") -const cmd: SubCommand = async (interaction) => { +const cmd: SubCommand = async ({ interaction }) => { await interaction.deferReply() if (interaction.user.id !== env.prod.DEV) { diff --git a/src/commands/staff/removeguildroles.ts b/src/commands/staff/removeguildroles.ts index 424b5cf..9a8ccbd 100644 --- a/src/commands/staff/removeguildroles.ts +++ b/src/commands/staff/removeguildroles.ts @@ -10,7 +10,7 @@ export const removeGuildRolesSub = new SlashCommandSubcommandBuilder() .setName("removeguildroles") .setDescription("Remove guild roles from non members") -const cmd: SubCommand = async (interaction) => { +const cmd: SubCommand = async ({ interaction }) => { await interaction.deferReply() const discordMember = interaction.member as GuildMember diff --git a/src/commands/staff/updateall.ts b/src/commands/staff/updateall.ts index 4710ef2..c98c888 100644 --- a/src/commands/staff/updateall.ts +++ b/src/commands/staff/updateall.ts @@ -12,7 +12,7 @@ export const updateAllSub = new SlashCommandSubcommandBuilder() .setName("updateall") .setDescription("Update the discord roles of all guild members") -const cmd: SubCommand = async (interaction) => { +const cmd: SubCommand = async ({ interaction }) => { await interaction.deferReply() const discordMember = interaction.member as GuildMember diff --git a/src/typings/SubCommand.ts b/src/typings/SubCommand.ts index a23e167..4a37636 100644 --- a/src/typings/SubCommand.ts +++ b/src/typings/SubCommand.ts @@ -1,5 +1,14 @@ import { ChatInputCommandInteraction } from "discord.js" import { ExtendedClient } from "~/utils/Client" -export type SubCommand = (interaction: ChatInputCommandInteraction) => Promise -export type SubCommmndClient = (interaction: ChatInputCommandInteraction, client: ExtendedClient) => Promise +type InteractionObject = { + interaction: ChatInputCommandInteraction +} + +type ClientObject = { + client: ExtendedClient +} + +type SubCommandObject = T extends true ? InteractionObject & ClientObject : InteractionObject + +export type SubCommand = (arg: SubCommandObject) => Promise