Skip to content

Commit

Permalink
refactor: Match subcommand (group) name casing with Discord's (#6204)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiralite authored Jul 29, 2021
1 parent 4beb647 commit a69e2f7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',

Expand Down
34 changes: 17 additions & 17 deletions src/structures/CommandInteractionOptionResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? [];
}

Expand Down Expand Up @@ -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');
}
Expand Down
10 changes: 5 additions & 5 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<CommandInteractionOption['channel']>;
Expand Down
18 changes: 9 additions & 9 deletions typings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,14 +668,14 @@ client.on('interactionCreate', async interaction => {
assertType<string | null>(interaction.options.getString('name', false));
assertType<string>(interaction.options.getString('name', true));

assertType<string>(interaction.options.getSubCommand());
assertType<string>(interaction.options.getSubCommand(true));
assertType<string | null>(interaction.options.getSubCommand(booleanValue));
assertType<string | null>(interaction.options.getSubCommand(false));

assertType<string>(interaction.options.getSubCommandGroup());
assertType<string>(interaction.options.getSubCommandGroup(true));
assertType<string | null>(interaction.options.getSubCommandGroup(booleanValue));
assertType<string | null>(interaction.options.getSubCommandGroup(false));
assertType<string>(interaction.options.getSubcommand());
assertType<string>(interaction.options.getSubcommand(true));
assertType<string | null>(interaction.options.getSubcommand(booleanValue));
assertType<string | null>(interaction.options.getSubcommand(false));

assertType<string>(interaction.options.getSubcommandGroup());
assertType<string>(interaction.options.getSubcommandGroup(true));
assertType<string | null>(interaction.options.getSubcommandGroup(booleanValue));
assertType<string | null>(interaction.options.getSubcommandGroup(false));
}
});

0 comments on commit a69e2f7

Please sign in to comment.