From 00de234fb7f6336630b3c3f5996a3dbaa6fd7be3 Mon Sep 17 00:00:00 2001 From: Raghav Narang Date: Tue, 13 Aug 2024 16:54:48 +0530 Subject: [PATCH] feat: add interaction_metadata for messages --- include/dpp/message.h | 42 ++++++++++++++++++++++++++++++++++++++++++ src/dpp/message.cpp | 15 +++++++++++++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/include/dpp/message.h b/include/dpp/message.h index 78d43eb67b..f63dc5e056 100644 --- a/include/dpp/message.h +++ b/include/dpp/message.h @@ -2010,6 +2010,43 @@ namespace cache_policy { }; +/** + * @brief Metadata about the interaction, including the source of the interaction and relevant server and user IDs. + */ +struct DPP_EXPORT interaction_metadata_type { + + /** + * @brief ID of the interaction + */ + snowflake id; + + /** + * @brief User who triggered the interaction + */ + uint8_t type; + + /** + * @brief User who triggered the interaction + */ + user usr; + + /** + * @brief ID of the original response message, present only on follow-up messages + */ + snowflake original_response_message_id; + + /** + * @brief ID of the message that contained interactive component, present only on messages created from component interactions + */ + snowflake interacted_message_id; + + // FIXME: Add this field sometime + /** + * @brief Metadata for the interaction that was used to open the modal, present only on modal submit interactions + */ + // interaction_metadata_type triggering_interaction_metadata; +}; + /** * @brief Represents messages sent and received on Discord */ @@ -2187,6 +2224,11 @@ struct DPP_EXPORT message : public managed, json_interface { user usr; } interaction; + /** + * @brief Sent if the message is sent as a result of an interaction + */ + interaction_metadata_type interaction_metadata; + /** * @brief Allowed mentions details */ diff --git a/src/dpp/message.cpp b/src/dpp/message.cpp index 6d416f0abb..c92ed7426d 100644 --- a/src/dpp/message.cpp +++ b/src/dpp/message.cpp @@ -649,14 +649,20 @@ std::optional poll::get_vote_count(uint32_t answer_id) const noexcept return 0; } - +void from_json(const json& j, interaction_metadata_type& i) { + i.id = snowflake_not_null(&j, "id"); + i.interacted_message_id = snowflake_not_null(&j, "interacted_message_id"); + i.original_response_message_id = snowflake_not_null(&j, "original_response_message_id"); + i.type = j["type"]; + i.usr = j["usr"]; +} embed::~embed() = default; embed::embed() : timestamp(0) { } -message::message() : managed(0), channel_id(0), guild_id(0), sent(0), edited(0), webhook_id(0), +message::message() : managed(0), channel_id(0), guild_id(0), sent(0), edited(0), webhook_id(0), interaction_metadata{}, owner(nullptr), type(mt_default), flags(0), pinned(false), tts(false), mention_everyone(false) { message_reference.channel_id = 0; @@ -1328,6 +1334,11 @@ message& message::fill_from_json(json* d, cache_policy_t cp) { this->author = *authoruser; } } + + if (auto it = d->find("interaction_medata"); it != d->end()) { + it->get_to(this->interaction_metadata); + } + if (d->find("interaction") != d->end()) { json& inter = (*d)["interaction"]; interaction.id = snowflake_not_null(&inter, "id");