Class: Discordrb::Poll::Answer
- Inherits:
-
Object
- Object
- Discordrb::Poll::Answer
- Defined in:
- lib/discordrb/data/poll.rb
Overview
A selectable poll answer.
Instance Attribute Summary collapse
-
#id ⇒ Integer
readonly
The ID of the poll answer.
-
#message_id ⇒ Integer
readonly
The ID of the message the answer is from.
-
#votes ⇒ Integer
(also: #vote_count)
readonly
The number of votes the answer has.
Instance Method Summary collapse
-
#==(other) ⇒ true, false
(also: #eql?)
Check if two poll answers are equivalent.
-
#emoji ⇒ Emoji?
Get the emoji of the poll answer.
-
#text ⇒ String
Get the text of the poll answer.
-
#voters(after: nil, limit: 100) ⇒ Array<User>
Get the users who voted for the poll answer.
-
#winner? ⇒ true, false
Check if the poll answer won the poll.
Instance Attribute Details
#id ⇒ Integer (readonly)
Returns the ID of the poll answer.
142 143 144 |
# File 'lib/discordrb/data/poll.rb', line 142 def id @id end |
#message_id ⇒ Integer (readonly)
Returns the ID of the message the answer is from.
149 150 151 |
# File 'lib/discordrb/data/poll.rb', line 149 def @message_id end |
#votes ⇒ Integer (readonly) Also known as: vote_count
Returns the number of votes the answer has.
145 146 147 |
# File 'lib/discordrb/data/poll.rb', line 145 def votes @votes end |
Instance Method Details
#==(other) ⇒ true, false Also known as: eql?
Check if two poll answers are equivalent.
210 211 212 213 214 |
# File 'lib/discordrb/data/poll.rb', line 210 def ==(other) return false unless other.is_a?(Answer) @message_id == other. && @id == other.id end |
#emoji ⇒ Emoji?
Get the emoji of the poll answer.
170 171 172 |
# File 'lib/discordrb/data/poll.rb', line 170 def emoji @media.emoji end |
#text ⇒ String
Get the text of the poll answer.
164 165 166 |
# File 'lib/discordrb/data/poll.rb', line 164 def text @media.text end |
#voters(after: nil, limit: 100) ⇒ Array<User>
Get the users who voted for the poll answer.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/discordrb/data/poll.rb', line 184 def voters(after: nil, limit: 100) stable = @poll.nil? || @poll.finalised? channel_id = @channel_id || @poll..channel.id after_time = after.is_a?(Time) ? IDObject.synthesise(after) : after&.resolve_id get_users = lambda do |limit, after| data = API::Channel.get_poll_voters(@bot.token, channel_id, @message_id, @id, after:, limit:) JSON.parse(data)['users'].collect { |poll_voter_data| @bot.ensure_user(poll_voter_data) } end return get_users.call(limit, after_time) if limit && limit <= 100 paginator = Paginator.new(limit, :down) do |last_page| if stable && last_page && last_page.count < 100 [] else get_users.call(100, last_page&.last&.id || after_time) end end paginator.to_a end |
#winner? ⇒ true, false
Check if the poll answer won the poll.
176 177 178 |
# File 'lib/discordrb/data/poll.rb', line 176 def winner? @poll.nil? || @poll.winner&.id == @id end |