From a69e2f79043117eb1ce52b98e4c0a5c58f18d6ea Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Thu, 29 Jul 2021 11:52:06 +0100 Subject: [PATCH] refactor: Match subcommand (group) name casing with Discord's (#6204) --- src/errors/Messages.js | 4 +-- .../CommandInteractionOptionResolver.js | 34 +++++++++---------- typings/index.d.ts | 10 +++--- typings/index.ts | 18 +++++----- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index ed5b98e6814e..ec74e261c9d4 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -138,8 +138,8 @@ const Messages = { `Option "${name}" is of type: ${type}; expected ${expected}.`, COMMAND_INTERACTION_OPTION_EMPTY: (name, type) => `Required option "${name}" is of type: ${type}; expected a non-empty value.`, - COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND: 'No sub-command specified for interaction.', - COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP: 'No sub-command group specified for interaction.', + COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND: 'No subcommand specified for interaction.', + COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP: 'No subcommand group specified for interaction.', INVITE_MISSING_SCOPES: 'At least one valid scope must be provided for the invite', diff --git a/src/structures/CommandInteractionOptionResolver.js b/src/structures/CommandInteractionOptionResolver.js index 02cf5874c071..920054efbae2 100644 --- a/src/structures/CommandInteractionOptionResolver.js +++ b/src/structures/CommandInteractionOptionResolver.js @@ -16,35 +16,35 @@ class CommandInteractionOptionResolver { Object.defineProperty(this, 'client', { value: client }); /** - * The name of the sub-command group. + * The name of the subcommand group. * @type {?string} * @private */ this._group = null; /** - * The name of the sub-command. + * The name of the subcommand. * @type {?string} * @private */ - this._subCommand = null; + this._subcommand = null; /** * The bottom-level options for the interaction. - * If there is a sub-command (or sub-command and group), this is the options for the sub-command. + * If there is a subcommand (or subcommand and group), this is the options for the subcommand. * @type {CommandInteractionOption[]} * @private */ this._hoistedOptions = options; - // Hoist sub-command group if present + // Hoist subcommand group if present if (this._hoistedOptions[0]?.type === 'SUB_COMMAND_GROUP') { this._group = this._hoistedOptions[0].name; this._hoistedOptions = this._hoistedOptions[0].options ?? []; } - // Hoist sub-command if present + // Hoist subcommand if present if (this._hoistedOptions[0]?.type === 'SUB_COMMAND') { - this._subCommand = this._hoistedOptions[0].name; + this._subcommand = this._hoistedOptions[0].name; this._hoistedOptions = this._hoistedOptions[0].options ?? []; } @@ -96,23 +96,23 @@ class CommandInteractionOptionResolver { } /** - * Gets the selected sub-command. - * @param {boolean} [required=true] Whether to throw an error if there is no sub-command. - * @returns {?string} The name of the selected sub-command, or null if not set and not required. + * Gets the selected subcommand. + * @param {boolean} [required=true] Whether to throw an error if there is no subcommand. + * @returns {?string} The name of the selected subcommand, or null if not set and not required. */ - getSubCommand(required = true) { - if (required && !this._subCommand) { + getSubcommand(required = true) { + if (required && !this._subcommand) { throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND'); } - return this._subCommand; + return this._subcommand; } /** - * Gets the selected sub-command group. - * @param {boolean} [required=true] Whether to throw an error if there is no sub-command group. - * @returns {?string} The name of the selected sub-command group, or null if not set and not required. + * Gets the selected subcommand group. + * @param {boolean} [required=true] Whether to throw an error if there is no subcommand group. + * @returns {?string} The name of the selected subcommand group, or null if not set and not required. */ - getSubCommandGroup(required = true) { + getSubcommandGroup(required = true) { if (required && !this._group) { throw new TypeError('COMMAND_INTERACTION_OPTION_NO_SUB_COMMAND_GROUP'); } diff --git a/typings/index.d.ts b/typings/index.d.ts index a0a6ddc05104..99f3b0f0dc54 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -431,7 +431,7 @@ export class CommandInteractionOptionResolver { public readonly data: readonly CommandInteractionOption[]; private _group: string | null; private _hoistedOptions: CommandInteractionOption[]; - private _subCommand: string | null; + private _subcommand: string | null; private _getTypedOption( name: string, type: ApplicationCommandOptionType, @@ -448,10 +448,10 @@ export class CommandInteractionOptionResolver { public get(name: string, required: true): CommandInteractionOption; public get(name: string, required?: boolean): CommandInteractionOption | null; - public getSubCommand(required?: true): string; - public getSubCommand(required: boolean): string | null; - public getSubCommandGroup(required?: true): string; - public getSubCommandGroup(required: boolean): string | null; + public getSubcommand(required?: true): string; + public getSubcommand(required: boolean): string | null; + public getSubcommandGroup(required?: true): string; + public getSubcommandGroup(required: boolean): string | null; public getBoolean(name: string, required: true): boolean; public getBoolean(name: string, required?: boolean): boolean | null; public getChannel(name: string, required: true): NonNullable; diff --git a/typings/index.ts b/typings/index.ts index 6cdc2d4c478c..4183866ff03a 100644 --- a/typings/index.ts +++ b/typings/index.ts @@ -668,14 +668,14 @@ client.on('interactionCreate', async interaction => { assertType(interaction.options.getString('name', false)); assertType(interaction.options.getString('name', true)); - assertType(interaction.options.getSubCommand()); - assertType(interaction.options.getSubCommand(true)); - assertType(interaction.options.getSubCommand(booleanValue)); - assertType(interaction.options.getSubCommand(false)); - - assertType(interaction.options.getSubCommandGroup()); - assertType(interaction.options.getSubCommandGroup(true)); - assertType(interaction.options.getSubCommandGroup(booleanValue)); - assertType(interaction.options.getSubCommandGroup(false)); + assertType(interaction.options.getSubcommand()); + assertType(interaction.options.getSubcommand(true)); + assertType(interaction.options.getSubcommand(booleanValue)); + assertType(interaction.options.getSubcommand(false)); + + assertType(interaction.options.getSubcommandGroup()); + assertType(interaction.options.getSubcommandGroup(true)); + assertType(interaction.options.getSubcommandGroup(booleanValue)); + assertType(interaction.options.getSubcommandGroup(false)); } });