Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Polls #9759

Merged
merged 173 commits into from May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
86f9860
Major changes to add poll feature
DA-344 Mar 19, 2024
fd5c37a
Merge branch 'master' of https://github.com/Rapptz/discord.py into polls
DA-344 Mar 19, 2024
f0eca90
Removed unnecessary slotted attributes
DA-344 Mar 19, 2024
7cb5911
Slotted PollAnswer and added poll param to async webhook handle messa…
DA-344 Mar 19, 2024
c660a7e
Added Gobot1234 suggested changes and PollAnswer to __all__
DA-344 Mar 19, 2024
5e58841
Commit owocado review
DA-344 Mar 19, 2024
263b7a1
Updated all the docstrings for send methods and added poll support fo…
DA-344 Mar 22, 2024
523faca
Merge branch 'master' of https://github.com/Rapptz/discord.py into polls
DA-344 Mar 22, 2024
1d9bd58
Added gateway events, updated docs and some more things
DA-344 Mar 22, 2024
b086bae
removed personal things from .gitignore
DA-344 Mar 22, 2024
e670095
Updated add_answer and added final blank line
DA-344 Mar 23, 2024
e6151d6
Update context.py 's send method docstring
DA-344 Mar 23, 2024
0c12a53
Added new overloads for all the send methods, updated poll object
DA-344 Mar 24, 2024
51a2e0f
Fixed a minor error in Poll Expiry handle
DA-344 Mar 24, 2024
1cadca0
Major changes to PollAnswers
DA-344 Mar 24, 2024
9f3ddc9
Polls cannot have message references
DA-344 Mar 26, 2024
85cdffc
Added new PollDuration's and updated results for polls
DA-344 Mar 27, 2024
07b21db
Removed answer param in on_poll_vote_... events docs
DA-344 Mar 27, 2024
0a61840
Updated 'id' param in Poll.get_answer
DA-344 Mar 27, 2024
e895389
Updated poll events docs, added answer parameter to poll events, chan…
DA-344 Mar 27, 2024
9d6ad95
Black polls files
DA-344 Mar 27, 2024
74c8efc
Fixed poll expiry route
DA-344 Mar 27, 2024
3444f80
Updated webhooks & interactions to support polls, updated all `reply`…
DA-344 Mar 27, 2024
6c7c49b
Updated polls docstring
DA-344 Mar 27, 2024
b9f74d8
Updated Webhooks polls docstring in send
DA-344 Mar 28, 2024
09f5437
Updated Raw Poll Event Model (its reusable)
DA-344 Mar 29, 2024
cba11b6
Testing commit to poll docs
DA-344 Apr 1, 2024
9bf1c3d
Added NamedTuple for PollMedia, and some changes to PollAnswer
DA-344 Apr 1, 2024
a5514e1
Added shortcut for Message.poll.end()
DA-344 Apr 2, 2024
0a38090
Bots support any duration polls if hours are in range 1 - 168!
DA-344 Apr 3, 2024
27bc8c7
Added new properties to PollAnswerCount & Poll
DA-344 Apr 3, 2024
89c3501
Added a new class for BaseMethods both answers share
DA-344 Apr 3, 2024
c0ca0fd
ACTUALLY fixing the types (once and for all)
DA-344 Apr 3, 2024
03e3ef0
Changed the users() PollAnswerBase AsyncIterator to also return Membe…
DA-344 Apr 3, 2024
96dfd72
Updated Poll object
DA-344 Apr 5, 2024
4094bf9
Changes to Poll Docs
DA-344 Apr 5, 2024
ca155da
Added PollMedia to docs
DA-344 Apr 8, 2024
824b003
Updated polls
DA-344 Apr 8, 2024
7456255
Added ValueError exception if polls have 0 or >10 answers
DA-344 Apr 8, 2024
cd821a0
Fixed PollMessage error
DA-344 Apr 11, 2024
1e9a1f6
Added newline from imports to __all__
DA-344 Apr 11, 2024
c4f9951
Updated some polls things
DA-344 Apr 11, 2024
d3cc82b
Updated the end_poll method
DA-344 Apr 11, 2024
7637d93
Updated poll.py file
DA-344 Apr 11, 2024
f7462ae
emoji was converted to a utils.cached_property by mistake lol
DA-344 Apr 11, 2024
cca6f9b
Grammar errors
DA-344 Apr 11, 2024
ddefc1f
Added versionadded to raw poll events
DA-344 Apr 11, 2024
8989529
Cannot override __slots__
DA-344 Apr 11, 2024
0419f3d
Fixed PollAnswer emojis
DA-344 Apr 13, 2024
c66bc51
Fixed an error where Message.poll would raise an error
DA-344 Apr 13, 2024
b754635
Added None as default value for poll, then set it later to prevent er…
DA-344 Apr 13, 2024
9193f70
Fixes to polls
DA-344 Apr 13, 2024
bd1e203
Moved duration errors to handle_message_parameters
DA-344 Apr 13, 2024
11f42ca
Fixed an error with the duration calculation when calling _from_data
DA-344 Apr 13, 2024
87e583d
Added overload for poll_vote_add/poll_vote_remove events
DA-344 Apr 13, 2024
d190bfb
Updated return type (forgot this should return tuples for multiple args)
DA-344 Apr 13, 2024
aadaea6
Added poll intents
DA-344 Apr 13, 2024
4ef2222
Moved Poll, PollAnswer and PollMedia to the data classes section, Pol…
DA-344 Apr 13, 2024
2410fed
Made poll a property instead of an attribute
DA-344 Apr 13, 2024
c48a24c
Added raw_poll_vote events to poll intents docstrings
DA-344 Apr 13, 2024
a4126c8
Fixed attributetable lol
DA-344 Apr 13, 2024
f4edabc
Fixed end_poll trying to replace a poll property instead of _poll att…
DA-344 Apr 13, 2024
e687146
Removed unnecessary type: ignore comments, removed PollMessage type a…
DA-344 Apr 13, 2024
aa75030
Fixed Context.send docstring
DA-344 Apr 13, 2024
648ada7
Updated poll intents docstrings
DA-344 Apr 13, 2024
9ea8df2
Black poll.py
DA-344 Apr 13, 2024
618658f
Removed PollEmoji as it is a PartialEmoji
DA-344 Apr 14, 2024
0dfb675
Update Poll._message & Poll._state when sending a message
DA-344 Apr 14, 2024
3258c32
Updated poll param in handle_parameters and updated after & limit in …
DA-344 Apr 14, 2024
8bf15cf
Added Poll._update to update the state, message, counts etc. attribut…
DA-344 Apr 14, 2024
fab8524
Call Poll._update when message is sent
DA-344 Apr 14, 2024
9860f35
.
DA-344 Apr 14, 2024
5253697
Updated poll._counts, PollAnswer.get_count docstring
DA-344 Apr 14, 2024
f877b54
Fix Messageable.send docstring
DA-344 Apr 15, 2024
fda6135
Prevent Pyright error
DA-344 Apr 15, 2024
a96a6e2
Added raw_poll_vote wait_for overloads
DA-344 Apr 15, 2024
1253761
Making `send` update the poll state
DA-344 Apr 16, 2024
c3de7c9
Makin `send` update the poll state (as well)
DA-344 Apr 16, 2024
8c6ed29
Removed unneccessary typed dicts and made answer_id an int instead of…
DA-344 Apr 16, 2024
e5b6468
Updated answer_id in PollVoteActionType and guild_id from Optional to…
DA-344 Apr 16, 2024
7170a04
Updated imports for the types changes
DA-344 Apr 16, 2024
0541527
Fix typo in PollAnswerBase.users docstring
DA-344 Apr 16, 2024
c246e8e
Moved end_poll from Message to PartialMessage
DA-344 Apr 17, 2024
f50456c
Merge branch 'polls' of https://github.com/DA-344/d.py into polls
DA-344 Apr 17, 2024
b091943
Reworked PollAnswerBase.users
DA-344 Apr 17, 2024
c621992
Fixed imports & change poll from NotRequired[Optional[...]] to NotReq…
DA-344 Apr 17, 2024
9583e84
Removed unneccessary warning in Poll docstring
DA-344 Apr 17, 2024
de1947a
Fixed check type annotation in wait_for poll related overloads
DA-344 Apr 17, 2024
b3f753a
Prevented circular import
DA-344 Apr 17, 2024
a9bcf4a
Added send_polls permission
DA-344 Apr 18, 2024
3db12c1
Made Intents.poll an alias_flag_value instead of a flag_value
DA-344 Apr 18, 2024
8b74a1a
use dict[key] instead of dict.get(key)
DA-344 Apr 18, 2024
20f33a8
Added newline
DA-344 Apr 18, 2024
1f1edeb
Added commas
DA-344 Apr 18, 2024
028899b
Added a comma
DA-344 Apr 18, 2024
8a1ebf9
Added a space before #type: ignore 's
DA-344 Apr 18, 2024
84be92c
Added a comma
DA-344 Apr 18, 2024
2f9b9c4
Added commas
DA-344 Apr 18, 2024
635f69c
Removed #type: ignore \'s
DA-344 Apr 18, 2024
d93954f
Merge branch 'polls' of https://github.com/DA-344/d.py into polls
DA-344 Apr 18, 2024
f118958
Resolve merge conflicts + update from master
DA-344 Apr 18, 2024
c4d9cc5
Added warning if cached message does not have a poll
DA-344 Apr 18, 2024
127a212
Oops 😬
DA-344 Apr 18, 2024
a4a9e0e
Remove length of recieved data from limit
DA-344 Apr 20, 2024
8ff203d
Add comma
DA-344 Apr 20, 2024
7396cb8
Poll changes
DA-344 Apr 20, 2024
ce37704
Merge branch 'polls' of https://github.com/DA-344/d.py into polls
DA-344 Apr 20, 2024
def3d76
Add comma (again)
DA-344 Apr 20, 2024
cc8d9d4
Another comma :v
DA-344 Apr 20, 2024
6f64ab8
And another comma >:v
DA-344 Apr 20, 2024
3f0c5dd
Another comma, again🙂👍
DA-344 Apr 20, 2024
63a3fd6
" " before "#type: ignore"
DA-344 Apr 20, 2024
1bd623c
,
DA-344 Apr 20, 2024
2bae4a0
Simplify polls
DA-344 Apr 20, 2024
fac840e
Added PollMedia to docs
DA-344 Apr 21, 2024
5f4ba13
Merge branch 'polls' of https://github.com/DA-344/d.py into polls
DA-344 Apr 21, 2024
f2c4cdb
Added Poll.copy
DA-344 Apr 21, 2024
09a4c59
Changes PollAnswerBase.voters docstring
DA-344 Apr 21, 2024
a24f1b0
warning -> note
DA-344 Apr 21, 2024
f17546f
poll: Poll = MISSING -> poll: Optional[Poll] = None
DA-344 Apr 21, 2024
8a49c88
not in (MISSING, None)
DA-344 Apr 21, 2024
ef3b685
Updated warning message
DA-344 Apr 21, 2024
2df6f0d
Added _add_vote_count to add a vote count if possible
DA-344 Apr 21, 2024
c81261f
Black
DA-344 Apr 21, 2024
cc01fff
Black
DA-344 Apr 21, 2024
082a1b9
Updated Messageables overloads
DA-344 Apr 21, 2024
065abab
Removed unnecessary overload
DA-344 Apr 21, 2024
bc41755
Merge branch 'master' of https://github.com/Rapptz/discord.py into polls
DA-344 Apr 22, 2024
e904668
Added base property 'poll'
DA-344 Apr 22, 2024
b74d2a5
BREAKING CHANGE | Edited poll events
DA-344 Apr 22, 2024
0093e66
Updated docs to show the latest commits
DA-344 Apr 22, 2024
ded24b0
Updated wait_for overload
DA-344 Apr 22, 2024
022e511
TypeHinted payload var in PollMedia.to_dict
DA-344 Apr 22, 2024
26f39be
Removed _add_vote_coun
DA-344 Apr 22, 2024
b83f7e0
poll events now update the cached message poll vote count
DA-344 Apr 23, 2024
f34f400
Merged all functionalities into PollAnswer
DA-344 Apr 23, 2024
b9a8da3
Added Message._handle_poll_vote to update inner poll vote counts
DA-344 Apr 23, 2024
4ead3f2
Removed PollAnswerCount
DA-344 Apr 23, 2024
4ac3dcf
rm #type: ignore
DA-344 Apr 23, 2024
807a72f
Updated self._poll attr to set the cached message's poll, if any
DA-344 Apr 24, 2024
004cefc
Updated poll to handle self_voted and PollAnswer repr to show its med…
DA-344 Apr 24, 2024
be53f23
Updated poll vote parser to update poll vote counts manually
DA-344 Apr 24, 2024
6a5e306
is not None
DA-344 Apr 25, 2024
e881dc7
reworked emoji dict in PollMedia.to_dict
DA-344 Apr 25, 2024
7038423
Return full answer payload instead of media
DA-344 Apr 25, 2024
c68ae70
Update poll._to_dict() with the poll answer changes
DA-344 Apr 25, 2024
7e427bc
Update Poll._to_dict
DA-344 Apr 25, 2024
ee1250f
Updated with @bijij suggestions
DA-344 Apr 25, 2024
98eda87
Updated Poll._from_data
DA-344 Apr 25, 2024
7940d43
Updated property name & doc and is_finalized
DA-344 Apr 25, 2024
63b65d4
Fixed check type annotation in Client.wait_for
DA-344 Apr 25, 2024
78d8c70
Merge branch 'master' of https://github.com/Rapptz/discord.py into polls
DA-344 May 5, 2024
d964851
remove poll checks
DA-344 May 5, 2024
492751e
Updated send docstring
DA-344 May 5, 2024
c941cad
update message.py with Rapptz suggestions
DA-344 May 5, 2024
7a174e3
Added create_polls permission alias
DA-344 May 5, 2024
ca8ca38
applied Rapptz suggestions
DA-344 May 5, 2024
91134e8
updated PollVoteActionEvent docstring
DA-344 May 5, 2024
e4d41bf
s
DA-344 May 5, 2024
41151c2
..versionadded:: -> .. versionadded::
DA-344 May 5, 2024
dfb124a
Black
DA-344 May 5, 2024
82bb213
change polls pos
DA-344 May 5, 2024
deb19f3
correct pos if sorted alphabetically
DA-344 May 5, 2024
6b0374a
merge branch 'master' from https://github.com/Rapptz/discord.py
DA-344 May 6, 2024
d952eae
Add alias for send_polls in permission overwrites
DA-344 May 6, 2024
8b2515e
PollMedia.__init__
DA-344 May 8, 2024
cbfcd15
Merge branch 'master' of https://github.com/Rapptz/discord.py into polls
DA-344 May 8, 2024
cdadbb1
Message._poll -> Message.poll (removed poll property)
DA-344 May 8, 2024
e120721
Updated Poll
DA-344 May 8, 2024
2a6c4ea
Updated PollMedia docstring
DA-344 May 8, 2024
0138dca
Added poll attr in Message docstring
DA-344 May 8, 2024
8fbce83
Fixed self type annotation
DA-344 May 9, 2024
8adaf0f
Remove Poll.emoji (no need for it)
DA-344 May 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions discord/__init__.py
Expand Up @@ -69,6 +69,7 @@
from .components import *
from .threads import *
from .automod import *
from .poll import *


class VersionInfo(NamedTuple):
Expand Down
7 changes: 7 additions & 0 deletions discord/abc.py
Expand Up @@ -92,6 +92,7 @@
VoiceChannel,
StageChannel,
)
from .poll import Poll
from .threads import Thread
from .ui.view import View
from .types.channel import (
Expand Down Expand Up @@ -1350,6 +1351,7 @@ async def send(
view: View = ...,
suppress_embeds: bool = ...,
silent: bool = ...,
poll: Poll = ...,
DA-344 marked this conversation as resolved.
Show resolved Hide resolved
) -> Message:
...

Expand All @@ -1370,6 +1372,7 @@ async def send(
view: View = ...,
suppress_embeds: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -1390,6 +1393,7 @@ async def send(
view: View = ...,
suppress_embeds: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -1410,6 +1414,7 @@ async def send(
view: View = ...,
suppress_embeds: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -1431,6 +1436,7 @@ async def send(
view: Optional[View] = None,
suppress_embeds: bool = False,
silent: bool = False,
poll: Poll = MISSING,
) -> Message:
"""|coro|

Expand Down Expand Up @@ -1582,6 +1588,7 @@ async def send(
stickers=sticker_ids,
view=view,
flags=flags,
poll=poll
DA-344 marked this conversation as resolved.
Show resolved Hide resolved
) as params:
data = await state.http.send_message(channel.id, params=params)

Expand Down
5 changes: 5 additions & 0 deletions discord/enums.py
Expand Up @@ -73,6 +73,7 @@
'SKUType',
'EntitlementType',
'EntitlementOwnerType',
'PollLayoutType',
)


Expand Down Expand Up @@ -809,6 +810,10 @@ class EntitlementOwnerType(Enum):
user = 2


class PollLayoutType(Enum):
normal = 1
DA-344 marked this conversation as resolved.
Show resolved Hide resolved


def create_unknown_value(cls: Type[E], val: Any) -> E:
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
name = f'unknown_{val}'
Expand Down
17 changes: 17 additions & 0 deletions discord/ext/commands/context.py
Expand Up @@ -50,6 +50,7 @@
from discord.message import MessageReference, PartialMessage
from discord.ui import View
from discord.types.interactions import ApplicationCommandInteractionData
from discord.poll import Poll

from .cog import Cog
from .core import Command
Expand Down Expand Up @@ -641,6 +642,7 @@ async def reply(
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
DA-344 marked this conversation as resolved.
Show resolved Hide resolved
) -> Message:
...

Expand All @@ -662,6 +664,7 @@ async def reply(
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -683,6 +686,7 @@ async def reply(
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -704,6 +708,7 @@ async def reply(
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand Down Expand Up @@ -826,6 +831,7 @@ async def send(
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -847,6 +853,7 @@ async def send(
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -868,6 +875,7 @@ async def send(
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -889,6 +897,7 @@ async def send(
suppress_embeds: bool = ...,
ephemeral: bool = ...,
silent: bool = ...,
poll: Poll = ...,
) -> Message:
...

Expand All @@ -911,6 +920,7 @@ async def send(
suppress_embeds: bool = False,
ephemeral: bool = False,
silent: bool = False,
poll: Poll = MISSING
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
poll: Poll = MISSING
poll: Poll = MISSING,

) -> Message:
"""|coro|

Expand Down Expand Up @@ -1000,6 +1010,11 @@ async def send(

.. versionadded:: 2.2

poll: :class:`Poll`
The linked poll for this message.

.. versionadded:: 2.4

Raises
--------
~discord.HTTPException
Expand Down Expand Up @@ -1037,6 +1052,7 @@ async def send(
view=view,
suppress_embeds=suppress_embeds,
silent=silent,
poll=poll
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
poll=poll
poll=poll,

) # type: ignore # The overloads don't support Optional but the implementation does

# Convert the kwargs from None to MISSING to appease the remaining implementations
Expand All @@ -1052,6 +1068,7 @@ async def send(
'suppress_embeds': suppress_embeds,
'ephemeral': ephemeral,
'silent': silent,
'poll': poll
DA-344 marked this conversation as resolved.
Show resolved Hide resolved
}

if self.interaction.response.is_done():
Expand Down
5 changes: 5 additions & 0 deletions discord/http.py
Expand Up @@ -68,6 +68,7 @@
from .embeds import Embed
from .message import Attachment
from .flags import MessageFlags
from .poll import Poll

from .types import (
appinfo,
Expand Down Expand Up @@ -154,6 +155,7 @@ def handle_message_parameters(
thread_name: str = MISSING,
channel_payload: Dict[str, Any] = MISSING,
applied_tags: Optional[SnowflakeList] = MISSING,
poll: Optional[Poll] = MISSING
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be refactored. This currently implies that passing no poll parameter and poll=None has the same behavior. Optional[T] = MISSING should be used when passing param=None has a separate behavior from not passing anything. Passing poll = None does not remove a poll from a message. Moreover, if poll not in (MISSING, None) should be updated with if poll is not MISSING.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would disagree, since it makes pyright angry on await ctx.send('Hello', poll=poll) where poll is Optional[Poll]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I was thrown off by the type hint for the send coroutines.

handle_message_parameters should have Optional[Poll] = None and all the send methods should have poll: Optional[Poll] = None in their function definition rather than poll: Poll = MISSING. In the handle_message_parameters block it should have if poll is not None: ...

Suggested change
poll: Optional[Poll] = MISSING
poll: Optional[Poll] = None
def handle_message_parameters(poll: Optional[Poll] = None) -> ...:
    if poll is not None: ...

) -> MultipartParameters:
if files is not MISSING and file is not MISSING:
raise TypeError('Cannot mix file and files keyword arguments.')
Expand Down Expand Up @@ -256,6 +258,9 @@ def handle_message_parameters(
}
payload.update(channel_payload)

if poll not in (MISSING, None):
payload['poll'] = poll._to_dict()

multipart = []
if files:
multipart.append({'name': 'payload_json', 'value': utils._to_json(payload)})
Expand Down
5 changes: 5 additions & 0 deletions discord/message.py
Expand Up @@ -63,6 +63,7 @@
from .sticker import StickerItem, GuildSticker
from .threads import Thread
from .channel import PartialMessageable
from .poll import Poll

if TYPE_CHECKING:
from typing_extensions import Self
Expand Down Expand Up @@ -1644,6 +1645,7 @@ class Message(PartialMessage, Hashable):
'role_subscription',
'application_id',
'position',
'poll',
)

if TYPE_CHECKING:
Expand Down Expand Up @@ -1682,6 +1684,9 @@ def __init__(
self.position: Optional[int] = data.get('position')
self.application_id: Optional[int] = utils._get_as_snowflake(data, 'application_id')
self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])]
poll = data.get('poll')

self.poll: Optional[Poll] = Poll._from_data(poll) if poll else None

try:
# if the channel doesn't have a guild attribute, we handle that
Expand Down