Skip to content

Commit

Permalink
feat: add interaction_metadata for messages
Browse files Browse the repository at this point in the history
  • Loading branch information
raxyte committed Aug 16, 2024
1 parent af6361f commit 00de234
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
42 changes: 42 additions & 0 deletions include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -2187,6 +2224,11 @@ struct DPP_EXPORT message : public managed, json_interface<message> {
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
*/
Expand Down
15 changes: 13 additions & 2 deletions src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,14 +649,20 @@ std::optional<uint32_t> 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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 00de234

Please sign in to comment.