Skip to content

Commit

Permalink
fix(docs): make callback response docs readable
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Sep 17, 2024
1 parent 6bdbfbc commit 8b04627
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 51 deletions.
62 changes: 36 additions & 26 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ export interface AutocompleteData {
*/
export type CommandAutocompleteRequestData = DMCommandAutocompleteRequestData | GuildCommandAutocompleteRequestData;

/* @private **/
/** @private */
export interface InteractionCallbackResponse {
interaction: {
id: string;
Expand Down Expand Up @@ -870,33 +870,43 @@ export interface CommandSubcommandOption {
}

/** The response to the initial interaction callback. */
export interface InitialInteractionResponse {
export interface InitialCallbackResponse {
/** The interaction associated with this response */
interaction: {
/** ID of the interaction */
id: string;
/** The type of the interaction */
type: InteractionType;
/** The instance ID of the activity if one was launched/joined */
activityInstanceID?: string;
/** The ID of the message created by the interaction */
responseMessageID?: string;
/** Whether or not the message is in a loading state */
responseMessageLoading?: boolean;
/** Whether or not the response message is ephemeral */
responseMessageEphemeral?: boolean;
};
interaction: InitialCallbackResponseInteraction;
/** The resource created by this interaction response. */
resource?: {
/** The type of the interaction response */
type: InteractionResponseType;
/** The activity instance launched by this interaction */
activityInstance?: {
id: string;
};
/** The message created by this interaction */
message?: Message;
};
resource?: InitialCallbackResponseResource;
}

/** The interaction associated with an initial interaction callback response. */
export interface InitialCallbackResponseInteraction {
/** ID of the interaction */
id: string;
/** The type of the interaction */
type: InteractionType;
/** The instance ID of the activity if one was launched/joined */
activityInstanceID?: string;
/** The ID of the message created by the interaction */
responseMessageID?: string;
/** Whether or not the message is in a loading state */
responseMessageLoading?: boolean;
/** Whether or not the response message is ephemeral */
responseMessageEphemeral?: boolean;
}

/** The resource created by an interaction. */
export interface InitialCallbackResponseResource {
/** The type of the interaction response */
type: InteractionResponseType;
/** The activity instance launched by this interaction */
activityInstance?: ActivityInstanceResource;
/** The message created by this interaction */
message?: Message;
}

/** The activity instance resource created by an interaction. */
export interface ActivityInstanceResource {
/** The instance ID of the activity */
id: string;
}

/** The types of components available. */
Expand Down
6 changes: 3 additions & 3 deletions src/structures/interfaces/autocompleteContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
AnyCommandOption,
CommandAutocompleteRequestData,
InitialInteractionResponse,
InitialCallbackResponse,
InteractionResponseType
} from '../../constants';
import { BaseSlashCreator } from '../../creator';
Expand Down Expand Up @@ -50,9 +50,9 @@ export class AutocompleteContext<ServerContext extends any = unknown> extends Ba
/**
* Sends the results of an autocomplete interaction.
* @param choices The choices to display
* @returns boolean or a {@link InitialInteractionResponse} if the response passed
* @returns boolean or a {@link InitialCallbackResponse} if the response passed
*/
async sendResults(choices: AutocompleteChoice[]): Promise<boolean | InitialInteractionResponse> {
async sendResults(choices: AutocompleteChoice[]): Promise<boolean | InitialCallbackResponse> {
if (this.responded) return false;

this.responded = true;
Expand Down
10 changes: 5 additions & 5 deletions src/structures/interfaces/componentContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
ComponentType,
InitialInteractionResponse,
InitialCallbackResponse,
InteractionResponseType,
MessageComponentRequestData
} from '../../constants';
Expand Down Expand Up @@ -55,7 +55,7 @@ export class ComponentContext<ServerContext extends any = unknown> extends Modal
* Acknowledges the interaction without replying.
* @returns Whether the acknowledgement passed or the callback response if available
*/
async acknowledge(): Promise<boolean | InitialInteractionResponse> {
async acknowledge(): Promise<boolean | InitialCallbackResponse> {
if (!this.initiallyResponded) {
this.initiallyResponded = true;
clearTimeout(this._timeout);
Expand All @@ -73,11 +73,11 @@ export class ComponentContext<ServerContext extends any = unknown> extends Modal

/**
* Edits the message that the component interaction came from.
* This will return `true` or a {@link InitialInteractionResponse} if it's an initial response, otherwise a {@link Message} will be returned.
* This will return `true` or a {@link InitialCallbackResponse} if it's an initial response, otherwise a {@link Message} will be returned.
* @param content The content of the message
* @returns `true` or a {@link InitialInteractionResponse} if the initial response passed, otherwise a {@link Message} of the parent message.
* @returns `true` or a {@link InitialCallbackResponse} if the initial response passed, otherwise a {@link Message} of the parent message.
*/
async editParent(content: string | EditMessageOptions): Promise<boolean | InitialInteractionResponse | Message> {
async editParent(content: string | EditMessageOptions): Promise<boolean | InitialCallbackResponse | Message> {
if (this.expired) throw new Error('This interaction has expired');

const options = typeof content === 'string' ? { content } : content;
Expand Down
14 changes: 7 additions & 7 deletions src/structures/interfaces/messageInteraction.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
AnyComponent,
InitialInteractionResponse,
InitialCallbackResponse,
InteractionResponseFlags,
InteractionResponseType
} from '../../constants';
Expand Down Expand Up @@ -61,12 +61,12 @@ export class MessageInteractionContext<
* Sends a message, if it already made an initial response, this will create a follow-up message.
* If the context has created a deferred message, it will edit that deferred message,
* and future calls to this function create follow ups.
* This will return `true` or a {@link InitialInteractionResponse} if it's an initial response, otherwise a {@link Message} will be returned.
* This will return `true` or a {@link InitialCallbackResponse} if it's an initial response, otherwise a {@link Message} will be returned.
* Note that when making a follow-up message, the `ephemeral` option is ignored.
* @param content The content of the message
* @returns `true` or a {@link InitialInteractionResponse} if the initial response passed, otherwise a {@link Message} of the follow-up message.
* @returns `true` or a {@link InitialCallbackResponse} if the initial response passed, otherwise a {@link Message} of the follow-up message.
*/
async send(content: string | MessageOptions): Promise<true | InitialInteractionResponse | Message> {
async send(content: string | MessageOptions): Promise<true | InitialCallbackResponse | Message> {
if (this.expired) throw new Error('This interaction has expired');

const options = typeof content === 'string' ? { content } : content;
Expand Down Expand Up @@ -204,7 +204,7 @@ export class MessageInteractionContext<
* @param ephemeral Whether to make the deferred message ephemeral.
* @returns Whether the deferred message passed or the callback response if available
*/
async defer(ephemeral = false): Promise<boolean | InitialInteractionResponse> {
async defer(ephemeral = false): Promise<boolean | InitialCallbackResponse> {
if (!this.initiallyResponded && !this.deferred) {
this.initiallyResponded = true;
this.deferred = true;
Expand All @@ -229,7 +229,7 @@ export class MessageInteractionContext<
* @returns Whether the message passed or the callback response if available
* @deprecated Use `ComponentButtonPremium` instead.
*/
async promptPremium(): Promise<boolean | InitialInteractionResponse> {
async promptPremium(): Promise<boolean | InitialCallbackResponse> {
if (!this.initiallyResponded && !this.deferred) {
this.initiallyResponded = true;
this.deferred = true;
Expand All @@ -251,7 +251,7 @@ export class MessageInteractionContext<
* Launches the activity this app is associated with.
* @returns Whether the message passed or the callback response if available
*/
async launchActivity(): Promise<boolean | InitialInteractionResponse> {
async launchActivity(): Promise<boolean | InitialCallbackResponse> {
if (!this.initiallyResponded && !this.deferred) {
this.initiallyResponded = true;
this.deferred = true;
Expand Down
10 changes: 5 additions & 5 deletions src/structures/interfaces/modalInteractionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
AnyComponent,
ComponentTextInput,
ComponentType,
InitialInteractionResponse,
InitialCallbackResponse,
InteractionResponseType,
ModalSubmitRequestData
} from '../../constants';
Expand Down Expand Up @@ -74,7 +74,7 @@ export class ModalInteractionContext<
* Acknowledges the interaction without replying.
* @returns Whether the acknowledgement passed or the callback response if available
*/
async acknowledge(): Promise<boolean | InitialInteractionResponse> {
async acknowledge(): Promise<boolean | InitialCallbackResponse> {
if (!this.initiallyResponded) {
this.initiallyResponded = true;
clearTimeout(this._timeout);
Expand All @@ -92,11 +92,11 @@ export class ModalInteractionContext<

/**
* Edits the message that the component interaction came from.
* This will return `true` or a {@link InitialInteractionResponse} if it's an initial response, otherwise a {@link Message} will be returned.
* This will return `true` or a {@link InitialCallbackResponse} if it's an initial response, otherwise a {@link Message} will be returned.
* @param content The content of the message
* @returns `true` or a {@link InitialInteractionResponse} if the initial response passed, otherwise a {@link Message} of the parent message.
* @returns `true` or a {@link InitialCallbackResponse} if the initial response passed, otherwise a {@link Message} of the parent message.
*/
async editParent(content: string | EditMessageOptions): Promise<true | InitialInteractionResponse | Message> {
async editParent(content: string | EditMessageOptions): Promise<true | InitialCallbackResponse | Message> {
if (this.expired) throw new Error('This interaction has expired');
if (!this.message) throw new Error('This interaction has no message');

Expand Down
4 changes: 2 additions & 2 deletions src/structures/interfaces/modalSendableContext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnyComponent, InitialInteractionResponse, InteractionResponseType } from '../../constants';
import { AnyComponent, InitialCallbackResponse, InteractionResponseType } from '../../constants';
import { ModalRegisterCallback, BaseSlashCreator } from '../../creator';
import { RespondFunction } from '../../server';
import { convertCallbackResponse, generateID } from '../../util';
Expand All @@ -25,7 +25,7 @@ export class ModalSendableContext<
callback?: ModalRegisterCallback
): Promise<{
customID: string;
response: InitialInteractionResponse | null;
response: InitialCallbackResponse | null;
}> {
if (this.expired) throw new Error('This interaction has expired');
if (this.initiallyResponded) throw new Error('This interaction has already responded.');
Expand Down
6 changes: 3 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
ApplicationCommandOption,
CommandOptionType,
InitialInteractionResponse,
InitialCallbackResponse,
InteractionCallbackResponse
} from './constants';
import { MessageInteractionContext } from './structures/interfaces/messageInteraction';
Expand Down Expand Up @@ -113,8 +113,8 @@ export function generateID() {
export function convertCallbackResponse(
response: InteractionCallbackResponse,
ctx: BaseInteractionContext
): InitialInteractionResponse {
const result: InitialInteractionResponse = {
): InitialCallbackResponse {
const result: InitialCallbackResponse = {
interaction: {
id: response.interaction.id,
type: response.interaction.type,
Expand Down

0 comments on commit 8b04627

Please sign in to comment.