-
Notifications
You must be signed in to change notification settings - Fork 134
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
feat(polls): implement Polls #1176
base: master
Are you sure you want to change the base?
Conversation
@@ -0,0 +1,426 @@ | |||
# SPDX-License-Identifier: MIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to have two separate objects for what the user can construct vs what the api returns; there's a bunch of fields the user constructible version won't have populated until some magic event, and you made accessing them throw AttributeError
I think you'd agree that physically restricting what the user can do with their object is better than merely mentioning it in the docstring (which seem to often grow large enough a good part of it won't be seen unless scrolled down)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this. Something similar to what I did in the Onboarding PR could be implemented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First off, thanks for implementing this, and sorry the review took so long! A bunch of other things unfortunately got in the way.
Many of these comments are simple documentation adjustments and can be committed as-is, some other parts are a bit more complex (as usual, coming up with a good developer interface is tricky).
There's still a bunch of bikeshedding to be done as you mentioned, so i've left out comments about a couple things that only make sense to talk about once everything else is taken care of, for now.
That said, a new permission and poll intents have been added to the api since, would be great to have them implemented here too.
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Co-authored-by: shiftinv <[email protected]> Signed-off-by: Snipy7374 <[email protected]>
Ty for the reviews and sorry if this is taking longer than expected, it's my first API feature so i'm quite inexperienced. I still have the same typing (skill) issue at |
No worries, it's a pretty substantial feature and this is already really good c:
Hm, seems that |
feat(polls): add poll answer voters iterator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far 👍
@@ -1344,6 +1361,11 @@ class EntitlementType(Enum): | |||
application_subscription = 8 | |||
|
|||
|
|||
class PollLayoutType(Enum): | |||
default = 1 | |||
"""The default poll layout type.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be documented in the respective .rst file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already documented in disnake.Event
page and in the messages API reference section too. Is there somewhere else this should be documented?
@@ -22,7 +22,7 @@ | |||
overload, | |||
) | |||
|
|||
from . import utils | |||
from . import poll, utils |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is so insignificant, but the Poll
class should be imported instead of doing this
@@ -0,0 +1,426 @@ | |||
# SPDX-License-Identifier: MIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this. Something similar to what I did in the Onboarding PR could be implemented.
The message ID that got or lost a vote. | ||
user_id: :class:`int` | ||
The user ID who added the vote or whose vote was removed. | ||
member: Optional[:class:`Member`] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this is not consistent across all raw models, changing this to cached_member
would be more descriptive.
member_id = raw.user_id | ||
guild = self._get_guild(raw.guild_id) | ||
if guild is not None: | ||
member = guild.get_member(member_id) | ||
if (message := self._get_message(raw.message_id)) and message.poll: | ||
answer = utils.get(message.poll.answers, id=raw.answer_id) | ||
else: | ||
answer = None | ||
if member is not None: | ||
raw.member = member | ||
else: | ||
raw.member = None | ||
else: | ||
raw.member = None | ||
answer = None | ||
self.dispatch(f"raw_message_poll_vote_{event_type}", raw) | ||
|
||
if raw.member and answer: | ||
self.dispatch(f"message_poll_vote_{event_type}", raw.member, answer) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
member_id = raw.user_id | |
guild = self._get_guild(raw.guild_id) | |
if guild is not None: | |
member = guild.get_member(member_id) | |
if (message := self._get_message(raw.message_id)) and message.poll: | |
answer = utils.get(message.poll.answers, id=raw.answer_id) | |
else: | |
answer = None | |
if member is not None: | |
raw.member = member | |
else: | |
raw.member = None | |
else: | |
raw.member = None | |
answer = None | |
self.dispatch(f"raw_message_poll_vote_{event_type}", raw) | |
if raw.member and answer: | |
self.dispatch(f"message_poll_vote_{event_type}", raw.member, answer) | |
guild = self._get_guild(raw.guild_id) | |
answer = None | |
if guild is not None: | |
member = guild.get_member(raw.user_id) | |
message = self._get_message(raw.message_id) | |
if message is not None and message.poll is not None: | |
answer = utils.get(message.poll.answers, id=raw.answer_id) | |
if member is not None: | |
raw.member = member | |
self.dispatch(f"raw_message_poll_vote_{event_type}", raw) | |
if raw.member is not None and answer is not None: | |
self.dispatch(f"message_poll_vote_{event_type}", raw.member, answer) |
Summary
Notes:
PollMedia
doesn't work yet... idk if this is an issue on my code or on the APIquestion
field onPoll
will be able to accept aPollMedia
too, andPollMedia
will likely supports new thingsDoubts:
I feel like i'm passing way too many arguments for the new events? What's your opinion?SolvedPoll
? The maximum allowed is 10 answers per pollI have a typing (skill) issue atSolvedpoll.py/PollAnswer#245
what am i supposed to do there?Should we make answers and polls be EQ comparable in some way? (we could use the internal message object, if set, to check if two polls are equals)Doesn't make sense on second thoughtChecklist
pdm lint
pdm pyright