From 9b37972aa7a9bbcb387aca32bebdba994cb19aa7 Mon Sep 17 00:00:00 2001 From: Donovan Daniels Date: Thu, 18 Apr 2024 13:46:10 -0500 Subject: [PATCH] Make message edit functions' content nullable Fixes #148 --- lib/routes/Channels.ts | 2 +- lib/routes/Interactions.ts | 6 +++--- lib/structures/CommandInteraction.ts | 7 ++++--- lib/structures/ComponentInteraction.ts | 5 +++-- lib/structures/ModalSubmitInteraction.ts | 5 +++-- lib/types/channels.d.ts | 5 +++-- lib/types/interactions.d.ts | 3 ++- lib/types/misc.d.ts | 3 +++ 8 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/routes/Channels.ts b/lib/routes/Channels.ts index 6b22ae75..07d13780 100644 --- a/lib/routes/Channels.ts +++ b/lib/routes/Channels.ts @@ -481,7 +481,7 @@ export default class Channels { * @caches {@link TextableChannel#messages | TextableChannel#messages}
{@link ThreadChannel#messages | ThreadChannel#messages}
{@link PrivateChannel#messages | PrivateChannel#messages} */ async editMessage(channelID: string, messageID: string, options: EditMessageOptions): Promise> { - const files = options.files; + const files = options.files ?? undefined; if (options.files) { delete options.files; } diff --git a/lib/routes/Interactions.ts b/lib/routes/Interactions.ts index 5b0e8aa1..20b0395c 100644 --- a/lib/routes/Interactions.ts +++ b/lib/routes/Interactions.ts @@ -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"; @@ -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(applicationID: string, interactionToken: string, messageID: string, options: InteractionContent): Promise> { + async editFollowupMessage(applicationID: string, interactionToken: string, messageID: string, options: EditInteractionContent): Promise> { return this.#manager.webhooks.editMessage(applicationID, interactionToken, messageID, options); } @@ -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(applicationID: string, interactionToken: string, options: InteractionContent): Promise> { + async editOriginalMessage(applicationID: string, interactionToken: string, options: EditInteractionContent): Promise> { return this.editFollowupMessage(applicationID, interactionToken, "@original", options); } diff --git a/lib/structures/CommandInteraction.ts b/lib/structures/CommandInteraction.ts index db9f8952..619a2bc2 100644 --- a/lib/structures/CommandInteraction.ts +++ b/lib/structures/CommandInteraction.ts @@ -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"; @@ -242,7 +243,7 @@ export default class CommandInteraction> { + async editFollowup(messageID: string, options: EditInteractionContent): Promise> { return this.client.rest.interactions.editFollowupMessage(this.applicationID, this.token, messageID, options); } @@ -250,7 +251,7 @@ export default class CommandInteraction> { + async editOriginal(options: EditInteractionContent): Promise> { return this.client.rest.interactions.editOriginalMessage(this.applicationID, this.token, options); } diff --git a/lib/structures/ComponentInteraction.ts b/lib/structures/ComponentInteraction.ts index df6d2e23..47f8109e 100644 --- a/lib/structures/ComponentInteraction.ts +++ b/lib/structures/ComponentInteraction.ts @@ -14,6 +14,7 @@ import type TestEntitlement from "./TestEntitlement"; import type Client from "../Client"; import type { AuthorizingIntegrationOwners, + EditInteractionContent, InitialInteractionContent, InteractionContent, InteractionGuild, @@ -255,7 +256,7 @@ export default class ComponentInteraction> { + async editFollowup(messageID: string, options: EditInteractionContent): Promise> { return this.client.rest.interactions.editFollowupMessage(this.applicationID, this.token, messageID, options); } @@ -263,7 +264,7 @@ export default class ComponentInteraction> { + async editOriginal(options: EditInteractionContent): Promise> { return this.client.rest.interactions.editOriginalMessage(this.applicationID, this.token, options); } diff --git a/lib/structures/ModalSubmitInteraction.ts b/lib/structures/ModalSubmitInteraction.ts index 1f9a0e60..5fe49d69 100644 --- a/lib/structures/ModalSubmitInteraction.ts +++ b/lib/structures/ModalSubmitInteraction.ts @@ -12,6 +12,7 @@ import type TestEntitlement from "./TestEntitlement"; import { InteractionResponseTypes, type InteractionTypes, type InteractionContextTypes } from "../Constants"; import type { AuthorizingIntegrationOwners, + EditInteractionContent, InitialInteractionContent, InteractionContent, InteractionGuild, @@ -185,7 +186,7 @@ export default class ModalSubmitInteraction> { + async editFollowup(messageID: string, options: EditInteractionContent): Promise> { return this.client.rest.interactions.editFollowupMessage(this.applicationID, this.token, messageID, options); } @@ -193,7 +194,7 @@ export default class ModalSubmitInteraction> { + async editOriginal(options: EditInteractionContent): Promise> { return this.client.rest.interactions.editOriginalMessage(this.applicationID, this.token, options); } diff --git a/lib/types/channels.d.ts b/lib/types/channels.d.ts index 54026aff..f3ca0f84 100644 --- a/lib/types/channels.d.ts +++ b/lib/types/channels.d.ts @@ -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, @@ -894,7 +895,7 @@ export interface GetReactionsOptions { type?: ReactionType; } -export interface EditMessageOptions extends Pick {} +export interface EditMessageOptions extends Nullable> {} export interface EditPermissionOptions { /** The permissions to allow. */ @@ -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; } diff --git a/lib/types/interactions.d.ts b/lib/types/interactions.d.ts index 32120a7c..243cadda 100644 --- a/lib/types/interactions.d.ts +++ b/lib/types/interactions.d.ts @@ -1,5 +1,5 @@ /** @module Types/Interactions */ -import type { ExecuteWebhookOptions } from "./webhooks"; +import type { EditWebhookMessageOptions, ExecuteWebhookOptions } from "./webhooks"; import type { AnyTextableGuildChannel, AnyPrivateChannel, @@ -46,6 +46,7 @@ import type Permission from "../structures/Permission"; import type ModalSubmitInteractionComponentsWrapper from "../util/interactions/ModalSubmitInteractionComponentsWrapper"; export interface InteractionContent extends Pick {} +export interface EditInteractionContent extends Pick {} export interface InitialInteractionContent extends Omit {} export type InteractionResponse = PingInteractionResponse | MessageInteractionResponse | DeferredInteractionResponse | AutocompleteInteractionResponse | ModalSubmitInteractionResponse | PremiumRequiredResponse; diff --git a/lib/types/misc.d.ts b/lib/types/misc.d.ts index 177f4675..a3452d49 100644 --- a/lib/types/misc.d.ts +++ b/lib/types/misc.d.ts @@ -11,3 +11,6 @@ export type ReverseMap> = { }; export type AnyClass> = new(data: T, client: Client, ...extra: E) => I; export type WithRequired = Omit & Required>; +export type Nullable = { + [K in keyof T]: T[K] | null; +};