mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor!: Better application command mention format approach (#10639)
BREAKING CHANGE: The parameters of `chatInputApplicationCommandMention()` have been reordered.
This commit is contained in:
@@ -153,20 +153,20 @@ describe('Message formatters', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('chatInputApplicationCommandMention', () => {
|
describe('chatInputApplicationCommandMention', () => {
|
||||||
test('GIVEN commandName and commandId THEN returns "</[commandName]:[commandId]>"', () => {
|
test('GIVEN commandId and commandName THEN returns "</[commandName]:[commandId]>"', () => {
|
||||||
expect(chatInputApplicationCommandMention('airhorn', '815434166602170409')).toEqual(
|
expect(chatInputApplicationCommandMention('815434166602170409', 'airhorn')).toEqual(
|
||||||
'</airhorn:815434166602170409>',
|
'</airhorn:815434166602170409>',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GIVEN commandName, subcommandName, and commandId THEN returns "</[commandName] [subcommandName]:[commandId]>"', () => {
|
test('GIVEN commandId, commandName, subcommandName THEN returns "</[commandName] [subcommandName]:[commandId]>"', () => {
|
||||||
expect(chatInputApplicationCommandMention('airhorn', 'sub', '815434166602170409')).toEqual(
|
expect(chatInputApplicationCommandMention('815434166602170409', 'airhorn', 'sub')).toEqual(
|
||||||
'</airhorn sub:815434166602170409>',
|
'</airhorn sub:815434166602170409>',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('GIVEN commandName, subcommandGroupName, subcommandName, and commandId THEN returns "</[commandName] [subcommandGroupName] [subcommandName]:[commandId]>"', () => {
|
test('GIVEN commandId, commandName, subcommandName, and subcommandGroupName, THEN returns "</[commandName] [subcommandGroupName] [subcommandName]:[commandId]>"', () => {
|
||||||
expect(chatInputApplicationCommandMention('airhorn', 'group', 'sub', '815434166602170409')).toEqual(
|
expect(chatInputApplicationCommandMention('815434166602170409', 'airhorn', 'sub', 'group')).toEqual(
|
||||||
'</airhorn group sub:815434166602170409>',
|
'</airhorn group sub:815434166602170409>',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -225,85 +225,85 @@ export function linkedRoleMention<RoleId extends Snowflake>(roleId: RoleId): `<i
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats an application command name, subcommand group name, subcommand name, and id into an application command mention.
|
* Formats an application command name and id into an application command mention.
|
||||||
*
|
*
|
||||||
* @typeParam CommandName - This is inferred by the supplied command name
|
|
||||||
* @typeParam SubcommandGroupName - This is inferred by the supplied subcommand group name
|
|
||||||
* @typeParam SubcommandName - This is inferred by the supplied subcommand name
|
|
||||||
* @typeParam CommandId - This is inferred by the supplied command id
|
* @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
|
||||||
* @param subcommandGroupName - The subcommand group name to format
|
|
||||||
* @param subcommandName - The subcommand name to format
|
|
||||||
* @param commandId - The application command id to format
|
* @param commandId - The application command id to format
|
||||||
|
* @param commandName - The application command name to format
|
||||||
*/
|
*/
|
||||||
export function chatInputApplicationCommandMention<
|
export function chatInputApplicationCommandMention<CommandId extends Snowflake, CommandName extends string>(
|
||||||
CommandName extends string,
|
|
||||||
SubcommandGroupName extends string,
|
|
||||||
SubcommandName extends string,
|
|
||||||
CommandId extends Snowflake,
|
|
||||||
>(
|
|
||||||
commandName: CommandName,
|
|
||||||
subcommandGroupName: SubcommandGroupName,
|
|
||||||
subcommandName: SubcommandName,
|
|
||||||
commandId: CommandId,
|
commandId: CommandId,
|
||||||
): `</${CommandName} ${SubcommandGroupName} ${SubcommandName}:${CommandId}>`;
|
commandName: CommandName,
|
||||||
|
): `</${CommandName}:${CommandId}>`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats an application command name, subcommand name, and id into an application command mention.
|
* 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 CommandName - This is inferred by the supplied command name
|
||||||
* @typeParam SubcommandName - This is inferred by the supplied subcommand 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 commandName - The application command name to format
|
||||||
* @param subcommandName - The subcommand name to format
|
* @param subcommandName - The subcommand name to format
|
||||||
* @param commandId - The application command id to format
|
|
||||||
*/
|
*/
|
||||||
export function chatInputApplicationCommandMention<
|
export function chatInputApplicationCommandMention<
|
||||||
|
CommandId extends Snowflake,
|
||||||
CommandName extends string,
|
CommandName extends string,
|
||||||
SubcommandName extends string,
|
SubcommandName extends string,
|
||||||
CommandId extends Snowflake,
|
|
||||||
>(
|
>(
|
||||||
|
commandId: CommandId,
|
||||||
commandName: CommandName,
|
commandName: CommandName,
|
||||||
subcommandName: SubcommandName,
|
subcommandName: SubcommandName,
|
||||||
commandId: CommandId,
|
|
||||||
): `</${CommandName} ${SubcommandName}:${CommandId}>`;
|
): `</${CommandName} ${SubcommandName}:${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
|
* @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 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 extends string, CommandId extends Snowflake>(
|
export function chatInputApplicationCommandMention<
|
||||||
commandName: CommandName,
|
CommandId extends Snowflake,
|
||||||
|
CommandName extends string,
|
||||||
|
SubcommandName extends string,
|
||||||
|
SubcommandGroupName extends string,
|
||||||
|
>(
|
||||||
commandId: CommandId,
|
commandId: CommandId,
|
||||||
): `</${CommandName}:${CommandId}>`;
|
commandName: CommandName,
|
||||||
|
subcommandName: SubcommandName,
|
||||||
|
subcommandGroupName: SubcommandGroupName,
|
||||||
|
): `</${CommandName} ${SubcommandGroupName} ${SubcommandName}:${CommandId}>`;
|
||||||
|
|
||||||
export function chatInputApplicationCommandMention<
|
export function chatInputApplicationCommandMention<
|
||||||
CommandName extends string,
|
|
||||||
SubcommandGroupName extends Snowflake | string,
|
|
||||||
SubcommandName extends Snowflake | string,
|
|
||||||
CommandId extends Snowflake,
|
CommandId extends Snowflake,
|
||||||
|
CommandName extends string,
|
||||||
|
SubcommandName extends string,
|
||||||
|
SubcommandGroupName extends string,
|
||||||
>(
|
>(
|
||||||
|
commandId: CommandId,
|
||||||
commandName: CommandName,
|
commandName: CommandName,
|
||||||
subcommandGroupName: SubcommandGroupName,
|
subcommandName?: SubcommandName | undefined,
|
||||||
subcommandName?: SubcommandName,
|
subcommandGroupName?: SubcommandGroupName | undefined,
|
||||||
commandId?: CommandId,
|
|
||||||
):
|
):
|
||||||
| `</${CommandName} ${SubcommandGroupName} ${SubcommandName}:${CommandId}>`
|
| `</${CommandName} ${SubcommandGroupName} ${SubcommandName}:${CommandId}>`
|
||||||
| `</${CommandName} ${SubcommandGroupName}:${SubcommandName}>`
|
| `</${CommandName} ${SubcommandName}:${CommandId}>`
|
||||||
| `</${CommandName}:${SubcommandGroupName}>` {
|
| `</${CommandName}:${CommandId}>` {
|
||||||
if (commandId !== undefined) {
|
if (subcommandGroupName !== undefined && subcommandName !== undefined) {
|
||||||
return `</${commandName} ${subcommandGroupName} ${subcommandName!}:${commandId}>`;
|
return `</${commandName} ${subcommandGroupName} ${subcommandName}:${commandId}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subcommandName !== undefined) {
|
if (subcommandName !== undefined) {
|
||||||
return `</${commandName} ${subcommandGroupName}:${subcommandName}>`;
|
return `</${commandName} ${subcommandName}:${commandId}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `</${commandName}:${subcommandGroupName}>`;
|
return `</${commandName}:${commandId}>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user