Skip to content

Commit

Permalink
fix: make embed color optional (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
erics118 authored Oct 20, 2023
1 parent 458ebb4 commit f9c55bf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/dpp/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ struct DPP_EXPORT embed {
/** Optional: timestamp of embed content */
time_t timestamp;
/** Optional: color code of the embed */
uint32_t color;
std::optional<uint32_t> color;
/** Optional: footer information */
std::optional<embed_footer> footer;
/** Optional: image information */
Expand Down
10 changes: 7 additions & 3 deletions src/dpp/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ component &component::add_default_value(const snowflake id, const component_defa

embed::~embed() = default;

embed::embed() : timestamp(0), color(0) {
embed::embed() : timestamp(0) {
}

message::message() : managed(0), channel_id(0), guild_id(0), sent(0), edited(0), webhook_id(0),
Expand Down Expand Up @@ -618,7 +618,9 @@ embed::embed(json* j) : embed() {
description = string_not_null(j, "description");
url = string_not_null(j, "url");
timestamp = ts_not_null(j, "timestamp");
color = int32_not_null(j, "color");
if (j->contains("color")) {
color = int32_not_null(j, "color");
}
if (j->contains("footer")) {
dpp::embed_footer f;
json& fj = (*j)["footer"];
Expand Down Expand Up @@ -962,7 +964,9 @@ json message::to_json(bool with_id, bool is_interaction_response) const {
if (!embed.url.empty()) {
e["url"] = embed.url;
}
e["color"] = embed.color;
if (embed.color.has_value()) {
e["color"] = embed.color.value();
}
if (embed.footer.has_value()) {
e["footer"]["text"] = embed.footer->text;
e["footer"]["icon_url"] = embed.footer->icon_url;
Expand Down

0 comments on commit f9c55bf

Please sign in to comment.