Skip to content

Commit

Permalink
feat: added avatar decoration url to the dpp::user class (brainboxdot…
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandserver authored and Mishura4 committed Sep 17, 2023
1 parent a03b0d2 commit e2989ea
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/dpp/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ class DPP_EXPORT user : public managed, public json_interface<user> {
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.
Expand Down Expand Up @@ -157,6 +159,15 @@ class DPP_EXPORT user : public managed, public json_interface<user> {
*/
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
*
Expand Down
12 changes: 12 additions & 0 deletions src/dpp/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e2989ea

Please sign in to comment.