From 3ddb73287bb1c834c25e19de847b5dfa193b75f9 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Sun, 12 Jan 2025 20:09:03 +0000 Subject: [PATCH] refactor!: Better application command mention format approach (#10639) BREAKING CHANGE: The parameters of `chatInputApplicationCommandMention()` have been reordered. --- .../formatters/__tests__/formatters.test.ts | 12 +-- packages/formatters/src/formatters.ts | 78 +++++++++---------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/packages/formatters/__tests__/formatters.test.ts b/packages/formatters/__tests__/formatters.test.ts index c91f4c694..628683813 100644 --- a/packages/formatters/__tests__/formatters.test.ts +++ b/packages/formatters/__tests__/formatters.test.ts @@ -153,20 +153,20 @@ describe('Message formatters', () => { }); describe('chatInputApplicationCommandMention', () => { - test('GIVEN commandName and commandId THEN returns ""', () => { - expect(chatInputApplicationCommandMention('airhorn', '815434166602170409')).toEqual( + test('GIVEN commandId and commandName THEN returns ""', () => { + expect(chatInputApplicationCommandMention('815434166602170409', 'airhorn')).toEqual( '', ); }); - test('GIVEN commandName, subcommandName, and commandId THEN returns ""', () => { - expect(chatInputApplicationCommandMention('airhorn', 'sub', '815434166602170409')).toEqual( + test('GIVEN commandId, commandName, subcommandName THEN returns ""', () => { + expect(chatInputApplicationCommandMention('815434166602170409', 'airhorn', 'sub')).toEqual( '', ); }); - test('GIVEN commandName, subcommandGroupName, subcommandName, and commandId THEN returns ""', () => { - expect(chatInputApplicationCommandMention('airhorn', 'group', 'sub', '815434166602170409')).toEqual( + test('GIVEN commandId, commandName, subcommandName, and subcommandGroupName, THEN returns ""', () => { + expect(chatInputApplicationCommandMention('815434166602170409', 'airhorn', 'sub', 'group')).toEqual( '', ); }); diff --git a/packages/formatters/src/formatters.ts b/packages/formatters/src/formatters.ts index 65c7af555..22914c368 100644 --- a/packages/formatters/src/formatters.ts +++ b/packages/formatters/src/formatters.ts @@ -225,85 +225,85 @@ export function linkedRoleMention(roleId: RoleId): `( - commandName: CommandName, - subcommandGroupName: SubcommandGroupName, - subcommandName: SubcommandName, +export function chatInputApplicationCommandMention( commandId: CommandId, -): ``; + commandName: CommandName, +): ``; /** * Formats an application command name, subcommand name, and id into an application command mention. * + * @typeParam CommandId - This is inferred by the supplied command id * @typeParam CommandName - This is inferred by the supplied command name * @typeParam SubcommandName - This is inferred by the supplied subcommand name - * @typeParam CommandId - This is inferred by the supplied command id + * @param commandId - The application command id to format * @param commandName - The application command name to format * @param subcommandName - The subcommand name to format - * @param commandId - The application command id to format */ export function chatInputApplicationCommandMention< + CommandId extends Snowflake, CommandName extends string, SubcommandName extends string, - CommandId extends Snowflake, >( + commandId: CommandId, commandName: CommandName, subcommandName: SubcommandName, - commandId: CommandId, ): ``; /** - * Formats an application command name and id into an application command mention. + * Formats an application command name, subcommand group name, subcommand name, and id into an application command mention. * - * @typeParam CommandName - This is inferred by the supplied command name * @typeParam CommandId - This is inferred by the supplied command id - * @param commandName - The application command name to format + * @typeParam CommandName - This is inferred by the supplied command name + * @typeParam SubcommandName - This is inferred by the supplied subcommand name + * @typeParam SubcommandGroupName - This is inferred by the supplied subcommand group name * @param commandId - The application command id to format + * @param commandName - The application command name to format + * @param subcommandName - The subcommand name to format + * @param subcommandGroupName - The subcommand group name to format */ -export function chatInputApplicationCommandMention( - commandName: CommandName, +export function chatInputApplicationCommandMention< + CommandId extends Snowflake, + CommandName extends string, + SubcommandName extends string, + SubcommandGroupName extends string, +>( commandId: CommandId, -): ``; + commandName: CommandName, + subcommandName: SubcommandName, + subcommandGroupName: SubcommandGroupName, +): ``; export function chatInputApplicationCommandMention< - CommandName extends string, - SubcommandGroupName extends Snowflake | string, - SubcommandName extends Snowflake | string, CommandId extends Snowflake, + CommandName extends string, + SubcommandName extends string, + SubcommandGroupName extends string, >( + commandId: CommandId, commandName: CommandName, - subcommandGroupName: SubcommandGroupName, - subcommandName?: SubcommandName, - commandId?: CommandId, + subcommandName?: SubcommandName | undefined, + subcommandGroupName?: SubcommandGroupName | undefined, ): | `` - | `` - | `` { - if (commandId !== undefined) { - return ``; + | `` + | `` { + if (subcommandGroupName !== undefined && subcommandName !== undefined) { + return ``; } if (subcommandName !== undefined) { - return ``; + return ``; } - return ``; + return ``; } /**