Skip to content

Commit

Permalink
Make message edit functions' content nullable
Browse files Browse the repository at this point in the history
Fixes #148
  • Loading branch information
DonovanDMC committed Apr 18, 2024
1 parent 99ec267 commit 9b37972
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/routes/Channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ export default class Channels {
* @caches {@link TextableChannel#messages | TextableChannel#messages}<br>{@link ThreadChannel#messages | ThreadChannel#messages}<br>{@link PrivateChannel#messages | PrivateChannel#messages}
*/
async editMessage<T extends AnyTextableChannel | Uncached = AnyTextableChannel | Uncached>(channelID: string, messageID: string, options: EditMessageOptions): Promise<Message<T>> {
const files = options.files;
const files = options.files ?? undefined;
if (options.files) {
delete options.files;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/Interactions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @module REST/Interactions */
import type { InteractionContent, InteractionResponse } from "../types/interactions";
import type { EditInteractionContent, InteractionContent, InteractionResponse } from "../types/interactions";
import type { ExecuteWebhookWaitOptions } from "../types/webhooks";
import * as Routes from "../util/Routes";
import { InteractionResponseTypes } from "../Constants";
Expand Down Expand Up @@ -117,7 +117,7 @@ export default class Interactions {
* @param options The options for editing the followup message.
* @caching This method **does not** cache its result.
*/
async editFollowupMessage<T extends AnyTextableChannel | Uncached>(applicationID: string, interactionToken: string, messageID: string, options: InteractionContent): Promise<Message<T>> {
async editFollowupMessage<T extends AnyTextableChannel | Uncached>(applicationID: string, interactionToken: string, messageID: string, options: EditInteractionContent): Promise<Message<T>> {
return this.#manager.webhooks.editMessage<T>(applicationID, interactionToken, messageID, options);
}

Expand All @@ -128,7 +128,7 @@ export default class Interactions {
* @param options The options for editing the original message.
* @caching This method **does not** cache its result.
*/
async editOriginalMessage<T extends AnyTextableChannel | Uncached>(applicationID: string, interactionToken: string, options: InteractionContent): Promise<Message<T>> {
async editOriginalMessage<T extends AnyTextableChannel | Uncached>(applicationID: string, interactionToken: string, options: EditInteractionContent): Promise<Message<T>> {
return this.editFollowupMessage<T>(applicationID, interactionToken, "@original", options);
}

Expand Down
7 changes: 4 additions & 3 deletions lib/structures/CommandInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import type {
ApplicationCommandInteractionResolvedData,
InitialInteractionContent,
InteractionGuild,
AuthorizingIntegrationOwners
AuthorizingIntegrationOwners,
EditInteractionContent
} from "../types/interactions";
import type Client from "../Client";
import type { RawMember } from "../types/guilds";
Expand Down Expand Up @@ -242,15 +243,15 @@ export default class CommandInteraction<T extends AnyInteractionChannel | Uncach
* @param messageID The ID of the message.
* @param options The options for editing the followup message.
*/
async editFollowup(messageID: string, options: InteractionContent): Promise<Message<T>> {
async editFollowup(messageID: string, options: EditInteractionContent): Promise<Message<T>> {
return this.client.rest.interactions.editFollowupMessage<T>(this.applicationID, this.token, messageID, options);
}

/**
* Edit the original interaction response.
* @param options The options for editing the original message.
*/
async editOriginal(options: InteractionContent): Promise<Message<T>> {
async editOriginal(options: EditInteractionContent): Promise<Message<T>> {
return this.client.rest.interactions.editOriginalMessage<T>(this.applicationID, this.token, options);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/structures/ComponentInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type TestEntitlement from "./TestEntitlement";
import type Client from "../Client";
import type {
AuthorizingIntegrationOwners,
EditInteractionContent,
InitialInteractionContent,
InteractionContent,
InteractionGuild,
Expand Down Expand Up @@ -255,15 +256,15 @@ export default class ComponentInteraction<V extends ComponentTypes.BUTTON | Sele
* @param messageID The ID of the message.
* @param options The options for editing the followup message.
*/
async editFollowup(messageID: string, options: InteractionContent): Promise<Message<T>> {
async editFollowup(messageID: string, options: EditInteractionContent): Promise<Message<T>> {
return this.client.rest.interactions.editFollowupMessage<T>(this.applicationID, this.token, messageID, options);
}

/**
* Edit the original interaction response.
* @param options The options for editing the original message.
*/
async editOriginal(options: InteractionContent): Promise<Message<T>> {
async editOriginal(options: EditInteractionContent): Promise<Message<T>> {
return this.client.rest.interactions.editOriginalMessage<T>(this.applicationID, this.token, options);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/structures/ModalSubmitInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type TestEntitlement from "./TestEntitlement";
import { InteractionResponseTypes, type InteractionTypes, type InteractionContextTypes } from "../Constants";
import type {
AuthorizingIntegrationOwners,
EditInteractionContent,
InitialInteractionContent,
InteractionContent,
InteractionGuild,
Expand Down Expand Up @@ -185,15 +186,15 @@ export default class ModalSubmitInteraction<T extends AnyInteractionChannel | Un
* @param messageID The ID of the message.
* @param options The options for editing the followup message.
*/
async editFollowup(messageID: string, options: InteractionContent): Promise<Message<T>> {
async editFollowup(messageID: string, options: EditInteractionContent): Promise<Message<T>> {
return this.client.rest.interactions.editFollowupMessage<T>(this.applicationID, this.token, messageID, options);
}

/**
* Edit the original interaction response.
* @param options The options for editing the original message.
*/
async editOriginal(options: InteractionContent): Promise<Message<T>> {
async editOriginal(options: EditInteractionContent): Promise<Message<T>> {
return this.client.rest.interactions.editOriginalMessage<T>(this.applicationID, this.token, options);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/types/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { File } from "./request-handler";
import type { RawScheduledEvent } from "./scheduled-events";
import { type Uncached } from "./shared";
import type { AuthorizingIntegrationOwners, SelectMenuDefaultValue } from "./interactions";
import type { Nullable } from "./misc";
import type {
ButtonStyles,
ChannelTypes,
Expand Down Expand Up @@ -894,7 +895,7 @@ export interface GetReactionsOptions {
type?: ReactionType;
}

export interface EditMessageOptions extends Pick<CreateMessageOptions, "content" | "embeds" | "allowedMentions" | "components" | "attachments" | "files" | "flags"> {}
export interface EditMessageOptions extends Nullable<Pick<CreateMessageOptions, "content" | "embeds" | "allowedMentions" | "components" | "attachments" | "files" | "flags">> {}

export interface EditPermissionOptions {
/** The permissions to allow. */
Expand Down Expand Up @@ -1237,6 +1238,6 @@ export interface PollAnswerCount {
id: number;
/** If the current user has voted for this answer. */
meVoted: boolean;
/** The IDs of the users that voted. This will always be out of sync unless you either {@link Poll#getAnswerUsers|fetch the answer voters over REST}, or if the poll was created after the bot started, and stays in the cache. */
/** The IDs of the users that voted. This will always be out of sync unless you either {@link Poll#getAnswerUsers | fetch the answer voters over REST}, or if the poll was created after the bot started, and stays in the cache. */
users: Array<string>;
}
3 changes: 2 additions & 1 deletion lib/types/interactions.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @module Types/Interactions */
import type { ExecuteWebhookOptions } from "./webhooks";
import type { EditWebhookMessageOptions, ExecuteWebhookOptions } from "./webhooks";
import type {
AnyTextableGuildChannel,
AnyPrivateChannel,
Expand Down Expand Up @@ -46,6 +46,7 @@ import type Permission from "../structures/Permission";
import type ModalSubmitInteractionComponentsWrapper from "../util/interactions/ModalSubmitInteractionComponentsWrapper";

export interface InteractionContent extends Pick<ExecuteWebhookOptions, "tts" | "content" | "embeds" | "allowedMentions" | "flags" | "components" | "attachments" | "files" | "poll"> {}
export interface EditInteractionContent extends Pick<EditWebhookMessageOptions, "content" | "embeds" | "allowedMentions" | "components" | "attachments" | "files"> {}
export interface InitialInteractionContent extends Omit<InteractionContent, "attachments" | "files"> {}

export type InteractionResponse = PingInteractionResponse | MessageInteractionResponse | DeferredInteractionResponse | AutocompleteInteractionResponse | ModalSubmitInteractionResponse | PremiumRequiredResponse;
Expand Down
3 changes: 3 additions & 0 deletions lib/types/misc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ export type ReverseMap<T extends Record<keyof T, keyof any>> = {
};
export type AnyClass<T, I, E extends Array<unknown>> = new(data: T, client: Client, ...extra: E) => I;
export type WithRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
export type Nullable<T> = {
[K in keyof T]: T[K] | null;
};

0 comments on commit 9b37972

Please sign in to comment.