Skip to content

Commit 6c41915

Browse files
committed
DiscordCoreAPI Release v2.0.8
1 parent e3b5dc2 commit 6c41915

File tree

17 files changed

+599
-461
lines changed

17 files changed

+599
-461
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build-and-Test-MSVC-Windows
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- dev
9+
10+
jobs:
11+
Build:
12+
runs-on: windows-latest
13+
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
msvc: [2022]
18+
build_type: [Debug, Release]
19+
std: [20]
20+
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Update Vcpkg and install other dependencies
25+
run: |
26+
cd C:/vcpkg
27+
./bootstrap-vcpkg.bat
28+
git stash
29+
git pull
30+
vcpkg update
31+
32+
- name: Install the dependencies
33+
run: |
34+
vcpkg install opus:x64-windows
35+
vcpkg install libsodium:x64-windows
36+
vcpkg install openssl:x64-windows
37+
38+
- name: Configure CMake
39+
working-directory: ./
40+
run: |
41+
cmake -S . -B ./Build -DDEV=true -DVCPKG_ROOT_DIR=C:/vcpkg
42+
43+
- name: Build the Test
44+
working-directory: ./Build
45+
run: |
46+
cmake --build . --config=${{matrix.build_type}}
47+
48+
- name: Install the Test
49+
working-directory: ./Build/
50+
run: |
51+
cmake --install ./ --config=${{matrix.build_type}}
52+
53+
- name: Clone DiscordCoreAPI-Binaries repository
54+
run: |
55+
git clone https://github.com/RealTimeChris/DiscordCoreAPI-Binaries.git ./DiscordCoreAPI-Binaries
56+
cd DiscordCoreAPI-Binaries
57+
git config user.name "GitHub Action"
58+
git config user.email "[email protected]"
59+
60+
- name: Copy build artifacts to DiscordCoreAPI-Binaries
61+
run: |
62+
cp -r -Force "C:/Program Files (x86)/DiscordCoreAPI/*" ./DiscordCoreAPI-Binaries/${{matrix.build_type}} -v
63+
cd ./DiscordCoreAPI-Binaries/${{matrix.build_type}}
64+
Remove-Item -Force ./bin/discordcoreapi.pdb
65+
66+
- name: Commit and push changes to DiscordCoreAPI-Binaries
67+
working-directory: ./DiscordCoreAPI-Binaries
68+
run: |
69+
git add .
70+
git commit -m "Update binaries for ${{matrix.build_type}} build"
71+
git push https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/RealTimeChris/DiscordCoreAPI-Binaries.git main
72+
continue-on-error: true

.github/workflows/MSVC-Windows.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,12 @@ jobs:
6565
6666
- name: Copy build artifacts to DiscordCoreAPI-Binaries
6767
run: |
68-
mkdir -p ./DiscordCoreAPI-Binaries/${{matrix.build_type}}
6968
cp -r ./Tests/Install/${{matrix.build_type}}/* ./DiscordCoreAPI-Binaries/${{matrix.build_type}}
7069
7170
- name: Commit and push changes to DiscordCoreAPI-Binaries
7271
working-directory: ./DiscordCoreAPI-Binaries
7372
run: |
7473
git add .
7574
git commit -m "Update binaries for ${{matrix.build_type}} build"
76-
git push https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/RealTimeChris/DiscordCoreAPI-Binaries.git main
75+
git push https://x-access-token:${{ secrets.PERSONAL_ACCESS_TOKEN }}@github.com/RealTimeChris/DiscordCoreAPI-Binaries.git main
7776
continue-on-error: true

CMake/DCADetectArchitecture.cmake

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,19 @@ execute_process(
3434
RESULT_VARIABLE DCA_CPU_INSTRUCTIONS_NEW
3535
)
3636

37-
set(AVX_FLAG "")
37+
function(is_numeric value result_var)
38+
string(REGEX MATCH "^[0-9]+(\\.[0-9]+)?$" is_numeric_match "${value}")
39+
if(is_numeric_match)
40+
set(${result_var} TRUE PARENT_SCOPE)
41+
else()
42+
set(${result_var} FALSE PARENT_SCOPE)
43+
endif()
44+
endfunction()
45+
46+
is_numeric("${DCA_CPU_INSTRUCTIONS_NEW}" is_numeric_result)
3847

48+
set(AVX_FLAG "")
49+
if (is_numeric_result)
3950
math(EXPR DCA_CPU_INSTRUCTIONS_NUMERIC "${DCA_CPU_INSTRUCTIONS_NEW}")
4051
math(EXPR DCA_CPU_INSTRUCTIONS 0)
4152

@@ -99,6 +110,8 @@ else()
99110
check_instruction_set("Avx2" "-mavx2;-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x40)
100111
check_instruction_set("Avx512" "-mavx512f;-mavx2;-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x80)
101112
endif()
102-
113+
else()
114+
set(DCA_CPU_INSTRUCTIONS "0")
115+
endif()
103116
set(AVX_FLAG "${AVX_FLAG}" CACHE STRING "AVX flags" FORCE)
104117
set(DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS}" CACHE STRING "CPU Instruction Sets" FORCE)

Documentation/Doxygen/Docs/Index.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
\mainpage DiscordCoreAPI
22
[![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)
3-
[![Discord](https://img.shields.io/discord/931640556814237706?color=red&label=Discord%20Server&style=plastic)](https://discord.gg/adgMqeBuhP)
3+
[![Discord](https://img.shields.io/discord/931640556814237706?color=red&label=Discord%20Server&style=plastic)](https://discord.gg/c33GH5BUe8)
44
![Commit Activity](https://img.shields.io/github/commit-activity/y/realtimechris/discordcoreapi?color=green&label=Commits&style=plastic)
5-
![Lines of Code](https://tokei.rs/b1/github/RealTimeChris/DiscordCoreAPI?color=light-blue&label=Lines%20Of%20Code%20&style=plastic)
5+
![Lines of Code](https://tokei.rs/b1/github/RealTimeChris/DiscordCoreAPI-Code-Only?color=light-blue&label=Lines%20Of%20Code%20&style=plastic)
66

77
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",
88
\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.
99

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

1212
## Compiler Support
13-
![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)
14-
![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)
15-
![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)
13+
![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)
14+
![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)
15+
![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)
1616

1717
## Operating System Support
18-
![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)
19-
![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)
20-
![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)
18+
![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)
19+
![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)
20+
![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)
2121

2222
# Documentation/Examples
2323
\ref documentation_examples
2424

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

2828
# Bot Template
2929
[A template for utilizing this library.](https://github.com/RealTimeChris/Bot-Template-for-DiscordCoreAPI)

Documentation/Doxygen/Docs/documentation_examples/music_bot/PlayQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ namespace discord_core_api {
162162
if (trackNumber >= song_api::getPlaylist(guild_data.id).songQueue.size()) {
163163
unique_ptr<embed_data> newEmbed{ makeUnique<embed_data>() };
164164
newEmbed->setAuthor(newEvent.getUserName(), newEvent.getAvatarUrl());
165-
newEmbed->setDescription("------\n__**sorry, but that number is out of the range of the current track list!**__\n------");
165+
newEmbed->setDescription("------\n__**sorry, but that number is out of the has_range of the current track list!**__\n------");
166166
newEmbed->setTimeStamp(getTimeAndDate());
167167
newEmbed->setTitle("__**playing issue:**__");
168168
newEmbed->setColor(discordGuild.data.borderColor);

Include/discordcoreapi/FoundationEntities.hpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#pragma once
3131

3232
#include <discordcoreapi/Utilities.hpp>
33+
#include <optional>
3334

3435
namespace discord_core_api {
3536

@@ -321,23 +322,27 @@ namespace discord_core_api {
321322
};
322323

323324
struct websocket_message {
324-
jsonifier::string t{};
325+
std::optional<jsonifier::string> t{};
326+
std::optional<int64_t> s{};
325327
int64_t op{ -1 };
326-
int64_t s{};
327328
};
328329

329330
template<typename value_type> struct websocket_message_data {
330331
unordered_set<jsonifier::string> jsonifierExcludedKeys{};
331-
jsonifier::string t{};
332+
std::optional<jsonifier::string> t{};
333+
std::optional<int64_t> s{};
332334
value_type d{};
333335
int64_t op{};
334-
int64_t s{};
335336

336337
DCA_INLINE operator discord_core_internal::etf_serializer() {
337338
etf_serializer data{};
338339
data["op"] = op;
339-
data["s"] = s;
340-
data["t"] = t;
340+
if (s.has_value()) {
341+
data["s"] = s.value();
342+
}
343+
if (t.has_value()) {
344+
data["t"] = t.value();
345+
}
341346
data["d"] = d.operator discord_core_internal::etf_serializer();
342347
return data;
343348
}
@@ -407,25 +412,28 @@ namespace discord_core_api {
407412

408413
template<typename value_type> class flag_entity {
409414
public:
410-
template<jsonifier::concepts::enum_t value_type02> DCA_INLINE auto setFlagValue(value_type02 theFlagToSet, bool enabled) {
411-
auto newValue = static_cast<int64_t>(static_cast<value_type*>(this)->flags);
415+
template<jsonifier::concepts::enum_t flag_type> DCA_INLINE void setFlagValue(flag_type theFlagToSet, bool enabled) {
416+
using underlying_type = std::underlying_type_t<flag_type>;
417+
auto newValue = static_cast<underlying_type>(static_cast<value_type*>(this)->flags);
412418
if (enabled) {
413-
newValue |= static_cast<int64_t>(theFlagToSet);
419+
newValue |= static_cast<underlying_type>(theFlagToSet);
414420
} else {
415-
newValue &= ~static_cast<int64_t>(theFlagToSet);
421+
newValue &= ~static_cast<underlying_type>(theFlagToSet);
416422
}
417-
static_cast<value_type*>(this)->flags = static_cast<value_type02>(newValue);
423+
static_cast<value_type*>(this)->flags = static_cast<flag_type>(newValue);
418424
}
419425

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

424431
protected:
425432
DCA_INLINE flag_entity() = default;
426433
DCA_INLINE ~flag_entity() = default;
427434
};
428435

436+
429437
enum class user_image_types {
430438
Banner = 0,
431439
Default_Avatar = 1,

Include/discordcoreapi/JsonSpecializations.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ namespace discord_core_api {
4141
websocket_message_data(const update_voice_state_data& data);
4242
unordered_set<jsonifier::string> jsonifierExcludedKeys{};
4343
using type = update_voice_state_data;
44+
std::optional<jsonifier::string> t{};
4445
int64_t op{ -1 };
45-
jsonifier::string t{};
4646
int32_t s{};
4747
type d{};
4848
operator etf_serializer();
@@ -53,8 +53,8 @@ namespace discord_core_api {
5353
websocket_message_data(const update_voice_state_data& data);
5454
unordered_set<jsonifier::string> jsonifierExcludedKeys{};
5555
using type = update_voice_state_data_dc;
56+
std::optional<jsonifier::string> t{};
5657
int64_t op{ -1 };
57-
jsonifier::string t{};
5858
int32_t s{};
5959
type d{};
6060
operator etf_serializer();
@@ -65,13 +65,13 @@ namespace discord_core_api {
6565
namespace jsonifier_internal {
6666

6767
template<typename value_type>
68-
concept snowflake_t = std::same_as<discord_core_api::snowflake, jsonifier_internal::unwrap_t<value_type>>;
68+
concept snowflake_t = std::same_as<discord_core_api::snowflake, std::remove_cvref_t<value_type>>;
6969

70-
template<jsonifier::serialize_options options, snowflake_t value_type, jsonifier::concepts::buffer_like buffer_type, typename serialize_context_type>
71-
struct serialize_impl<options, value_type, buffer_type, serialize_context_type> {
72-
template<typename value_type_new> JSONIFIER_ALWAYS_INLINE static void impl(value_type_new&& value, buffer_type& buffer, serialize_context_type& serializePair) noexcept {
70+
template<jsonifier::serialize_options options, snowflake_t value_type, jsonifier::concepts::buffer_like buffer_type, typename index_type, typename indent_type>
71+
struct serialize_impl<options, value_type, buffer_type, index_type, indent_type> {
72+
template<typename value_type_new> JSONIFIER_ALWAYS_INLINE static void impl(value_type_new&& value, buffer_type& buffer, index_type&index, indent_type& indent) noexcept {
7373
jsonifier::string newString{ static_cast<jsonifier::string>(value) };
74-
serialize<options>::impl(newString, buffer, serializePair);
74+
serialize<options>::impl(newString, buffer, index, indent);
7575
}
7676
};
7777

@@ -88,13 +88,13 @@ namespace jsonifier_internal {
8888
};
8989

9090
template<typename value_type>
91-
concept time_stamp_t = std::same_as<discord_core_api::time_stamp, jsonifier_internal::unwrap_t<value_type>>;
91+
concept time_stamp_t = std::same_as<discord_core_api::time_stamp, std::remove_cvref_t<value_type>>;
9292

93-
template<jsonifier::serialize_options options, time_stamp_t value_type, jsonifier::concepts::buffer_like buffer_type, typename serialize_context_type>
94-
struct serialize_impl<options, value_type, buffer_type, serialize_context_type> {
95-
template<typename value_type_new> JSONIFIER_ALWAYS_INLINE static void impl(value_type_new&& value, buffer_type& buffer, serialize_context_type& serializePair) noexcept {
93+
template<jsonifier::serialize_options options, time_stamp_t value_type, jsonifier::concepts::buffer_like buffer_type, typename index_type, typename indent_type>
94+
struct serialize_impl<options, value_type, buffer_type, index_type, indent_type> {
95+
template<typename value_type_new> JSONIFIER_ALWAYS_INLINE static void impl(value_type_new&& value, buffer_type& buffer, index_type& index, indent_type& indent) noexcept {
9696
jsonifier::string newString{ static_cast<jsonifier::string>(value) };
97-
serialize<options>::impl(newString, buffer, serializePair);
97+
serialize<options>::impl(newString, buffer, index, indent);
9898
}
9999
};
100100

Include/discordcoreapi/Utilities/Etf.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,24 +446,25 @@ namespace discord_core_api {
446446
/// @brief Constructor for etf_serialize_error.
447447
/// @param message the error message.
448448
/// @param location source location where the error occurred.
449-
DCA_INLINE etf_serialize_error(const jsonifier::string_view& message, std::source_location location = std::source_location::current()) : dca_exception{ message, location } {};
449+
DCA_INLINE etf_serialize_error(const jsonifier::string_view& message, std::source_location location = std::source_location::current())
450+
: dca_exception{ message, location } {};
450451
};
451452

452453
/// @brief Enumeration for different json value types.
453454
enum class json_type : uint8_t { null_t = 0, object_t = 1, array_t = 2, string_t = 3, float_t = 4, uint_t = 5, int_t = 6, bool_t = 7 };
454455

455456
/// @brief Concept for array types excluding etf_serializer.
456457
template<typename value_type>
457-
concept array_t = jsonifier::concepts::range<value_type> && jsonifier::concepts::has_resize<jsonifier_internal::unwrap_t<value_type>> &&
458-
jsonifier::concepts::has_emplace_back<jsonifier_internal::unwrap_t<value_type>> && jsonifier::concepts::vector_subscriptable<jsonifier_internal::unwrap_t<value_type>> &&
458+
concept array_t = jsonifier::concepts::has_range<value_type> && jsonifier::concepts::has_resize<std::remove_cvref_t<value_type>> &&
459+
jsonifier::concepts::has_emplace_back<std::remove_cvref_t<value_type>> && jsonifier::concepts::vector_subscriptable<std::remove_cvref_t<value_type>> &&
459460
requires(value_type&& data) { typename value_type::value_type; };
460461

461462
/// @brief Concept for object (associative container) types excluding etf_serializer.
462463
template<typename value_type>
463464
concept object_t = requires(value_type data) {
464465
typename value_type::mapped_type;
465466
typename value_type::key_type;
466-
} && jsonifier::concepts::range<value_type>;
467+
} && jsonifier::concepts::has_range<value_type>;
467468

468469
class etf_serializer {
469470
public:
@@ -609,19 +610,19 @@ namespace discord_core_api {
609610
*this = str;
610611
}
611612

612-
template<jsonifier::concepts::float_type value_type> DCA_INLINE etf_serializer& operator=(value_type&& data) {
613+
template<jsonifier::concepts::float_t value_type> DCA_INLINE etf_serializer& operator=(value_type&& data) {
613614
setValue<json_type::float_t>(std::forward<value_type>(data));
614615
return *this;
615616
}
616617

617-
template<jsonifier::concepts::float_type value_type> DCA_INLINE etf_serializer(value_type&& data) {
618+
template<jsonifier::concepts::float_t value_type> DCA_INLINE etf_serializer(value_type&& data) {
618619
*this = std::forward<value_type>(data);
619620
}
620621

621622
template<jsonifier::concepts::integer_t value_type> DCA_INLINE etf_serializer& operator=(value_type&& data) {
622-
if constexpr (jsonifier::concepts::signed_type<value_type>) {
623+
if constexpr (jsonifier::concepts::signed_t<value_type>) {
623624
setValue<json_type::int_t>(std::forward<value_type>(data));
624-
} else if constexpr (jsonifier::concepts::unsigned_type<value_type>) {
625+
} else if constexpr (jsonifier::concepts::unsigned_t<value_type>) {
625626
setValue<json_type::uint_t>(std::forward<value_type>(data));
626627
}
627628
return *this;

0 commit comments

Comments
 (0)