From d24beaa59cdc3558656aaca86281cb382c72d681 Mon Sep 17 00:00:00 2001 From: Yukino Date: Wed, 30 Jul 2025 02:26:47 +0200 Subject: [PATCH] feat: Added `follow_up` and `co_follow_up` functions and improve docs --- include/dpp/cluster.h | 10 +++++----- include/dpp/dispatcher.h | 32 ++++++++++++++++++++++++++++++++ src/dpp/dispatcher.cpp | 18 +++++++++++++++++- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index ed6573dbd8..e7b995d085 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -1650,7 +1650,7 @@ class DPP_EXPORT cluster { 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 + * @brief Create a followup message for an interaction * * @see https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response * @param token Token for the interaction webhook @@ -1661,7 +1661,7 @@ class DPP_EXPORT cluster { void interaction_followup_create(const std::string &token, const message &m, command_completion_event_t callback = utility::log_error()); /** - * @brief Edit original followup message to a slash command + * @brief Edit original followup message for an interaction * This is an alias for cluster::interaction_response_edit * @see cluster::interaction_response_edit * @@ -1683,7 +1683,7 @@ class DPP_EXPORT cluster { void interaction_followup_delete(const std::string &token, command_completion_event_t callback = utility::log_error()); /** - * @brief Edit followup message to a slash command + * @brief Edit followup message for an interaction * The message ID in the message you pass should be correctly set to that of a followup message you previously sent * * @see https://discord.com/developers/docs/interactions/receiving-and-responding#edit-followup-message @@ -1695,7 +1695,7 @@ class DPP_EXPORT cluster { void interaction_followup_edit(const std::string &token, const message &m, command_completion_event_t callback = utility::log_error()); /** - * @brief Get the followup message to a slash command + * @brief Get the followup message for an interaction * * @see https://discord.com/developers/docs/interactions/receiving-and-responding#get-followup-message * @param token Token for the interaction webhook @@ -1706,7 +1706,7 @@ class DPP_EXPORT cluster { 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 + * @brief Get the original followup message for an interaction * This is an alias for cluster::interaction_response_get_original * @see cluster::interaction_response_get_original * diff --git a/include/dpp/dispatcher.h b/include/dpp/dispatcher.h index a960633765..d9f3457223 100644 --- a/include/dpp/dispatcher.h +++ b/include/dpp/dispatcher.h @@ -569,6 +569,22 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t { */ void reply(const std::string& mt, command_completion_event_t callback = utility::log_error()) const; + /** + * @brief Create a follow-up message for this interaction. + * @param m Message object to send. Not all fields are supported by Discord. + * @param callback User function to execute when the api call completes. + * On success the callback will contain a dpp::confirmation 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 follow_up(const message& m, command_completion_event_t callback = utility::log_error()) const; + + /** + * @brief Create a follow-up message for this interaction. + * @param mt The string value to send, for simple text only messages + * @param callback User function to execute when the api call completes. + * On success the callback will contain a dpp::confirmation 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 follow_up(const std::string& mt, command_completion_event_t callback = utility::log_error()) const; + /** * @brief Reply to interaction with a dialog box * @@ -681,6 +697,22 @@ struct DPP_EXPORT interaction_create_t : public event_dispatch_t { */ dpp::async co_reply(const std::string& mt) const; + /** + * @brief Create a follow-up message for this interaction. + * + * @param m Message object to send. Not all fields are supported by Discord. + * On success the result will contain a dpp::confirmation 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(). + */ + dpp::async co_follow_up(const message& m) const; + + /** + * @brief Create a follow-up message for this interaction. + * + * @param mt The string value to send, for simple text only messages + * On success the result will contain a dpp::confirmation 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(). + */ + dpp::async co_follow_up(const std::string& mt) const; + /** * @brief Reply to interaction with a dialog box * diff --git a/src/dpp/dispatcher.cpp b/src/dpp/dispatcher.cpp index d2584771ab..1f773e9296 100644 --- a/src/dpp/dispatcher.cpp +++ b/src/dpp/dispatcher.cpp @@ -216,6 +216,14 @@ void interaction_create_t::reply(const std::string& mt, command_completion_event this->reply(ir_channel_message_with_source, dpp::message(this->command.channel_id, mt, mt_application_command), callback); } +void interaction_create_t::follow_up(const message& m, command_completion_event_t callback) const { + owner->interaction_followup_create(this->command.token, m, std::move(callback)); +} + +void interaction_create_t::follow_up(const std::string& mt, command_completion_event_t callback) const { + owner->interaction_followup_create(this->command.token, dpp::message(this->command.channel_id, mt, mt_application_command), std::move(callback)); +} + void interaction_create_t::edit_response(const message& m, command_completion_event_t callback) const { owner->interaction_response_edit(this->command.token, m, std::move(callback)); } @@ -237,7 +245,7 @@ void interaction_create_t::edit_original_response(const message& m, command_comp std::vector file_contents{}; std::vector file_mimetypes{}; - for(message_file_data data : m.file_data) { + for(const message_file_data& data : m.file_data) { file_names.push_back(data.name); file_contents.push_back(data.content); file_mimetypes.push_back(data.mimetype); @@ -280,6 +288,14 @@ async interaction_create_t::co_reply(const std::string& return dpp::async{[&, this] (T&& cb) { this->reply(mt, std::forward(cb)); }}; } +async interaction_create_t::co_follow_up(const message& m) const { + return dpp::async{[&, this] (T&& cb) { this->follow_up(m, std::forward(cb)); }}; +} + +async interaction_create_t::co_follow_up(const std::string& mt) const { + return dpp::async{[&, this] (T&& cb) { this->follow_up(mt, std::forward(cb)); }}; +} + async interaction_create_t::co_dialog(const interaction_modal_response& mr) const { return dpp::async{[&, this] (T&& cb) { this->dialog(mr, std::forward(cb)); }}; }