Skip to content

Commit

Permalink
fix(#957): support iconhash/image data variant fields (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 authored Oct 25, 2023
1 parent 3eb549d commit c90d17a
Show file tree
Hide file tree
Showing 14 changed files with 770 additions and 148 deletions.
14 changes: 12 additions & 2 deletions include/dpp/emoji.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class DPP_EXPORT emoji : public managed, public json_interface<emoji> {
/**
* @brief Image data for the emoji, if uploading.
*/
std::string image_data;
utility::image_data image_data;

/**
* @brief Flags for the emoji from dpp::emoji_flags.
Expand Down Expand Up @@ -185,7 +185,7 @@ class DPP_EXPORT emoji : public managed, public json_interface<emoji> {
bool is_available() const;

/**
* @brief Load an image into the object as base64
* @brief Load an image into the object
*
* @param image_blob Image binary data
* @param type Type of image. It can be one of `i_gif`, `i_jpg` or `i_png`.
Expand All @@ -194,6 +194,16 @@ class DPP_EXPORT emoji : public managed, public json_interface<emoji> {
*/
emoji& load_image(std::string_view image_blob, const image_type type);

/**
* @brief Load an image into the object
*
* @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
* @throw dpp::length_exception Image content exceeds discord maximum of 256 kilobytes
*/
emoji& load_image(const std::byte* data, uint32_t size, const image_type type);

/**
* @brief Format to name if unicode, name:id if has id or a:name:id if animated
*
Expand Down
118 changes: 110 additions & 8 deletions include/dpp/guild.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,17 +713,17 @@ class DPP_EXPORT guild : public managed, public json_interface<guild> {
*/
dpp::welcome_screen welcome_screen;

/** Guild icon hash */
utility::iconhash icon;
/** Guild icon */
utility::icon icon;

/** Guild splash hash */
utility::iconhash splash;
/** Guild splash */
utility::icon splash;

/** Guild discovery splash hash */
utility::iconhash discovery_splash;
/** Guild discovery splash */
utility::icon discovery_splash;

/** Server banner hash */
utility::iconhash banner;
/** Server banner */
utility::icon banner;

/** Snowflake id of guild owner */
snowflake owner_id;
Expand Down Expand Up @@ -945,6 +945,108 @@ class DPP_EXPORT guild : public managed, public json_interface<guild> {
*/
guild& set_name(const std::string& n);

/**
* @brief Remove the guild banner.
* @return guild& Reference to self for chaining
*/
guild& remove_banner();

/**
* @brief Set the guild banner image. Server needs banner feature.
* Must be 16:9, and depending on nitro level, must be png or jpeg.
* Animated gif needs the animated banner server feature.
* @param format Image format.
* @param data Image data in bytes
* @return guild& Reference to self for chaining
*/
guild& set_banner(image_type format, std::string_view data);

/**
* @brief Set the guild banner image. Server needs banner feature.
* Must be 16:9, and depending on nitro level, must be png or jpeg.
* Animated gif needs the animated banner server feature.
* @param format Image format.
* @param data Image data in bytes
* @param size Size of the data in bytes
* @return guild& Reference to self for chaining
*/
guild& set_banner(image_type format, const std::byte* data, uint32_t size);

/**
* @brief Remove the guild discovery splash.
* @return guild& Reference to self for chaining
*/
guild& remove_discovery_splash();

/**
* @brief Set the guild discovery splash image. Server needs discoverable feature.
* Must be 16:9 and png or jpeg.
* @param format Image format.
* @param data Image data in bytes
* @return guild& Reference to self for chaining
*/
guild& set_discovery_splash(image_type format, std::string_view data);

/**
* @brief Set the guild discovery splash image. Server needs discoverable feature.
* Must be 16:9 and png or jpeg.
* @param format Image format.
* @param data Image data in bytes
* @param size Size of the data in bytes
* @return guild& Reference to self for chaining
*/
guild& set_discovery_splash(image_type format, const std::byte* data, uint32_t size);

/**
* @brief Remove the guild invite splash.
* @return guild& Reference to self for chaining
*/
guild& remove_splash();

/**
* @brief Set the guild invite splash image. Server needs invite splash feature.
* Must be 16:9 and png or jpeg.
* @param format Image format.
* @param data Image data in bytes
* @return guild& Reference to self for chaining
*/
guild& set_splash(image_type format, std::string_view data);

/**
* @brief Set the guild invite splash image. Server needs invite splash feature.
* Must be 16:9 and png or jpeg.
* @param format Image format.
* @param data Image data in bytes
* @param size Size of the data in bytes
* @return guild& Reference to self for chaining
*/
guild& set_splash(image_type format, const std::byte* data, uint32_t size);

/**
* @brief Remove the guild icon.
* @return guild& Reference to self for chaining
*/
guild& remove_icon();

/**
* @brief Set the guild icon image.
* Must be 1024x1024 and png or jpeg. Gif allowed only if the server has animated icon.
* @param format Image format.
* @param data Image data in bytes
* @return guild& Reference to self for chaining
*/
guild& set_icon(image_type format, std::string_view data);

/**
* @brief Set the 1024x1024 guild icon image.
* Must be png or jpeg. Gif allowed only if the server has animated icon.
* @param format Image format.
* @param data Image data in bytes
* @param size Size of the data in bytes
* @return guild& Reference to self for chaining
*/
guild& set_icon(image_type format, const std::byte* data, uint32_t size);

/**
* @brief Is a large server (>250 users)
* @return bool is a large guild
Expand Down
73 changes: 54 additions & 19 deletions include/dpp/role.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,45 +74,71 @@ class DPP_EXPORT role : public managed, public json_interface<role> {
* @brief Role name
* Between 1 and 100 characters.
*/
std::string name;
std::string name{};
/**
* @brief Guild ID
*/
snowflake guild_id;
snowflake guild_id{0};
/**
* @brief Role colour.
* A colour of 0 means no colour. If you want a black role,
* you must use the value 0x000001.
*/
uint32_t colour;
uint32_t colour{0};
/** Role position */
uint8_t position;
uint8_t position{0};
/** Role permissions bitmask values from dpp::permissions */
permission permissions;
permission permissions{};
/** Role flags from dpp::role_flags */
uint8_t flags;
uint8_t flags{0};
/** Integration id if any (e.g. role is a bot's role created when it was invited) */
snowflake integration_id;
snowflake integration_id{};
/** Bot id if any (e.g. role is a bot's role created when it was invited) */
snowflake bot_id;
snowflake bot_id{};
/** The id of the role's subscription sku and listing */
snowflake subscription_listing_id;
snowflake subscription_listing_id{};
/** The unicode emoji used for the role's icon, can be an empty string */
std::string unicode_emoji;
/** The role icon hash, can be an empty string */
utility::iconhash icon;
/** Image data for the role icon (if any) */
std::string* image_data;
std::string unicode_emoji{};
/** The role icon */
utility::icon icon{};

/**
* @brief Construct a new role object
*/
role();
role() = default;

/**
* @brief Construct a new role object.
*
* @param rhs Role object to copy
*/
role(const role& rhs) = default;

/**
* @brief Construct a new role object.
*
* @param rhs Role object to move
*/
role(role&& rhs) = default;

/**
* @brief Copy another role object
*
* @param rhs Role object to copy
*/
role &operator=(const role& rhs) = default;

/**
* @brief Move from another role object
*
* @param rhs Role object to copy
*/
role &operator=(role&& rhs) = default;

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

/**
* @brief Create a mentionable role.
Expand Down Expand Up @@ -210,13 +236,22 @@ class DPP_EXPORT role : public managed, public json_interface<role> {
std::string get_icon_url(uint16_t size = 0, const image_type format = i_png) const;

/**
* @brief Load an image into the object as base64
*
* @brief Load a role icon
*
* @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
*/
role& load_image(std::string_view image_blob, const image_type type);

/**
* @brief Load a role icon
*
* @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
*/
role& load_image(const std::string &image_blob, const image_type type);
role& load_image(const std::byte* data, uint32_t size, const image_type type);

/**
* @brief Operator less than, used for checking if a role is below another.
Expand Down
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
2 changes: 1 addition & 1 deletion include/dpp/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class DPP_EXPORT user : public managed, public json_interface<user> {
uint32_t flags;
/** Discriminator (aka tag), 4 digits usually displayed with leading zeroes.
*
* @note To print the discriminator with leading zeroes, use format_username().
* @note To print the discriminator with leading zeroes, use format_username().
* 0 for users that have migrated to the new username format.
*/
uint16_t discriminator;
Expand Down
Loading

0 comments on commit c90d17a

Please sign in to comment.