Skip to content

Commit

Permalink
DiscordCoreAPI Release v2.0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
RealTimeChris committed Oct 20, 2024
1 parent e3b5dc2 commit 1c911ae
Show file tree
Hide file tree
Showing 16 changed files with 578 additions and 446 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/MSVC-Windows-Binaries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build-and-Test-MSVC-Windows

on:
workflow_dispatch:
push:
branches:
- main
- dev

jobs:
Build:
runs-on: windows-latest

strategy:
fail-fast: false
matrix:
msvc: [2022]
build_type: [Debug, Release]
std: [20]

steps:
- uses: actions/checkout@v4

- name: Update Vcpkg and install other dependencies
run: |
cd C:/vcpkg
./bootstrap-vcpkg.bat
git stash
git pull
vcpkg update
- name: Install the dependencies
run: |
vcpkg install opus:x64-windows
vcpkg install libsodium:x64-windows
vcpkg install openssl:x64-windows
- name: Configure CMake
working-directory: ./
run: |
cmake -S . -B ./Build -DDEV=true -DVCPKG_ROOT_DIR=C:/vcpkg
- name: Build the Test
working-directory: ./Build
run: |
cmake --build . --config=${{matrix.build_type}}
- name: Install the Test
working-directory: ./Build/
run: |
cmake --install ./ --config=${{matrix.build_type}}
- name: Clone DiscordCoreAPI-Binaries repository
run: |
git clone https://github.com/RealTimeChris/DiscordCoreAPI-Binaries.git ./DiscordCoreAPI-Binaries
cd DiscordCoreAPI-Binaries
git config user.name "GitHub Action"
git config user.email "action@github.com"
- name: Copy build artifacts to DiscordCoreAPI-Binaries
run: |
cp -r -Force "C:/Program Files (x86)/DiscordCoreAPI/*" ./DiscordCoreAPI-Binaries/${{matrix.build_type}} -v
cd ./DiscordCoreAPI-Binaries/${{matrix.build_type}}
Remove-Item -Force ./bin/discordcoreapi.pdb
- name: Commit and push changes to DiscordCoreAPI-Binaries
working-directory: ./DiscordCoreAPI-Binaries
run: |
git add .
git commit -m "Update binaries for ${{matrix.build_type}} build"
git push https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/RealTimeChris/DiscordCoreAPI-Binaries.git main
continue-on-error: true
3 changes: 1 addition & 2 deletions .github/workflows/MSVC-Windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,12 @@ jobs:
- name: Copy build artifacts to DiscordCoreAPI-Binaries
run: |
mkdir -p ./DiscordCoreAPI-Binaries/${{matrix.build_type}}
cp -r ./Tests/Install/${{matrix.build_type}}/* ./DiscordCoreAPI-Binaries/${{matrix.build_type}}
- name: Commit and push changes to DiscordCoreAPI-Binaries
working-directory: ./DiscordCoreAPI-Binaries
run: |
git add .
git commit -m "Update binaries for ${{matrix.build_type}} build"
git push https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/RealTimeChris/DiscordCoreAPI-Binaries.git main
git push https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/RealTimeChris/DiscordCoreAPI-Binaries.git main
continue-on-error: true
17 changes: 15 additions & 2 deletions CMake/DCADetectArchitecture.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,19 @@ execute_process(
RESULT_VARIABLE DCA_CPU_INSTRUCTIONS_NEW
)

set(AVX_FLAG "")
function(is_numeric value result_var)
string(REGEX MATCH "^[0-9]+(\\.[0-9]+)?$" is_numeric_match "${value}")
if(is_numeric_match)
set(${result_var} TRUE PARENT_SCOPE)
else()
set(${result_var} FALSE PARENT_SCOPE)
endif()
endfunction()

is_numeric("${DCA_CPU_INSTRUCTIONS_NEW}" is_numeric_result)

set(AVX_FLAG "")
if (is_numeric_result)
math(EXPR DCA_CPU_INSTRUCTIONS_NUMERIC "${DCA_CPU_INSTRUCTIONS_NEW}")
math(EXPR DCA_CPU_INSTRUCTIONS 0)

Expand Down Expand Up @@ -99,6 +110,8 @@ else()
check_instruction_set("Avx2" "-mavx2;-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x40)
check_instruction_set("Avx512" "-mavx512f;-mavx2;-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x80)
endif()

else()
set(DCA_CPU_INSTRUCTIONS "0")
endif()
set(AVX_FLAG "${AVX_FLAG}" CACHE STRING "AVX flags" FORCE)
set(DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS}" CACHE STRING "CPU Instruction Sets" FORCE)
18 changes: 9 additions & 9 deletions Documentation/Doxygen/Docs/Index.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
\mainpage DiscordCoreAPI
[![Codacy Badge](https://img.shields.io/codacy/grade/1e5ae970aed34d0b96249cdfd02099cf?color=lightblue&label=Code%20Quality&style=plastic)](https://www.codacy.com/gh/RealTimeChris/DiscordCoreAPI/dashboard?utm_source=github.com&utm_medium=referral&utm_content=RealTimeChris/DiscordCoreAPI&utm_campaign=Badge_Grade)
[![Discord](https://img.shields.io/discord/931640556814237706?color=red&label=Discord%20Server&style=plastic)](https://discord.gg/adgMqeBuhP)
[![Discord](https://img.shields.io/discord/931640556814237706?color=red&label=Discord%20Server&style=plastic)](https://discord.gg/c33GH5BUe8)
![Commit Activity](https://img.shields.io/github/commit-activity/y/realtimechris/discordcoreapi?color=green&label=Commits&style=plastic)
![Lines of Code](https://tokei.rs/b1/github/RealTimeChris/DiscordCoreAPI?color=light-blue&label=Lines%20Of%20Code%20&style=plastic)
![Lines of Code](https://tokei.rs/b1/github/RealTimeChris/DiscordCoreAPI-Code-Only?color=light-blue&label=Lines%20Of%20Code%20&style=plastic)

Hello, and welcome to DiscordCoreAPI! This is a Discord bot library, written in C++, that leverages custom asynchronous \ref discord_core_api::co_routine "CoRoutines", as well as a home-brew set of \ref discord_core_api::discord_core_internal::https_client "Https",
\ref discord_core_api::discord_core_internal::websocket_client "WebSocket", and \ref discord_core_api::voice_connection "Datagram" socket clients - all to deliver the utmost performance and efficiency for your bot. It uses roughly 0.1% of an Intel i7 9750h CPU to stream audio in high quality (Opus @ 48Khz, 16-bit) to a single server.

![imageDiscordCoreAPI](./TheLogo.png "A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.")

## Compiler Support
![MSVC_20922](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/MSVC_2022-Windows.yml?style=plastic&logo=microsoft&logoColor=green&label=MSVC_2022&labelColor=pewter&color=blue)
![CLANG_18](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/CLANG_18-Ubuntu.yml?style=plastic&logo=linux&logoColor=green&label=CLANG_18&labelColor=pewter&color=blue)
![GCC_13](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/GCC_13-MacOS.yml?style=plastic&logo=apple&logoColor=green&label=GCC_13&labelColor=pewter&color=blue)
![MSVC_20922](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/MSVC-Windows.yml?style=plastic&logo=microsoft&logoColor=green&label=MSVC_2022&labelColor=pewter&color=blue)
![CLANG_18](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/CLANG-Ubuntu.yml?style=plastic&logo=linux&logoColor=green&label=CLANG_18&labelColor=pewter&color=blue)
![GCC_13](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/GCC-MacOS.yml?style=plastic&logo=apple&logoColor=green&label=GCC_13&labelColor=pewter&color=blue)

## Operating System Support
![Windows](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/MSVC_2022-Windows.yml?style=plastic&logo=microsoft&logoColor=green&label=Windows&labelColor=pewter&color=blue)
![Linux](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/CLANG_18-Ubuntu.yml?style=plastic&logo=linux&logoColor=green&label=Linux&labelColor=pewter&color=blue)
![Mac](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/GCC_13-MacOS.yml?style=plastic&logo=apple&logoColor=green&label=MacOS&labelColor=pewter&color=blue)
![Windows](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/MSVC-Windows.yml?style=plastic&logo=microsoft&logoColor=green&label=Windows&labelColor=pewter&color=blue)
![Linux](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/CLANG-Ubuntu.yml?style=plastic&logo=linux&logoColor=green&label=Linux&labelColor=pewter&color=blue)
![Mac](https://img.shields.io/github/actions/workflow/status/RealTimeChris/DiscordCoreAPI/GCC-MacOS.yml?style=plastic&logo=apple&logoColor=green&label=MacOS&labelColor=pewter&color=blue)

# Documentation/Examples
\ref documentation_examples

# Discord Server
[This is a link to the Discord server!](https://discord.gg/adgMqeBuhP)
[This is a link to the Discord server!](https://discord.gg/c33GH5BUe8)

# Bot Template
[A template for utilizing this library.](https://github.com/RealTimeChris/Bot-Template-for-DiscordCoreAPI)
Expand Down
34 changes: 21 additions & 13 deletions Include/discordcoreapi/FoundationEntities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#pragma once

#include <discordcoreapi/Utilities.hpp>
#include <optional>

namespace discord_core_api {

Expand Down Expand Up @@ -321,23 +322,27 @@ namespace discord_core_api {
};

struct websocket_message {
jsonifier::string t{};
std::optional<jsonifier::string> t{};
std::optional<int64_t> s{};
int64_t op{ -1 };
int64_t s{};
};

template<typename value_type> struct websocket_message_data {
unordered_set<jsonifier::string> jsonifierExcludedKeys{};
jsonifier::string t{};
std::optional<jsonifier::string> t{};
std::optional<int64_t> s{};
value_type d{};
int64_t op{};
int64_t s{};

DCA_INLINE operator discord_core_internal::etf_serializer() {
etf_serializer data{};
data["op"] = op;
data["s"] = s;
data["t"] = t;
if (s.has_value()) {
data["s"] = s.value();
}
if (t.has_value()) {
data["t"] = t.value();
}
data["d"] = d.operator discord_core_internal::etf_serializer();
return data;
}
Expand Down Expand Up @@ -407,25 +412,28 @@ namespace discord_core_api {

template<typename value_type> class flag_entity {
public:
template<jsonifier::concepts::enum_t value_type02> DCA_INLINE auto setFlagValue(value_type02 theFlagToSet, bool enabled) {
auto newValue = static_cast<int64_t>(static_cast<value_type*>(this)->flags);
template<jsonifier::concepts::enum_t flag_type> DCA_INLINE void setFlagValue(flag_type theFlagToSet, bool enabled) {
using underlying_type = std::underlying_type_t<flag_type>;
auto newValue = static_cast<underlying_type>(static_cast<value_type*>(this)->flags);
if (enabled) {
newValue |= static_cast<int64_t>(theFlagToSet);
newValue |= static_cast<underlying_type>(theFlagToSet);
} else {
newValue &= ~static_cast<int64_t>(theFlagToSet);
newValue &= ~static_cast<underlying_type>(theFlagToSet);
}
static_cast<value_type*>(this)->flags = static_cast<value_type02>(newValue);
static_cast<value_type*>(this)->flags = static_cast<flag_type>(newValue);
}

template<jsonifier::concepts::enum_t value_type02> DCA_INLINE bool getFlagValue(value_type02 theFlagToCheckFor) const {
return static_cast<int64_t>(static_cast<const value_type*>(this)->flags) & static_cast<int64_t>(theFlagToCheckFor);
template<jsonifier::concepts::enum_t flag_type> DCA_INLINE bool getFlagValue(flag_type theFlagToCheckFor) const {
using underlying_type = std::underlying_type_t<flag_type>;
return static_cast<underlying_type>(static_cast<const value_type*>(this)->flags) & static_cast<underlying_type>(theFlagToCheckFor);
}

protected:
DCA_INLINE flag_entity() = default;
DCA_INLINE ~flag_entity() = default;
};


enum class user_image_types {
Banner = 0,
Default_Avatar = 1,
Expand Down
8 changes: 4 additions & 4 deletions Include/discordcoreapi/JsonSpecializations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ namespace discord_core_api {
websocket_message_data(const update_voice_state_data& data);
unordered_set<jsonifier::string> jsonifierExcludedKeys{};
using type = update_voice_state_data;
std::optional<jsonifier::string> t{};
int64_t op{ -1 };
jsonifier::string t{};
int32_t s{};
type d{};
operator etf_serializer();
Expand All @@ -53,8 +53,8 @@ namespace discord_core_api {
websocket_message_data(const update_voice_state_data& data);
unordered_set<jsonifier::string> jsonifierExcludedKeys{};
using type = update_voice_state_data_dc;
std::optional<jsonifier::string> t{};
int64_t op{ -1 };
jsonifier::string t{};
int32_t s{};
type d{};
operator etf_serializer();
Expand All @@ -65,7 +65,7 @@ namespace discord_core_api {
namespace jsonifier_internal {

template<typename value_type>
concept snowflake_t = std::same_as<discord_core_api::snowflake, jsonifier_internal::unwrap_t<value_type>>;
concept snowflake_t = std::same_as<discord_core_api::snowflake, std::remove_cvref_t<value_type>>;

template<jsonifier::serialize_options options, snowflake_t value_type, jsonifier::concepts::buffer_like buffer_type, typename serialize_context_type>
struct serialize_impl<options, value_type, buffer_type, serialize_context_type> {
Expand All @@ -88,7 +88,7 @@ namespace jsonifier_internal {
};

template<typename value_type>
concept time_stamp_t = std::same_as<discord_core_api::time_stamp, jsonifier_internal::unwrap_t<value_type>>;
concept time_stamp_t = std::same_as<discord_core_api::time_stamp, std::remove_cvref_t<value_type>>;

template<jsonifier::serialize_options options, time_stamp_t value_type, jsonifier::concepts::buffer_like buffer_type, typename serialize_context_type>
struct serialize_impl<options, value_type, buffer_type, serialize_context_type> {
Expand Down
4 changes: 2 additions & 2 deletions Include/discordcoreapi/Utilities/Etf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,8 @@ namespace discord_core_api {

/// @brief Concept for array types excluding etf_serializer.
template<typename value_type>
concept array_t = jsonifier::concepts::range<value_type> && jsonifier::concepts::has_resize<jsonifier_internal::unwrap_t<value_type>> &&
jsonifier::concepts::has_emplace_back<jsonifier_internal::unwrap_t<value_type>> && jsonifier::concepts::vector_subscriptable<jsonifier_internal::unwrap_t<value_type>> &&
concept array_t = jsonifier::concepts::range<value_type> && jsonifier::concepts::has_resize<std::remove_cvref_t<value_type>> &&
jsonifier::concepts::has_emplace_back<std::remove_cvref_t<value_type>> && jsonifier::concepts::vector_subscriptable<std::remove_cvref_t<value_type>> &&
requires(value_type&& data) { typename value_type::value_type; };

/// @brief Concept for object (associative container) types excluding etf_serializer.
Expand Down
30 changes: 15 additions & 15 deletions Include/discordcoreapi/Utilities/RingBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ namespace discord_core_api {
arrayValue.resize(size);
}

DCA_INLINE ring_buffer_interface& operator=(ring_buffer_interface&&) noexcept = default;
DCA_INLINE ring_buffer_interface(ring_buffer_interface&&) noexcept = default;
DCA_INLINE ring_buffer_interface& operator=(const ring_buffer_interface&) noexcept = default;
DCA_INLINE ring_buffer_interface(const ring_buffer_interface&) noexcept = default;
DCA_INLINE ring_buffer_interface& operator=(ring_buffer_interface&&) noexcept = default;
DCA_INLINE ring_buffer_interface(ring_buffer_interface&&) noexcept = default;
DCA_INLINE ring_buffer_interface& operator=(const ring_buffer_interface&) noexcept = default;
DCA_INLINE ring_buffer_interface(const ring_buffer_interface&) noexcept = default;

// forward declaration to grant friendship to the ring_buffer class.
template<typename value_type2, size_type slice_count> friend class ring_buffer;
Expand Down Expand Up @@ -125,7 +125,7 @@ namespace discord_core_api {
}

protected:
jsonifier::vector<jsonifier_internal::unwrap_t<value_type>> arrayValue{};///< The underlying data array.
jsonifier::vector<std::remove_cvref_t<value_type>> arrayValue{};///< The underlying data array.
size_type tail{};///< The tail position in the buffer.
size_type head{};///< The head position in the buffer.
};
Expand All @@ -134,18 +134,18 @@ namespace discord_core_api {
/// @tparam value_type the type of data stored in the buffer.
/// @tparam slice_count the number of slices.
template<typename value_type_new, uint64_t slice_count> class ring_buffer
: public ring_buffer_interface<ring_buffer_interface<jsonifier_internal::unwrap_t<value_type_new>, 1024 * 16>, slice_count> {
: public ring_buffer_interface<ring_buffer_interface<std::remove_cvref_t<value_type_new>, 1024 * 16>, slice_count> {
public:
using base_type = ring_buffer_interface<ring_buffer_interface<jsonifier_internal::unwrap_t<value_type_new>, 1024 * 16>, slice_count>;
using value_type = typename ring_buffer_interface<jsonifier_internal::unwrap_t<value_type_new>, 1024 * 16>::value_type;
using base_type = ring_buffer_interface<ring_buffer_interface<std::remove_cvref_t<value_type_new>, 1024 * 16>, slice_count>;
using value_type = typename ring_buffer_interface<std::remove_cvref_t<value_type_new>, 1024 * 16>::value_type;
using const_pointer = const value_type*;
using pointer = value_type*;
using size_type = uint64_t;

/// @brief Default constructor. initializes the buffer size.
DCA_INLINE ring_buffer() noexcept = default;
DCA_INLINE ring_buffer& operator=(ring_buffer&&) noexcept = default;
DCA_INLINE ring_buffer(ring_buffer&&) noexcept = default;
DCA_INLINE ring_buffer() noexcept = default;
DCA_INLINE ring_buffer& operator=(ring_buffer&&) noexcept = default;
DCA_INLINE ring_buffer(ring_buffer&&) noexcept = default;
DCA_INLINE ring_buffer& operator=(const ring_buffer&) noexcept = default;
DCA_INLINE ring_buffer(const ring_buffer&) noexcept = default;

Expand All @@ -166,11 +166,11 @@ namespace discord_core_api {

/// @brief Read data from the buffer.
/// @return a string view containing the read data.
DCA_INLINE jsonifier::string_view_base<jsonifier_internal::unwrap_t<value_type>> readData() {
jsonifier::string_view_base<jsonifier_internal::unwrap_t<value_type>> returnData{};
DCA_INLINE jsonifier::string_view_base<std::remove_cvref_t<value_type>> readData() {
jsonifier::string_view_base<std::remove_cvref_t<value_type>> returnData{};
if (base_type::getCurrentTail()->getUsedSpace() > 0) {
returnData = jsonifier::string_view_base<jsonifier_internal::unwrap_t<value_type>>{ base_type::getCurrentTail()->getCurrentTail(),
base_type::getCurrentTail()->getUsedSpace() };
returnData =
jsonifier::string_view_base<std::remove_cvref_t<value_type>>{ base_type::getCurrentTail()->getCurrentTail(), base_type::getCurrentTail()->getUsedSpace() };
base_type::getCurrentTail()->clear();
base_type::modifyReadOrWritePosition(ring_buffer_access_type::read, 1);
}
Expand Down
4 changes: 2 additions & 2 deletions Include/discordcoreapi/Utilities/UnboundedMessageBlock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
namespace discord_core_api {

template<typename value_type>
concept copyable_or_movable = std::copyable<jsonifier_internal::unwrap_t<value_type>> || std::movable<jsonifier_internal::unwrap_t<value_type>>;
concept copyable_or_movable = std::copyable<std::remove_cvref_t<value_type>> || std::movable<std::remove_cvref_t<value_type>>;

/// @brief A thread-safe messaging block for data-structures.
/// @tparam value_type the type of object that will be sent over the message block.
Expand Down Expand Up @@ -87,7 +87,7 @@ namespace discord_core_api {
std::mutex accessMutex{};
};

template<typename value_type> DCA_INLINE bool waitForTimeToPass(unbounded_message_block<jsonifier_internal::unwrap_t<value_type>>& outBuffer, value_type& argOne, uint64_t timeInMsNew) {
template<typename value_type> DCA_INLINE bool waitForTimeToPass(unbounded_message_block<std::remove_cvref_t<value_type>>& outBuffer, value_type& argOne, uint64_t timeInMsNew) {
stop_watch<milliseconds> stopWatch{ milliseconds{ timeInMsNew } };
stopWatch.reset();
while (!outBuffer.tryReceive(argOne)) {
Expand Down
Loading

0 comments on commit 1c911ae

Please sign in to comment.