Skip to content

Commit

Permalink
Add polls (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
mifuyutsuki authored Jun 2, 2024
1 parent 7ced28c commit 742333c
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions discord_typings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from ._resources._guild_scheduled_events import *
from ._resources._guild_template import *
from ._resources._invite import *
from ._resources._poll import *
from ._resources._role_connection_metadata import *
from ._resources._stage_instance import *
from ._resources._sticker import *
Expand Down
36 changes: 36 additions & 0 deletions discord_typings/_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@
'StageInstanceUpdateEvent',
'StageInstanceDeleteData',
'StageInstanceDeleteEvent',
'MessagePollVoteAddData',
'MessagePollVoteAddEvent',
'MessagePollVoteRemoveData',
'MessagePollVoteRemoveEvent',
'DispatchEvent',
'GatewayCommand',
'GatewayEvent',
Expand Down Expand Up @@ -1301,6 +1305,38 @@ class WebhooksUpdateData(TypedDict):
]


# https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-add


class MessagePollVoteAddData(TypedDict):
user_id: 'discord_typings.Snowflake'
channel_id: 'discord_typings.Snowflake'
message_id: 'discord_typings.Snowflake'
guild_id: NotRequired['discord_typings.Snowflake']
answer_id: int


MessagePollVoteAddEvent = GenericDispatchEvent[
Literal['MESSAGE_POLL_VOTE_ADD'], MessagePollVoteAddData
]


# https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-remove


class MessagePollVoteRemoveData(TypedDict):
user_id: 'discord_typings.Snowflake'
channel_id: 'discord_typings.Snowflake'
message_id: 'discord_typings.Snowflake'
guild_id: NotRequired['discord_typings.Snowflake']
answer_id: int


MessagePollVoteRemoveEvent = GenericDispatchEvent[
Literal['MESSAGE_POLL_VOTE_REMOVE'], MessagePollVoteRemoveData
]


# Generalized unions for the typings in this file


Expand Down
1 change: 1 addition & 0 deletions discord_typings/_interactions/_receiving.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ class InteractionMessageCallbackData(TypedDict):
flags: NotRequired[int]
components: NotRequired[List['discord_typings.ComponentData']]
attachments: NotRequired[List['discord_typings.PartialAttachmentData']]
poll: NotRequired['discord_typings.PollCreateRequestData']


class InteractionAutocompleteCallbackData(TypedDict, Generic[_T]):
Expand Down
1 change: 1 addition & 0 deletions discord_typings/_resources/_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class _ChannelMessageData(TypedDict):
position: NotRequired[int]
role_subscription_data: NotRequired['discord_typings.RoleSubscriptionData']
resolved: NotRequired['discord_typings.ResolvedInteractionDataData']
poll: NotRequired['discord_typings.PollCreateRequestData']


class _GuildMessageData(_ChannelMessageData):
Expand Down
77 changes: 77 additions & 0 deletions discord_typings/_resources/_poll.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from typing import List, Optional

from typing_extensions import Literal, NotRequired, TypedDict

import discord_typings

__all__ = (
'PollData',
'PollCreateRequestData',
'PollLayoutType',
'PollMediaData',
'PollAnswerData',
'PollResultsData',
'PollAnswerCountData',
)


# https://discord.com/developers/docs/resources/poll#poll-object-poll-object-structure


class PollData(TypedDict):
question: 'discord_typings.PollMediaData'
answers: List['discord_typings.PollAnswerData']
expiry: Optional[str]
allow_multiselect: bool
layout_type: 'discord_typings.PollLayoutType'
results: NotRequired['discord_typings.PollResultsData']


# https://discord.com/developers/docs/resources/poll#poll-create-request-object-poll-create-request-object-structure


class PollCreateRequestData(TypedDict):
question: 'discord_typings.PollMediaData'
answers: List['discord_typings.PollAnswerData']
duration: int
allow_multiselect: bool
layout_type: NotRequired['discord_typings.PollLayoutType']


# https://discord.com/developers/docs/resources/poll#layout-type


PollLayoutType = Literal[1]


# https://discord.com/developers/docs/resources/poll#poll-media-object-poll-media-object-structure


class PollMediaData(TypedDict):
text: NotRequired[str]
emoji: NotRequired['discord_typings.EmojiData']


# https://discord.com/developers/docs/resources/poll#poll-answer-object-poll-answer-object-structure


class PollAnswerData(TypedDict):
answer_id: int
poll_media: 'discord_typings.PollMediaData'


# https://discord.com/developers/docs/resources/poll#poll-results-object-poll-results-object-structure


class PollResultsData(TypedDict):
is_finalized: bool
answer_counts: List['discord_typings.PollAnswerCountData']


# https://discord.com/developers/docs/resources/poll#poll-results-object-poll-answer-count-object-structure


class PollAnswerCountData(TypedDict):
id: int
count: int
me_voted: bool

0 comments on commit 742333c

Please sign in to comment.