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

Implement Polls #1922

Open
wants to merge 80 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
1ed6fcf
Initial commit on implementing polls
PythonTryHard May 19, 2024
2c53e90
Towncrier chore
PythonTryHard May 19, 2024
89088f1
New poll endpoints
PythonTryHard May 19, 2024
2888d76
Ensure route naming consistency
PythonTryHard May 20, 2024
f31effb
Basic implementation of poll-related classes
PythonTryHard May 20, 2024
36e5963
I forgor to format my code
PythonTryHard May 20, 2024
b7979c4
Poll-specific events
PythonTryHard May 20, 2024
a32ac57
Only import hikari.Emoji on type checking
PythonTryHard May 20, 2024
153fab3
Remove erroneous `__slots__` from PollResult
PythonTryHard May 20, 2024
3daae57
Integrate poll classes and events into hikari
PythonTryHard May 20, 2024
aaab4c4
Implement poll in EntityFactory and REST
PythonTryHard May 27, 2024
4be409f
Update typing stub
PythonTryHard May 27, 2024
8d3220b
Apparently `Emoji` needs to be imported
PythonTryHard May 27, 2024
a330fcd
added `_serialize_poll_media()`
mplatypus May 27, 2024
ff5413e
Removal of counter
mplatypus May 27, 2024
64d7b33
Merge pull request #1 from MPlatypus/fix/polls
PythonTryHard May 27, 2024
f7f58b7
Credit's where credit's due
PythonTryHard May 27, 2024
a5dbfe7
Throw error on adding answer with existing ID
PythonTryHard May 27, 2024
a6ba51e
Apparently we don't need to set _answer to None
PythonTryHard May 27, 2024
ea9de9e
Docstring, dammit
PythonTryHard May 27, 2024
a7fa5a6
Apply suggestions from code review
PythonTryHard May 27, 2024
e7768d3
`Emoji` is now `emojis.Emoji`
PythonTryHard May 28, 2024
65c333f
`PollObject` is now `Poll`
PythonTryHard May 28, 2024
6102e92
Correct `duration` key in `serialize_poll`
PythonTryHard May 28, 2024
2347199
Finalize a7fa5a6b on de-underscoring and `.get()`
PythonTryHard May 28, 2024
b2730be
Change event name for consistency
PythonTryHard May 28, 2024
0d2de42
I forgor to update `__all__`
PythonTryHard May 28, 2024
b5bc835
Dav please
PythonTryHard May 28, 2024
cfb4446
Use UNDEFINED for nullable guild in poll events
PythonTryHard May 28, 2024
9fc84a9
Nox
PythonTryHard May 28, 2024
e6d642f
Implement poll events in EventFactory
PythonTryHard May 28, 2024
7fe8a12
Correct fallback value for guild_id.
PythonTryHard May 28, 2024
405458d
`PollCreate` is now `PollBuilder`
PythonTryHard May 28, 2024
313d673
....shit
PythonTryHard May 28, 2024
fd21d87
fixed naming of poll events in event manager
mplatypus May 28, 2024
6a4c892
added poll vote add/remove intents
mplatypus May 28, 2024
6f0b79f
forgor nox
mplatypus May 28, 2024
bf34490
added extra intents.
mplatypus May 28, 2024
543d20c
Fixed PollCreate to PollBuilder
mplatypus May 28, 2024
917e35e
fixed emojis, and answer handling.
mplatypus May 28, 2024
515325e
Fixed naming
mplatypus May 28, 2024
1517482
fixed naming and docs
mplatypus May 28, 2024
d6fbf67
Migrate remnant `PollCreate`
PythonTryHard Jul 10, 2024
e911c06
Inline the two `_deserialize`
PythonTryHard Jul 10, 2024
629a1bb
Inline _serialize_poll_partial_emoji
PythonTryHard Jul 10, 2024
c846391
Merge pull request #4 from mplatypus/polls
PythonTryHard Jul 10, 2024
9e8a50c
Minor improvement to docstrings
PythonTryHard Jul 10, 2024
1e05101
What the hell Platy?
PythonTryHard Jul 10, 2024
001e2e2
Add missing `poll_events` import
PythonTryHard Jul 10, 2024
aaed77e
added poll endpoints
mplatypus Jul 10, 2024
46a425c
ruff formatting + changed to sequence
mplatypus Jul 10, 2024
38dd771
Nox format
PythonTryHard Jul 10, 2024
1dc17f4
Resolve typing conflict of `_answer` field
PythonTryHard Jul 10, 2024
13ef0cd
added some more tests.
mplatypus Jul 10, 2024
9d8cb17
Rework Poll events
PythonTryHard Jul 10, 2024
064baed
fixed failing tests.
mplatypus Jul 10, 2024
43fee96
Merge pull request #5 from mplatypus/polls
PythonTryHard Jul 10, 2024
bc65d79
Merge remote-tracking branch 'fork/master' into polls
PythonTryHard Jul 10, 2024
add6bf5
Appease flake8
PythonTryHard Jul 10, 2024
fbe5d1a
Appease mypy
PythonTryHard Jul 10, 2024
700521e
Correct docstring after renaming
PythonTryHard Jul 10, 2024
250cb47
Edit message endpoint doesn't support polls
PythonTryHard Jul 10, 2024
bfd338e
Improve names and docstrings
PythonTryHard Jul 10, 2024
385e62d
finished most tests.
mplatypus Jul 11, 2024
db85774
Merge pull request #6 from mplatypus/polls
PythonTryHard Jul 11, 2024
1f6db34
Merge remote-tracking branch 'fork/master' into polls
PythonTryHard Jul 11, 2024
51fe4e4
Correct edit_message tests
PythonTryHard Jul 11, 2024
eb41493
Correct poll answer payload extraction
PythonTryHard Jul 11, 2024
25ce6f2
Correct event name in test
PythonTryHard Jul 11, 2024
afeeebf
...missed some
PythonTryHard Jul 11, 2024
3440a15
Fix test_fetch_poll_voter occasionally not working
PythonTryHard Jul 11, 2024
9b33958
added missing tests.
mplatypus Aug 1, 2024
46d9cbc
Added tests for polls
mplatypus Aug 1, 2024
69c0e6c
Merge pull request #7 from mplatypus/polls
PythonTryHard Aug 10, 2024
9f0e4c8
Remove leftover inlined method
PythonTryHard Jul 12, 2024
ff06143
Update copyright holder
PythonTryHard Aug 7, 2024
466af5b
Fix failing poll tests
PythonTryHard Aug 10, 2024
f2131f6
I guess this is fine
PythonTryHard Aug 10, 2024
a751cc4
I did a dumb
PythonTryHard Aug 10, 2024
2011519
Merge remote-tracking branch 'origin/master' into polls
PythonTryHard Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/1922.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for built-in polls
PythonTryHard marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions hikari/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
from hikari.events.member_events import *
from hikari.events.message_events import *
from hikari.events.monetization_events import *
from hikari.events.poll_events import *
from hikari.events.reaction_events import *
from hikari.events.role_events import *
from hikari.events.scheduled_events import *
Expand Down Expand Up @@ -115,6 +116,7 @@
from hikari.messages import *
from hikari.monetization import *
from hikari.permissions import *
from hikari.polls import *
from hikari.presences import *
from hikari.scheduled_events import *
from hikari.sessions import *
Expand Down
2 changes: 2 additions & 0 deletions hikari/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ from hikari.events.lifetime_events import *
from hikari.events.member_events import *
from hikari.events.message_events import *
from hikari.events.monetization_events import *
from hikari.events.poll_events import *
from hikari.events.reaction_events import *
from hikari.events.role_events import *
from hikari.events.scheduled_events import *
Expand Down Expand Up @@ -90,6 +91,7 @@ from hikari.locales import *
from hikari.messages import *
from hikari.monetization import *
from hikari.permissions import *
from hikari.polls import *
from hikari.presences import *
from hikari.scheduled_events import *
from hikari.sessions import *
Expand Down
35 changes: 35 additions & 0 deletions hikari/api/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from hikari import invites as invite_models
from hikari import messages as message_models
from hikari import monetization as entitlement_models
from hikari import polls as poll_models
from hikari import presences as presence_models
from hikari import scheduled_events as scheduled_events_models
from hikari import sessions as gateway_models
Expand Down Expand Up @@ -1994,3 +1995,37 @@ def deserialize_stage_instance(self, payload: data_binding.JSONObject) -> stage_
hikari.stage_intances.StageInstance
The deserialized stage instance object
"""

###############
# POLL MODELS #
###############

@abc.abstractmethod
def deserialize_poll(self, payload: data_binding.JSONObject) -> poll_models.Poll:
"""Parse a raw payload from Discord into a poll object.

Parameters
----------
payload
The JSON payload to deserialize.

Returns
-------
hikari.polls.Poll
The deserialized poll object.
"""

@abc.abstractmethod
def serialize_poll(self, poll: poll_models.PollBuilder) -> data_binding.JSONObject:
"""Serialize a poll object to a json serializable dict.

Parameters
----------
poll
The poll object to serialize.

Returns
-------
hikari.internal.data_binding.JSONObject
The serialized representation of the poll.
"""
43 changes: 43 additions & 0 deletions hikari/api/event_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from hikari.events import member_events
from hikari.events import message_events
from hikari.events import monetization_events
from hikari.events import poll_events
from hikari.events import reaction_events
from hikari.events import role_events
from hikari.events import scheduled_events
Expand Down Expand Up @@ -1469,3 +1470,45 @@ def deserialize_stage_instance_delete_event(
hikari.events.stage_events.StageInstanceDeleteEvent
The parsed stage instance delete event object.
"""

################
# POLL EVENTS #
################

@abc.abstractmethod
def deserialize_poll_vote_create_event(
self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject
) -> poll_events.PollVoteCreateEvent:
"""Parse a raw payload from Discord into a poll vote create event object.

Parameters
----------
shard
The shard that emitted this event.
payload
The dict payload to parse.

Returns
-------
hikari.events.poll_events.PollVoteCreateEvent
The parsed poll vote create event object.
"""

@abc.abstractmethod
def deserialize_poll_vote_delete_event(
self, shard: gateway_shard.GatewayShard, payload: data_binding.JSONObject
) -> poll_events.PollVoteDeleteEvent:
"""Parse a raw payload from Discord into a poll vote delete event object.

Parameters
----------
shard
The shard that emitted this event.
payload
The dict payload to parse.

Returns
-------
hikari.events.poll_events.PollVoteDeleteEvent
The parsed poll vote delete event object.
"""
81 changes: 81 additions & 0 deletions hikari/api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
from hikari import messages as messages_
from hikari import monetization
from hikari import permissions as permissions_
from hikari import polls
from hikari import sessions
from hikari import snowflakes
from hikari import stage_instances
Expand Down Expand Up @@ -1043,6 +1044,7 @@ async def create_message(
components: undefined.UndefinedOr[typing.Sequence[special_endpoints.ComponentBuilder]] = undefined.UNDEFINED,
embed: undefined.UndefinedOr[embeds_.Embed] = undefined.UNDEFINED,
embeds: undefined.UndefinedOr[typing.Sequence[embeds_.Embed]] = undefined.UNDEFINED,
poll: undefined.UndefinedOr[polls.PollBuilder] = undefined.UNDEFINED,
sticker: undefined.UndefinedOr[snowflakes.SnowflakeishOr[stickers_.PartialSticker]] = undefined.UNDEFINED,
stickers: undefined.UndefinedOr[
snowflakes.SnowflakeishSequence[stickers_.PartialSticker]
Expand Down Expand Up @@ -1120,6 +1122,8 @@ async def create_message(
If provided, the message embed.
embeds
If provided, the message embeds.
poll
If provided, the poll to create.
sticker
If provided, the object or ID of a sticker to send on the message.

Expand Down Expand Up @@ -8654,3 +8658,80 @@ async def delete_stage_instance(self, channel: snowflakes.SnowflakeishOr[channel
hikari.errors.InternalServerError
If an internal error occurs on Discord while handling the request.
"""

@abc.abstractmethod
async def fetch_poll_voters(
self,
channel: snowflakes.SnowflakeishOr[channels_.TextableChannel],
message: snowflakes.SnowflakeishOr[messages_.PartialMessage],
answer_id: int,
/,
*,
after: undefined.UndefinedOr[snowflakes.SnowflakeishOr[users.PartialUser]] = undefined.UNDEFINED,
limit: undefined.UndefinedOr[int] = undefined.UNDEFINED,
) -> typing.Sequence[users.User]:
"""Fetch users that voted for a specific answer.

Parameters
----------
channel
The channel the poll is in.
message
The message the poll is in.
answer_id
The answers id.
after
The votes to collect, after this user voted.
limit
The amount of votes to collect. Maximum 100, default 25

Returns
-------
typing.Sequence[users.User]
An sequence of Users.

Raises
------
hikari.errors.BadRequestError
If any of the fields that are passed have an invalid value.
hikari.errors.UnauthorizedError
If you are unauthorized to make the request (invalid/missing token).
hikari.errors.NotFoundError
If the entitlement was not found.
hikari.errors.RateLimitTooLongError
Raised in the event that a rate limit occurs that is
longer than `max_rate_limit` when making a request.
hikari.errors.InternalServerError
If an internal error occurs on Discord while handling the request.
"""

@abc.abstractmethod
async def end_poll(
self,
channel: snowflakes.SnowflakeishOr[channels_.TextableChannel],
message: snowflakes.SnowflakeishOr[messages_.PartialMessage],
/,
) -> None:
"""End a poll.

Parameters
----------
channel
The channel the poll is in.
message
The message the poll is in.

Raises
------
hikari.errors.BadRequestError
If any of the fields that are passed have an invalid value.
hikari.errors.UnauthorizedError
If you are unauthorized to make the request (invalid/missing token).
hikari.errors.NotFoundError
If the entitlement was not found.
hikari.errors.RateLimitTooLongError
Raised in the event that a rate limit occurs that is
longer than `max_rate_limit` when making a request.
hikari.errors.InternalServerError
If an internal error occurs on Discord while handling the request.
"""
Loading