Skip to content

Commit

Permalink
feat: cluster::interaction_followup_get_original (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 authored Jul 13, 2023
1 parent e179555 commit 2660203
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
21 changes: 21 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -1289,6 +1289,16 @@ class DPP_EXPORT cluster {
*/
void interaction_response_edit(const std::string &token, const message &m, command_completion_event_t callback = utility::log_error());

/**
* @brief Get the original response to a slash command
*
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response
* @param token Token for the interaction webhook
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::message 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 interaction_response_get_original(const std::string &token, command_completion_event_t callback = utility::log_error());

/**
* @brief Create a followup message to a slash command
*
Expand Down Expand Up @@ -1344,6 +1354,17 @@ class DPP_EXPORT cluster {
* On success the callback will contain a dpp::message 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 interaction_followup_get(const std::string &token, snowflake message_id, command_completion_event_t callback);

/**
* @brief Get the original followup message to a slash command
* This is an alias for cluster::interaction_response_get_original
* @see cluster::interaction_response_get_original
*
* @param token Token for the interaction webhook
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::message 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 interaction_followup_get_original(const std::string &token, command_completion_event_t callback = utility::log_error());

/**
* @brief Create a global slash command (a bot can have a maximum of 100 of these).
Expand Down
27 changes: 27 additions & 0 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,19 @@ auto inline co_interaction_response_edit(const std::string &token, const message
return dpp::awaitable(this, [&] (auto cc) { this->interaction_response_edit(token, m, cc); });
}

/**
* @brief Get the original response to a slash command
*
* @see dpp::cluster::interaction_response_get_original
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response
* @param token Token for the interaction webhook
* @return message returned object on completion
* \memberof dpp::cluster
*/
auto inline co_interaction_response_get_original(const std::string &token) {
return dpp::awaitable(this, [&] (auto cc) { this->interaction_response_get_original(token, cc); });
}

/**
* @brief Create a followup message to a slash command
*
Expand Down Expand Up @@ -354,6 +367,20 @@ auto inline co_interaction_followup_get(const std::string &token, snowflake mess
return dpp::awaitable(this, [&] (auto cc) { this->interaction_followup_get(token, message_id, cc); });
}

/**
* @brief Get the original followup message to a slash command
* This is an alias for cluster::interaction_response_get_original
* @see dpp::cluster::interaction_followup_get_original
* @see cluster::interaction_response_get_original
*
* @param token Token for the interaction webhook
* @return message returned object on completion
* \memberof dpp::cluster
*/
auto inline co_interaction_followup_get_original(const std::string &token) {
return dpp::awaitable(this, [&] (auto cc) { this->interaction_followup_get_original(token, cc); });
}

/**
* @brief Get all auto moderation rules for a guild
*
Expand Down
29 changes: 29 additions & 0 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,20 @@ confirmation interaction_response_create_sync(snowflake interaction_id, const st
*/
confirmation interaction_response_edit_sync(const std::string &token, const message &m);

/**
* @brief Get the original response to a slash command
*
* @see dpp::cluster::interaction_response_get_original
* @see https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response
* @param token Token for the interaction webhook
* @return message returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
message interaction_response_get_original_sync(const std::string &token);

/**
* @brief Create a followup message to a slash command
*
Expand Down Expand Up @@ -377,6 +391,21 @@ confirmation interaction_followup_edit_sync(const std::string &token, const mess
*/
message interaction_followup_get_sync(const std::string &token, snowflake message_id);

/**
* @brief Get the original followup message to a slash command
* This is an alias for cluster::interaction_response_get_original
* @see dpp::cluster::interaction_followup_get_original
* @see cluster::interaction_response_get_original
*
* @param token Token for the interaction webhook
* @return message returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
message interaction_followup_get_original_sync(const std::string &token);

/**
* @brief Get all auto moderation rules for a guild
*
Expand Down
8 changes: 8 additions & 0 deletions src/dpp/cluster/appcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ void cluster::interaction_response_edit(const std::string &token, const message
}, m.filename, m.filecontent, m.filemimetype);
}

void cluster::interaction_response_get_original(const std::string &token, command_completion_event_t callback) {
rest_request<message>(this, API_PATH "/webhooks",std::to_string(me.id), utility::url_encode(token) + "/messages/@original", m_get, "", callback);
}

void cluster::interaction_followup_create(const std::string &token, const message &m, command_completion_event_t callback) {
this->post_rest_multipart(API_PATH "/webhooks", std::to_string(me.id), utility::url_encode(token), m_post, m.build_json(), [this, callback](json &j, const http_request_completion_t& http) {
if (callback) {
Expand Down Expand Up @@ -175,4 +179,8 @@ void cluster::interaction_followup_get(const std::string &token, snowflake messa
rest_request<message>(this, API_PATH "/webhooks",std::to_string(me.id), utility::url_encode(token) + "/messages/" + std::to_string(message_id), m_get, "", callback);
}

void cluster::interaction_followup_get_original(const std::string &token, command_completion_event_t callback) {
rest_request<message>(this, API_PATH "/webhooks",std::to_string(me.id), utility::url_encode(token) + "/messages/@original", m_get, "", callback);
}

};
8 changes: 8 additions & 0 deletions src/dpp/cluster_sync_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ confirmation cluster::interaction_response_edit_sync(const std::string &token, c
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(const std::string &, const message &, command_completion_event_t)>(&cluster::interaction_response_edit), token, m);
}

message cluster::interaction_response_get_original_sync(const std::string &token) {
return dpp::sync<message>(this, static_cast<void (cluster::*)(const std::string &, command_completion_event_t)>(&cluster::interaction_response_get_original), token);
}

confirmation cluster::interaction_followup_create_sync(const std::string &token, const message &m) {
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(const std::string &, const message &, command_completion_event_t)>(&cluster::interaction_followup_create), token, m);
}
Expand All @@ -125,6 +129,10 @@ message cluster::interaction_followup_get_sync(const std::string &token, snowfla
return dpp::sync<message>(this, static_cast<void (cluster::*)(const std::string &, snowflake, command_completion_event_t)>(&cluster::interaction_followup_get), token, message_id);
}

message cluster::interaction_followup_get_original_sync(const std::string &token) {
return dpp::sync<message>(this, static_cast<void (cluster::*)(const std::string &, command_completion_event_t)>(&cluster::interaction_followup_get_original), token);
}

automod_rule_map cluster::automod_rules_get_sync(snowflake guild_id) {
return dpp::sync<automod_rule_map>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::automod_rules_get), guild_id);
}
Expand Down

0 comments on commit 2660203

Please sign in to comment.