Skip to content

Commit

Permalink
feat: added roles to emojis (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 authored Oct 21, 2023
1 parent cad6668 commit f19db87
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
22 changes: 15 additions & 7 deletions include/dpp/emoji.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,29 @@ class DPP_EXPORT emoji : public managed, public json_interface<emoji> {

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<snowflake> 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
Expand Down
22 changes: 16 additions & 6 deletions src/dpp/emoji.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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 "";
}


Expand Down

0 comments on commit f19db87

Please sign in to comment.