Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added roles to emojis #959

Merged
merged 7 commits into from
Oct 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions include/dpp/emoji.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,22 +71,11 @@ class DPP_EXPORT emoji : public managed, public json_interface<emoji> {
json to_json_impl(bool with_id = false) const;

public:
/**
* @brief Emoji name
*/
std::string name{};
/**
* @brief User id who uploaded the emoji
*/
snowflake user_id{0};
/**
* @brief Flags for the emoji from dpp::emoji_flags
*/
uint8_t flags{0};
/**
* @brief Image data for the emoji if uploading
*/
std::string image_data{};
std::string name{}; //!< emoji name
Mishura4 marked this conversation as resolved.
Show resolved Hide resolved
std::vector<snowflake> roles; //!< roles allowed to use this emoji
snowflake user_id; //!< user id that created this emoji
std::string image_data{}; //!< Image data for the emoji if uploading
uint8_t flags{0}; //!< Flags for the emoji from dpp::emoji_flags

/**
* @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