Skip to content

Add support for polls #534

New issue

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

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

Already on GitHub? # to your account

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 tests for Poll helper methods
  • Loading branch information
jb3 committed Apr 14, 2024
commit c3e267e41166cf7ecd3e147360bce4a7c4dfb342
2 changes: 2 additions & 0 deletions lib/nostrum/struct/message/poll.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule Nostrum.Struct.Message.Poll do
@moduledoc """
Struct representing a poll object in a Discord chat.

There are various helper methods on this structure to create new poll, see `create_poll/2` and `put_answer/2` & `put_answer/3` for code samples.
"""

alias Nostrum.Util
40 changes: 40 additions & 0 deletions test/nostrum/struct/message/poll_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule Nostrum.Struct.Message.PollTest do
use ExUnit.Case, async: true

alias Nostrum.Struct.Message.Poll

doctest Poll

test "Poll.create_poll/2" do
assert Poll.create_poll("Craigs Cats!", duration: 1, allow_multiselect: true) ==
%Nostrum.Struct.Message.Poll{
question: %Nostrum.Struct.Message.Poll.MediaObject{
text: "Craigs Cats!",
emoji: nil
},
answers: [],
expiry: nil,
duration: 1,
allow_multiselect: true,
layout_type: 1,
results: nil
}
end

test "Poll.put_answer/2" do
poll =
Poll.create_poll("Craigs Cats!", duration: 1, allow_multiselect: true)
|> Poll.put_answer("Yes!")

assert Enum.at(poll.answers, 0).poll_media.text == "Yes!"
end

test "Poll.put_answer/3" do
poll =
Poll.create_poll("Craigs Cats!", duration: 1, allow_multiselect: true)
|> Poll.put_answer("Yes!", custom_emoji: 112_233_445_566_778_899)

assert Enum.at(poll.answers, 0).poll_media.text == "Yes!"
assert Enum.at(poll.answers, 0).poll_media.emoji.id == 112_233_445_566_778_899
end
end