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>
This commit is contained in:
Marcos Susaña 2024-09-04 17:33:24 -04:00 committed by GitHub
parent 0cef3a9f6f
commit 29f7b769e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 52 additions and 12 deletions

View File

@ -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<

View File

@ -450,8 +450,8 @@ export class Interaction<
): Promise<When<FR, WebhookMessageStructure, void>>;
async editOrReply<FR extends true = true>(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);
}

View File

@ -206,9 +206,6 @@ export class InMessageEmbed {
return this.data.title;
}
/**
* @deprecated
*/
get type() {
return this.data.type;
}

View File

@ -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<T extends string, V extends string = string> {
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
*

View File

@ -257,7 +257,7 @@ export interface RESTGetAPIWebhookWithTokenMessageQuery {
* https://discord.com/developers/docs/resources/webhook#edit-webhook-message
*/
export type RESTPatchAPIWebhookWithTokenMessageJSONBody = AddUndefinedToPossiblyUndefinedPropertiesOfInterface<
Nullable<Pick<RESTPostAPIWebhookWithTokenJSONBody, 'allowed_mentions' | 'components' | 'content' | 'embeds'>>
Nullable<Pick<RESTPostAPIWebhookWithTokenJSONBody, 'allowed_mentions' | 'components' | 'content' | 'embeds' | 'poll'>>
> & {
/**
* Attached files to keep