Skip to content

Commit

Permalink
Merge pull request #384 from Commandserver/dev
Browse files Browse the repository at this point in the history
added application icon getters
  • Loading branch information
braindigitalis authored May 13, 2022
2 parents 6fbc895 + 3999bed commit 6bbba3f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
16 changes: 16 additions & 0 deletions include/dpp/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ class DPP_EXPORT application : public managed, public json_interface<application
* @return A reference to self
*/
application& fill_from_json(nlohmann::json* j);

/**
* @brief Get the applications cover image url if they have one, otherwise returns an empty string
*
* @param size The size of the cover image in pixels. It can be any power of two between 16 and 4096. if not specified, the default sized cover image is returned.
* @return std::string cover image url or empty string
*/
std::string get_cover_image_url(uint16_t size = 0) const;

/**
* @brief Get the applications icon url if they have one, otherwise returns an empty string
*
* @param size The size of the icon in pixels. It can be any power of two between 16 and 4096. if not specified, the default sized icon is returned.
* @return std::string icon url or empty string
*/
std::string get_icon_url(uint16_t size = 0) const;
};

/** A group of applications.
Expand Down
29 changes: 28 additions & 1 deletion src/dpp/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <dpp/snowflake.h>
#include <dpp/managed.h>
#include <dpp/nlohmann/json.hpp>
#include <dpp/fmt-minimal.h>

namespace dpp {

Expand Down Expand Up @@ -62,7 +63,7 @@ application& application::fill_from_json(nlohmann::json* j) {
json& t = (*j)["team"];
std::string i = string_not_null(&t, "icon");
if (!i.empty()) {
icon = i;
this->team.icon = i;
}
set_snowflake_not_null(&t, "id", this->team.id);
set_string_not_null(&t, "name", this->team.name);
Expand All @@ -79,5 +80,31 @@ application& application::fill_from_json(nlohmann::json* j) {
return *this;
}

std::string application::get_cover_image_url(uint16_t size) const {
if (!this->cover_image.to_string().empty()) {
return fmt::format("{}/app-icons/{}/{}.png{}",
utility::cdn_host,
this->id,
this->cover_image.to_string(),
utility::avatar_size(size)
);
} else {
return std::string();
}
}

std::string application::get_icon_url(uint16_t size) const {
if (!this->icon.to_string().empty()) {
return fmt::format("{}/app-icons/{}/{}.png{}",
utility::cdn_host,
this->id,
this->icon.to_string(),
utility::avatar_size(size)
);
} else {
return std::string();
}
}

};

0 comments on commit 6bbba3f

Please sign in to comment.