Skip to content

Commit

Permalink
feat(#957): add methods to set a scheduled event's banner
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 committed Oct 24, 2023
1 parent 70fb2c5 commit a3fb106
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
27 changes: 20 additions & 7 deletions include/dpp/scheduled_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ struct DPP_EXPORT scheduled_event : public managed, public json_interface<schedu
*
* @return std::string Json of this object
*/
virtual json to_json_impl(bool with_id = false) const;
json to_json_impl(bool with_id = false) const;

public:
snowflake guild_id; //!< the guild id which the scheduled event belongs to
snowflake channel_id; //!< the channel id in which the scheduled event will be hosted, or null if scheduled entity type is EXTERNAL (may be empty)
snowflake creator_id; //!< Optional: the id of the user that created the scheduled event
std::string name; //!< the name of the scheduled event
std::string description; //!< Optional: the description of the scheduled event (1-1000 characters)
std::string image; //!< the image of the scheduled event (may be empty)
utility::icon image; //!< the image of the scheduled event (may be empty)
time_t scheduled_start_time; //!< the time the scheduled event will start
time_t scheduled_end_time; //!< the time the scheduled event will end, or null if the event does not have a scheduled time to end (may be empty)
event_privacy_level privacy_level; //!< the privacy level of the scheduled event
Expand All @@ -136,11 +136,6 @@ struct DPP_EXPORT scheduled_event : public managed, public json_interface<schedu
*/
scheduled_event();

/**
* @brief Destroy the scheduled_event object
*/
~scheduled_event() = default;

/**
* @brief Set the name of the event
* Minimum length: 1, Maximum length: 100
Expand Down Expand Up @@ -213,6 +208,24 @@ struct DPP_EXPORT scheduled_event : public managed, public json_interface<schedu
* @throw dpp::length_error if time is before now
*/
scheduled_event& set_end_time(time_t t);

/**
* @brief Load an image for the event cover
*
* @param image_blob Image binary data
* @param type Type of image. It can be one of `i_gif`, `i_jpg` or `i_png`.
* @return emoji& Reference to self
*/
scheduled_event& load_image(std::string_view image_blob, const image_type type);

/**
* @brief Load an image for the event cover
*
* @param image_blob Image binary data
* @param type Type of image. It can be one of `i_gif`, `i_jpg` or `i_png`.
* @return emoji& Reference to self
*/
scheduled_event& load_image(const std::byte* data, uint32_t size, const image_type type);
};

/**
Expand Down
17 changes: 14 additions & 3 deletions src/dpp/scheduled_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ scheduled_event& scheduled_event::set_end_time(time_t t) {
return *this;
}

scheduled_event& scheduled_event::load_image(std::string_view image_blob, const image_type type) {
image = utility::image_data{type, image_blob};
return *this;
}

scheduled_event& scheduled_event::load_image(const std::byte* data, uint32_t size, const image_type type) {
image = utility::image_data{type, data, size};
return *this;
}

scheduled_event& scheduled_event::fill_from_json_impl(const json* j) {
set_snowflake_not_null(j, "id", this->id);
set_snowflake_not_null(j, "guild_id", this->guild_id);
Expand All @@ -117,7 +127,8 @@ scheduled_event& scheduled_event::fill_from_json_impl(const json* j) {
set_snowflake_not_null(j, "creator_id", this->creator_id);
set_string_not_null(j, "name", this->name);
set_string_not_null(j, "description", this->description);
set_string_not_null(j, "image", this->image);
if (auto it = j->find("image"); it != j->end() && !it->is_null())
this->image = utility::iconhash{it->get<std::string>()};
set_ts_not_null(j, "scheduled_start_time", this->scheduled_start_time);
set_ts_not_null(j, "scheduled_end_time", this->scheduled_end_time);
this->privacy_level = static_cast<dpp::event_privacy_level>(int8_not_null(j, "privacy_level"));
Expand All @@ -144,8 +155,8 @@ json scheduled_event::to_json_impl(bool with_id) const {
if (!this->description.empty()) {
j["description"] = this->description;
}
if (!this->image.empty()) {
j["image"] = this->image;
if (image.is_image_data()) {
j["icon"] = image.as_image_data().to_nullable_json();
}
j["privacy_level"] = this->privacy_level;
j["status"] = this->status;
Expand Down

0 comments on commit a3fb106

Please sign in to comment.