diff --git a/include/dpp/emoji.h b/include/dpp/emoji.h index 69f8a7b3b5..b8eba59cf5 100644 --- a/include/dpp/emoji.h +++ b/include/dpp/emoji.h @@ -72,21 +72,29 @@ class DPP_EXPORT emoji : public managed, public json_interface { public: /** - * @brief Emoji name + * @brief Emoji name. */ std::string name{}; + /** - * @brief User id who uploaded the emoji + * @brief Roles allowed to use this emoji. */ - snowflake user_id{0}; + std::vector roles; + /** - * @brief Flags for the emoji from dpp::emoji_flags + * @brief The id of the user that created this emoji. */ - uint8_t flags{0}; + snowflake user_id; + /** - * @brief Image data for the emoji if uploading + * @brief Image data for the emoji, if uploading. */ - std::string image_data{}; + std::string image_data; + + /** + * @brief Flags for the emoji from dpp::emoji_flags. + */ + uint8_t flags{0}; /** * @brief Construct a new emoji object diff --git a/src/dpp/emoji.cpp b/src/dpp/emoji.cpp index b033366e32..7793c34c85 100644 --- a/src/dpp/emoji.cpp +++ b/src/dpp/emoji.cpp @@ -41,6 +41,13 @@ emoji& emoji::fill_from_json_impl(nlohmann::json* j) { json & user = (*j)["user"]; user_id = snowflake_not_null(&user, "id"); } + + if(j->contains("roles")) { + for (const auto& role : (*j)["roles"]) { + this->roles.emplace_back(to_string(role)); + } + } + if (bool_not_null(j, "require_colons")) { flags |= e_require_colons; } @@ -65,6 +72,10 @@ json emoji::to_json_impl(bool with_id) const { if (!image_data.empty()) { j["image"] = image_data; } + j["roles"] = json::array(); + for (const auto& role : roles) { + j["roles"].push_back(role.str()); + } return j; } @@ -94,8 +105,7 @@ emoji& emoji::load_image(std::string_view image_blob, const image_type type) { return *this; } -std::string emoji::format() const -{ +std::string emoji::format() const { return id ? ((is_animated() ? "a:" : "") + name + ":" + std::to_string(id)) : name; } @@ -106,11 +116,11 @@ std::string emoji::get_mention() const { std::string emoji::get_url(uint16_t size, const dpp::image_type format, bool prefer_animated) const { if (this->id) { return utility::cdn_endpoint_url({ i_jpg, i_png, i_webp, i_gif }, - "emojis/" + std::to_string(this->id), - format, size, prefer_animated, is_animated()); - } else { - return std::string(); + "emojis/" + std::to_string(this->id), + format, size, prefer_animated, is_animated()); } + + return ""; }