Skip to content

Commit

Permalink
fix: banner blob now correctly throws for banner blob size. coro and …
Browse files Browse the repository at this point in the history
…sync calls updated
  • Loading branch information
Jaskowicz1 committed Jul 13, 2024
1 parent 5903abd commit 7e7bd2d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
8 changes: 5 additions & 3 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2253,13 +2253,15 @@
* @see dpp::cluster::current_user_edit
* @see https://discord.com/developers/docs/resources/user#modify-current-user
* @param nickname Nickname to set
* @param image_blob Avatar data to upload (NOTE: Very heavily rate limited!)
* @param type Type of image for avatar. It can be one of `i_gif`, `i_jpg` or `i_png`.
* @param avatar_blob Avatar data to upload (NOTE: Very heavily rate limited!)
* @param avatar_type Type of image for avatar. It can be one of `i_gif`, `i_jpg` or `i_png`.
* @param banner_blob Banner data to upload (NOTE: Very heavily rate limited!)
* @param banner_type Type of image for Banner. It can be one of `i_gif`, `i_jpg` or `i_png`.
* @return user returned object on completion
* @throw dpp::length_exception Image data is larger than the maximum size of 256 kilobytes
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_current_user_edit(const std::string &nickname, const std::string& image_blob = "", const image_type type = i_png);
[[nodiscard]] async<confirmation_callback_t> co_current_user_edit(const std::string &nickname, const std::string& avatar_blob = "", const image_type avatar_type = i_png, const std::string& banner_blob = "", const image_type banner_type = i_png);

/**
* @brief Get current (bot) application
Expand Down
8 changes: 5 additions & 3 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2772,16 +2772,18 @@ thread thread_get_sync(snowflake thread_id);
* @see dpp::cluster::current_user_edit
* @see https://discord.com/developers/docs/resources/user#modify-current-user
* @param nickname Nickname to set
* @param image_blob Avatar data to upload (NOTE: Very heavily rate limited!)
* @param type Type of image for avatar. It can be one of `i_gif`, `i_jpg` or `i_png`.
* @param avatar_blob Avatar data to upload (NOTE: Very heavily rate limited!)
* @param avatar_type Type of image for avatar. It can be one of `i_gif`, `i_jpg` or `i_png`.
* @param banner_blob Banner data to upload (NOTE: Very heavily rate limited!)
* @param banner_type Type of image for Banner. It can be one of `i_gif`, `i_jpg` or `i_png`.
* @return user returned object on completion
* @throw dpp::length_exception Image data is larger than the maximum size of 256 kilobytes
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
user current_user_edit_sync(const std::string &nickname, const std::string& image_blob = "", const image_type type = i_png);
user current_user_edit_sync(const std::string &nickname, const std::string& avatar_blob = "", const image_type avatar_type = i_png, const std::string& banner_blob = "", const image_type banner_type = i_png);

/**
* @brief Get current (bot) application
Expand Down
3 changes: 2 additions & 1 deletion src/dpp/cluster/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void cluster::current_user_edit(const std::string &nickname, const std::string&
{ i_gif, "image/gif" },
{ i_jpg, "image/jpeg" },
{ i_png, "image/png" },
{ i_webp, "image/webp" }, /* Whilst webp isn't supported (as of 13/07/24, UK date), best to keep this here for when Discord support webp */
};

if (!avatar_blob.empty()) {
Expand All @@ -44,7 +45,7 @@ void cluster::current_user_edit(const std::string &nickname, const std::string&
}

if (!banner_blob.empty()) {
if (avatar_blob.size() > MAX_EMOJI_SIZE) {
if (banner_blob.size() > MAX_EMOJI_SIZE) {
throw dpp::length_exception(err_icon_size, "User banner file exceeds discord limit of 256 kilobytes");
}
j["banner"] = "data:" + mimetypes.find(banner_type)->second + ";base64," + base64_encode((unsigned char const*)banner_blob.data(), static_cast<unsigned int>(banner_blob.length()));
Expand Down
4 changes: 2 additions & 2 deletions src/dpp/cluster_coro_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,8 +747,8 @@ async<confirmation_callback_t> cluster::co_thread_get(snowflake thread_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::thread_get), thread_id };
}

async<confirmation_callback_t> cluster::co_current_user_edit(const std::string &nickname, const std::string& image_blob, const image_type type) {
return async{ this, static_cast<void (cluster::*)(const std::string &, const std::string&, const image_type, command_completion_event_t)>(&cluster::current_user_edit), nickname, image_blob, type };
async<confirmation_callback_t> cluster::co_current_user_edit(const std::string &nickname, const std::string& avatar_blob, const image_type avatar_type, const std::string& banner_blob, const image_type banner_type) {
return async{ this, static_cast<void (cluster::*)(const std::string &, const std::string&, const image_type, const std::string&, const image_type, command_completion_event_t)>(&cluster::current_user_edit), nickname, avatar_blob, avatar_type, banner_blob, banner_type };
}

async<confirmation_callback_t> cluster::co_current_application_get() {
Expand Down
4 changes: 2 additions & 2 deletions src/dpp/cluster_sync_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,8 +745,8 @@ thread cluster::thread_get_sync(snowflake thread_id) {
return dpp::sync<thread>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::thread_get), thread_id);
}

user cluster::current_user_edit_sync(const std::string &nickname, const std::string& image_blob, const image_type type) {
return dpp::sync<user>(this, static_cast<void (cluster::*)(const std::string &, const std::string&, const image_type, command_completion_event_t)>(&cluster::current_user_edit), nickname, image_blob, type);
user cluster::current_user_edit_sync(const std::string &nickname, const std::string& avatar_blob, const image_type avatar_type, const std::string& banner_blob, const image_type banner_type) {
return dpp::sync<user>(this, static_cast<void (cluster::*)(const std::string &, const std::string&, const image_type, const std::string&, const image_type, command_completion_event_t)>(&cluster::current_user_edit), nickname, avatar_blob, avatar_type, banner_blob, banner_type);
}

application cluster::current_application_get_sync() {
Expand Down

0 comments on commit 7e7bd2d

Please sign in to comment.