From 4f8391411f9171c42980600a7293f2dd4f9da761 Mon Sep 17 00:00:00 2001 From: Kai Tamkun <13513421+heimskr@users.noreply.github.com> Date: Sat, 23 Mar 2024 09:54:54 -0700 Subject: [PATCH] Ability to suppress embeds (#1107) --- include/dpp/cluster.h | 9 +++++++++ include/dpp/message.h | 8 ++++++++ src/dpp/cluster/message.cpp | 10 ++++++++++ src/dpp/message.cpp | 13 +++++++++++-- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index 7f18f6e9aa..54e446a5ca 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -1769,6 +1769,15 @@ class DPP_EXPORT cluster { */ void message_edit(const struct message &m, command_completion_event_t callback = utility::log_error()); + /** + * @brief Edit the flags of a message on a channel. The callback function is called when the message has been edited + * + * @param m Message to edit the flags of + * @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 message_edit_flags(const struct message &m, command_completion_event_t callback = utility::log_error()); + /** * @brief Add a reaction to a message. The reaction string must be either an `emojiname:id` or a unicode character. * diff --git a/include/dpp/message.h b/include/dpp/message.h index 2d11b527e2..6455540e62 100644 --- a/include/dpp/message.h +++ b/include/dpp/message.h @@ -2130,6 +2130,14 @@ struct DPP_EXPORT message : public managed, json_interface { */ bool suppress_embeds() const; + /** + * @brief Set whether embeds should be suppressed + * + * @param suppress whether embeds should be suppressed + * @return message& reference to self + */ + message& suppress_embeds(bool suppress); + /** * @brief True if source message was deleted * diff --git a/src/dpp/cluster/message.cpp b/src/dpp/cluster/message.cpp index 231670b31c..06fc23faba 100644 --- a/src/dpp/cluster/message.cpp +++ b/src/dpp/cluster/message.cpp @@ -119,6 +119,16 @@ void cluster::message_edit(const message &m, command_completion_event_t callback }, m.file_data); } +void cluster::message_edit_flags(const message &m, command_completion_event_t callback) { + this->post_rest_multipart(API_PATH "/channels", std::to_string(m.channel_id), "messages/" + std::to_string(m.id), m_patch, nlohmann::json{ + {"flags", m.flags}, + }.dump(), [this, callback](json &j, const http_request_completion_t& http) { + if (callback) { + callback(confirmation_callback_t(this, message(this).fill_from_json(&j), http)); + } + }, m.file_data); +} + void cluster::message_get(snowflake message_id, snowflake channel_id, command_completion_event_t callback) { rest_request(this, API_PATH "/channels", std::to_string(channel_id), "messages/" + std::to_string(message_id), m_get, "", callback); diff --git a/src/dpp/message.cpp b/src/dpp/message.cpp index 850a6c67ed..31e53ea3fb 100644 --- a/src/dpp/message.cpp +++ b/src/dpp/message.cpp @@ -357,7 +357,7 @@ void to_json(json& j, const component& cp) { o["type"] = "channel"; } else if (v.type == dpp::cdt_user) { o["type"] = "user"; - } + } j["default_values"].push_back(o); } } @@ -844,7 +844,7 @@ reaction::reaction(json* j) { } } -attachment::attachment(struct message* o) +attachment::attachment(struct message* o) : id(0) , size(0) , width(0) @@ -1071,6 +1071,15 @@ bool message::suppress_embeds() const { return flags & m_suppress_embeds; } +message& message::suppress_embeds(bool suppress) { + if (suppress) { + flags |= m_suppress_embeds; + } else { + flags &= ~m_suppress_embeds; + } + return *this; +} + bool message::is_source_message_deleted() const { return flags & m_source_message_deleted; }