Skip to content

Commit

Permalink
Add API route for expiring polls early
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Apr 14, 2024
1 parent a4ed73c commit 594eb47
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/nostrum/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,24 @@ defmodule Nostrum.Api do
|> bangify
end

@doc ~S"""
Expire (close voting on) a poll before the scheduled end time. Returns a message object.
"""
@spec expire_poll(Channel.id(), Message.id()) :: error | {:ok, Message.t()}
def expire_poll(channel_id, message_id) do
request(:post, Constants.poll_expire(channel_id, message_id))
|> handle_request_with_decode({:struct, Message})
end

@doc ~S"""
Same as `expire_poll/2`, but raises `Nostrum.Error.ApiError` in case of failure.
"""
@spec expire_poll!(Channel.id(), Message.id()) :: Message.t()
def expire_poll!(channel_id, message_id) do
expire_poll(channel_id, message_id)
|> bangify
end

@doc ~S"""
Gets a channel.
Expand Down
3 changes: 3 additions & 0 deletions lib/nostrum/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ defmodule Nostrum.Constants do
def poll_answer_voters(channel_id, message_id, answer_id),
do: "/channels/#{channel_id}/polls/#{message_id}/answers/#{answer_id}"

def poll_expire(channel_id, message_id),
do: "/channels/#{channel_id}/polls/#{message_id}/expire"

def discord_epoch, do: 1_420_070_400_000

def opcodes do
Expand Down

0 comments on commit 594eb47

Please # to comment.