From 29f7b769e174f713ec042bbd4bb0d1bf8a9cfda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20Susa=C3=B1a?= Date: Wed, 4 Sep 2024 17:33:24 -0400 Subject: [PATCH] feat: polls improvement (#249) * feat: polls improvement * fix: poll in editOrReply * feat(api-types): type APIEmbedPollResult --------- Co-authored-by: MARCROCK22 <57925328+MARCROCK22@users.noreply.github.com> --- src/common/types/write.ts | 6 ++--- src/structures/Interaction.ts | 4 +-- src/structures/Message.ts | 3 --- src/types/payloads/channel.ts | 49 ++++++++++++++++++++++++++++++++--- src/types/rest/webhook.ts | 2 +- 5 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/common/types/write.ts b/src/common/types/write.ts index ed8e9fb..d31c41b 100644 --- a/src/common/types/write.ts +++ b/src/common/types/write.ts @@ -54,14 +54,14 @@ export type MessageWebhookCreateBodyRequest = OmitInsert< export type MessageWebhookUpdateBodyRequest = OmitInsert< RESTPatchAPIWebhookWithTokenMessageJSONBody, - 'components' | 'embeds', + 'components' | 'embeds' | 'poll', ResolverProps >; export type InteractionMessageUpdateBodyRequest = OmitInsert< RESTPatchAPIWebhookWithTokenMessageJSONBody, - 'components' | 'embeds', - ResolverProps + 'components' | 'embeds' | 'poll', + SendResolverProps >; export type ComponentInteractionMessageUpdate = OmitInsert< diff --git a/src/structures/Interaction.ts b/src/structures/Interaction.ts index 33a5d94..e9c0704 100644 --- a/src/structures/Interaction.ts +++ b/src/structures/Interaction.ts @@ -450,8 +450,8 @@ export class Interaction< ): Promise>; async editOrReply(body: InteractionMessageUpdateBodyRequest, fetchReply?: FR) { if (await this.replied) { - const { content, embeds, allowed_mentions, components, files, attachments } = body; - return this.editResponse({ content, embeds, allowed_mentions, components, files, attachments }); + const { content, embeds, allowed_mentions, components, files, attachments, poll } = body; + return this.editResponse({ content, embeds, allowed_mentions, components, files, attachments, poll }); } return this.write(body as InteractionCreateBodyRequest, fetchReply); } diff --git a/src/structures/Message.ts b/src/structures/Message.ts index e699e29..e3e3f8d 100644 --- a/src/structures/Message.ts +++ b/src/structures/Message.ts @@ -206,9 +206,6 @@ export class InMessageEmbed { return this.data.title; } - /** - * @deprecated - */ get type() { return this.data.type; } diff --git a/src/types/payloads/channel.ts b/src/types/payloads/channel.ts index 46cd147..2992ba3 100644 --- a/src/types/payloads/channel.ts +++ b/src/types/payloads/channel.ts @@ -1079,8 +1079,6 @@ export interface APIEmbed { /** * Type of embed (always "rich" for webhook embeds) * - * @deprecated *Embed types should be considered deprecated and might be removed in a future API version* - * * See https://discord.com/developers/docs/resources/channel#embed-object-embed-types */ type?: EmbedType; @@ -1148,10 +1146,50 @@ export interface APIEmbed { fields?: APIEmbedField[]; } +/** + * https://discord.com/developers/docs/resources/message#embed-fields-by-embed-type-poll-result-embed-fields + */ +export interface PollResultEmbedField { + name: T; + value: V; + inline: false; +} + +/** + * https://discord.com/developers/docs/resources/message#embed-fields-by-embed-type-poll-result-embed-fields + */ +export type PollResultEmbedFields = [ + /** question text from the original poll */ + PollResultEmbedField<'poll_question_text'>, + /** number of votes for the answer(s) with the most votes */ + PollResultEmbedField<'victor_answer_votes', `${number}`>, + /** total number of votes in the poll */ + PollResultEmbedField<'total_votes', `${number}`>, + /** id for the winning answer */ + PollResultEmbedField<'victor_answer_id', `${number}`> | undefined, + /** text for the winning answer */ + PollResultEmbedField<'victor_answer_text'> | undefined, + /** id for an emoji associated with the winning answer */ + PollResultEmbedField<'victor_answer_emoji_id'> | undefined, + /** name for an emoji associated with the winning answer */ + PollResultEmbedField<'victor_answer_emoji_name'> | undefined, + /** if an emoji associated with the winning answer is animated */ + PollResultEmbedField<'victor_answer_emoji_animated', `${boolean}`> | undefined, +]; + +export type APIEmbedPollResult = { + type: EmbedType.PollResult; + fields: PollResultEmbedFields; + /** + * @unstable This field is not officially documented by Discord. + * Current observations indicate a consistent value of 0 for all embeds. + */ + content_scan_version: number; +}; + /** * https://discord.com/developers/docs/resources/channel#embed-object-embed-types * - * @deprecated *Embed types should be considered deprecated and might be removed in a future API version* */ export enum EmbedType { /** @@ -1178,6 +1216,11 @@ export enum EmbedType { * Link embed */ Link = 'link', + /** + * Poll result embed + * https://discord.com/developers/docs/resources/message#embed-fields-by-embed-type-poll-result-embed-fields + */ + PollResult = 'poll_result', /** * Auto moderation alert embed * diff --git a/src/types/rest/webhook.ts b/src/types/rest/webhook.ts index be0dddd..0aa21d2 100644 --- a/src/types/rest/webhook.ts +++ b/src/types/rest/webhook.ts @@ -257,7 +257,7 @@ export interface RESTGetAPIWebhookWithTokenMessageQuery { * https://discord.com/developers/docs/resources/webhook#edit-webhook-message */ export type RESTPatchAPIWebhookWithTokenMessageJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface< - Nullable> + Nullable> > & { /** * Attached files to keep