docs: add missing, fix existing (#10842)

* docs: add missing, fix existing

* refactor: new stuff

* fix: requested changes

* fix: use `@link` for `@mixes`

Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>

* chore: disable bad eslint rule

---------

Co-authored-by: Qjuh <76154676+Qjuh@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Almeida
2025-06-02 18:35:43 +01:00
committed by GitHub
parent 8d50e92516
commit e094faf225
62 changed files with 377 additions and 139 deletions

View File

@@ -16,9 +16,17 @@ export interface CommandData
>
> {}
/**
* The base class for all command builders.
*/
export abstract class CommandBuilder<Command extends RESTPostAPIApplicationCommandsJSONBody>
implements JSONEncodable<Command>
{
/**
* The API data associated with this command.
*
* @internal
*/
declare protected readonly data: CommandData;
/**

View File

@@ -7,6 +7,9 @@ export interface SharedNameData
* This mixin holds name and description symbols for chat input commands.
*/
export class SharedName {
/**
* @internal
*/
protected readonly data: SharedNameData = {};
/**

View File

@@ -10,6 +10,9 @@ export interface SharedNameAndDescriptionData
* This mixin holds name and description symbols for chat input commands.
*/
export class SharedNameAndDescription extends SharedName {
/**
* @internal
*/
protected override readonly data: SharedNameAndDescriptionData = {};
/**

View File

@@ -1,4 +1,3 @@
/* eslint-disable jsdoc/valid-types */
import { ApplicationCommandType, type RESTPostAPIChatInputApplicationCommandsJSONBody } from 'discord-api-types/v10';
import { Mixin } from 'ts-mixer';
import { validate } from '../../../util/validation.js';

View File

@@ -26,8 +26,16 @@ export class ChatInputCommandSubcommandGroupBuilder
extends SharedNameAndDescription
implements JSONEncodable<APIApplicationCommandSubcommandGroupOption>
{
/**
* The API data associated with this subcommand group.
*
* @internal
*/
declare protected readonly data: ChatInputCommandSubcommandGroupData & SharedNameAndDescriptionData;
/**
* The options within this subcommand group.
*/
public get options(): readonly ChatInputCommandSubcommandBuilder[] {
return (this.data.options ??= []);
}
@@ -78,6 +86,8 @@ export class ChatInputCommandSubcommandGroupBuilder
/**
* A builder that creates API-compatible JSON data for chat input command subcommands.
*
* @mixes {@link SharedNameAndDescription}
* @mixes {@link SharedChatInputCommandOptions}
* @see {@link https://discord.com/developers/docs/interactions/application-commands#subcommands-and-subcommand-groups}
*/
export class ChatInputCommandSubcommandBuilder

View File

@@ -7,6 +7,9 @@ export interface ApplicationCommandNumericOptionMinMaxValueData
* This mixin holds minimum and maximum symbols used for options.
*/
export abstract class ApplicationCommandNumericOptionMinMaxValueMixin {
/**
* @internal
*/
declare protected readonly data: ApplicationCommandNumericOptionMinMaxValueData;
/**

View File

@@ -26,6 +26,9 @@ export interface ApplicationCommandOptionChannelTypesData
* This mixin holds channel type symbols used for options.
*/
export class ApplicationCommandOptionChannelTypesMixin {
/**
* @internal
*/
declare protected readonly data: ApplicationCommandOptionChannelTypesData;
/**

View File

@@ -15,6 +15,9 @@ export interface ApplicationCommandOptionWithAutocompleteData extends Pick<Autoc
* This mixin holds choices and autocomplete symbols used for options.
*/
export class ApplicationCommandOptionWithAutocompleteMixin {
/**
* @internal
*/
declare protected readonly data: ApplicationCommandOptionWithAutocompleteData;
/**

View File

@@ -8,8 +8,13 @@ export interface ApplicationCommandOptionWithChoicesData {
/**
* This mixin holds choices and autocomplete symbols used for options.
*
* @typeParam ChoiceType - The type of the choices within this option
*/
export class ApplicationCommandOptionWithChoicesMixin<ChoiceType extends number | string> {
/**
* @internal
*/
declare protected readonly data: ApplicationCommandOptionWithChoicesData;
/**

View File

@@ -17,12 +17,16 @@ export interface SharedChatInputCommandOptionsData {
/**
* This mixin holds symbols that can be shared in chat input command options.
*
* @typeParam TypeAfterAddingOptions - The type this class should return after adding an option.
*/
export class SharedChatInputCommandOptions {
/**
* @internal
*/
declare protected readonly data: SharedChatInputCommandOptionsData;
/**
* The options within this command.
*/
public get options(): readonly ApplicationCommandOptionBase[] {
return (this.data.options ??= []);
}

View File

@@ -12,10 +12,11 @@ export interface SharedChatInputCommandSubcommandsData {
/**
* This mixin holds symbols that can be shared in chat input subcommands.
*
* @typeParam TypeAfterAddingSubcommands - The type this class should return after adding a subcommand or subcommand group.
*/
export class SharedChatInputCommandSubcommands {
/**
* @internal
*/
declare protected readonly data: SharedChatInputCommandSubcommandsData;
/**

View File

@@ -21,10 +21,21 @@ export abstract class ApplicationCommandOptionBase
extends SharedNameAndDescription
implements JSONEncodable<APIApplicationCommandBasicOption>
{
/**
* @internal
*/
protected static readonly predicate: z.ZodTypeAny = basicOptionPredicate;
/**
* @internal
*/
declare protected readonly data: ApplicationCommandOptionBaseData & SharedNameAndDescriptionData;
/**
* Creates a new application command option builder.
*
* @param type - The type of the option
*/
public constructor(type: ApplicationCommandOptionType) {
super();
this.data.type = type;

View File

@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
* A chat input command attachment option.
*/
export class ChatInputCommandAttachmentOption extends ApplicationCommandOptionBase {
/**
* Creates a new attachment option.
*/
public constructor() {
super(ApplicationCommandOptionType.Attachment);
}

View File

@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
* A chat input command boolean option.
*/
export class ChatInputCommandBooleanOption extends ApplicationCommandOptionBase {
/**
* Creates a new boolean option.
*/
public constructor() {
super(ApplicationCommandOptionType.Boolean);
}

View File

@@ -6,13 +6,22 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
/**
* A chat input command channel option.
*
* @mixes {@link ApplicationCommandOptionBase}
* @mixes {@link ApplicationCommandOptionChannelTypesMixin}
*/
export class ChatInputCommandChannelOption extends Mixin(
ApplicationCommandOptionBase,
ApplicationCommandOptionChannelTypesMixin,
) {
/**
* @internal
*/
protected static override readonly predicate = channelOptionPredicate;
/**
* Creates a new channel option.
*/
public constructor() {
super(ApplicationCommandOptionType.Channel);
}

View File

@@ -8,6 +8,11 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
/**
* A chat input command integer option.
*
* @mixes {@link ApplicationCommandOptionBase}
* @mixes {@link ApplicationCommandNumericOptionMinMaxValueMixin}
* @mixes {@link ApplicationCommandOptionWithAutocompleteMixin}
* @mixes {@link ApplicationCommandOptionWithChoicesMixin}\<number\>
*/
export class ChatInputCommandIntegerOption extends Mixin(
ApplicationCommandOptionBase,
@@ -15,8 +20,14 @@ export class ChatInputCommandIntegerOption extends Mixin(
ApplicationCommandOptionWithAutocompleteMixin,
ApplicationCommandOptionWithChoicesMixin<number>,
) {
/**
* @internal
*/
protected static override readonly predicate = integerOptionPredicate;
/**
* Creates a new integer option.
*/
public constructor() {
super(ApplicationCommandOptionType.Integer);
}

View File

@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
* A chat input command mentionable option.
*/
export class ChatInputCommandMentionableOption extends ApplicationCommandOptionBase {
/**
* Creates a new mentionable option.
*/
public constructor() {
super(ApplicationCommandOptionType.Mentionable);
}

View File

@@ -8,6 +8,11 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
/**
* A chat input command number option.
*
* @mixes {@link ApplicationCommandOptionBase}
* @mixes {@link ApplicationCommandNumericOptionMinMaxValueMixin}
* @mixes {@link ApplicationCommandOptionWithAutocompleteMixin}
* @mixes {@link ApplicationCommandOptionWithChoicesMixin}\<number\>
*/
export class ChatInputCommandNumberOption extends Mixin(
ApplicationCommandOptionBase,
@@ -15,8 +20,14 @@ export class ChatInputCommandNumberOption extends Mixin(
ApplicationCommandOptionWithAutocompleteMixin,
ApplicationCommandOptionWithChoicesMixin<number>,
) {
/**
* @internal
*/
protected static override readonly predicate = numberOptionPredicate;
/**
* Creates a new number option.
*/
public constructor() {
super(ApplicationCommandOptionType.Number);
}

View File

@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
* A chat input command role option.
*/
export class ChatInputCommandRoleOption extends ApplicationCommandOptionBase {
/**
* Creates a new role option.
*/
public constructor() {
super(ApplicationCommandOptionType.Role);
}

View File

@@ -10,19 +10,32 @@ import type { ApplicationCommandOptionBaseData } from './ApplicationCommandOptio
/**
* A chat input command string option.
*
* @mixes {@link ApplicationCommandOptionBase}
* @mixes {@link ApplicationCommandOptionWithAutocompleteMixin}
* @mixes {@link ApplicationCommandOptionWithChoicesMixin}\<string\>
*/
export class ChatInputCommandStringOption extends Mixin(
ApplicationCommandOptionBase,
ApplicationCommandOptionWithAutocompleteMixin,
ApplicationCommandOptionWithChoicesMixin<string>,
) {
/**
* @internal
*/
protected static override readonly predicate = stringOptionPredicate;
/**
* @internal
*/
declare protected readonly data: ApplicationCommandOptionBaseData &
ApplicationCommandOptionWithAutocompleteData &
ApplicationCommandOptionWithChoicesData &
Partial<Pick<APIApplicationCommandStringOption, 'max_length' | 'min_length'>>;
/**
* Creates a new string option builder.
*/
public constructor() {
super(ApplicationCommandOptionType.String);
}

View File

@@ -5,6 +5,9 @@ import { ApplicationCommandOptionBase } from './ApplicationCommandOptionBase.js'
* A chat input command user option.
*/
export class ChatInputCommandUserOption extends ApplicationCommandOptionBase {
/**
* Creates a new user option.
*/
public constructor() {
super(ApplicationCommandOptionType.User);
}

View File

@@ -10,13 +10,26 @@ export type ContextMenuCommandType = ApplicationCommandType.Message | Applicatio
/**
* A builder that creates API-compatible JSON data for context menu commands.
*
* @mixes {@link CommandBuilder}\<{@link discord-api-types/v10#(RESTPostAPIContextMenuApplicationCommandsJSONBody:interface)}\>
* @mixes {@link SharedName}
*/
export abstract class ContextMenuCommandBuilder extends Mixin(
CommandBuilder<RESTPostAPIContextMenuApplicationCommandsJSONBody>,
SharedName,
) {
/**
* The API data associated with this context menu command.
*
* @internal
*/
protected override readonly data: Partial<RESTPostAPIContextMenuApplicationCommandsJSONBody>;
/**
* Creates a new context menu command.
*
* @param data - The API data to create this context menu command with
*/
public constructor(data: Partial<RESTPostAPIContextMenuApplicationCommandsJSONBody> = {}) {
super();
this.data = structuredClone(data);

View File

@@ -3,6 +3,9 @@ import { validate } from '../../../util/validation.js';
import { messageCommandPredicate } from './Assertions.js';
import { ContextMenuCommandBuilder } from './ContextMenuCommand.js';
/**
* A builder that creates API-compatible JSON data for message context menu commands.
*/
export class MessageContextCommandBuilder extends ContextMenuCommandBuilder {
/**
* {@inheritDoc CommandBuilder.toJSON}

View File

@@ -3,6 +3,9 @@ import { validate } from '../../../util/validation.js';
import { userCommandPredicate } from './Assertions.js';
import { ContextMenuCommandBuilder } from './ContextMenuCommand.js';
/**
* A builder that creates API-compatible JSON data for user context menu commands.
*/
export class UserContextCommandBuilder extends ContextMenuCommandBuilder {
/**
* {@inheritDoc CommandBuilder.toJSON}

View File

@@ -1,5 +1,3 @@
/* eslint-disable jsdoc/check-param-names */
import type { JSONEncodable } from '@discordjs/util';
import type {
APIActionRowComponent,
@@ -34,13 +32,15 @@ export class ModalBuilder implements JSONEncodable<APIModalInteractionResponseCa
}
/**
* Creates a new modal from API data.
* Creates a new modal.
*
* @param data - The API data to create this modal with
*/
public constructor({ components = [], ...data }: Partial<APIModalInteractionResponseCallbackData> = {}) {
public constructor(data: Partial<APIModalInteractionResponseCallbackData> = {}) {
const { components = [], ...rest } = data;
this.data = {
...structuredClone(data),
...structuredClone(rest),
components: components.map((component) => createComponentBuilder(component)),
};
}