diff --git a/include/dpp/user.h b/include/dpp/user.h index 71c0978e7e..267a2d26ff 100644 --- a/include/dpp/user.h +++ b/include/dpp/user.h @@ -93,6 +93,8 @@ class DPP_EXPORT user : public managed, public json_interface { std::string global_name; /** Avatar hash */ utility::iconhash avatar; + /** Avatar decoration hash */ + utility::iconhash avatar_decoration; /** Flags built from a bitmask of values in dpp::user_flags */ uint32_t flags; /** Discriminator (aka tag), 4 digits usually displayed with leading zeroes. @@ -157,6 +159,15 @@ class DPP_EXPORT user : public managed, public json_interface { */ std::string get_default_avatar_url() const; + /** + * @brief Get the avatar decoration url of the user if they have one, otherwise returns an empty string. + * + * @param size The size of the avatar decoration in pixels. It can be any power of two between 16 and 4096, + * otherwise the default sized avatar decoration is returned. + * @return std::string avatar url or an empty string + */ + std::string get_avatar_decoration_url(uint16_t size = 0) const; + /** * @brief Return a ping/mention for the user * diff --git a/src/dpp/user.cpp b/src/dpp/user.cpp index d40b5eb401..d2dc7e0143 100644 --- a/src/dpp/user.cpp +++ b/src/dpp/user.cpp @@ -119,6 +119,16 @@ std::string user::get_default_avatar_url() const { } } +std::string user::get_avatar_decoration_url(uint16_t size) const { + if (this->id) { + return utility::cdn_endpoint_url_hash({ i_png }, + "avatar-decorations/" + std::to_string(this->id), this->avatar_decoration.to_string(), + i_png, size); + } else { + return std::string(); + } +} + std::string user::format_username() const { if (!global_name.empty()) { return global_name; @@ -279,6 +289,8 @@ void from_json(const nlohmann::json& j, user& u) { } u.avatar = av; + u.avatar_decoration = string_not_null(&j, "avatar_decoration"); + u.discriminator = (uint16_t)snowflake_not_null(&j, "discriminator"); u.flags |= bool_not_null(&j, "bot") ? dpp::u_bot : 0;