Skip to content

Commit

Permalink
feat: poll support
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 committed May 1, 2024
1 parent 6288cb8 commit 4de0eae
Show file tree
Hide file tree
Showing 14 changed files with 919 additions and 20 deletions.
66 changes: 66 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,24 @@ class DPP_EXPORT cluster {
*/
event_router_t<message_create_t> on_message_create;

/**
* @brief Called when a vote is added to a message poll.
*
* @see https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-add
* @note Use operator() to attach a lambda to this event, and the detach method to detach the listener using the returned ID.
* The function signature for this event takes a single `const` reference of type message_poll_vote_add_t&, and returns void.
*/
event_router_t<message_poll_vote_add_t> on_message_poll_vote_add;

/**
* @brief Called when a vote is removed from a message poll.
*
* @see https://discord.com/developers/docs/topics/gateway-events#message-poll-vote-remove
* @note Use operator() to attach a lambda to this event, and the detach method to detach the listener using the returned ID.
* The function signature for this event takes a single `const` reference of type message_poll_vote_remove_t&, and returns void.
*/
event_router_t<message_poll_vote_remove_t> on_message_poll_vote_remove;

/**
* @brief Called when a guild audit log entry is created.
*
Expand Down Expand Up @@ -1948,6 +1966,54 @@ class DPP_EXPORT cluster {
*/
void message_delete_bulk(const std::vector<snowflake> &message_ids, snowflake channel_id, command_completion_event_t callback = utility::log_error());

/**
* @brief Get a list of users that voted for this specific answer.
*
* @param m Message that contains the poll to retrieve the answers from
* @param answer_id ID of the answer to retrieve votes from (see poll_answer::answer_id)
* @param after Users after this ID should be retrieved if this is set to non-zero
* @param limit This number of users maximum should be returned, up to 100
* @param callback Function to call when the API call completes.
* @see https://discord.com/developers/docs/resources/poll#get-answer-voters
* On success the callback will contain a dpp::user_map object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void poll_get_answer_voters(const message& m, uint32_t answer_id, snowflake after, uint64_t limit, command_completion_event_t callback = utility::log_error());

/**
* @brief Get a list of users that voted for this specific answer.
*
* @param message_id ID of the message with the poll to retrieve the answers from
* @param channel_id ID of the channel with the poll to retrieve the answers from
* @param answer_id ID of the answer to retrieve votes from (see poll_answer::answer_id)
* @param after Users after this ID should be retrieved if this is set to non-zero
* @param limit This number of users maximum should be returned, up to 100
* @param callback Function to call when the API call completes.
* @see https://discord.com/developers/docs/resources/poll#get-answer-voters
* On success the callback will contain a dpp::user_map object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void poll_get_answer_voters(snowflake message_id, snowflake channel_id, uint32_t answer_id, snowflake after, uint64_t limit, command_completion_event_t callback = utility::log_error());

/**
* @brief Immediately end a poll.
*
* @param m Message that contains the poll
* @param callback Function to call when the API call completes.
* @see https://discord.com/developers/docs/resources/poll#end-poll
* On success the callback will contain a dpp::message object representing the message containing the poll in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void poll_end(const message &m, command_completion_event_t callback = utility::log_error());

/**
* @brief Immediately end a poll.
*
* @param message_id ID of the message with the poll to end
* @param channel_id ID of the channel with the poll to end
* @param callback Function to call when the API call completes.
* @see https://discord.com/developers/docs/resources/poll#end-poll
* On success the callback will contain a dpp::message object representing the message containing the poll in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void poll_end(snowflake message_id, snowflake channel_id, command_completion_event_t callback = utility::log_error());

/**
* @brief Get a channel
*
Expand Down
52 changes: 52 additions & 0 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,58 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_message_unpin(snowflake channel_id, snowflake message_id);

/**
* @brief Get a list of users that voted for this specific answer.
*
* @param m Message that contains the poll to retrieve the answers from
* @param answer_id ID of the answer to retrieve votes from (see poll_answer::answer_id)
* @param after Users after this ID should be retrieved if this is set to non-zero
* @param limit This number of users maximum should be returned, up to 100
* @return user_map returned object on completion
* @see dpp::cluster::poll_get_answer_voters
* @see https://discord.com/developers/docs/resources/poll#get-answer-voters
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_poll_get_answer_voters(const message& m, uint32_t answer_id, snowflake after, uint64_t limit);

/**
* @brief Get a list of users that voted for this specific answer.
*
* @param message_id ID of the message with the poll to retrieve the answers from
* @param channel_id ID of the channel with the poll to retrieve the answers from
* @param answer_id ID of the answer to retrieve votes from (see poll_answer::answer_id)
* @param after Users after this ID should be retrieved if this is set to non-zero
* @param limit This number of users maximum should be returned, up to 100
* @return user_map returned object on completion
* @see dpp::cluster::poll_get_answer_voters
* @see https://discord.com/developers/docs/resources/poll#get-answer-voters
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_poll_get_answer_voters(snowflake message_id, snowflake channel_id, uint32_t answer_id, snowflake after, uint64_t limit);

/**
* @brief Immediately end a poll.
*
* @param m Message that contains the poll
* @return message returned object on completion
* @see dpp::cluster::poll_end
* @see https://discord.com/developers/docs/resources/poll#end-poll
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_poll_end(const message &m);

/**
* @brief Immediately end a poll.
*
* @param message_id ID of the message with the poll to end
* @param channel_id ID of the channel with the poll to end
* @return message returned object on completion
* @see dpp::cluster::poll_end
* @see https://discord.com/developers/docs/resources/poll#end-poll
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_poll_end(snowflake message_id, snowflake channel_id);

/**
* @brief Get a channel's pins
* @see dpp::cluster::channel_pins_get
Expand Down
66 changes: 66 additions & 0 deletions include/dpp/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -1687,6 +1687,72 @@ struct DPP_EXPORT message_create_t : public event_dispatch_t {
void reply(message&& msg, bool mention_replied_user = false, command_completion_event_t callback = utility::log_error()) const;
};

/**
* @brief Message poll vote add
*/
struct DPP_EXPORT message_poll_vote_add_t : public event_dispatch_t {
using event_dispatch_t::event_dispatch_t;
using event_dispatch_t::operator=;

/**
* @brief ID of the user who added the vote
*/
snowflake user_id;

/**
* @brief ID of the channel containing the vote
*/
snowflake channel_id;

/**
* @brief ID of the message containing the vote
*/
snowflake message_id;

/**
* @brief ID of the guild containing the vote or 0 for DMs
*/
snowflake guild_id;

/**
* @brief ID of the answer in the message poll object
*/
uint32_t answer_id;
};

/**
* @brief Message poll vote remove
*/
struct DPP_EXPORT message_poll_vote_remove_t : public event_dispatch_t {
using event_dispatch_t::event_dispatch_t;
using event_dispatch_t::operator=;

/**
* @brief ID of the user who added the vote
*/
snowflake user_id;

/**
* @brief ID of the channel containing the vote
*/
snowflake channel_id;

/**
* @brief ID of the message containing the vote
*/
snowflake message_id;

/**
* @brief ID of the guild containing the vote or 0 for DMs
*/
snowflake guild_id;

/**
* @brief ID of the answer in the message poll object
*/
uint32_t answer_id;
};

/**
* @brief Guild audit log entry create
*/
Expand Down
2 changes: 2 additions & 0 deletions include/dpp/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ event_decl(message_create,MESSAGE_CREATE);
event_decl(message_update,MESSAGE_UPDATE);
event_decl(message_delete,MESSAGE_DELETE);
event_decl(message_delete_bulk,MESSAGE_DELETE_BULK);
event_decl(message_poll_vote_add,MESSAGE_POLL_VOTE_ADD);
event_decl(message_poll_vote_remove,MESSAGE_POLL_VOTE_REMOVE);

/* Presence/typing */
event_decl(presence_update,PRESENCE_UPDATE);
Expand Down
Loading

0 comments on commit 4de0eae

Please sign in to comment.