Skip to content

Commit 2f5ad40

Browse files
committed
DiscordCoreAPI Release v2.0.1
-Modified the connection behavior of the VoiceConnection class. -Added support for the Discord "custom bot status"es. -Modified the getCached(x) functions to retrieve from the HTTPS endpoints when the object is absent from the cache. -Replaced all of std::string with jsonifier::string, std::string_view with jsonifier::string_view. -Added a ToEntity interface for collecting data-structures from their Snowflake ids. -Modified the CMakeLists.txt files. -Also modified calls to stoull et al. -Removed a bunch of superfluous concepts. -Refactored the KeyHasher and KeyAccessor classes. -Modified the VoiceConnection class to better avoid unnecessary calls to getUserAsync. -Switched from using strings to using string_views in the Https client classes. -Fixed an issue with a moved-from object. -Updated the caching behaviors of the EventManager class.
1 parent ee84cdb commit 2f5ad40

File tree

164 files changed

+14937
-5219
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

164 files changed

+14937
-5219
lines changed

.github/workflows/CLANG_18-Ubuntu.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
- uses: actions/checkout@v3
2222

2323
- name: Install the latest Clang compiler.
24-
working-directory: Tests
24+
working-directory: ./
2525
run: |
2626
wget https://apt.llvm.org/llvm.sh
2727
chmod +x llvm.sh
@@ -38,35 +38,24 @@ jobs:
3838
git pull
3939
vcpkg update
4040
41-
- name: Copy the Jsonifier repo over.
42-
run: |
43-
sudo git clone https://github.com/RealTimeChris/Jsonifier
44-
sudo cp -r -v ./Jsonifier/Vcpkg/* /usr/local/share/vcpkg/
45-
4641
- name: Install the dependencies.
4742
run: |
48-
vcpkg install jsonifier:x64-linux
4943
vcpkg install opus:x64-linux
5044
vcpkg install libsodium:x64-linux
5145
vcpkg install openssl:x64-linux
5246
5347
- name: Configure CMake
54-
working-directory: Tests
48+
working-directory: ./
5549
run: |
56-
cmake -S . -B ./Build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=/usr/bin/clang++-18 -DGITHUB_BRANCH_TYPE=${{github.ref}}
50+
cmake -S . -B ./Build -DCMAKE_CXX_COMPILER=/usr/bin/clang++-18 -DDEV=true -DDISCORDCOREAPI_TEST=true -DVCPKG_ROOT_DIR=/usr/local/share/vcpkg
5751
5852
- name: Build the Test
59-
working-directory: Tests/Build
53+
working-directory: ./Build
6054
run: |
6155
cmake --build . --config=${{matrix.build_type}}
6256
63-
- name: Install the Test
64-
working-directory: Tests/Build
65-
run: |
66-
cmake --install ./ --config=${{matrix.build_type}}
67-
6857
- name: Run the Test
69-
working-directory: Tests/Install/${{matrix.build_type}}
58+
working-directory: ./Build/Tests
7059
run: |
7160
chmod u+x ./DiscordCoreAPITest
7261
./DiscordCoreAPITest

.github/workflows/GCC_13-MacOS.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,24 @@ jobs:
2424
run: |
2525
brew install gcc
2626
27-
- name: Copy the Jsonifier repo over.
28-
run: |
29-
sudo git clone https://github.com/RealTimeChris/Jsonifier
30-
sudo cp -r -v ./Jsonifier/Vcpkg/* /usr/local/share/vcpkg/
31-
3227
- name: Install the dependencies.
3328
run: |
34-
vcpkg install jsonifier:x64-osx
3529
vcpkg install opus:x64-osx
3630
vcpkg install libsodium:x64-osx
3731
vcpkg install openssl:x64-osx
3832
3933
- name: Configure CMake
40-
working-directory: Tests
34+
working-directory: ./
4135
run: |
42-
cmake -S . -B ./Build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DCMAKE_CXX_COMPILER=/usr/local/opt/gcc@13/bin/g++-13 -DGITHUB_BRANCH_TYPE=${{github.ref}}
36+
cmake -S . -B ./Build -DCMAKE_CXX_COMPILER=/usr/local/opt/gcc@13/bin/g++-13 -DDEV=true -DDISCORDCOREAPI_TEST=true -DVCPKG_ROOT_DIR=/usr/local/share/vcpkg
4337
4438
- name: Build the Test
45-
working-directory: Tests/Build
39+
working-directory: ./Build
4640
run: |
4741
cmake --build . --config=${{matrix.build_type}}
4842
49-
- name: Install the Test
50-
working-directory: Tests/Build
51-
run: |
52-
cmake --install ./ --config=${{matrix.build_type}}
53-
5443
- name: Run the Test
55-
working-directory: Tests/Install/${{matrix.build_type}}
44+
working-directory: ./Build/Tests
5645
run: |
5746
chmod u+x ./DiscordCoreAPITest
5847
./DiscordCoreAPITest

.github/workflows/MSVC_2022-Windows.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,24 @@ jobs:
2828
git pull
2929
vcpkg update
3030
31-
- name: Copy the Jsonifier repo over.
32-
run: |
33-
git clone https://github.com/RealTimeChris/Jsonifier
34-
Copy-Item -Path ./Jsonifier/Vcpkg/* -Destination C:/Vcpkg/ -Recurse -Force
35-
3631
- name: Install the dependencies.
3732
run: |
38-
vcpkg install jsonifier:x64-windows
3933
vcpkg install opus:x64-windows
4034
vcpkg install libsodium:x64-windows
4135
vcpkg install openssl:x64-windows
4236
4337
- name: Configure CMake
44-
working-directory: Tests
38+
working-directory: ./
4539
run: |
46-
cmake -S . -B ./Build -DCMAKE_BUILD_TYPE=${{matrix.build_type}} -DGITHUB_BRANCH_TYPE=${{github.ref}}
40+
cmake -S . -B ./Build -DDEV=true -DDISCORDCOREAPI_TEST=true -DVCPKG_ROOT_DIR=C:/vcpkg
4741
4842
- name: Build the Test
49-
working-directory: Tests/Build
43+
working-directory: ./Build
5044
run: |
5145
cmake --build . --config=${{matrix.build_type}}
5246
53-
- name: Install the Test
54-
working-directory: Tests/Build
55-
run: |
56-
cmake --install ./ --config=${{matrix.build_type}}
57-
5847
- name: Run the Test
59-
working-directory: Tests/Install/${{matrix.build_type}}
48+
working-directory: ./Install/${{matrix.build_type}}
6049
run: |
6150
./DiscordCoreAPITest.exe
6251
continue-on-error: true

BuildTools/Classes/Packager/Vcpkg.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,16 @@ function constructPortAndVersionFile(string $sha512 = "0"): string
160160
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin")
161161
endif()
162162
163-
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/License.md")';
163+
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/License.md")
164+
';
164165

165166
$versionFileContent = '{
166167
"name": "discordcoreapi",
167168
"version": ' . json_encode($this->getVersion()) . ',
168169
"description": "A Discord bot library written in C++ using custom asynchronous coroutines.",
169170
"homepage": "https://discordcoreapi.com",
170171
"license": "MIT",
171-
"supports": "(windows & x64 & !xbox) | (linux & x64)",
172+
"supports": "(windows & x64 & !xbox) | (linux & x64) | (osx & x64)",
172173
"dependencies": [
173174
"jsonifier",
174175
"libsodium",

CMake/CollectVersion.cmake

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,27 @@
2222
# May 13, 2021
2323
# https://discordcoreapi.com
2424

25-
function(collect_version)
25+
function(collect_version project_name)
2626

27-
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/../Vcpkg/ports/discordcoreapi/vcpkg.json" JSON_STRING)
27+
set(PRODUCT_VERSION "")
28+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/Vcpkg/ports/${project_name}/vcpkg.json" JSON_STRING)
2829
foreach(IDX RANGE 1)
2930
string(JSON PRODUCT_VERSION GET "${JSON_STRING}" "version")
3031
endforeach()
31-
set(PRODUCT_VERSION "${PRODUCT_VERSION}" PARENT_SCOPE)
3232
string(REPLACE "." ";" PRODUCT_VERSION_LIST "${PRODUCT_VERSION}")
3333
list(GET PRODUCT_VERSION_LIST 0 VERSION_MAJOR)
34+
list(APPEND PRODUCT_VERSION_NEW "${VERSION_MAJOR}")
3435
set(VERSION_MAJOR "${VERSION_MAJOR}" PARENT_SCOPE)
3536
list(GET PRODUCT_VERSION_LIST 1 VERSION_MINOR)
37+
list(APPEND PRODUCT_VERSION_NEW "${VERSION_MINOR}")
3638
set(VERSION_MINOR "${VERSION_MINOR}" PARENT_SCOPE)
39+
list(LENGTH PRODUCT_VERSION_LIST LIST_SIZE)
40+
if (LIST_SIZE GREATER 2)
41+
list(GET PRODUCT_VERSION_LIST 2 VERSION_PATCH)
42+
set(VERSION_PATCH "${VERSION_PATCH}" PARENT_SCOPE)
43+
list(APPEND PRODUCT_VERSION_NEW "${VERSION_PATCH}")
44+
endif()
45+
string(REPLACE ";" "." PRODUCT_VERSION_NEW "${PRODUCT_VERSION_NEW}")
46+
set(PRODUCT_VERSION "${PRODUCT_VERSION_NEW}" PARENT_SCOPE)
3747

3848
endfunction()

CMake/DCADetectArchitecture.cmake

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# MIT License
2+
#
3+
# Copyright (c) 2023 RealTimeChris
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
6+
# software and associated documentation files (the "Software"), to deal in the Software
7+
# without restriction, including without limitation the rights to use, copy, modify, merge,
8+
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit
9+
# persons to whom the Software is furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in all copies or
12+
# substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15+
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16+
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
17+
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18+
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19+
# DEALINGS IN THE SOFTWARE.
20+
# JsonifierDetectArchitecture.cmake - Script for detecting the CPU architecture.
21+
# Sept 18, 2023
22+
# https://discordcoreapi.com
23+
include(CheckCXXSourceRuns)
24+
25+
function(jsonifier_check_instruction_set INSTRUCTION_SET_NAME INSTRUCTION_SET_IN_FLAG INSTRUCTION_SET_OUT_FLAG INSTRUCTION_SET_INTRINSIC)
26+
set(INSTRUCTION_SET_CODE "
27+
#include <immintrin.h>
28+
#include <stdint.h>
29+
30+
int32_t main()
31+
{
32+
${INSTRUCTION_SET_INTRINSIC};
33+
return 0;
34+
}")
35+
36+
set(CMAKE_REQUIRED_FLAGS "${INSTRUCTION_SET_IN_FLAG}")
37+
set(CHECK_RESULT_VAR "${INSTRUCTION_SET_NAME}")
38+
CHECK_CXX_SOURCE_RUNS("${INSTRUCTION_SET_CODE}" "DiscordCoreAPI-${CHECK_RESULT_VAR}")
39+
if(DiscordCoreAPI-${CHECK_RESULT_VAR})
40+
set(${INSTRUCTION_SET_NAME} "${INSTRUCTION_SET_OUT_FLAG}" PARENT_SCOPE)
41+
list(APPEND JSONIFIER_CPU_INSTRUCTIONS "${INSTRUCTION_SET_NAME}")
42+
string(REPLACE ";" "," JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS}")
43+
set(JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS}" PARENT_SCOPE)
44+
else()
45+
message(STATUS "Instruction set ${INSTRUCTION_SET_NAME} not supported.")
46+
return()
47+
endif()
48+
endfunction()
49+
50+
set(INSTRUCTION_SET_NAMES "POPCNT" "LZCNT" "BMI" "AVX" "AVX2" "AVX512")
51+
set (INSTRUCTION_SET_CODE
52+
"auto result = _mm_popcnt_u64(uint64_t{})"
53+
"auto result = _lzcnt_u64(int64_t{})"
54+
"auto result = _blsr_u64(uint64_t{})"
55+
"auto result = _mm_castsi128_pd(__m128i{}).auto result02 = _mm_setzero_si128()"
56+
"auto result = _mm256_add_epi32(__m256i{}, __m256i{})"
57+
"auto result = _mm512_add_ps(__m512i{}, __m512i{}).auto result2 = _mm512_cmplt_epu8_mask(__m512i{}, __m512i{}).auto result03 = _mm_abs_epi64 (__m128i{})"
58+
)
59+
60+
set(INDEX_SET "0" "1" "2" "3" "4" "5")
61+
62+
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
63+
set(INSTRUCTION_SET_IN_FLAGS "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX2" "/arch:AVX512")
64+
set(INSTRUCTION_SET_OUT_FLAGS "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX" "/arch:AVX2" "/arch:AVX512")
65+
else()
66+
set(INSTRUCTION_SET_IN_FLAGS "-march=native" "-march=native" "-march=native" "-march=native" "-march=native" "-march=native")
67+
set(INSTRUCTION_SET_OUT_FLAGS "-mpopcnt" "-mlzcnt" "-mbmi" "-mavx.-mpclmul" "-mavx2.-mpclmul" "-mavx512f.-mavx512bw.-mavx512vl.-mpclmul")
68+
endif()
69+
70+
set(CMAKE_REQUIRED_FLAGS_SAVE "${CMAKE_REQUIRED_FLAGS}")
71+
72+
if ((${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "i386") OR (${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64"))
73+
74+
foreach(CURRENT_INDEX IN LISTS INDEX_SET)
75+
list(GET INSTRUCTION_SET_NAMES "${CURRENT_INDEX}" INSTRUCTION_SET_NAME)
76+
list(GET INSTRUCTION_SET_CODE "${CURRENT_INDEX}" INSTRUCTION_SET_INTRINSIC)
77+
list(GET INSTRUCTION_SET_IN_FLAGS "${CURRENT_INDEX}" INSTRUCTION_SET_IN_FLAG)
78+
list(GET INSTRUCTION_SET_OUT_FLAGS "${CURRENT_INDEX}" INSTRUCTION_SET_OUT_FLAG)
79+
string(REPLACE "." ";" INSTRUCTION_SET_OUT_FLAG "${INSTRUCTION_SET_OUT_FLAG}")
80+
string(REPLACE "." ";" INSTRUCTION_SET_INTRINSIC "${INSTRUCTION_SET_INTRINSIC}")
81+
jsonifier_check_instruction_set("${INSTRUCTION_SET_NAME}" "${INSTRUCTION_SET_IN_FLAG}" "${INSTRUCTION_SET_OUT_FLAG}" "${INSTRUCTION_SET_INTRINSIC}")
82+
endforeach()
83+
84+
message(STATUS "Detected CPU Architecture: ${JSONIFIER_CPU_INSTRUCTIONS}")
85+
else()
86+
message(STATUS "SSE not supported by architecture ${CMAKE_SYSTEM_PROCESSOR}")
87+
endif()
88+
89+
set(AVX_FLAG)
90+
set(JSONIFIER_CPU_INSTRUCTIONS 0)
91+
92+
if (NOT "${POPCNT}" STREQUAL "")
93+
list(APPEND AVX_FLAG "${POPCNT}")
94+
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 0" OUTPUT_FORMAT DECIMAL)
95+
endif()
96+
if (NOT "${LZCNT}" STREQUAL "")
97+
list(APPEND AVX_FLAG "${LZCNT}")
98+
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 1" OUTPUT_FORMAT DECIMAL)
99+
endif()
100+
if (NOT "${BMI}" STREQUAL "")
101+
list(APPEND AVX_FLAG "${BMI}")
102+
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 2" OUTPUT_FORMAT DECIMAL)
103+
endif()
104+
if (NOT "${AVX512}" STREQUAL "")
105+
list(APPEND AVX_FLAG "${AVX512}")
106+
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 5" OUTPUT_FORMAT DECIMAL)
107+
elseif (NOT "${AVX2}" STREQUAL "")
108+
list(APPEND AVX_FLAG "${AVX2}")
109+
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 4" OUTPUT_FORMAT DECIMAL)
110+
elseif (NOT "${AVX}" STREQUAL "")
111+
list(APPEND AVX_FLAG "${AVX}")
112+
math(EXPR JSONIFIER_CPU_INSTRUCTIONS "${JSONIFIER_CPU_INSTRUCTIONS} | 1 << 3" OUTPUT_FORMAT DECIMAL)
113+
endif()
114+
115+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS_SAVE}")

CMake/DetectArchitecture.cmake

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)