Skip to content

Commit

Permalink
Merge branch 'dev' into coro
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishura4 authored Jul 18, 2024
2 parents 6f06990 + 4ff0420 commit 99e6f60
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 92 deletions.
36 changes: 20 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ jobs:
# GitHub hosted runners on Azure
# arm7hf is a self-hosted docker-based runner at Brainbox.cc. Raspberry Pi 4, 8gb 4-core with NEON
cfg:
- { arch: 'amd64', concurrency: 2, os: ubuntu-20.04, package: clang-10, cpp-version: clang++-10, cmake-flags: '', cpack: 'no', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-11, cpp-version: clang++-11, cmake-flags: '', cpack: 'no', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-12, cpp-version: clang++-12, cmake-flags: '', cpack: 'no', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-13, cpp-version: clang++-13, cmake-flags: '', cpack: 'no', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-14, cpp-version: clang++-14, cmake-flags: '', cpack: 'no', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: clang-15, cpp-version: clang++-15, cmake-flags: '-DDPP_CORO=ON', cpack: 'no', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-12, cpp-version: g++-12, cmake-flags: '-DDPP_CORO=ON', cpack: 'no', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-11, cpp-version: g++-11, cmake-flags: '-DDPP_CORO=ON', cpack: 'no', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-22.04, package: g++-10, cpp-version: g++-10, cmake-flags: '', cpack: 'yes', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-20.04, package: g++-9, cpp-version: g++-9, cmake-flags: '', cpack: 'no', ctest: 'no' }
- { arch: 'amd64', concurrency: 2, os: ubuntu-20.04, package: g++-8, cpp-version: g++-8, cmake-flags: '', cpack: 'no', ctest: 'yes' }
- { arch: 'arm7hf', concurrency: 4, os: [self-hosted, linux, ARM], package: g++-12, cpp-version: g++-12, cmake-flags: '', cpack: 'yes', ctest: 'no' }
- { arch: 'arm64', concurrency: 4, os: [self-hosted, linux, ARM64], package: g++-12, cpp-version: g++-12, cmake-flags: '', cpack: 'yes', ctest: 'no' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-20.04, package: clang-10, cpp-version: clang++-10, cmake-flags: '', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-22.04, package: clang-11, cpp-version: clang++-11, cmake-flags: '', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-22.04, package: clang-12, cpp-version: clang++-12, cmake-flags: '', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-22.04, package: clang-13, cpp-version: clang++-13, cmake-flags: '', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-22.04, package: clang-14, cpp-version: clang++-14, cmake-flags: '', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-22.04, package: clang-15, cpp-version: clang++-15, cmake-flags: '-DDPP_CORO=ON', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-24.04, package: g++-13, cpp-version: g++-13, cmake-flags: '-DDPP_CORO=ON', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-24.04, package: g++-14, cpp-version: g++-14, cmake-flags: '-DDPP_CORO=ON', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-22.04, package: g++-12, cpp-version: g++-12, cmake-flags: '-DDPP_CORO=ON', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-22.04, package: g++-11, cpp-version: g++-11, cmake-flags: '-DDPP_CORO=ON', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-22.04, package: g++-10, cpp-version: g++-10, cmake-flags: '', cpack: 'yes', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-20.04, package: g++-9, cpp-version: g++-9, cmake-flags: '', cpack: 'no', ctest: 'no', mold: 'yes' }
- { arch: 'amd64', concurrency: 4, os: ubuntu-20.04, package: g++-8, cpp-version: g++-8, cmake-flags: '', cpack: 'no', ctest: 'yes', mold: 'yes' }
- { arch: 'arm7hf', concurrency: 4, os: [self-hosted, linux, ARM], package: g++-12, cpp-version: g++-12, cmake-flags: '', cpack: 'yes', ctest: 'no', mold: 'no' }
- { arch: 'arm64', concurrency: 4, os: [self-hosted, linux, ARM64], package: g++-12, cpp-version: g++-12, cmake-flags: '', cpack: 'yes', ctest: 'no', mold: 'yes' }
steps:
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
Expand All @@ -66,8 +68,12 @@ jobs:
- name: Install apt packages
run: sudo sed -i 's/azure\.//' /etc/apt/sources.list && sudo apt update && sudo apt-get install -y ${{ matrix.cfg.package }} pkg-config libsodium-dev libopus-dev zlib1g-dev rpm

- name: Setup mold
if: ${{ matrix.cfg.mold == 'yes' }}
uses: rui314/setup-mold@2e332a0b602c2fc65d2d3995941b1b29a5f554a0

- name: Generate CMake
run: mkdir build && cd build && cmake -DDPP_NO_VCPKG=ON -DAVX_TYPE=AVX0 -DCMAKE_BUILD_TYPE=Release ${{matrix.cfg.cmake-flags}} ..
run: cmake -B build -DDPP_NO_VCPKG=ON -DAVX_TYPE=AVX0 -DCMAKE_BUILD_TYPE=Release ${{matrix.cfg.cmake-flags}}
env:
CXX: ${{matrix.cfg.cpp-version}}

Expand Down Expand Up @@ -111,10 +117,8 @@ jobs:
strategy:
fail-fast: false # Don't fail everything if one fails. We want to test each OS/Compiler individually
matrix:
# arm64 is a self-hosted runner on a Mac M2 Mini, ran inside a virtual machine by Archie Jaskowicz. NOTE: This runner no longer exists. It may come back in a few months.
cfg:
- { arch: 'x64', concurrency: 3, os: macos-latest, cpp-version: clang++-14, cmake-flags: ''}
# - { arch: 'arm64', concurrency: 2, os: [self-hosted, ARM64, macOS], cpp-version: clang++-15, cmake-flags: ''}
steps:
- name: Harden Runner
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ jobs:
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.

- name: Setup mold
uses: rui314/setup-mold@2e332a0b602c2fc65d2d3995941b1b29a5f554a0

- name: Build
run: |
mkdir build
cd build
cmake -DDPP_NO_VCPKG=ON -DCMAKE_BUILD_TYPE=Debug ..
make -j2
run: cmake -B build -DDPP_NO_VCPKG=ON -DAVX_TYPE=AVX0 -DCMAKE_BUILD_TYPE=Release && cmake --build build -j4

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@b611370bb5703a7efb587f9d136a52ea24c5c38c # v3.25.11
Expand Down
17 changes: 11 additions & 6 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3253,19 +3253,24 @@ class DPP_EXPORT cluster {
void current_user_get_guilds(command_completion_event_t callback);

/**
* @brief Edit current (bot) user
* @brief Edit current (bot) user.
*
* Modify the requester's user account settings. Returns a dpp::user object on success.
* Fires a User Update Gateway event.
*
* @note There appears to be no limit to the image size, however, if your image cannot be processed/uploaded in time, you will receive a malformed http request.
*
* Modifies the current member in a guild. Returns the updated guild_member object on success.
* Fires a `Guild Member Update` Gateway event.
* @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
* @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
* @param banner_type Type of image for Banner. It can be one of `i_gif`, `i_jpg` or `i_png`.
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::user object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
* @throw dpp::length_exception Image data is larger than the maximum size of 256 kilobytes
*/
void current_user_edit(const std::string &nickname, const std::string& image_blob = "", const image_type type = i_png, command_completion_event_t callback = utility::log_error());
void 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, command_completion_event_t callback = utility::log_error());

/**
* @brief Get current user DM channels
Expand Down
17 changes: 11 additions & 6 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2246,20 +2246,25 @@
[[nodiscard]] async<confirmation_callback_t> co_thread_get(snowflake thread_id);

/**
* @brief Edit current (bot) user
* @brief Edit current (bot) user.
*
* Modify the requester's user account settings. Returns a dpp::user object on success.
* Fires a User Update Gateway event.
*
* @note There appears to be no limit to the image size, however, if your image cannot be processed/uploaded in time, you will receive a malformed http request.
*
* Modifies the current member in a guild. Returns the updated guild_member object on success.
* Fires a `Guild Member Update` Gateway event.
* @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
* @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
* @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
17 changes: 11 additions & 6 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2765,23 +2765,28 @@ confirmation thread_member_remove_sync(snowflake thread_id, snowflake user_id);
thread thread_get_sync(snowflake thread_id);

/**
* @brief Edit current (bot) user
* @brief Edit current (bot) user.
*
* Modify the requester's user account settings. Returns a dpp::user object on success.
* Fires a User Update Gateway event.
*
* @note There appears to be no limit to the image size, however, if your image cannot be processed/uploaded in time, you will receive a malformed http request.
*
* Modifies the current member in a guild. Returns the updated guild_member object on success.
* Fires a `Guild Member Update` Gateway event.
* @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
* @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
* @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
2 changes: 1 addition & 1 deletion include/dpp/misc-enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace dpp {
/**
* @brief Supported image types for profile pictures and CDN endpoints
*/
enum image_type {
enum image_type : uint8_t {
/**
* @brief image/png
*/
Expand Down
28 changes: 16 additions & 12 deletions src/dpp/cluster/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,27 @@

namespace dpp {

void cluster::current_user_edit(const std::string &nickname, const std::string& image_blob, const image_type type, command_completion_event_t callback) {
void cluster::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, command_completion_event_t callback) {
json j = json::parse("{\"nickname\": null}");
if (!nickname.empty()) {
j["nickname"] = nickname;
}
if (!image_blob.empty()) {
static const std::map<image_type, std::string> mimetypes = {
{ i_gif, "image/gif" },
{ i_jpg, "image/jpeg" },
{ i_png, "image/png" },
{ i_webp, "image/webp" },
};
if (image_blob.size() > MAX_EMOJI_SIZE) {
throw dpp::length_exception(err_icon_size, "User icon file exceeds discord limit of 256 kilobytes");
}
j["avatar"] = "data:" + mimetypes.find(type)->second + ";base64," + base64_encode((unsigned char const*)image_blob.data(), (unsigned int)image_blob.length());

static const std::map<image_type, std::string> mimetypes = {
{ 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()) {
j["avatar"] = "data:" + mimetypes.find(avatar_type)->second + ";base64," + base64_encode((unsigned char const*)avatar_blob.data(), static_cast<unsigned int>(avatar_blob.length()));
}

if (!banner_blob.empty()) {
j["banner"] = "data:" + mimetypes.find(banner_type)->second + ";base64," + base64_encode((unsigned char const*)banner_blob.data(), static_cast<unsigned int>(banner_blob.length()));
}

rest_request<user>(this, API_PATH "/users", "@me", "", m_patch, j.dump(-1, ' ', false, json::error_handler_t::replace), callback);
}

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
Loading

0 comments on commit 99e6f60

Please sign in to comment.