Skip to content
This repository was archived by the owner on Jan 8, 2022. It is now read-only.

Commit 95599c5

Browse files
authored
refactor: sub command => subcommand (#18)
1 parent 34a1530 commit 95599c5

File tree

7 files changed

+95
-95
lines changed

7 files changed

+95
-95
lines changed

docs/examples/Slash Command Builders.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,20 @@ boopCommand.addIntegerOption((option) =>
4848
const rawData = boopCommand.toJSON();
4949
```
5050

51-
## Sub commands and sub command groups
51+
## Subcommands and subcommand groups
5252

5353
```ts
5454
import { SlashCommandBuilder } from '@discordjs/builders';
5555

5656
const pointsCommand = new SlashCommandBuilder().setName('points').setDescription('Lists or manages user points');
5757

5858
// Add a manage group
59-
pointsCommand.addSubCommandGroup((group) =>
59+
pointsCommand.addSubcommandGroup((group) =>
6060
group
6161
.setName('manage')
6262
.setDescription('Shows or manages points in the server')
63-
.addSubCommand((subCommand) =>
64-
subCommand
63+
.addSubcommand((subcommand) =>
64+
subcommand
6565
.setName('user_points')
6666
.setDescription("Alters a user's points")
6767
.addUserOption((option) =>
@@ -83,15 +83,15 @@ pointsCommand.addSubCommandGroup((group) =>
8383
);
8484

8585
// Add an information group
86-
pointsCommand.addSubCommandGroup((group) =>
86+
pointsCommand.addSubcommandGroup((group) =>
8787
group
8888
.setName('info')
8989
.setDescription('Shows information about points in the guild')
90-
.addSubCommand((subCommand) =>
91-
subCommand.setName('total').setDescription('Tells you the total amount of points given in the guild'),
90+
.addSubcommand((subcommand) =>
91+
subcommand.setName('total').setDescription('Tells you the total amount of points given in the guild'),
9292
)
93-
.addSubCommand((subCommand) =>
94-
subCommand
93+
.addSubcommand((subcommand) =>
94+
subcommand
9595
.setName('user')
9696
.setDescription("Lists a user's points")
9797
.addUserOption((option) =>

src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export * from './messages/formatters';
22

33
export * as SlashCommandAssertions from './interactions/slashCommands/Assertions';
44
export * from './interactions/slashCommands/SlashCommandBuilder';
5-
export * from './interactions/slashCommands/SlashCommandSubCommands';
5+
export * from './interactions/slashCommands/SlashCommandSubcommands';
66
export * from './interactions/slashCommands/options/boolean';
77
export * from './interactions/slashCommands/options/channel';
88
export * from './interactions/slashCommands/options/integer';

src/interactions/slashCommands/Assertions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { APIApplicationCommandOptionChoice } from 'discord-api-types/v9';
33
import ow from 'ow';
44
import type { SlashCommandOptionBase } from './mixins/CommandOptionBase';
55
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
6-
import type { SlashCommandSubCommandBuilder, SlashCommandSubCommandGroupBuilder } from './SlashCommandSubCommands';
6+
import type { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands';
77

88
export function validateRequiredParameters(
99
name: string,
@@ -49,7 +49,7 @@ export function validateMaxChoicesLength(choices: APIApplicationCommandOptionCho
4949
}
5050

5151
export function assertReturnOfBuilder<
52-
T extends SlashCommandOptionBase | SlashCommandSubCommandBuilder | SlashCommandSubCommandGroupBuilder,
52+
T extends SlashCommandOptionBase | SlashCommandSubcommandBuilder | SlashCommandSubcommandGroupBuilder,
5353
>(input: unknown, ExpectedInstanceOf: new () => T): asserts input is T {
5454
const instanceName = ExpectedInstanceOf.name;
5555

src/interactions/slashCommands/SlashCommandBuilder.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mix } from 'ts-mixer';
33
import { assertReturnOfBuilder, validateMaxOptionsLength, validateRequiredParameters } from './Assertions';
44
import { SharedNameAndDescription } from './mixins/NameAndDescription';
55
import { SharedSlashCommandOptions } from './mixins/CommandOptions';
6-
import { SlashCommandSubCommandBuilder, SlashCommandSubCommandGroupBuilder } from './SlashCommandSubCommands';
6+
import { SlashCommandSubcommandBuilder, SlashCommandSubcommandGroupBuilder } from './SlashCommandSubcommands';
77

88
@mix(SharedSlashCommandOptions, SharedNameAndDescription)
99
export class SlashCommandBuilder {
@@ -37,27 +37,27 @@ export class SlashCommandBuilder {
3737
}
3838

3939
/**
40-
* Adds a new sub command group to this command
41-
* @param input A function that returns a sub command group builder, or an already built builder
40+
* Adds a new subcommand group to this command
41+
* @param input A function that returns a subcommand group builder, or an already built builder
4242
*/
43-
public addSubCommandGroup(
43+
public addSubcommandGroup(
4444
input:
45-
| SlashCommandSubCommandGroupBuilder
46-
| ((subCommandGroup: SlashCommandSubCommandGroupBuilder) => SlashCommandSubCommandGroupBuilder),
47-
): SlashCommandSubCommandGroupsOnlyBuilder {
45+
| SlashCommandSubcommandGroupBuilder
46+
| ((subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder),
47+
): SlashCommandSubcommandGroupsOnlyBuilder {
4848
const { options } = this;
4949

5050
// First, assert options conditions - we cannot have more than 25 options
5151
validateMaxOptionsLength(options);
5252

53-
// Make sure there is no sub command at the root level - if there is, throw
54-
const hasSubCommands = options.some((item) => item instanceof SlashCommandSubCommandBuilder);
55-
if (hasSubCommands) throw new RangeError(`You cannot mix sub commands and sub command groups at the root level.`);
53+
// Make sure there is no subcommand at the root level - if there is, throw
54+
const hasSubcommands = options.some((item) => item instanceof SlashCommandSubcommandBuilder);
55+
if (hasSubcommands) throw new RangeError(`You cannot mix subcommands and subcommand groups at the root level.`);
5656

5757
// Get the final result
58-
const result = typeof input === 'function' ? input(new SlashCommandSubCommandGroupBuilder()) : input;
58+
const result = typeof input === 'function' ? input(new SlashCommandSubcommandGroupBuilder()) : input;
5959

60-
assertReturnOfBuilder(result, SlashCommandSubCommandGroupBuilder);
60+
assertReturnOfBuilder(result, SlashCommandSubcommandGroupBuilder);
6161

6262
// Push it
6363
options.push(result);
@@ -66,28 +66,28 @@ export class SlashCommandBuilder {
6666
}
6767

6868
/**
69-
* Adds a new sub command to this command
70-
* @param input A function that returns a sub command builder, or an already built builder
69+
* Adds a new subcommand to this command
70+
* @param input A function that returns a subcommand builder, or an already built builder
7171
*/
72-
public addSubCommand(
72+
public addSubcommand(
7373
input:
74-
| SlashCommandSubCommandBuilder
75-
| ((subCommandGroup: SlashCommandSubCommandBuilder) => SlashCommandSubCommandBuilder),
76-
): SlashCommandSubCommandsOnlyBuilder {
74+
| SlashCommandSubcommandBuilder
75+
| ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder),
76+
): SlashCommandSubcommandsOnlyBuilder {
7777
const { options } = this;
7878

7979
// First, assert options conditions - we cannot have more than 25 options
8080
validateMaxOptionsLength(options);
8181

82-
// Make sure there is no sub command at the root level - if there is, throw
83-
const hasSubCommandGroups = options.some((item) => item instanceof SlashCommandSubCommandGroupBuilder);
84-
if (hasSubCommandGroups)
85-
throw new RangeError(`You cannot mix sub commands and sub command groups at the root level.`);
82+
// Make sure there is no subcommand at the root level - if there is, throw
83+
const hasSubcommandGroups = options.some((item) => item instanceof SlashCommandSubcommandGroupBuilder);
84+
if (hasSubcommandGroups)
85+
throw new RangeError(`You cannot mix subcommands and subcommand groups at the root level.`);
8686

8787
// Get the final result
88-
const result = typeof input === 'function' ? input(new SlashCommandSubCommandBuilder()) : input;
88+
const result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;
8989

90-
assertReturnOfBuilder(result, SlashCommandSubCommandBuilder);
90+
assertReturnOfBuilder(result, SlashCommandSubcommandBuilder);
9191

9292
// Push it
9393
options.push(result);
@@ -98,13 +98,13 @@ export class SlashCommandBuilder {
9898

9999
export interface SlashCommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions {}
100100

101-
export interface SlashCommandSubCommandsOnlyBuilder
101+
export interface SlashCommandSubcommandsOnlyBuilder
102102
extends SharedNameAndDescription,
103-
Pick<SlashCommandBuilder, 'toJSON' | 'addSubCommand'> {}
103+
Pick<SlashCommandBuilder, 'toJSON' | 'addSubcommand'> {}
104104

105-
export interface SlashCommandSubCommandGroupsOnlyBuilder
105+
export interface SlashCommandSubcommandGroupsOnlyBuilder
106106
extends SharedNameAndDescription,
107-
Pick<SlashCommandBuilder, 'toJSON' | 'addSubCommandGroup'> {}
107+
Pick<SlashCommandBuilder, 'toJSON' | 'addSubcommandGroup'> {}
108108

109109
export interface SlashCommandOptionsOnlyBuilder
110110
extends SharedNameAndDescription,

src/interactions/slashCommands/SlashCommandSubCommands.ts src/interactions/slashCommands/SlashCommandSubcommands.ts

+19-19
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,45 @@ import { SharedNameAndDescription } from './mixins/NameAndDescription';
66
import type { ToAPIApplicationCommandOptions } from './SlashCommandBuilder';
77

88
/**
9-
* Represents a folder for sub commands
9+
* Represents a folder for subcommands
1010
*
1111
* For more information, go to https://discord.com/developers/docs/interactions/slash-commands#subcommands-and-subcommand-groups
1212
*/
1313
@mix(SharedNameAndDescription)
14-
export class SlashCommandSubCommandGroupBuilder implements ToAPIApplicationCommandOptions {
14+
export class SlashCommandSubcommandGroupBuilder implements ToAPIApplicationCommandOptions {
1515
/**
16-
* The name of this sub command group
16+
* The name of this subcommand group
1717
*/
1818
public readonly name: string = undefined!;
1919

2020
/**
21-
* The description of this sub command group
21+
* The description of this subcommand group
2222
*/
2323
public readonly description: string = undefined!;
2424

2525
/**
26-
* The sub commands part of this sub command group
26+
* The subcommands part of this subcommand group
2727
*/
2828
public readonly options: ToAPIApplicationCommandOptions[] = [];
2929

3030
/**
31-
* Adds a new sub command to this group
32-
* @param input A function that returns a sub command builder, or an already built builder
31+
* Adds a new subcommand to this group
32+
* @param input A function that returns a subcommand builder, or an already built builder
3333
*/
34-
public addSubCommand(
34+
public addSubcommand(
3535
input:
36-
| SlashCommandSubCommandBuilder
37-
| ((subCommandGroup: SlashCommandSubCommandBuilder) => SlashCommandSubCommandBuilder),
36+
| SlashCommandSubcommandBuilder
37+
| ((subcommandGroup: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder),
3838
) {
3939
const { options } = this;
4040

4141
// First, assert options conditions - we cannot have more than 25 options
4242
validateMaxOptionsLength(options);
4343

4444
// Get the final result
45-
const result = typeof input === 'function' ? input(new SlashCommandSubCommandBuilder()) : input;
45+
const result = typeof input === 'function' ? input(new SlashCommandSubcommandBuilder()) : input;
4646

47-
assertReturnOfBuilder(result, SlashCommandSubCommandBuilder);
47+
assertReturnOfBuilder(result, SlashCommandSubcommandBuilder);
4848

4949
// Push it
5050
options.push(result);
@@ -63,27 +63,27 @@ export class SlashCommandSubCommandGroupBuilder implements ToAPIApplicationComma
6363
}
6464
}
6565

66-
export interface SlashCommandSubCommandGroupBuilder extends SharedNameAndDescription {}
66+
export interface SlashCommandSubcommandGroupBuilder extends SharedNameAndDescription {}
6767

6868
/**
69-
* Represents a sub command
69+
* Represents a subcommand
7070
*
7171
* For more information, go to https://discord.com/developers/docs/interactions/slash-commands#subcommands-and-subcommand-groups
7272
*/
7373
@mix(SharedNameAndDescription, SharedSlashCommandOptions)
74-
export class SlashCommandSubCommandBuilder implements ToAPIApplicationCommandOptions {
74+
export class SlashCommandSubcommandBuilder implements ToAPIApplicationCommandOptions {
7575
/**
76-
* The name of this sub command
76+
* The name of this subcommand
7777
*/
7878
public readonly name: string = undefined!;
7979

8080
/**
81-
* The description of this sub command
81+
* The description of this subcommand
8282
*/
8383
public readonly description: string = undefined!;
8484

8585
/**
86-
* The options of this sub command
86+
* The options of this subcommand
8787
*/
8888
public readonly options: ToAPIApplicationCommandOptions[] = [];
8989

@@ -98,4 +98,4 @@ export class SlashCommandSubCommandBuilder implements ToAPIApplicationCommandOpt
9898
}
9999
}
100100

101-
export interface SlashCommandSubCommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions<false> {}
101+
export interface SlashCommandSubcommandBuilder extends SharedNameAndDescription, SharedSlashCommandOptions<false> {}

src/interactions/slashCommands/mixins/CommandOptions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { SlashCommandStringOption } from '../options/string';
99
import { SlashCommandUserOption } from '../options/user';
1010
import type { ToAPIApplicationCommandOptions } from '../SlashCommandBuilder';
1111

12-
export class SharedSlashCommandOptions<ShouldOmitSubCommandFunctions = true> {
12+
export class SharedSlashCommandOptions<ShouldOmitSubcommandFunctions = true> {
1313
public readonly options!: ToAPIApplicationCommandOptions[];
1414

1515
/**
@@ -81,7 +81,7 @@ export class SharedSlashCommandOptions<ShouldOmitSubCommandFunctions = true> {
8181
private _sharedAddOptionMethod<T extends SlashCommandOptionBase>(
8282
input: T | ((builder: T) => T),
8383
Instance: new () => T,
84-
): ShouldOmitSubCommandFunctions extends true ? Omit<this, 'addSubCommand' | 'addSubCommandGroup'> : this {
84+
): ShouldOmitSubcommandFunctions extends true ? Omit<this, 'addSubcommand' | 'addSubcommandGroup'> : this {
8585
const { options } = this;
8686

8787
// First, assert options conditions - we cannot have more than 25 options

0 commit comments

Comments
 (0)