Skip to content

Commit

Permalink
Merge branch 'dev' into coroutines_pr
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 committed Jul 15, 2023
2 parents 0a0192d + 3874652 commit 1eeca65
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# TODO: Discuss about -readability-identifier-length, -readability-avoid-const-params-in-decls
Checks: "-*,bugprone-*,cert-*,clang-analyzer-*,concurrency-*,cppcoreguidelines-*,llvm-namespace-comment,modernize-*,performance-*,portability-*,readability-*,-bugprone-implicit-widening-of-multiplication-result, -bugprone-easily-swappable-parameters,-readability-identifier-length,-portability-restrict-system-includes,-modernize-use-trailing-return-type,-cppcoreguidelines-non-private-member-variables-in-classes,-readability-avoid-const-params-in-decls"
30 changes: 29 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,35 @@
"CORO",
"cback",
"mentionables",
"awaiter",
"checkered",
"ramen",
"dango",
"tanabata",
"diya",
"nazar",
"hamsa",
"tada",
"izakaya",
"rofl",
"thumbup",
"mwgb",
"mwbb",
"wwgb",
"mwgg",
"wwbb",
"wwgg",
"mmgb",
"mmgg",
"womans",
"mans",
"mens",
"womens",
"mmbb",
"fleur",
"koko",
"moyai",
"kaaba",
"stringified"
],
"flagWords": [
Expand All @@ -104,4 +133,3 @@
"allowCompoundWords": true,
"useCompounds": true
}

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
23 changes: 23 additions & 0 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ awaitable<confirmation_callback_t> co_interaction_response_create(snowflake inte
*/
awaitable<confirmation_callback_t> co_interaction_response_edit(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
*/
awaitable<confirmation_callback_t> co_interaction_response_get_original(const std::string &token);

/**
* @brief Create a followup message to a slash command
*
Expand Down Expand Up @@ -308,6 +319,18 @@ awaitable<confirmation_callback_t> co_interaction_followup_edit(const std::strin
*/
awaitable<confirmation_callback_t> co_interaction_followup_get(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
*/
awaitable<confirmation_callback_t> co_interaction_followup_get_original(const std::string &token);

/**
* @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_coro_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ awaitable<confirmation_callback_t> cluster::co_interaction_response_edit(const s
return {this, static_cast<void (cluster::*)(const std::string &, const message &, command_completion_event_t)>(&cluster::interaction_response_edit), token, m};
}

awaitable<confirmation_callback_t> cluster::co_interaction_response_get_original(const std::string &token) {
return {this, static_cast<void (cluster::*)(const std::string &, command_completion_event_t)>(&cluster::interaction_response_get_original), token};
}

awaitable<confirmation_callback_t> cluster::co_interaction_followup_create(const std::string &token, const message &m) {
return {this, static_cast<void (cluster::*)(const std::string &, const message &, command_completion_event_t)>(&cluster::interaction_followup_create), token, m};
}
Expand All @@ -127,6 +131,10 @@ awaitable<confirmation_callback_t> cluster::co_interaction_followup_get(const st
return {this, static_cast<void (cluster::*)(const std::string &, snowflake, command_completion_event_t)>(&cluster::interaction_followup_get), token, message_id};
}

awaitable<confirmation_callback_t> cluster::co_interaction_followup_get_original(const std::string &token) {
return {this, static_cast<void (cluster::*)(const std::string &, command_completion_event_t)>(&cluster::interaction_followup_get_original), token};
}

awaitable<confirmation_callback_t> cluster::co_automod_rules_get(snowflake guild_id) {
return {this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::automod_rules_get), guild_id};
}
Expand Down
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 1eeca65

Please sign in to comment.