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 #534

Merged
merged 35 commits into from
Apr 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
425e660
Bump Credo to 1.7.5 to stop deprecation warnings
jb3 Apr 13, 2024
125bd92
Add structures for Discord polls
jb3 Apr 13, 2024
64f2848
Add the new `poll` attribute to Message types
jb3 Apr 13, 2024
d7a3f44
Meet Credo checks
jb3 Apr 13, 2024
7a14f9d
Add missing typespec to method Poll.create_poll/2
jb3 Apr 13, 2024
33fd626
Add democracy manifest propaganda
jb3 Apr 14, 2024
d346bbb
Add new gateway struct for poll vote changes
jb3 Apr 14, 2024
7414520
Add new dispatch logic for poll vote changes
jb3 Apr 14, 2024
11ba7e5
Add new gateway intents for poll vote changes
jb3 Apr 14, 2024
2ee7662
Update intents test with new values
jb3 Apr 14, 2024
a4ed73c
Add API route for fetching voters for a poll
jb3 Apr 14, 2024
594eb47
Add API route for expiring polls early
jb3 Apr 14, 2024
22ee041
Add new typing for new gateway events to consumer
jb3 Apr 14, 2024
09791c7
Add documentation for helper methods on Poll
jb3 Apr 14, 2024
c3e267e
Add tests for Poll helper methods
jb3 Apr 14, 2024
a6b897f
Update Polls API module naming and documentation
jb3 Apr 15, 2024
2774595
Documentation improvements in PollVoteChange
jb3 Apr 15, 2024
c79c6b8
Simplify Map creation in PollVoteChange
jb3 Apr 15, 2024
40c15c2
Documentation improvements in Poll struct
jb3 Apr 15, 2024
4528747
Further documentation improvements in Poll struct
jb3 Apr 15, 2024
109b0d4
Documentation and simplifications in MediaObject
jb3 Apr 15, 2024
83d1589
Documentation improvements in Poll Results struct
jb3 Apr 15, 2024
6c022f3
Update Api.get_poll_answer_voters!/4 with new name
jb3 Apr 15, 2024
29f11e9
mix format to remove whitespace
jb3 Apr 15, 2024
17049c8
Update documentation about pagination
jb3 Apr 15, 2024
abfed4b
Actually fix the get_poll_answer_voters!/4 method
jb3 Apr 15, 2024
ac62d3d
Replace types of PollVoteChange with ID types
jb3 Apr 15, 2024
879d5cb
Update PollVoteChange to link to Poll.answers type
jb3 Apr 15, 2024
a447c75
Correct typing in Message struct
jb3 Apr 15, 2024
f0fe367
Better document results attribute of Poll
jb3 Apr 15, 2024
4de7b2f
Simplify Map creation for Results struct
jb3 Apr 15, 2024
747119b
Stop Credo complaints about PollVoteChange
jb3 Apr 15, 2024
6733306
Add new `send_polls` permission
jb3 Apr 17, 2024
dd57fa1
Clarify pagination return value
jb3 Apr 17, 2024
688d558
Add clarification on layout_type attribute
jb3 Apr 17, 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
Prev Previous commit
Next Next commit
Add API route for fetching voters for a poll
jb3 committed Apr 14, 2024

Verified

This commit was signed with the committer’s verified signature.
snyk-bot Snyk bot
commit a4ed73cb59fc84864ed55c52f1a6471007c20123
31 changes: 31 additions & 0 deletions lib/nostrum/api.ex
Original file line number Diff line number Diff line change
@@ -57,6 +57,7 @@ defmodule Nostrum.Api do
Interaction,
Invite,
Message,
Message.Poll,
ThreadMember,
User,
Webhook
@@ -618,6 +619,36 @@ defmodule Nostrum.Api do
|> bangify
end

@doc ~S"""
Get voters for the provided answer on the poll attached to the provided message.

If successful, returns `{:ok, users}`. Otherwise, returns `t:Nostrum.Api.error/0`.

The optional `params` are `after`, the user ID to query after, absent by default,
and `limit`, the max number of users to return, 1-100, 25 by default.
jb3 marked this conversation as resolved.
Show resolved Hide resolved
"""
@spec get_answer_voters(Channel.id(), Message.id(), Poll.Answer.answer_id()) ::
error | {:ok, [User.t()]}
def get_answer_voters(channel_id, message_id, answer_id, params \\ []) do
jb3 marked this conversation as resolved.
Show resolved Hide resolved
result =
request(:get, Constants.poll_answer_voters(channel_id, message_id, answer_id), "", params)
|> handle_request_with_decode()

case result do
{:ok, %{users: users}} -> {:ok, Util.cast(users, {:list, {:struct, User}})}
_ -> result
end
end

@doc ~S"""
Same as `get_answer_voters/4`, but raises `Nostrum.Error.ApiError` in case of failure.
"""
@spec get_answer_voters!(Channel.id(), Message.id(), Poll.Answer.answer_id()) :: [User.t()]
def get_answer_voters!(channel_id, message_id, answer_id, params \\ []) do
get_answer_voters(channel_id, message_id, answer_id, params)
|> bangify
end

@doc ~S"""
Gets a channel.

3 changes: 3 additions & 0 deletions lib/nostrum/constants.ex
Original file line number Diff line number Diff line change
@@ -174,6 +174,9 @@ defmodule Nostrum.Constants do
def guild_auto_moderation_rule(guild_id, rule_id),
do: "/guilds/#{guild_id}/auto-moderation/rules/#{rule_id}"

def poll_answer_voters(channel_id, message_id, answer_id),
do: "/channels/#{channel_id}/polls/#{message_id}/answers/#{answer_id}"

def discord_epoch, do: 1_420_070_400_000

def opcodes do