Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:brainboxdotcc/DPP
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Sep 23, 2024
2 parents 775b474 + aa29f33 commit f892394
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
32 changes: 30 additions & 2 deletions include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,24 @@ namespace cache_policy {
};

/**
* @brief Message Reference type
*/
enum DPP_EXPORT message_ref_type : uint8_t {
/**
* A reply or crosspost
*/
mrt_default = 0,
/**
* A forwarded message
*/
mrt_forward = 1,
};

template <typename T> struct message_snapshot {
std::vector<T> messages;
};

/**
* @brief Represents messages sent and received on Discord
*/
struct DPP_EXPORT message : public managed, json_interface<message> {
Expand Down Expand Up @@ -2140,6 +2158,10 @@ struct DPP_EXPORT message : public managed, json_interface<message> {
* @brief Reference to another message, e.g. a reply
*/
struct message_ref {
/**
* @brief Message reference type, set to 1 to forward a message
*/
message_ref_type type{mrt_default};
/**
* @brief ID of the originating message.
*/
Expand All @@ -2162,10 +2184,15 @@ struct DPP_EXPORT message : public managed, json_interface<message> {
bool fail_if_not_exists;
} message_reference;

/**
* @brief Message snapshots for a forwarded message
*/
message_snapshot<message> message_snapshots;

/**
* @brief Reference to an interaction
*/
struct message_interaction_struct{
struct message_interaction_struct {
/**
* @brief ID of the interaction.
*/
Expand Down Expand Up @@ -2342,9 +2369,10 @@ struct DPP_EXPORT message : public managed, json_interface<message> {
* @param _guild_id guild id to reply to (optional)
* @param _channel_id channel id to reply to (optional)
* @param fail_if_not_exists true if the message send should fail if these values are invalid (optional)
* @param type Type of reference
* @return message& reference to self
*/
message& set_reference(snowflake _message_id, snowflake _guild_id = 0, snowflake _channel_id = 0, bool fail_if_not_exists = false);
message& set_reference(snowflake _message_id, snowflake _guild_id = 0, snowflake _channel_id = 0, bool fail_if_not_exists = false, message_ref_type type = mrt_default);

/**
* @brief Set the allowed mentions object for pings on the message
Expand Down
11 changes: 10 additions & 1 deletion src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,12 @@ message::message(class cluster* o) : message() {
owner = o;
}

message& message::set_reference(snowflake _message_id, snowflake _guild_id, snowflake _channel_id, bool fail_if_not_exists) {
message& message::set_reference(snowflake _message_id, snowflake _guild_id, snowflake _channel_id, bool fail_if_not_exists, message_ref_type type) {
message_reference.channel_id = _channel_id;
message_reference.guild_id = _guild_id;
message_reference.message_id = _message_id;
message_reference.fail_if_not_exists = fail_if_not_exists;
message_reference.type = type;
return *this;
}

Expand Down Expand Up @@ -1119,6 +1120,7 @@ json message::to_json(bool with_id, bool is_interaction_response) const {
/* Populate message reference */
if (message_reference.channel_id || message_reference.guild_id || message_reference.message_id) {
j["message_reference"] = json::object();
j["message_reference"]["type"] = static_cast<uint32_t>(message_reference.type);
if (message_reference.channel_id) {
j["message_reference"]["channel_id"] = std::to_string(message_reference.channel_id);
}
Expand Down Expand Up @@ -1408,10 +1410,17 @@ message& message::fill_from_json(json* d, cache_policy_t cp) {
}
if (d->find("message_reference") != d->end()) {
json& mr = (*d)["message_reference"];
message_reference.type = static_cast<message_ref_type>(int8_not_null(&mr, "type"));
message_reference.channel_id = snowflake_not_null(&mr, "channel_id");
message_reference.guild_id = snowflake_not_null(&mr, "guild_id");
message_reference.message_id = snowflake_not_null(&mr, "message_id");
message_reference.fail_if_not_exists = bool_not_null(&mr, "fail_if_not_exists");

if (message_reference.type == mrt_forward) {
for (auto& e : (*d)["message_snapshots"]) {
message_snapshots.messages.emplace_back(message().fill_from_json(&(e["message"]), cp));
}
}
}
if (auto it = d->find("poll"); it != d->end()) {
from_json(*it, attached_poll.emplace());
Expand Down

0 comments on commit f892394

Please sign in to comment.