Skip to content

Commit

Permalink
feat: add support for polls (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateo-tem committed Apr 21, 2024
1 parent 29d8844 commit a36449a
Show file tree
Hide file tree
Showing 36 changed files with 984 additions and 0 deletions.
45 changes: 45 additions & 0 deletions deno/gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ export enum GatewayIntentBits {
GuildScheduledEvents = 1 << 16,
AutoModerationConfiguration = 1 << 20,
AutoModerationExecution = 1 << 21,
GuildMessagePolls = 1 << 24,
DirectMessagePolls = 1 << 25,
}

/**
Expand Down Expand Up @@ -260,6 +262,8 @@ export enum GatewayDispatchEvents {
VoiceServerUpdate = 'VOICE_SERVER_UPDATE',
VoiceStateUpdate = 'VOICE_STATE_UPDATE',
WebhooksUpdate = 'WEBHOOKS_UPDATE',
MessagePollVoteAdd = 'MESSAGE_POLL_VOTE_ADD',
MessagePollVoteRemove = 'MESSAGE_POLL_VOTE_REMOVE',
GuildScheduledEventCreate = 'GUILD_SCHEDULED_EVENT_CREATE',
GuildScheduledEventUpdate = 'GUILD_SCHEDULED_EVENT_UPDATE',
GuildScheduledEventDelete = 'GUILD_SCHEDULED_EVENT_DELETE',
Expand Down Expand Up @@ -328,6 +332,8 @@ export type GatewayDispatchPayload =
| GatewayMessageCreateDispatch
| GatewayMessageDeleteBulkDispatch
| GatewayMessageDeleteDispatch
| GatewayMessagePollVoteAddDispatch
| GatewayMessagePollVoteRemoveDispatch
| GatewayMessageReactionAddDispatch
| GatewayMessageReactionRemoveAllDispatch
| GatewayMessageReactionRemoveDispatch
Expand Down Expand Up @@ -1813,6 +1819,45 @@ export interface GatewayGuildAuditLogEntryCreateDispatchData extends APIAuditLog
guild_id: Snowflake;
}

/**
* https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-add
*/
export type GatewayMessagePollVoteAddDispatch = DataPayload<
GatewayDispatchEvents.MessagePollVoteAdd,
GatewayMessagePollVoteDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-remove
*/
export type GatewayMessagePollVoteRemoveDispatch = DataPayload<
GatewayDispatchEvents.MessagePollVoteRemove,
GatewayMessagePollVoteDispatchData
>;

export interface GatewayMessagePollVoteDispatchData {
/**
* ID of the user
*/
user_id: Snowflake;
/**
* ID of the channel
*/
channel_id: Snowflake;
/**
* ID of the message
*/
message_id: Snowflake;
/**
* ID of the guild
*/
guild_id?: Snowflake;
/**
* ID of the answer
*/
answer_id: number;
}

// #endregion Dispatch Payloads

// #region Sendable Payloads
Expand Down
45 changes: 45 additions & 0 deletions deno/gateway/v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ export enum GatewayIntentBits {
GuildScheduledEvents = 1 << 16,
AutoModerationConfiguration = 1 << 20,
AutoModerationExecution = 1 << 21,
GuildMessagePolls = 1 << 24,
DirectMessagePolls = 1 << 25,
}

/**
Expand Down Expand Up @@ -259,6 +261,8 @@ export enum GatewayDispatchEvents {
VoiceServerUpdate = 'VOICE_SERVER_UPDATE',
VoiceStateUpdate = 'VOICE_STATE_UPDATE',
WebhooksUpdate = 'WEBHOOKS_UPDATE',
MessagePollVoteAdd = 'MESSAGE_POLL_VOTE_ADD',
MessagePollVoteRemove = 'MESSAGE_POLL_VOTE_REMOVE',
GuildScheduledEventCreate = 'GUILD_SCHEDULED_EVENT_CREATE',
GuildScheduledEventUpdate = 'GUILD_SCHEDULED_EVENT_UPDATE',
GuildScheduledEventDelete = 'GUILD_SCHEDULED_EVENT_DELETE',
Expand Down Expand Up @@ -327,6 +331,8 @@ export type GatewayDispatchPayload =
| GatewayMessageCreateDispatch
| GatewayMessageDeleteBulkDispatch
| GatewayMessageDeleteDispatch
| GatewayMessagePollVoteAddDispatch
| GatewayMessagePollVoteRemoveDispatch
| GatewayMessageReactionAddDispatch
| GatewayMessageReactionRemoveAllDispatch
| GatewayMessageReactionRemoveDispatch
Expand Down Expand Up @@ -1812,6 +1818,45 @@ export interface GatewayGuildAuditLogEntryCreateDispatchData extends APIAuditLog
guild_id: Snowflake;
}

/**
* https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-add
*/
export type GatewayMessagePollVoteAddDispatch = DataPayload<
GatewayDispatchEvents.MessagePollVoteAdd,
GatewayMessagePollVoteDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-remove
*/
export type GatewayMessagePollVoteRemoveDispatch = DataPayload<
GatewayDispatchEvents.MessagePollVoteRemove,
GatewayMessagePollVoteDispatchData
>;

export interface GatewayMessagePollVoteDispatchData {
/**
* ID of the user
*/
user_id: Snowflake;
/**
* ID of the channel
*/
channel_id: Snowflake;
/**
* ID of the message
*/
message_id: Snowflake;
/**
* ID of the guild
*/
guild_id?: Snowflake;
/**
* ID of the answer
*/
answer_id: number;
}

// #endregion Dispatch Payloads

// #region Sendable Payloads
Expand Down
6 changes: 6 additions & 0 deletions deno/payloads/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@ export const PermissionFlagsBits = {
* Applies to channel types: Text, Voice, Stage
*/
SendVoiceMessages: 1n << 46n,
/**
* Allows sending polls
*
* Applies to channel types: Text, Voice, Stage
*/
SendPolls: 1n << 49n,
} as const;

/**
Expand Down
12 changes: 12 additions & 0 deletions deno/payloads/v10/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { APIPartialEmoji } from './emoji.ts';
import type { APIGuildMember } from './guild.ts';
import type { APIInteractionDataResolved, APIMessageInteraction } from './interactions.ts';
import type { APIRole } from './permissions.ts';
import type { APIPoll } from './poll.ts';
import type { APISticker, APIStickerItem } from './sticker.ts';
import type { APIUser } from './user.ts';

Expand Down Expand Up @@ -715,6 +716,17 @@ export interface APIMessage {
* See https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure
*/
resolved?: APIInteractionDataResolved;
/**
* A poll!
*
* The `MESSAGE_CONTENT` privileged gateway intent is required for verified applications to receive a non-empty value from this field
*
* In the Discord Developers Portal, you need to enable the toggle of this intent of your application in **Bot > Privileged Gateway Intents**.
* You also need to specify the intent bit value (`1 << 15`) if you are connecting to the gateway
*
* See https://support-dev.discord.com/hc/articles/4404772028055
*/
poll?: APIPoll;
}

/**
Expand Down
1 change: 1 addition & 0 deletions deno/payloads/v10/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './guildScheduledEvent.ts';
export * from './interactions.ts';
export * from './invite.ts';
export * from './oauth2.ts';
export * from './poll.ts';
export * from './permissions.ts';
export * from './stageInstance.ts';
export * from './sticker.ts';
Expand Down
107 changes: 107 additions & 0 deletions deno/payloads/v10/poll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/**
* Types extracted from https://discord.com/developers/docs/resources/poll
*/

import type { APIPartialEmoji } from './emoji.ts';

/**
* https://discord.com/developers/docs/resources/poll#poll-object-poll-object-structure
*/
export interface APIPoll {
/**
* The question of the poll
*/
question: APIPollMedia;
/**
* Each of the answers available in the poll, up to 10
*/
answers: APIPollAnswer[];
/**
* The time when the poll ends (IS08601 timestamp)
*/
expiry: string;
/**
* Whether a user can select multiple answers
*/
allow_multiselect: boolean;
/**
* The layout type of the poll
*/
layout_type: PollLayoutType;
/**
* The results of the poll
*/
results?: APIPollResults;
}

/**
* https://discord.com/developers/docs/resources/poll#layout-type
*/
export enum PollLayoutType {
/**
* The, uhm, default layout type
*/
Default = 1,
}

/**
* https://discord.com/developers/docs/resources/poll#poll-media-object-poll-media-object-structure
*/
export interface APIPollMedia {
/**
* The text of the field
*
* The maximum length is `300` for the question, and `55` for any answer
*/
text?: string;
/**
* The emoji of the field
*/
emoji?: APIPartialEmoji;
}

/**
* https://discord.com/developers/docs/resources/poll#poll-answer-object-poll-answer-object-structure
*/
export interface APIPollAnswer {
/**
* The ID of the answer. Starts at `1` for the first answer and goes up sequentially
*/
answer_id: number;
/**
* The data of the answer
*/
media: APIPollMedia;
}

/**
* https://discord.com/developers/docs/resources/poll#poll-results-object-poll-results-object-structure
*/
export interface APIPollResults {
/**
* Whether the votes have been precisely counted
*/
is_finalized: boolean;
/**
* The counts for each answer
*/
answer_counts: APIPollAnswerCount[];
}

/**
* https://discord.com/developers/docs/resources/poll#poll-results-object-poll-answer-count-object-structure
*/
export interface APIPollAnswerCount {
/**
* The `answer_id`
*/
id: number;
/**
* The number of votes for this answer
*/
count: number;
/**
* Whether the current user voted for this answer
*/
me_voted: boolean;
}
12 changes: 12 additions & 0 deletions deno/payloads/v9/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type { APIPartialEmoji } from './emoji.ts';
import type { APIGuildMember } from './guild.ts';
import type { APIInteractionDataResolved, APIMessageInteraction } from './interactions.ts';
import type { APIRole } from './permissions.ts';
import type { APIPoll } from './poll.ts';
import type { APISticker, APIStickerItem } from './sticker.ts';
import type { APIUser } from './user.ts';

Expand Down Expand Up @@ -702,6 +703,17 @@ export interface APIMessage {
* See https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure
*/
resolved?: APIInteractionDataResolved;
/**
* A poll!
*
* The `MESSAGE_CONTENT` privileged gateway intent is required for verified applications to receive a non-empty value from this field
*
* In the Discord Developers Portal, you need to enable the toggle of this intent of your application in **Bot > Privileged Gateway Intents**.
* You also need to specify the intent bit value (`1 << 15`) if you are connecting to the gateway
*
* See https://support-dev.discord.com/hc/articles/4404772028055
*/
poll?: APIPoll;
}

/**
Expand Down
1 change: 1 addition & 0 deletions deno/payloads/v9/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './guildScheduledEvent.ts';
export * from './interactions.ts';
export * from './invite.ts';
export * from './oauth2.ts';
export * from './poll.ts';
export * from './permissions.ts';
export * from './stageInstance.ts';
export * from './sticker.ts';
Expand Down
Loading

0 comments on commit a36449a

Please sign in to comment.