From 0d3f5f7a8dcaa0cb3cbb2b72e8bfb580f3e5591d Mon Sep 17 00:00:00 2001 From: RealTimeChris <40668522+RealTimeChris@users.noreply.github.com> Date: Sun, 13 Oct 2024 21:59:00 -0400 Subject: [PATCH] DiscordCoreAPI Release 2.0.8 * Updated to keep in track with Jsonifier dependency. * Removed the compile-time CPU architecture script. --- .github/workflows/MSVC-Windows-Binaries.yml | 14 +- .github/workflows/MSVC-Windows.yml | 2 +- CMake/BuildFeatureTester.bat | 2 - CMake/BuildFeatureTester.sh | 3 - CMake/CMakeLists.txt | 5 - CMake/DCADetectArchitecture.cmake | 115 --- CMake/RCa06928 | Bin 0 -> 2490 bytes CMake/main.cpp | 184 ---- Documentation/Doxygen/Docs/Index.md | 18 +- .../documentation_examples/music_bot/PlayQ.md | 2 +- Include/discordcoreapi/FoundationEntities.hpp | 34 +- .../discordcoreapi/JsonSpecializations.hpp | 36 +- Include/discordcoreapi/Utilities.hpp | 45 +- Include/discordcoreapi/Utilities/Base.hpp | 94 +-- Include/discordcoreapi/Utilities/Config.hpp | 161 ++++ Include/discordcoreapi/Utilities/Etf.hpp | 410 +++------ Include/discordcoreapi/Utilities/ISA/AVX.hpp | 2 +- Include/discordcoreapi/Utilities/ISA/AVX2.hpp | 4 +- .../discordcoreapi/Utilities/ISA/AVX512.hpp | 4 +- .../discordcoreapi/Utilities/ISA/Fallback.hpp | 2 +- .../Utilities/ISA/ISADetectionBase.hpp | 62 ++ Include/discordcoreapi/Utilities/ISA/Neon.hpp | 2 +- .../discordcoreapi/Utilities/RingBuffer.hpp | 30 +- .../Utilities/UnboundedMessageBlock.hpp | 4 +- .../discordcoreapi/Utilities/UnorderedSet.hpp | 4 +- .../Utilities/WebSocketClient.hpp | 4 +- Library/CMake/BuildFeatureTester.bat | 2 - Library/CMakeLists.txt | 18 +- ReadMe.md | 16 +- Source/EventManager.cpp | 120 +-- Source/FoundationEntities.cpp | 8 +- Source/SoundCloudAPI.cpp | 83 +- Source/VoiceConnection.cpp | 12 +- Source/WebSocketClient.cpp | 788 +++++++++--------- Source/YouTubeAPI.cpp | 4 +- Tests/main.cpp | 2 + Vcpkg/ports/discordcoreapi/portfile.cmake | 17 +- Vcpkg/ports/discordcoreapi/vcpkg.json | 2 +- Vcpkg/versions/d-/discordcoreapi.json | 10 + 39 files changed, 1021 insertions(+), 1304 deletions(-) delete mode 100644 CMake/BuildFeatureTester.bat delete mode 100644 CMake/BuildFeatureTester.sh delete mode 100644 CMake/CMakeLists.txt delete mode 100644 CMake/DCADetectArchitecture.cmake create mode 100644 CMake/RCa06928 delete mode 100644 CMake/main.cpp create mode 100644 Include/discordcoreapi/Utilities/Config.hpp create mode 100644 Include/discordcoreapi/Utilities/ISA/ISADetectionBase.hpp delete mode 100644 Library/CMake/BuildFeatureTester.bat diff --git a/.github/workflows/MSVC-Windows-Binaries.yml b/.github/workflows/MSVC-Windows-Binaries.yml index 295de2300..8fc7e3b03 100644 --- a/.github/workflows/MSVC-Windows-Binaries.yml +++ b/.github/workflows/MSVC-Windows-Binaries.yml @@ -46,16 +46,10 @@ jobs: cmake --build . --config=${{matrix.build_type}} - name: Install the Test - working-directory: ./Build/Tests + working-directory: ./Build/ run: | cmake --install ./ --config=${{matrix.build_type}} - - name: Run the Test - working-directory: ./Tests/Install/${{matrix.build_type}} - run: | - ./DiscordCoreAPITest.exe - continue-on-error: true - - name: Clone DiscordCoreAPI-Binaries repository run: | git clone https://github.com/RealTimeChris/DiscordCoreAPI-Binaries.git ./DiscordCoreAPI-Binaries @@ -65,12 +59,14 @@ jobs: - name: Copy build artifacts to DiscordCoreAPI-Binaries run: | - cp -r ./Tests/Install/${{matrix.build_type}}/* ./DiscordCoreAPI-Binaries/${{matrix.build_type}} + 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.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 diff --git a/.github/workflows/MSVC-Windows.yml b/.github/workflows/MSVC-Windows.yml index 6393f58b6..961bb1667 100644 --- a/.github/workflows/MSVC-Windows.yml +++ b/.github/workflows/MSVC-Windows.yml @@ -72,5 +72,5 @@ jobs: 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 diff --git a/CMake/BuildFeatureTester.bat b/CMake/BuildFeatureTester.bat deleted file mode 100644 index 62c7a1dd1..000000000 --- a/CMake/BuildFeatureTester.bat +++ /dev/null @@ -1,2 +0,0 @@ -"C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" -S ./ -B ./Build -DCMAKE_BUILD_TYPE=Release -"C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" --build ./Build --config=Release \ No newline at end of file diff --git a/CMake/BuildFeatureTester.sh b/CMake/BuildFeatureTester.sh deleted file mode 100644 index 4cd8e7aed..000000000 --- a/CMake/BuildFeatureTester.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -cmake -S ./ -B ./Build -DCMAKE_BUILD_TYPE=Release -cmake --build ./Build --config=Release diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt deleted file mode 100644 index a1565c512..000000000 --- a/CMake/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -cmake_minimum_required(VERSION 3.10) -project(FeatureDetection) -set(CMAKE_CXX_STANDARD 17) -# Add your source file(s) -add_executable(feature_detector main.cpp) diff --git a/CMake/DCADetectArchitecture.cmake b/CMake/DCADetectArchitecture.cmake deleted file mode 100644 index 56ee6304e..000000000 --- a/CMake/DCADetectArchitecture.cmake +++ /dev/null @@ -1,115 +0,0 @@ -# JsonifierDetectArchitecture.cmake - Script for detecting the CPU architecture. -# MIT License -# Copyright (c) 2023 RealTimeChris -# https://discordcoreapi.com - -if (UNIX OR APPLE) - file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/BuildFeatureTester.sh" "#!/bin/bash -\"${CMAKE_COMMAND}\" -S ./ -B ./Build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -\"${CMAKE_COMMAND}\" --build ./Build --config=Release") - execute_process( - COMMAND chmod +x "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/BuildFeatureTester.sh" - RESULT_VARIABLE CHMOD_RESULT - ) - if(NOT ${CHMOD_RESULT} EQUAL 0) - message(FATAL_ERROR "Failed to set executable permissions for BuildFeatureTester.sh") - endif() - execute_process( - COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/BuildFeatureTester.sh" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../CMake" - ) - set(FEATURE_TESTER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/Build/feature_detector") -elseif(WIN32) - file(WRITE "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/BuildFeatureTester.bat" "\"${CMAKE_COMMAND}\" -S ./ -B ./Build -DCMAKE_BUILD_TYPE=Release -\"${CMAKE_COMMAND}\" --build ./Build --config=Release") - execute_process( - COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/BuildFeatureTester.bat" - WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../CMake" - ) - set(FEATURE_TESTER_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/Build/Release/feature_detector.exe") -endif() - -execute_process( - COMMAND "${FEATURE_TESTER_FILE}" - RESULT_VARIABLE DCA_CPU_INSTRUCTIONS_NEW -) - -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) - -function(check_instruction_set INSTRUCTION_SET_NAME INSTRUCTION_SET_FLAG INSTRUCTION_SET_NUMERIC_VALUE) - math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & ${INSTRUCTION_SET_NUMERIC_VALUE} )") - if(INSTRUCTION_PRESENT) - message(STATUS "Instruction Set Found: ${INSTRUCTION_SET_NAME}") - math(EXPR DCA_CPU_INSTRUCTIONS "( ${DCA_CPU_INSTRUCTIONS} | ${INSTRUCTION_SET_NUMERIC_VALUE} )") - set(AVX_FLAG "${AVX_FLAG};${INSTRUCTION_SET_FLAG}" PARENT_SCOPE) - endif() -endfunction() - -math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x1 )") -if(INSTRUCTION_PRESENT) - math(EXPR DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS} | 1 << 0" OUTPUT_FORMAT DECIMAL) -endif() -math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x2 )") -if(INSTRUCTION_PRESENT) - math(EXPR DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS} | 1 << 1" OUTPUT_FORMAT DECIMAL) -endif() -math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x4 )") -if(INSTRUCTION_PRESENT) - math(EXPR DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS} | 1 << 2" OUTPUT_FORMAT DECIMAL) -endif() -math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x8 )") -if(INSTRUCTION_PRESENT) - math(EXPR DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS} | 1 << 3" OUTPUT_FORMAT DECIMAL) -endif() - -math(EXPR INSTRUCTION_PRESENT "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x10 )") -if(INSTRUCTION_PRESENT) - math(EXPR DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS} | 1 << 4" OUTPUT_FORMAT DECIMAL) -endif() -math(EXPR INSTRUCTION_PRESENT128 "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x20 )") -math(EXPR INSTRUCTION_PRESENT256 "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x40 )") -math(EXPR INSTRUCTION_PRESENT512 "( ${DCA_CPU_INSTRUCTIONS_NUMERIC} & 0x80 )") -if(INSTRUCTION_PRESENT512) - math(EXPR DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS} | 1 << 7" OUTPUT_FORMAT DECIMAL) -elseif(INSTRUCTION_PRESENT256) - math(EXPR DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS} | 1 << 6" OUTPUT_FORMAT DECIMAL) -elseif(INSTRUCTION_PRESENT128) - math(EXPR DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS} | 1 << 5" OUTPUT_FORMAT DECIMAL) -endif() - -if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - check_instruction_set("LzCnt" "" 0x1) - check_instruction_set("PopCnt" "" 0x2) - check_instruction_set("Bmi" "" 0x4) - check_instruction_set("Bmi2" "" 0x8) - check_instruction_set("Neon" "" 0x10) - check_instruction_set("Avx" "/arch:AVX" 0x20) - check_instruction_set("Avx2" "/arch:AVX2" 0x40) - check_instruction_set("Avx512" "/arch:AVX512" 0x80) -else() - check_instruction_set("LzCnt" "-mlzcnt" 0x1) - check_instruction_set("PopCnt" "-mpopcnt" 0x2) - check_instruction_set("Bmi" "-mbmi" 0x4) - check_instruction_set("Bmi2" "-mbmi2" 0x8) - check_instruction_set("Neon" "" 0x10) - check_instruction_set("Avx" "-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x20) - check_instruction_set("Avx2" "-mavx2;-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x40) - check_instruction_set("Avx512" "-mavx512f;-mavx2;-mavx;-mlzcnt;-mpopcnt;-mbmi;-mbmi2" 0x80) -endif() -endif() -set(AVX_FLAG "${AVX_FLAG}" CACHE STRING "AVX flags" FORCE) -set(DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS}" CACHE STRING "CPU Instruction Sets" FORCE) diff --git a/CMake/RCa06928 b/CMake/RCa06928 new file mode 100644 index 0000000000000000000000000000000000000000..f85794e0c74e95a7877d7f3302465d32b94a7c32 GIT binary patch literal 2490 zcmb7`|7+S%6vgk)gZ&S|!f0XZ>{`k?Mq$15k+E%u;qLyy3KYpL{l9)Ub zvyD*mzTA86dFS5y(jEJ5GrPB`1$JN+tJypI!qc}UYYTogtJxjnSv*_XgFP}IW1-yz z?>TFcZQa?8nJ;XDr`}WhU|qY2vD!AWZ?W%yx1!9jySFQ5S@eDO#;|&B&uqtI8m)-= znDs{@=>!$?@h;fE0eK((d6dH#cZN;i5N={ECd`LCZ8%?A(>~j=9l4dje)DYZ9@-nX zD^{<00zAb{p0Di5dB5~l6aM+gyAJ6Njh2l36YhcWf+vb!Y_n_ci6}qmzI10lwY~LO zeZ`7wBW_c4RShIeH~mJa_S1{8%`(eI`BXMeW85h`C$PO)&(o-hl0C9oGwJu)oohly zpWqf)&+7JRE5mHuvY6QpICf|)>Q#B~^KRNXk&=}mHQFa`kIImZSoK&r%UIO$Xt3L7 zEsWV^W4v{11N?@Z>>Na)bwC@sdTTHaHg;5pT9?KRtXlZ_zQKAuk9vi55AQy)YK(=_ zW!yo(J}Y4k%isMs#DrJFY0)HN8x?wFD6lHEa!8h2u^!ucPTHNpsp*|GMU0RR);QTJ z&Bu?ds~PKTwI%i)I7XI7v1PIo+BG^U|KguSO?IQa`!-3eGrXEEo6=g<(LrY^Q6buj zzEOwXlCv3oHpMc!siIq|%)1Jgs-5t6WMBC$@))3d3l+s&clv|<;8Cxw=$neG+RY5t zVA$q4r_w?=igyvtoSW(1eql9om}O{P*CW@|^(7-==TQ>{>h880J7wnZjJ^oP=t%~K z)UPVLMlD~EsgPgw(e^0*_aQ=0(fp25uls#7Bv#039$)!eae@W!5g9F4N8KEPedTm% zmFm+1_10l3k8_k)?c8#Qu1YhRYOl<8sbp!?w2ws2^Y6r{s!H)svZ9$Pr#KIt7*pp_ z#SPbY(Dr)a`Wbo2-Q+HG6_ literal 0 HcmV?d00001 diff --git a/CMake/main.cpp b/CMake/main.cpp deleted file mode 100644 index 1943a5f86..000000000 --- a/CMake/main.cpp +++ /dev/null @@ -1,184 +0,0 @@ -#include -#include -#include -#include - -#if defined(_MSC_VER) - #include -#elif defined(HAVE_GCC_GET_CPUID) && defined(USE_GCC_GET_CPUID) - #include -#endif - -enum instruction_set { - DEFAULT = 0x0, - LZCNT = 0x1, - POPCNT = 0x2, - BMI1 = 0x4, - BMI2 = 0x8, - NEON = 0x10, - AVX = 0x20, - AVX2 = 0x40, - AVX512F = 0x80, -}; - -namespace { - constexpr uint32_t cpuidAvx2Bit = 1ul << 5; - constexpr uint32_t cpuidBmi1Bit = 1ul << 3; - constexpr uint32_t cpuidBmi2Bit = 1ul << 8; - constexpr uint32_t cpuidAvx512Bit = 1ul << 16; - constexpr uint64_t cpuidAvx256Saved = 1ull << 2; - constexpr uint64_t cpuidAvx512Saved = 7ull << 5; - constexpr uint32_t cpuidOsxSave = (1ul << 26) | (1ul << 27); - constexpr uint32_t cpuidLzcntBit = 1ul << 5; - constexpr uint32_t cpuidPopcntBit = 1ul << 23; -} - -#if defined(__x86_64__) || defined(_M_AMD64) -static inline void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx); -inline static uint64_t xgetbv(); -#endif - -static void getCPUBrandString(char* brand) { -#if defined(__x86_64__) || defined(_M_AMD64) - uint32_t regs[12]; - regs[0] = 0x80000000; - cpuid(regs, regs + 1, regs + 2, regs + 3); - if (regs[0] < 0x80000004) - return; - regs[0] = 0x80000002; - cpuid(regs, regs + 1, regs + 2, regs + 3); - regs[4] = 0x80000003; - cpuid(regs + 4, regs + 5, regs + 6, regs + 7); - regs[8] = 0x80000004; - cpuid(regs + 8, regs + 9, regs + 10, regs + 11); - - memcpy(brand, regs, sizeof(regs)); -#endif -} - -void printCPUInfo(uint32_t supportedISA) { -#if defined(__x86_64__) || defined(_M_AMD64) - char brand[49] = { 0 }; - getCPUBrandString(brand); - std::cout << "CPU Brand: " << brand << "\n"; -#endif -} - -#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) - -inline static uint32_t detectSupportedArchitectures() { - return instruction_set::NEON; -} - -#elif defined(__x86_64__) || defined(_M_AMD64) - -static inline void cpuid(uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) { - #if defined(_MSC_VER) - int32_t cpuInfo[4]; - __cpuidex(cpuInfo, *eax, *ecx); - *eax = cpuInfo[0]; - *ebx = cpuInfo[1]; - *ecx = cpuInfo[2]; - *edx = cpuInfo[3]; - #elif defined(HAVE_GCC_GET_CPUID) && defined(USE_GCC_GET_CPUID) - uint32_t level = *eax; - __get_cpuid(level, eax, ebx, ecx, edx); - #else - uint32_t a = *eax, b, c = *ecx, d; - asm volatile("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "a"(a), "c"(c)); - *eax = a; - *ebx = b; - *ecx = c; - *edx = d; - #endif -} - -inline static uint64_t xgetbv() { - #if defined(_MSC_VER) - return _xgetbv(0); - #else - uint32_t eax, edx; - asm volatile("xgetbv" : "=a"(eax), "=d"(edx) : "c"(0)); - return (( uint64_t )edx << 32) | eax; - #endif -} - -inline static uint32_t detectSupportedArchitectures() { - std::uint32_t eax = 0; - std::uint32_t ebx = 0; - std::uint32_t ecx = 0; - std::uint32_t edx = 0; - std::uint32_t hostIsa = 0x0; - - eax = 0x1; - ecx = 0x0; - cpuid(&eax, &ebx, &ecx, &edx); - - if (ecx & cpuidLzcntBit) { - hostIsa |= instruction_set::LZCNT; - } - - if (ecx & cpuidPopcntBit) { - hostIsa |= instruction_set::POPCNT; - } - - if ((ecx & cpuidOsxSave) != cpuidOsxSave) { - return hostIsa; - } - - uint64_t xcr0 = xgetbv(); - - if ((xcr0 & cpuidAvx256Saved) == 0) { - return hostIsa; - } - - if (ecx & cpuidAvx256Saved) { - hostIsa |= instruction_set::AVX; - } - - eax = 0x7; - ecx = 0x0; - cpuid(&eax, &ebx, &ecx, &edx); - - if (ebx & cpuidAvx2Bit) { - hostIsa |= instruction_set::AVX2; - } - - if (ebx & cpuidBmi1Bit) { - hostIsa |= instruction_set::BMI1; - } - - if (ebx & cpuidBmi2Bit) { - hostIsa |= instruction_set::BMI2; - } - - if (!((xcr0 & cpuidAvx512Saved) == cpuidAvx512Saved)) { - return hostIsa; - } - - if (ebx & cpuidAvx512Bit) { - hostIsa |= instruction_set::AVX512F; - } - - return hostIsa; -} - -#elif defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) - -inline static uint32_t detectSupportedArchitectures() { - return instruction_set::NEON; -} - -#else - -inline static uint32_t detectSupportedArchitectures() { - return instruction_set::DEFAULT; -} - -#endif - -int32_t main() { - const auto supportedISA = detectSupportedArchitectures(); - printCPUInfo(supportedISA); - return supportedISA; -} \ No newline at end of file diff --git a/Documentation/Doxygen/Docs/Index.md b/Documentation/Doxygen/Docs/Index.md index aa5ed0c5f..ca840302c 100644 --- a/Documentation/Doxygen/Docs/Index.md +++ b/Documentation/Doxygen/Docs/Index.md @@ -1,8 +1,8 @@ \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. @@ -10,20 +10,20 @@ Hello, and welcome to DiscordCoreAPI! This is a Discord bot library, written in ![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) diff --git a/Documentation/Doxygen/Docs/documentation_examples/music_bot/PlayQ.md b/Documentation/Doxygen/Docs/documentation_examples/music_bot/PlayQ.md index a1e31462e..b1c4dc562 100644 --- a/Documentation/Doxygen/Docs/documentation_examples/music_bot/PlayQ.md +++ b/Documentation/Doxygen/Docs/documentation_examples/music_bot/PlayQ.md @@ -162,7 +162,7 @@ namespace discord_core_api { if (trackNumber >= song_api::getPlaylist(guild_data.id).songQueue.size()) { unique_ptr newEmbed{ makeUnique() }; newEmbed->setAuthor(newEvent.getUserName(), newEvent.getAvatarUrl()); - newEmbed->setDescription("------\n__**sorry, but that number is out of the range of the current track list!**__\n------"); + newEmbed->setDescription("------\n__**sorry, but that number is out of the has_range of the current track list!**__\n------"); newEmbed->setTimeStamp(getTimeAndDate()); newEmbed->setTitle("__**playing issue:**__"); newEmbed->setColor(discordGuild.data.borderColor); diff --git a/Include/discordcoreapi/FoundationEntities.hpp b/Include/discordcoreapi/FoundationEntities.hpp index ce54f4108..0f4304785 100644 --- a/Include/discordcoreapi/FoundationEntities.hpp +++ b/Include/discordcoreapi/FoundationEntities.hpp @@ -30,6 +30,7 @@ #pragma once #include +#include namespace discord_core_api { @@ -321,23 +322,27 @@ namespace discord_core_api { }; struct websocket_message { - jsonifier::string t{}; + std::optional t{}; + std::optional s{}; int64_t op{ -1 }; - int64_t s{}; }; template struct websocket_message_data { unordered_set jsonifierExcludedKeys{}; - jsonifier::string t{}; + std::optional t{}; + std::optional 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; } @@ -407,18 +412,20 @@ namespace discord_core_api { template class flag_entity { public: - template DCA_INLINE auto setFlagValue(value_type02 theFlagToSet, bool enabled) { - auto newValue = static_cast(static_cast(this)->flags); + template DCA_INLINE void setFlagValue(flag_type theFlagToSet, bool enabled) { + using underlying_type = std::underlying_type_t; + auto newValue = static_cast(static_cast(this)->flags); if (enabled) { - newValue |= static_cast(theFlagToSet); + newValue |= static_cast(theFlagToSet); } else { - newValue &= ~static_cast(theFlagToSet); + newValue &= ~static_cast(theFlagToSet); } - static_cast(this)->flags = static_cast(newValue); + static_cast(this)->flags = static_cast(newValue); } - template DCA_INLINE bool getFlagValue(value_type02 theFlagToCheckFor) const { - return static_cast(static_cast(this)->flags) & static_cast(theFlagToCheckFor); + template DCA_INLINE bool getFlagValue(flag_type theFlagToCheckFor) const { + using underlying_type = std::underlying_type_t; + return static_cast(static_cast(this)->flags) & static_cast(theFlagToCheckFor); } protected: @@ -426,6 +433,7 @@ namespace discord_core_api { DCA_INLINE ~flag_entity() = default; }; + enum class user_image_types { Banner = 0, Default_Avatar = 1, diff --git a/Include/discordcoreapi/JsonSpecializations.hpp b/Include/discordcoreapi/JsonSpecializations.hpp index d68bb5950..fcc782b53 100644 --- a/Include/discordcoreapi/JsonSpecializations.hpp +++ b/Include/discordcoreapi/JsonSpecializations.hpp @@ -41,8 +41,8 @@ namespace discord_core_api { websocket_message_data(const update_voice_state_data& data); unordered_set jsonifierExcludedKeys{}; using type = update_voice_state_data; + std::optional t{}; int64_t op{ -1 }; - jsonifier::string t{}; int32_t s{}; type d{}; operator etf_serializer(); @@ -53,8 +53,8 @@ namespace discord_core_api { websocket_message_data(const update_voice_state_data& data); unordered_set jsonifierExcludedKeys{}; using type = update_voice_state_data_dc; + std::optional t{}; int64_t op{ -1 }; - jsonifier::string t{}; int32_t s{}; type d{}; operator etf_serializer(); @@ -65,48 +65,48 @@ namespace discord_core_api { namespace jsonifier_internal { template - concept snowflake_t = std::same_as>; + concept snowflake_t = std::same_as>; - template - struct serialize_impl { - template JSONIFIER_ALWAYS_INLINE static void impl(value_type_new&& value, buffer_type& buffer, serialize_context_type& serializePair) noexcept { + template + struct serialize_impl { + template DCA_ALWAYS_INLINE static void impl(value_type_new&& value, buffer_type& buffer, index_type&index, indent_type& indent) noexcept { jsonifier::string newString{ static_cast(value) }; - serialize::impl(newString, buffer, serializePair); + serialize::impl(newString, buffer, index, indent); } }; template struct parse_impl { - JSONIFIER_ALWAYS_INLINE static void impl(value_type& value, parse_context_type& context) noexcept { + DCA_ALWAYS_INLINE static void impl(value_type& value, parse_context_type& context) noexcept { jsonifier::raw_json_data newString{}; parse::impl(newString, context); if (newString.getType() == jsonifier::json_type::String) { - value = newString.operator jsonifier::string(); + value = newString.get(); } else { - value = newString.operator uint64_t(); + value = newString.get(); } } }; template - concept time_stamp_t = std::same_as>; + concept time_stamp_t = std::same_as>; - template - struct serialize_impl { - template JSONIFIER_ALWAYS_INLINE static void impl(value_type_new&& value, buffer_type& buffer, serialize_context_type& serializePair) noexcept { + template + struct serialize_impl { + template DCA_ALWAYS_INLINE static void impl(value_type_new&& value, buffer_type& buffer, index_type& index, indent_type& indent) noexcept { jsonifier::string newString{ static_cast(value) }; - serialize::impl(newString, buffer, serializePair); + serialize::impl(newString, buffer, index, indent); } }; template struct parse_impl { - JSONIFIER_ALWAYS_INLINE static void impl(value_type& value, parse_context_type& context) noexcept { + DCA_ALWAYS_INLINE static void impl(value_type& value, parse_context_type& context) noexcept { jsonifier::raw_json_data newString{}; parse::impl(newString, context); if (newString.getType() == jsonifier::json_type::String) { - value = newString.operator jsonifier::string(); + value = newString.get(); } else { - value = newString.operator uint64_t(); + value = newString.get(); } } }; diff --git a/Include/discordcoreapi/Utilities.hpp b/Include/discordcoreapi/Utilities.hpp index f969e0a9d..b86a52a9a 100644 --- a/Include/discordcoreapi/Utilities.hpp +++ b/Include/discordcoreapi/Utilities.hpp @@ -164,27 +164,29 @@ namespace discord_core_api { /// @brief Gateway intents. enum class gateway_intents : uint32_t { - guilds = 1 << 0,///< Intent for receipt of guild information. - Guild_Members = 1 << 1,///< Intent for receipt of guild members. - Guild_Bans = 1 << 2,///< Intent for receipt of guild bans. - Guild_Emojis = 1 << 3,///< Intent for receipt of guild emojis. - Guild_Integrations = 1 << 4,///< Intent for receipt of guild integrations. - Guild_Webhooks = 1 << 5,///< Intent for receipt of guild webhooks. - Guild_Invites = 1 << 6,///< Intent for receipt of guild invites. - Guild_VoiceStates = 1 << 7,///< Intent for receipt of guild voice states. - Guild_Presences = 1 << 8,///< Intent for receipt of guild presences. - Guild_Messages = 1 << 9,///< Intent for receipt of guild messages. - Guild_Message_Reactions = 1 << 10,///< Intent for receipt of guild message reactions. - Guild_Message_Typing = 1 << 11,///< Intent for receipt of guild message typing notifications. - Direct_Messages = 1 << 12,///< Intent for receipt of direct messages (dms). - Direct_Message_Reactions = 1 << 13,///< Intent for receipt of direct message reactions. - Direct_Message_Typing = 1 << 14,///< Intent for receipt of direct message typing notifications. - Message_Content = 1 << 15,///< Intent for receipt of message content. - Guild_Scheduled_Events = 1 << 16,///< Scheduled events. - Auto_Moderation_Configuration = 1 << 20,/// auto moderation configuration. - Auto_Moderation_Execution = 1 << 21,///< Auto moderation execution. - Default_Intents = guilds | Guild_Bans | Guild_Emojis | Guild_Integrations | Guild_Webhooks | Guild_Invites | Guild_VoiceStates | Guild_Messages | Guild_Message_Reactions | - Guild_Message_Typing | Direct_Messages | Direct_Message_Reactions | Direct_Message_Typing | Guild_Scheduled_Events | Auto_Moderation_Configuration | + Guilds = 1 << 0, + Guild_Members = 1 << 1, + Guild_Moderation = 1 << 2, + Guild_Expressions = 1 << 3, + Guild_Integrations = 1 << 4, + Guild_Webhooks = 1 << 5, + Guild_Invites = 1 << 6, + Guild_Voice_States = 1 << 7, + Guild_Presences = 1 << 8, + Guild_Messages = 1 << 9, + Guild_Message_Reactions = 1 << 10, + Guild_Message_Typing = 1 << 11, + Direct_Messages = 1 << 12, + Direct_Message_Reactions = 1 << 13, + Direct_Message_Typing = 1 << 14, + Message_Content = 1 << 15, + Guild_Scheduled_Events = 1 << 16, + Auto_Moderation_Configuration = 1 << 20, + Auto_Moderation_Execution = 1 << 21, + Guild_Message_Polls = 1 << 24, + Direct_Message_Polls = 1 << 25,///< Auto moderation execution. + Default_Intents = Guilds | Guild_Integrations | Guild_Webhooks | Guild_Invites | Guild_Voice_States | Guild_Messages | Guild_Message_Reactions | Guild_Message_Typing | + Direct_Messages | Direct_Message_Reactions | Direct_Message_Typing | Guild_Scheduled_Events | Auto_Moderation_Configuration | Auto_Moderation_Execution,///< Default intents (all non-privileged intents). Privileged_Intents = Guild_Members | Guild_Presences | Message_Content,///< Privileged intents requiring id. All_Intents = Default_Intents | Privileged_Intents///< Every single intent. @@ -534,7 +536,6 @@ namespace discord_core_api { /// @brief Permissions_base class, for representing and manipulating permission values. template class permissions_base { public: - /// @brief Returns a string containing all of a given user's permissions_base for a given channel. /// @param guildMember the guild_member_data who's permissions_base to analyze. /// @param channel the channel_data withint which to check for permissions_base. diff --git a/Include/discordcoreapi/Utilities/Base.hpp b/Include/discordcoreapi/Utilities/Base.hpp index 42d15ce1d..35cba56ff 100644 --- a/Include/discordcoreapi/Utilities/Base.hpp +++ b/Include/discordcoreapi/Utilities/Base.hpp @@ -29,99 +29,7 @@ /// \file Base.hpp #pragma once -#if !defined(__GNUC__) - #pragma warning(disable : 4710) - #pragma warning(disable : 4711) - #pragma warning(disable : 4251) - #pragma warning(disable : 4371) - #pragma warning(disable : 4514) - #pragma warning(disable : 4623) - #pragma warning(disable : 4625) - #pragma warning(disable : 4626) - #pragma warning(disable : 4820) - #pragma warning(disable : 5267) - #pragma warning(disable : 5026) - #pragma warning(disable : 5027) - #pragma warning(disable : 5045) - #pragma warning(disable : 5246) -#endif - -#if defined(__clang__) && defined(NDEBUG) && !defined(DCA_INLINE) - #define DCA_INLINE inline __attribute__((always_inline)) -#elif !defined(DCA_INLINE) - #define DCA_INLINE inline -#endif - -#if !defined(DCA_CPU_INSTRUCTIONS) - #define DCA_CPU_INSTRUCTIONS 0 -#endif - -#if !defined(DCA_CHECK_FOR_INSTRUCTION) - #define DCA_CHECK_FOR_INSTRUCTION(x) (DCA_CPU_INSTRUCTIONS & x) -#endif - -#if !defined(DCA_CHECK_FOR_AVX) - #define DCA_CHECK_FOR_AVX(x) (DCA_CPU_INSTRUCTIONS >= x) -#endif - -#if !defined(DCA_NEON) - #define DCA_NEON (1 << 4) -#endif -#if !defined(DCA_AVX) - #define DCA_AVX (1 << 5) -#endif -#if !defined(DCA_AVX2) - #define DCA_AVX2 (1 << 6) -#endif -#if !defined(DCA_AVX512) - #define DCA_AVX512 (1 << 7) -#endif - -#if defined _WIN32 - #if !defined DiscordCoreAPI_EXPORTS_NOPE - #if defined DiscordCoreAPI_EXPORTS - #if !defined DiscordCoreAPI_Dll - #define DiscordCoreAPI_Dll __declspec(dllexport) - #endif - #else - #if !defined DiscordCoreAPI_Dll - #define DiscordCoreAPI_Dll __declspec(dllimport) - #endif - #endif - #else - #define DiscordCoreAPI_Dll - #endif - #if !defined WIN32_LEAN_AND_MEAN - #define WIN32_LEAN_AND_MEAN - #endif - #if !defined WINRT_LEAN_AND_MEAN - #define WINRT_LEAN_AND_MEAN - #endif - #if !defined(NOMINMAX) - #define NOMINMAX - #endif - #include -DCA_INLINE tm getTime(time_t time) { - tm timeNew{}; - gmtime_s(&timeNew, &time); - return timeNew; -} - #include -#else - #if !defined DiscordCoreAPI_Dll - #define DiscordCoreAPI_Dll - #endif - #include - #include - #include - #include - #include - #include - #include -DCA_INLINE tm getTime(time_t time) { - return *gmtime(&time); -} -#endif +#include #include diff --git a/Include/discordcoreapi/Utilities/Config.hpp b/Include/discordcoreapi/Utilities/Config.hpp new file mode 100644 index 000000000..c014d53ab --- /dev/null +++ b/Include/discordcoreapi/Utilities/Config.hpp @@ -0,0 +1,161 @@ +/* + MIT License + + DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines. + + Copyright 2022, 2023 Chris M. (RealTimeChris) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +/// Config.hpp - Header for the some of the base definitions and includes. +/// Nov 8, 2021 +/// https://discordcoreapi.com +/// \file Base.hpp +#pragma once + +#if !defined(__GNUC__) + #pragma warning(disable : 4710) + #pragma warning(disable : 4711) + #pragma warning(disable : 4251) + #pragma warning(disable : 4371) + #pragma warning(disable : 4514) + #pragma warning(disable : 4623) + #pragma warning(disable : 4625) + #pragma warning(disable : 4626) + #pragma warning(disable : 4820) + #pragma warning(disable : 5267) + #pragma warning(disable : 5026) + #pragma warning(disable : 5027) + #pragma warning(disable : 5045) + #pragma warning(disable : 5246) +#endif + +#if defined(__clang__) || (defined(__GNUC__) && defined(__llvm__)) + #define DCA_CLANG 1 +#elif defined(_MSC_VER) + #pragma warning(disable : 4820) + #pragma warning(disable : 4371) + #pragma warning(disable : 4324) + #define DCA_MSVC 1 +#elif defined(__GNUC__) && !defined(__clang__) + #define DCA_GNUCXX 1 +#endif + +#if defined(DCA_MSVC) + #define DCA_VISUAL_STUDIO 1 + #if defined(DCA_CLANG) + #define DCA_CLANG_VISUAL_STUDIO 1 + #else + #define DCA_REGULAR_VISUAL_STUDIO 1 + #endif +#endif + +#define DCA_GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__) + +#if defined(macintosh) || defined(Macintosh) || (defined(__APPLE__) && defined(__MACH__)) || defined(TARGET_OS_MAC) + #define DCA_MAC 1 +#elif defined(linux) || defined(__linux) || defined(__linux__) || defined(__gnu_linux__) + #define DCA_LINUX 1 +#elif defined(WIN32) || defined(_WIN32) || defined(_WIN64) + #define DCA_WIN 1 +#else + #error "Undetected platform." +#endif + +#if defined(__cpp_inline_variables) && __cpp_inline_variables >= 201606L + #define DCA_HAS_INLINE_VARIABLE 1 +#elif __cplusplus >= 201703L + #define DCA_HAS_INLINE_VARIABLE 1 +#elif defined(DCA_MSVC) && DCA_MSVC >= 1912 && _MSVC_LANG >= 201703L + #define DCA_HAS_INLINE_VARIABLE 1 +#else + #define DCA_HAS_INLINE_VARIABLE 0 +#endif + +#if DCA_HAS_INLINE_VARIABLE + #define DCA_ALWAYS_INLINE_VARIABLE inline constexpr +#else + #define DCA_ALWAYS_INLINE_VARIABLE static constexpr +#endif + +#if defined(NDEBUG) + #if defined(DCA_MSVC) + #define DCA_ALWAYS_INLINE [[msvc::forceinline]] inline + #define DCA_CLANG_ALWAYS_INLINE inline + #define DCA_INLINE inline + #elif defined(DCA_CLANG) + #define DCA_ALWAYS_INLINE inline __attribute__((always_inline)) + #define DCA_CLANG_ALWAYS_INLINE inline __attribute__((always_inline)) + #define DCA_INLINE inline + #elif defined(DCA_GNUCXX) + #define DCA_ALWAYS_INLINE inline __attribute__((always_inline)) + #define DCA_CLANG_ALWAYS_INLINE inline + #define DCA_INLINE inline + #endif +#else + #define DCA_ALWAYS_INLINE inline + #define DCA_CLANG_ALWAYS_INLINE inline + #define DCA_INLINE inline +#endif + +#if defined _WIN32 + #if !defined DiscordCoreAPI_EXPORTS_NOPE + #if defined DiscordCoreAPI_EXPORTS + #if !defined DiscordCoreAPI_Dll + #define DiscordCoreAPI_Dll __declspec(dllexport) + #endif + #else + #if !defined DiscordCoreAPI_Dll + #define DiscordCoreAPI_Dll __declspec(dllimport) + #endif + #endif + #else + #define DiscordCoreAPI_Dll + #endif + #if !defined WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif + #if !defined WINRT_LEAN_AND_MEAN + #define WINRT_LEAN_AND_MEAN + #endif + #if !defined(NOMINMAX) + #define NOMINMAX + #endif + #include +DCA_INLINE tm getTime(time_t time) { + tm timeNew{}; + gmtime_s(&timeNew, &time); + return timeNew; +} + #include +#else + #if !defined DiscordCoreAPI_Dll + #define DiscordCoreAPI_Dll + #endif + #include + #include + #include + #include + #include + #include + #include +DCA_INLINE tm getTime(time_t time) { + return *gmtime(&time); +} +#endif diff --git a/Include/discordcoreapi/Utilities/Etf.hpp b/Include/discordcoreapi/Utilities/Etf.hpp index 6540805e1..b723d1be5 100644 --- a/Include/discordcoreapi/Utilities/Etf.hpp +++ b/Include/discordcoreapi/Utilities/Etf.hpp @@ -446,7 +446,8 @@ namespace discord_core_api { /// @brief Constructor for etf_serialize_error. /// @param message the error message. /// @param location source location where the error occurred. - DCA_INLINE etf_serialize_error(const jsonifier::string_view& message, std::source_location location = std::source_location::current()) : dca_exception{ message, location } {}; + DCA_INLINE etf_serialize_error(const jsonifier::string_view& message, std::source_location location = std::source_location::current()) + : dca_exception{ message, location } {}; }; /// @brief Enumeration for different json value types. @@ -454,8 +455,8 @@ namespace discord_core_api { /// @brief Concept for array types excluding etf_serializer. template - concept array_t = jsonifier::concepts::range && jsonifier::concepts::has_resize> && - jsonifier::concepts::has_emplace_back> && jsonifier::concepts::vector_subscriptable> && + concept array_t = jsonifier::concepts::has_range && jsonifier::concepts::has_resize> && + jsonifier::concepts::has_emplace_back> && jsonifier::concepts::vector_subscriptable> && requires(value_type&& data) { typename value_type::value_type; }; /// @brief Concept for object (associative container) types excluding etf_serializer. @@ -463,7 +464,7 @@ namespace discord_core_api { concept object_t = requires(value_type data) { typename value_type::mapped_type; typename value_type::key_type; - } && jsonifier::concepts::range; + } && jsonifier::concepts::has_range; class etf_serializer { public: @@ -476,53 +477,13 @@ namespace discord_core_api { using int_type = int64_t; using bool_type = bool; - DCA_INLINE etf_serializer() = default; + DCA_INLINE etf_serializer(){ + value = std::nullptr_t{}; + }; DCA_INLINE etf_serializer& operator=(etf_serializer&& data) noexcept { - destroy(); - stringReal = std::move(data.stringReal); - type = data.type; - data.type = json_type::null_t; - switch (type) { - case json_type::object_t: { - objectValue = data.objectValue; - data.objectValue = nullptr; - break; - } - case json_type::array_t: { - arrayValue = data.arrayValue; - data.arrayValue = nullptr; - break; - } - case json_type::string_t: { - stringValue = data.stringValue; - data.stringValue = nullptr; - break; - } - case json_type::float_t: { - floatValue = data.floatValue; - data.floatValue = nullptr; - break; - } - case json_type::int_t: { - intValue = data.intValue; - data.intValue = nullptr; - break; - } - case json_type::uint_t: { - uintValue = data.uintValue; - data.uintValue = nullptr; - break; - } - case json_type::bool_t: { - boolValue = data.boolValue; - data.boolValue = nullptr; - break; - } - case json_type::null_t: { - break; - } - } + stringReal.swap(data.stringReal); + value.swap(data.value); return *this; } @@ -531,40 +492,7 @@ namespace discord_core_api { } DCA_INLINE etf_serializer& operator=(const etf_serializer& data) { - destroy(); - switch (data.type) { - case json_type::object_t: { - setValue(data.getObject()); - break; - } - case json_type::array_t: { - setValue(data.getArray()); - break; - } - case json_type::string_t: { - setValue(data.getString()); - break; - } - case json_type::float_t: { - setValue(data.getFloat()); - break; - } - case json_type::uint_t: { - setValue(data.getUint()); - break; - } - case json_type::int_t: { - setValue(data.getInt()); - break; - } - case json_type::bool_t: { - setValue(data.getBool()); - break; - } - case json_type::null_t: { - break; - } - } + value = data.value; stringReal = data.stringReal; return *this; } @@ -574,7 +502,7 @@ namespace discord_core_api { } template DCA_INLINE etf_serializer& operator=(value_type&& data) noexcept { - setValue(std::forward(data)); + value = std::forward(data); return *this; } @@ -583,7 +511,7 @@ namespace discord_core_api { } template DCA_INLINE etf_serializer& operator=(value_type&& data) noexcept { - setValue(std::forward(data)); + value = std::forward(data); return *this; } @@ -592,7 +520,7 @@ namespace discord_core_api { } template DCA_INLINE etf_serializer& operator=(value_type&& data) noexcept { - setValue(std::forward(data)); + value = std::forward(data); return *this; } @@ -601,7 +529,7 @@ namespace discord_core_api { } template DCA_INLINE etf_serializer& operator=(const char (&str)[str_length]) { - setValue(str); + value = str; return *this; } @@ -609,20 +537,20 @@ namespace discord_core_api { *this = str; } - template DCA_INLINE etf_serializer& operator=(value_type&& data) { - setValue(std::forward(data)); + template DCA_INLINE etf_serializer& operator=(value_type&& data) { + value = std::forward(data); return *this; } - template DCA_INLINE etf_serializer(value_type&& data) { + template DCA_INLINE etf_serializer(value_type&& data) { *this = std::forward(data); } template DCA_INLINE etf_serializer& operator=(value_type&& data) { - if constexpr (jsonifier::concepts::signed_type) { - setValue(std::forward(data)); - } else if constexpr (jsonifier::concepts::unsigned_type) { - setValue(std::forward(data)); + if constexpr (jsonifier::concepts::signed_t) { + value = static_cast(std::forward(data)); + } else if constexpr (jsonifier::concepts::unsigned_t) { + value = static_cast(std::forward(data)); } return *this; } @@ -632,7 +560,7 @@ namespace discord_core_api { } template DCA_INLINE etf_serializer& operator=(value_type&& data) { - setValue(std::forward(data)); + value = std::forward(data); return *this; } @@ -641,7 +569,7 @@ namespace discord_core_api { } template DCA_INLINE etf_serializer& operator=(value_type&& data) noexcept { - setValue(static_cast(std::forward(data))); + value = static_cast(std::forward(data)); return *this; } @@ -650,38 +578,37 @@ namespace discord_core_api { } DCA_INLINE etf_serializer& operator=(json_type data) { - destroy(); switch (data) { case json_type::object_t: { - setValue(); + value = object_type{}; break; } case json_type::array_t: { - setValue(); + value = array_type{}; break; } case json_type::string_t: { - setValue(); + value = string_type{}; break; } case json_type::float_t: { - setValue(); + value = float_type{}; break; } case json_type::uint_t: { - setValue(); + value = uint_type{}; break; } case json_type::int_t: { - setValue(); + value = int_type{}; break; } case json_type::bool_t: { - setValue(); + value = bool_type{}; break; } case json_type::null_t: { - setValue(); + value = nullptr_t{}; break; } } @@ -693,7 +620,23 @@ namespace discord_core_api { } DCA_INLINE json_type getType() const { - return type; + if (std::holds_alternative(value)) { + return json_type::object_t; + } else if (std::holds_alternative(value)) { + return json_type::array_t; + } else if (std::holds_alternative(value)) { + return json_type::string_t; + } else if (std::holds_alternative(value)) { + return json_type::float_t; + } else if (std::holds_alternative(value)) { + return json_type::uint_t; + } else if (std::holds_alternative(value)) { + return json_type::int_t; + } else if (std::holds_alternative(value)) { + return json_type::bool_t; + } else { + return json_type::null_t; + } } DCA_INLINE operator jsonifier::string_base() { @@ -704,22 +647,22 @@ namespace discord_core_api { } DCA_INLINE etf_serializer& operator[](typename object_type::key_type&& key) { - if (type == json_type::null_t) { - setValue(); + if (getType() == json_type::null_t) { + value = object_type{}; } - if (type == json_type::object_t) { + if (getType() == json_type::object_t) { return getObject().operator[](std::forward(key)); } throw etf_serialize_error{ "Sorry, but this value's type is not object." }; } DCA_INLINE etf_serializer& operator[](uint_type index) { - if (type == json_type::null_t) { - setValue(); + if (getType() == json_type::null_t) { + value = array_type{}; } - if (type == json_type::array_t) { + if (getType() == json_type::array_t) { if (index >= getArray().size()) { getArray().resize(index + 1); } @@ -730,11 +673,11 @@ namespace discord_core_api { } DCA_INLINE void emplaceBack(etf_serializer&& data) { - if (type == json_type::null_t) { - setValue(); + if (getType() == json_type::null_t) { + value = array_type{}; } - if (type == json_type::array_t) { + if (getType() == json_type::array_t) { getArray().emplace_back(std::move(data)); return; } @@ -742,11 +685,11 @@ namespace discord_core_api { } DCA_INLINE void emplaceBack(const etf_serializer& rhs) { - if (type == json_type::null_t) { - setValue(); + if (getType() == json_type::null_t) { + value = array_type{}; } - if (type == json_type::array_t) { + if (getType() == json_type::array_t) { getArray().emplace_back(rhs); return; } @@ -754,106 +697,118 @@ namespace discord_core_api { } DCA_INLINE bool_type operator==(const etf_serializer& rhs) const { - if (rhs.type != type) { + if (rhs.getType() != getType()) { return false; } - switch (type) { - case json_type::object_t: { - return *objectValue == *rhs.objectValue; - } - case json_type::array_t: { - return *arrayValue == *rhs.arrayValue; - } - case json_type::string_t: { - return *stringValue == *rhs.stringValue; - } - case json_type::float_t: { - return *floatValue == *rhs.floatValue; - } - case json_type::uint_t: { - return *uintValue == *rhs.uintValue; - } - case json_type::int_t: { - return *intValue == *rhs.intValue; - } - case json_type::bool_t: { - return *boolValue == *rhs.boolValue; - } - case json_type::null_t: { - break; - } - } - return true; + return value == rhs.value; } - DCA_INLINE object_type& getObject() const { - if (type != json_type::object_t) { + DCA_INLINE object_type& getObject() { + if (getType() != json_type::object_t) { throw etf_serialize_error{ "Sorry, but this value's type is not object!" }; } - return *objectValue; + return std::get(value); } - DCA_INLINE array_type& getArray() const { - if (type != json_type::array_t) { + DCA_INLINE array_type& getArray() { + if (getType() != json_type::array_t) { throw etf_serialize_error{ "Sorry, but this value's type is not array!" }; } - return *arrayValue; + return std::get(value); } - DCA_INLINE string_type& getString() const { - if (type != json_type::string_t) { + DCA_INLINE string_type& getString() { + if (getType() != json_type::string_t) { throw etf_serialize_error{ "Sorry, but this value's type is not string!" }; } - return *stringValue; + return std::get(value); } - DCA_INLINE float_type& getFloat() const { - if (type != json_type::float_t) { + DCA_INLINE float_type& getFloat() { + if (getType() != json_type::float_t) { throw etf_serialize_error{ "Sorry, but this value's type is not float!" }; } - return *floatValue; + return std::get(value); } - DCA_INLINE uint_type& getUint() const { - if (type != json_type::uint_t) { + DCA_INLINE uint_type& getUint() { + if (getType() != json_type::uint_t) { throw etf_serialize_error{ "Sorry, but this value's type is not uint!" }; } - return *uintValue; + return std::get(value); } - DCA_INLINE int_type& getInt() const { - if (type != json_type::int_t) { + DCA_INLINE int_type& getInt() { + if (getType() != json_type::int_t) { throw etf_serialize_error{ "Sorry, but this value's type is not int!" }; } - return *intValue; + return std::get(value); } - DCA_INLINE bool_type& getBool() const { - if (type != json_type::bool_t) { + DCA_INLINE bool_type& getBool() { + if (getType() != json_type::bool_t) { throw etf_serialize_error{ "Sorry, but this value's type is not bool!" }; } - return *boolValue; + return std::get(value); } - DCA_INLINE ~etf_serializer() { - destroy(); + DCA_INLINE const object_type& getObject() const { + if (getType() != json_type::object_t) { + throw etf_serialize_error{ "Sorry, but this value's type is not object!" }; + } + return std::get(value); } + DCA_INLINE const array_type& getArray() const { + if (getType() != json_type::array_t) { + throw etf_serialize_error{ "Sorry, but this value's type is not array!" }; + } + return std::get(value); + } + + DCA_INLINE const string_type& getString() const { + if (getType() != json_type::string_t) { + throw etf_serialize_error{ "Sorry, but this value's type is not string!" }; + } + return std::get(value); + } + + DCA_INLINE const float_type& getFloat() const { + if (getType() != json_type::float_t) { + throw etf_serialize_error{ "Sorry, but this value's type is not float!" }; + } + return std::get(value); + } + + DCA_INLINE const uint_type& getUint() const { + if (getType() != json_type::uint_t) { + throw etf_serialize_error{ "Sorry, but this value's type is not uint!" }; + } + return std::get(value); + } + + DCA_INLINE const int_type& getInt() const { + if (getType() != json_type::int_t) { + throw etf_serialize_error{ "Sorry, but this value's type is not int!" }; + } + return std::get(value); + } + + DCA_INLINE const bool_type& getBool() const { + if (getType() != json_type::bool_t) { + throw etf_serialize_error{ "Sorry, but this value's type is not bool!" }; + } + return std::get(value); + } + + DCA_INLINE ~etf_serializer() = default; + protected: jsonifier::string_base stringReal{}; - json_type type{ json_type::null_t }; - union { - object_type* objectValue; - array_type* arrayValue; - string_type* stringValue; - float_type* floatValue; - uint_type* uintValue; - int_type* intValue; - bool_type* boolValue; - }; + std::variant value{}; DCA_INLINE void serializeJsonToEtfString(const etf_serializer& dataToParse) { - switch (dataToParse.type) { + switch (dataToParse.getType()) { case json_type::object_t: { return writeEtfObject(dataToParse.getObject()); } @@ -1043,101 +998,6 @@ namespace discord_core_api { uint8_t newBuffer[5]{ static_cast(etf_type::Small_Atom_Ext), static_cast(3), 'n', 'i', 'l' }; writeString(newBuffer, std::size(newBuffer)); } - - template DCA_INLINE void setValue(value_types&&... args) { - destroy(); - type = typeNew; - if constexpr (typeNew == json_type::object_t) { - allocator alloc{}; - objectValue = alloc.allocate(1); - alloc.construct(objectValue, std::forward(args)...); - } else if constexpr (typeNew == json_type::array_t) { - allocator alloc{}; - arrayValue = alloc.allocate(1); - alloc.construct(arrayValue, std::forward(args)...); - } else if constexpr (typeNew == json_type::string_t) { - allocator alloc{}; - stringValue = alloc.allocate(1); - alloc.construct(stringValue, std::forward(args)...); - } else if constexpr (typeNew == json_type::float_t) { - allocator alloc{}; - floatValue = alloc.allocate(1); - alloc.construct(floatValue, std::forward(args)...); - } else if constexpr (typeNew == json_type::uint_t) { - allocator alloc{}; - uintValue = alloc.allocate(1); - alloc.construct(uintValue, std::forward(args)...); - } else if constexpr (typeNew == json_type::int_t) { - allocator alloc{}; - intValue = alloc.allocate(1); - alloc.construct(intValue, std::forward(args)...); - } else if constexpr (typeNew == json_type::bool_t) { - allocator alloc{}; - boolValue = alloc.allocate(1); - alloc.construct(boolValue, std::forward(args)...); - } - } - - DCA_INLINE void destroy() { - switch (type) { - case json_type::object_t: { - allocator alloc{}; - alloc.destroy(objectValue); - alloc.deallocate(static_cast(objectValue)); - objectValue = nullptr; - break; - } - case json_type::array_t: { - allocator alloc{}; - alloc.destroy(arrayValue); - alloc.deallocate(static_cast(arrayValue)); - arrayValue = nullptr; - break; - } - case json_type::string_t: { - allocator alloc{}; - alloc.destroy(stringValue); - alloc.deallocate(static_cast(stringValue)); - stringValue = nullptr; - break; - } - case json_type::float_t: { - allocator alloc{}; - alloc.destroy(floatValue); - alloc.deallocate(static_cast(floatValue)); - floatValue = nullptr; - break; - } - case json_type::uint_t: { - allocator alloc{}; - alloc.destroy(uintValue); - alloc.deallocate(static_cast(uintValue)); - uintValue = nullptr; - break; - } - case json_type::int_t: { - allocator alloc{}; - alloc.destroy(intValue); - alloc.deallocate(static_cast(intValue)); - intValue = nullptr; - break; - } - case json_type::bool_t: { - allocator alloc{}; - alloc.destroy(boolValue); - alloc.deallocate(static_cast(boolValue)); - boolValue = nullptr; - break; - } - case json_type::null_t: { - break; - } - default: { - break; - } - } - type = json_type::null_t; - } }; /**@}*/ diff --git a/Include/discordcoreapi/Utilities/ISA/AVX.hpp b/Include/discordcoreapi/Utilities/ISA/AVX.hpp index 0fccf4187..22b5c0d77 100644 --- a/Include/discordcoreapi/Utilities/ISA/AVX.hpp +++ b/Include/discordcoreapi/Utilities/ISA/AVX.hpp @@ -29,7 +29,7 @@ /// \file AVX.hpp #pragma once -#include +#include #if DCA_CHECK_FOR_INSTRUCTION(DCA_AVX) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX2) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512) diff --git a/Include/discordcoreapi/Utilities/ISA/AVX2.hpp b/Include/discordcoreapi/Utilities/ISA/AVX2.hpp index 24a68dd96..dc30319d0 100644 --- a/Include/discordcoreapi/Utilities/ISA/AVX2.hpp +++ b/Include/discordcoreapi/Utilities/ISA/AVX2.hpp @@ -29,9 +29,9 @@ /// \file AVX2.hpp #pragma once -#include +#include -#if DCA_CHECK_FOR_INSTRUCTION(DCA_AVX2) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512) +#if DCA_CHECK_FOR_INSTRUCTION(DCA_AVX2) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512) #include #include diff --git a/Include/discordcoreapi/Utilities/ISA/AVX512.hpp b/Include/discordcoreapi/Utilities/ISA/AVX512.hpp index 487bce979..d5203a732 100644 --- a/Include/discordcoreapi/Utilities/ISA/AVX512.hpp +++ b/Include/discordcoreapi/Utilities/ISA/AVX512.hpp @@ -30,9 +30,9 @@ /// #pragma once -#include +#include -#if DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX) && !DCA_CHECK_FOR_INSTRUCTION(DCA_AVX2) +#if DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512) #include #include diff --git a/Include/discordcoreapi/Utilities/ISA/Fallback.hpp b/Include/discordcoreapi/Utilities/ISA/Fallback.hpp index 73113acb8..09b8f6638 100644 --- a/Include/discordcoreapi/Utilities/ISA/Fallback.hpp +++ b/Include/discordcoreapi/Utilities/ISA/Fallback.hpp @@ -29,7 +29,7 @@ /// \file Fallback.hpp #pragma once -#include +#include #if (!DCA_CHECK_FOR_INSTRUCTION(DCA_AVX)) && (!DCA_CHECK_FOR_INSTRUCTION(DCA_AVX2)) && (!DCA_CHECK_FOR_INSTRUCTION(DCA_AVX512)) diff --git a/Include/discordcoreapi/Utilities/ISA/ISADetectionBase.hpp b/Include/discordcoreapi/Utilities/ISA/ISADetectionBase.hpp new file mode 100644 index 000000000..04b201ed9 --- /dev/null +++ b/Include/discordcoreapi/Utilities/ISA/ISADetectionBase.hpp @@ -0,0 +1,62 @@ +/* + MIT License + + DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines. + + Copyright 2022, 2023 Chris M. (RealTimeChris) + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +/// Isadetection.hpp - Header for the detection of the AVX instruction set. +/// Nov 8, 2021 +/// https://discordcoreapi.com +/// \file ISADetection.hpp +#pragma once + +#include + +#if !defined(DCA_CHECK_FOR_INSTRUCTION) + #define DCA_CHECK_FOR_INSTRUCTION(x) (DCA_CPU_INSTRUCTIONS & x) +#endif + +#if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC) + #define DCA_NEON 1 << 4 +#else + #define DCA_NEON 0 +#endif +#if defined(__AVX__) + #define DCA_AVX 1 << 5 +#else + #define DCA_AVX 0 +#endif +#if defined(__AVX2__) + #define DCA_AVX2 1 << 6 +#else + #define DCA_AVX2 0 +#endif +#if defined(__AVX512__) + #define DCA_AVX512 1 << 7 +#else + #define DCA_AVX512 0 +#endif + +#if !defined(DCA_CPU_INSTRUCTIONS) + #define DCA_CPU_INSTRUCTIONS (DCA_NEON | DCA_AVX | DCA_AVX2 | DCA_AVX512) +#endif + diff --git a/Include/discordcoreapi/Utilities/ISA/Neon.hpp b/Include/discordcoreapi/Utilities/ISA/Neon.hpp index 34004bed1..7966ad57d 100644 --- a/Include/discordcoreapi/Utilities/ISA/Neon.hpp +++ b/Include/discordcoreapi/Utilities/ISA/Neon.hpp @@ -29,7 +29,7 @@ /// \file AVX.hpp #pragma once -#include +#include #if DCA_CHECK_FOR_INSTRUCTION(DCA_NEON) diff --git a/Include/discordcoreapi/Utilities/RingBuffer.hpp b/Include/discordcoreapi/Utilities/RingBuffer.hpp index a7134eba6..90de1f4bd 100644 --- a/Include/discordcoreapi/Utilities/RingBuffer.hpp +++ b/Include/discordcoreapi/Utilities/RingBuffer.hpp @@ -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 friend class ring_buffer; @@ -125,7 +125,7 @@ namespace discord_core_api { } protected: - jsonifier::vector> arrayValue{};///< The underlying data array. + jsonifier::vector> arrayValue{};///< The underlying data array. size_type tail{};///< The tail position in the buffer. size_type head{};///< The head position in the buffer. }; @@ -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 class ring_buffer - : public ring_buffer_interface, 1024 * 16>, slice_count> { + : public ring_buffer_interface, 1024 * 16>, slice_count> { public: - using base_type = ring_buffer_interface, 1024 * 16>, slice_count>; - using value_type = typename ring_buffer_interface, 1024 * 16>::value_type; + using base_type = ring_buffer_interface, 1024 * 16>, slice_count>; + using value_type = typename ring_buffer_interface, 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; @@ -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> readData() { - jsonifier::string_view_base> returnData{}; + DCA_INLINE jsonifier::string_view_base> readData() { + jsonifier::string_view_base> returnData{}; if (base_type::getCurrentTail()->getUsedSpace() > 0) { - returnData = jsonifier::string_view_base>{ base_type::getCurrentTail()->getCurrentTail(), - base_type::getCurrentTail()->getUsedSpace() }; + returnData = + jsonifier::string_view_base>{ base_type::getCurrentTail()->getCurrentTail(), base_type::getCurrentTail()->getUsedSpace() }; base_type::getCurrentTail()->clear(); base_type::modifyReadOrWritePosition(ring_buffer_access_type::read, 1); } diff --git a/Include/discordcoreapi/Utilities/UnboundedMessageBlock.hpp b/Include/discordcoreapi/Utilities/UnboundedMessageBlock.hpp index d938b6670..c4c2029ca 100644 --- a/Include/discordcoreapi/Utilities/UnboundedMessageBlock.hpp +++ b/Include/discordcoreapi/Utilities/UnboundedMessageBlock.hpp @@ -34,7 +34,7 @@ namespace discord_core_api { template - concept copyable_or_movable = std::copyable> || std::movable>; + concept copyable_or_movable = std::copyable> || std::movable>; /// @brief A thread-safe messaging block for data-structures. /// @tparam value_type the type of object that will be sent over the message block. @@ -87,7 +87,7 @@ namespace discord_core_api { std::mutex accessMutex{}; }; - template DCA_INLINE bool waitForTimeToPass(unbounded_message_block>& outBuffer, value_type& argOne, uint64_t timeInMsNew) { + template DCA_INLINE bool waitForTimeToPass(unbounded_message_block>& outBuffer, value_type& argOne, uint64_t timeInMsNew) { stop_watch stopWatch{ milliseconds{ timeInMsNew } }; stopWatch.reset(); while (!outBuffer.tryReceive(argOne)) { diff --git a/Include/discordcoreapi/Utilities/UnorderedSet.hpp b/Include/discordcoreapi/Utilities/UnorderedSet.hpp index bfa465513..033e7bff2 100644 --- a/Include/discordcoreapi/Utilities/UnorderedSet.hpp +++ b/Include/discordcoreapi/Utilities/UnorderedSet.hpp @@ -36,7 +36,7 @@ namespace discord_core_api { template class unordered_set; template - concept set_container_iterator_t = std::same_as::iterator, jsonifier_internal::unwrap_t>; + concept set_container_iterator_t = std::same_as::iterator, std::remove_cvref_t>; template class unordered_set : protected hash_policy>, protected jsonifier_internal::alloc_wrapper, protected object_compare { @@ -309,7 +309,7 @@ namespace discord_core_api { } template DCA_INLINE uint64_t getKey(value_type_newer&& keyValue) const { - return key_accessor>::getHashKey(std::forward(keyValue)); + return key_accessor>::getHashKey(std::forward(keyValue)); } DCA_INLINE void resize(size_type capacityNew) { diff --git a/Include/discordcoreapi/Utilities/WebSocketClient.hpp b/Include/discordcoreapi/Utilities/WebSocketClient.hpp index 025d4a255..59f02f4a0 100644 --- a/Include/discordcoreapi/Utilities/WebSocketClient.hpp +++ b/Include/discordcoreapi/Utilities/WebSocketClient.hpp @@ -234,7 +234,7 @@ namespace discord_core_api { }; /// @brief A websocket client, for communication via a tcp-connection. - class websocket_client : public websocket_core { + class DiscordCoreAPI_Dll websocket_client : public websocket_core { public: friend struct discord_core_api::on_voice_server_update_data; friend struct discord_core_api::on_voice_state_update_data; @@ -275,7 +275,7 @@ namespace discord_core_api { snowflake userId{}; }; - class base_socket_agent { + class DiscordCoreAPI_Dll base_socket_agent { public: friend class discord_core_api::discord_core_client; friend class discord_core_api::bot_user; diff --git a/Library/CMake/BuildFeatureTester.bat b/Library/CMake/BuildFeatureTester.bat deleted file mode 100644 index 62c7a1dd1..000000000 --- a/Library/CMake/BuildFeatureTester.bat +++ /dev/null @@ -1,2 +0,0 @@ -"C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" -S ./ -B ./Build -DCMAKE_BUILD_TYPE=Release -"C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" --build ./Build --config=Release \ No newline at end of file diff --git a/Library/CMakeLists.txt b/Library/CMakeLists.txt index 7133807bb..62178daef 100644 --- a/Library/CMakeLists.txt +++ b/Library/CMakeLists.txt @@ -88,12 +88,9 @@ find_package(OpenSSL REQUIRED) find_package(Opus CONFIG REQUIRED) find_package(unofficial-sodium CONFIG REQUIRED) -if(NOT DEFINED DCA_CPU_INSTRUCTIONS) - include("DCADetectArchitecture") -endif() - -set(DCA_CPU_INSTRUCTIONS "${DCA_CPU_INSTRUCTIONS}" CACHE INTERNAL "For the CPU architecture selection.") -set(AVX_FLAG "${AVX_FLAG}" CACHE INTERNAL "For the CPU flag selection.") +set(DCA_CPU_INSTRUCTIONS + "$,${DCA_CPU_FLAGS},$,/arch:AVX512,-march=native>>" +) target_include_directories( "${LIB_NAME}" PUBLIC @@ -111,18 +108,13 @@ target_link_libraries( "$<$:Opus::opus>" ) -target_compile_definitions( - "${LIB_NAME}" PUBLIC - "$<$>:DiscordCoreAPI_EXPORTS_NOPE>" - "DCA_CPU_INSTRUCTIONS=${DCA_CPU_INSTRUCTIONS}" -) - include(ProcessorCount) ProcessorCount(N) MATH(EXPR THREAD_COUNT "${N} / 3") target_compile_options( "${LIB_NAME}" PUBLIC + "$,${DCA_CPU_INSTRUCTIONS},$,/arch:AVX512,-march=native>>" "$<$:$<$:/fsanitize=address>>" "$<$:/MP${THREAD_COUNT}>" "$<$:-fcoroutines>" @@ -135,7 +127,7 @@ target_compile_options( "$<$:/EHsc>" "$<$:-Wall>" "$<$:/Zi>" - "${AVX_FLAG}" + "${DCA_CPU_FLAGS}" ) target_link_options( diff --git a/ReadMe.md b/ReadMe.md index 0f946bc58..70c83c5ad 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -1,6 +1,6 @@ # 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-Code-Only?color=light-blue&label=Lines%20Of%20Code%20&style=plastic) @@ -11,20 +11,20 @@ Hello, and welcome to DiscordCoreAPI! This is a Discord bot library, written in alt="DiscordCoreAPI WebSite" width="500"/>

## 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 [Documentation/Examples](https://discordcoreapi.com/documentation_examples.html) # 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) diff --git a/Source/EventManager.cpp b/Source/EventManager.cpp index daf1d24cf..24e155768 100644 --- a/Source/EventManager.cpp +++ b/Source/EventManager.cpp @@ -186,7 +186,7 @@ namespace discord_core_api { template<> unordered_map*> object_collector::objectsBuffersMap; on_input_event_creation_data::on_input_event_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -196,7 +196,7 @@ namespace discord_core_api { on_application_command_permissions_update_data::on_application_command_permissions_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -205,7 +205,7 @@ namespace discord_core_api { } on_auto_moderation_rule_creation_data::on_auto_moderation_rule_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -214,7 +214,7 @@ namespace discord_core_api { } on_auto_moderation_rule_update_data::on_auto_moderation_rule_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -223,7 +223,7 @@ namespace discord_core_api { } on_auto_moderation_rule_deletion_data::on_auto_moderation_rule_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -232,7 +232,7 @@ namespace discord_core_api { } on_auto_moderation_action_execution_data::on_auto_moderation_action_execution_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -241,7 +241,7 @@ namespace discord_core_api { } on_channel_creation_data::on_channel_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -258,7 +258,7 @@ namespace discord_core_api { } on_channel_update_data::on_channel_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (channels::doWeCacheChannels()) { oldValue = channels::getCachedChannel({ .channelId = value.id }); channels::insertChannel(static_cast(value)); @@ -266,7 +266,7 @@ namespace discord_core_api { } on_channel_deletion_data::on_channel_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -287,7 +287,7 @@ namespace discord_core_api { } on_channel_pins_update_data::on_channel_pins_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -296,7 +296,7 @@ namespace discord_core_api { } on_thread_creation_data::on_thread_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -305,7 +305,7 @@ namespace discord_core_api { } on_thread_update_data::on_thread_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -314,7 +314,7 @@ namespace discord_core_api { } on_thread_deletion_data::on_thread_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -323,7 +323,7 @@ namespace discord_core_api { } on_thread_list_sync_data::on_thread_list_sync_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -332,7 +332,7 @@ namespace discord_core_api { } on_thread_member_update_data::on_thread_member_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -341,7 +341,7 @@ namespace discord_core_api { } on_thread_members_update_data::on_thread_members_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -350,7 +350,7 @@ namespace discord_core_api { } on_guild_creation_data::on_guild_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -416,7 +416,7 @@ namespace discord_core_api { } on_guild_update_data::on_guild_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (guilds::doWeCacheGuilds()) { oldValue = guilds::getCachedGuild({ value.id }); guilds::insertGuild(static_cast(value)); @@ -424,7 +424,7 @@ namespace discord_core_api { } on_guild_deletion_data::on_guild_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -445,7 +445,7 @@ namespace discord_core_api { } on_guild_ban_add_data::on_guild_ban_add_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -462,7 +462,7 @@ namespace discord_core_api { } on_guild_ban_remove_data::on_guild_ban_remove_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -471,7 +471,7 @@ namespace discord_core_api { } on_guild_emojis_update_data::on_guild_emojis_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -486,7 +486,7 @@ namespace discord_core_api { } on_guild_stickers_update_data::on_guild_stickers_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -495,7 +495,7 @@ namespace discord_core_api { } on_guild_integrations_update_data::on_guild_integrations_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -504,7 +504,7 @@ namespace discord_core_api { } on_guild_member_add_data::on_guild_member_add_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -522,7 +522,7 @@ namespace discord_core_api { } on_guild_member_remove_data::on_guild_member_remove_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -545,7 +545,7 @@ namespace discord_core_api { } on_guild_member_update_data::on_guild_member_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (guild_members::doWeCacheGuildMembers()) { oldValue = guild_members::getCachedGuildMember({ .guildMemberId = value.user.id, .guildId = value.guildId }); guild_members::insertGuildMember(static_cast(value)); @@ -553,7 +553,7 @@ namespace discord_core_api { } on_guild_members_chunk_data::on_guild_members_chunk_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -562,7 +562,7 @@ namespace discord_core_api { } on_role_creation_data::on_role_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -579,7 +579,7 @@ namespace discord_core_api { } on_role_update_data::on_role_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (roles::doWeCacheRoles()) { oldValue = roles::getCachedRole({ .guildId = value.guildId, .roleId = value.role.id }); roles::insertRole(static_cast(value.role)); @@ -587,7 +587,7 @@ namespace discord_core_api { } on_role_deletion_data::on_role_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -609,7 +609,7 @@ namespace discord_core_api { on_voice_server_update_data::on_voice_server_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse, discord_core_internal::websocket_client* sslShard) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -633,7 +633,7 @@ namespace discord_core_api { }; on_guild_scheduled_event_creation_data::on_guild_scheduled_event_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -642,7 +642,7 @@ namespace discord_core_api { } on_guild_scheduled_event_update_data::on_guild_scheduled_event_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -651,7 +651,7 @@ namespace discord_core_api { } on_guild_scheduled_event_deletion_data::on_guild_scheduled_event_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -660,7 +660,7 @@ namespace discord_core_api { } on_guild_scheduled_event_user_add_data::on_guild_scheduled_event_user_add_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -669,7 +669,7 @@ namespace discord_core_api { } on_guild_scheduled_event_user_remove_data::on_guild_scheduled_event_user_remove_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -678,7 +678,7 @@ namespace discord_core_api { } on_integration_creation_data::on_integration_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -687,7 +687,7 @@ namespace discord_core_api { } on_integration_update_data::on_integration_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -696,7 +696,7 @@ namespace discord_core_api { } on_integration_deletion_data::on_integration_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -705,7 +705,7 @@ namespace discord_core_api { } on_interaction_creation_data::on_interaction_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -789,7 +789,7 @@ namespace discord_core_api { } on_invite_creation_data::on_invite_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -798,7 +798,7 @@ namespace discord_core_api { } on_invite_deletion_data::on_invite_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -807,7 +807,7 @@ namespace discord_core_api { } on_message_creation_data::on_message_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -819,7 +819,7 @@ namespace discord_core_api { } on_message_update_data::on_message_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -831,7 +831,7 @@ namespace discord_core_api { } on_message_deletion_data::on_message_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -840,7 +840,7 @@ namespace discord_core_api { } on_message_delete_bulk_data::on_message_delete_bulk_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -849,7 +849,7 @@ namespace discord_core_api { } on_reaction_add_data::on_reaction_add_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -861,7 +861,7 @@ namespace discord_core_api { } on_reaction_remove_data::on_reaction_remove_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -870,7 +870,7 @@ namespace discord_core_api { } on_reaction_remove_all_data::on_reaction_remove_all_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -879,7 +879,7 @@ namespace discord_core_api { } on_reaction_remove_emoji_data::on_reaction_remove_emoji_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -888,7 +888,7 @@ namespace discord_core_api { } on_presence_update_data::on_presence_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -897,7 +897,7 @@ namespace discord_core_api { } on_stage_instance_creation_data::on_stage_instance_creation_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -906,7 +906,7 @@ namespace discord_core_api { } on_stage_instance_update_data::on_stage_instance_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -915,7 +915,7 @@ namespace discord_core_api { } on_stage_instance_deletion_data::on_stage_instance_deletion_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -924,7 +924,7 @@ namespace discord_core_api { } on_typing_start_data::on_typing_start_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -933,7 +933,7 @@ namespace discord_core_api { } on_user_update_data::on_user_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); oldValue = users::getCachedUser({ value.id }); if (users::doWeCacheUsers()) { users::insertUser(static_cast(value)); @@ -942,7 +942,7 @@ namespace discord_core_api { on_voice_state_update_data::on_voice_state_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse, discord_core_internal::websocket_client* sslShard) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -970,7 +970,7 @@ namespace discord_core_api { } on_webhook_update_data::on_webhook_update_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -979,7 +979,7 @@ namespace discord_core_api { } on_auto_complete_entry_data::on_auto_complete_entry_data(jsonifier::jsonifier_core& parserNew, jsonifier::string_view_base dataToParse) { - parserNew.parseJson(*static_cast(this), dataToParse); + parserNew.parseJson(*static_cast(this), dataToParse); if (auto result = parserNew.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); diff --git a/Source/FoundationEntities.cpp b/Source/FoundationEntities.cpp index bb07d8631..0c2164ad1 100644 --- a/Source/FoundationEntities.cpp +++ b/Source/FoundationEntities.cpp @@ -890,7 +890,7 @@ namespace discord_core_api { application_command_option_choice_data choiceData{}; choiceData.nameLocalizations = theNameLocalizations; choiceData.name = theName; - choiceData.value = jsonifier::string{ value.operator jsonifier::string_base() }; + choiceData.value = jsonifier::raw_json_data{ parser, value.operator jsonifier::string_base() }; choices.emplace_back(choiceData); return *this; } @@ -1061,13 +1061,13 @@ namespace discord_core_api { commandName = inputEventData.interactionData->data.name; } if (inputEventData.interactionData->data.targetId != 0) { - optionsArgs.values.emplace("target_id", jsonifier::raw_json_data{ inputEventData.interactionData->data.targetId.operator jsonifier::string() }); + optionsArgs.values.emplace("target_id", jsonifier::raw_json_data{ parser, inputEventData.interactionData->data.targetId.operator jsonifier::string() }); } else if (inputEventData.interactionData->data.targetId != 0) { - optionsArgs.values.emplace("target_id", jsonifier::raw_json_data{ inputEventData.interactionData->data.targetId.operator jsonifier::string() }); + optionsArgs.values.emplace("target_id", jsonifier::raw_json_data{ parser, inputEventData.interactionData->data.targetId.operator jsonifier::string() }); } eventData = makeUnique(inputEventData); for (auto& value: eventData->interactionData->data.options) { - jsonifier::raw_json_data serializer{ value.value.operator jsonifier::string() }; + jsonifier::raw_json_data serializer{ parser, value.value.get() }; optionsArgs.values[value.name] = serializer; parseCommandDataOption(optionsArgs.values, value); } diff --git a/Source/SoundCloudAPI.cpp b/Source/SoundCloudAPI.cpp index bec68ad17..496b7db69 100644 --- a/Source/SoundCloudAPI.cpp +++ b/Source/SoundCloudAPI.cpp @@ -118,23 +118,23 @@ namespace discord_core_api { (returnData.responseData.find("window.__sc_hydration = ") + jsonifier::string{ "window.__sc_hydration = " }.size())); } welcome resultsNew{}; - parser.parseJson(resultsNew, returnData.responseData); + parser.parseJson(resultsNew, returnData.responseData); jsonifier::string avatarUrl{}; jsonifier::string collectionString{ "tracks?ids=" }; for (auto& value: resultsNew.data) { if (value.data.getType() == jsonifier::json_type::Object) { - auto newObject = value.data.operator jsonifier::raw_json_data::object_type(); - avatarUrl = newObject["avatar_url"].operator jsonifier::string(); + auto newObject = value.data.get(); + avatarUrl = newObject["avatar_url"].get(); if (value.hydratable == "playlist") { - auto newerObject = value.data.operator jsonifier::raw_json_data::object_type(); + auto newerObject = value.data.get(); for (auto& [key, valueNew]: newerObject) { if (key == "tracks") { - auto newArray = valueNew.operator jsonifier::raw_json_data::array_type(); + auto newArray = valueNew.get(); uint32_t currentIndex{}; auto arraySize = newArray.size(); for (auto& newValue: newArray) { - newObject = newValue.operator jsonifier::raw_json_data::object_type(); - collectionString += jsonifier::toString(newValue.operator jsonifier::raw_json_data::object_type()["id"].operator uint64_t()); + newObject = newValue.get(); + collectionString += jsonifier::toString(newValue.get()["id"].get()); if (currentIndex < arraySize - 1) { collectionString += "%2C"; } @@ -153,32 +153,32 @@ namespace discord_core_api { dataPackage02.workloadClass = https_workload_class::Get; returnData = submitWorkloadAndGetResult(std::move(dataPackage02)); jsonifier::vector resultsNewer{}; - parser.parseJson(resultsNewer, returnData.responseData); + parser.parseJson(resultsNewer, returnData.responseData); for (auto& value: resultsNewer) { song results{}; if (value.getType() == jsonifier::json_type::Object) { - auto newObject = value.operator jsonifier::raw_json_data::object_type(); - avatarUrl = newObject["avatar_url"].operator jsonifier::string(); - if (newObject["title"].operator jsonifier::string() == "") { + auto newObject = value.get(); + avatarUrl = newObject["avatar_url"].get(); + if (newObject["title"].get() == "") { continue; } bool isItFound{}; - for (auto& valueNew: newObject["media"].operator jsonifier::raw_json_data::object_type()["transcodings"].operator jsonifier::raw_json_data::array_type()) { - if (valueNew.operator jsonifier::raw_json_data::object_type()["preset"].operator jsonifier::string() == "opus_0_0") { + for (auto& valueNew: newObject["media"].get()["transcodings"].get()) { + if (valueNew.get()["preset"].get() == "opus_0_0") { isItFound = true; - results.firstDownloadUrl = valueNew.operator jsonifier::raw_json_data::object_type()["url"].operator jsonifier::string(); - results.songId = valueNew.operator jsonifier::raw_json_data::object_type()["url"].operator jsonifier::string(); + results.firstDownloadUrl = valueNew.get()["url"].get(); + results.songId = valueNew.get()["url"].get(); } } if (isItFound) { - jsonifier::string newString = newObject["title"].operator jsonifier::string(); + jsonifier::string newString = newObject["title"].get(); if (newString.size() > 0) { if (newString.size() > 256) { newString = newString.substr(0, 256); } results.songTitle = utf8MakeValid(newString); } - newString = newObject["description"].operator jsonifier::string(); + newString = newObject["description"].get(); if (newString.size() > 0) { if (newString.size() > 256) { newString = newString.substr(0, 256); @@ -186,17 +186,17 @@ namespace discord_core_api { results.description = utf8MakeValid(newString); results.description += "..."; } - newString = newObject["artwork_url"].operator jsonifier::string(); + newString = newObject["artwork_url"].get(); if (newString.size() > 0) { results.thumbnailUrl = utf8MakeValid(newString); } - results.viewUrl = newObject["permalink_url"].operator jsonifier::string(); - results.duration = time_stamp::convertMsToDurationString(static_cast(newObject["duration"].operator uint64_t())); + results.viewUrl = newObject["permalink_url"].get(); + results.duration = time_stamp::convertMsToDurationString(static_cast(newObject["duration"].get())); results.firstDownloadUrl += - "?client_id=" + sound_cloud_request_builder::clientId + "&track_authorization=" + newObject["track_authorization"].operator jsonifier::string(); - if (newObject["artwork_url"].operator jsonifier::string().find("-") != jsonifier::string::npos) { + "?client_id=" + sound_cloud_request_builder::clientId + "&track_authorization=" + newObject["track_authorization"].get(); + if (newObject["artwork_url"].get().find("-") != jsonifier::string::npos) { jsonifier::string newerString = - newObject["artwork_url"].operator jsonifier::string().substr(0, newObject["artwork_url"].operator jsonifier::string().findLastOf("-") + 1); + newObject["artwork_url"].get().substr(0, newObject["artwork_url"].get().findLastOf("-") + 1); newerString += "t500x500.jpg"; results.thumbnailUrl = newerString; } else if (avatarUrl.find("-") != jsonifier::string::npos) { @@ -235,35 +235,34 @@ namespace discord_core_api { (returnData.responseData.find("window.__sc_hydration = ") + jsonifier::string{ "window.__sc_hydration = " }.size())); } welcome resultsNew{}; - parser.parseJson(resultsNew, returnData.responseData); + parser.parseJson(resultsNew, returnData.responseData); jsonifier::string avatarUrl{}; for (auto& value: resultsNew.data) { if (value.data.getType() == jsonifier::json_type::Object) { - auto newObject = value.data.operator jsonifier::raw_json_data::object_type(); - avatarUrl = newObject["avatar_url"].operator jsonifier::string(); + auto newObject = value.data.get(); + avatarUrl = newObject["avatar_url"].get(); if (value.hydratable == "sound") { - if (newObject["title"].operator jsonifier::string() == "") { + if (newObject["title"].get() == "") { continue; } bool isItFound{}; - for (auto& valueNew: - newObject["media"].operator jsonifier::raw_json_data::object_type()["transcodings"].operator jsonifier::raw_json_data::array_type()) { - if (valueNew.operator jsonifier::raw_json_data::object_type()["preset"].operator jsonifier::string() == "opus_0_0") { + for (auto& valueNew: newObject["media"].get()["transcodings"].get()) { + if (valueNew.get()["preset"].get() == "opus_0_0") { isItFound = true; - results.firstDownloadUrl = valueNew.operator jsonifier::raw_json_data::object_type()["url"].operator jsonifier::string(); - results.songId = valueNew.operator jsonifier::raw_json_data::object_type()["url"].operator jsonifier::string(); + results.firstDownloadUrl = valueNew.get()["url"].get(); + results.songId = valueNew.get()["url"].get(); } } if (isItFound) { - jsonifier::string newString = newObject["title"].operator jsonifier::string(); + jsonifier::string newString = newObject["title"].get(); if (newString.size() > 0) { if (newString.size() > 256) { newString = newString.substr(0, 256); } results.songTitle = utf8MakeValid(newString); } - newString = newObject["description"].operator jsonifier::string(); + newString = newObject["description"].get(); if (newString.size() > 0) { if (newString.size() > 256) { newString = newString.substr(0, 256); @@ -271,17 +270,17 @@ namespace discord_core_api { results.description = utf8MakeValid(newString); results.description += "..."; } - newString = newObject["artwork_url"].operator jsonifier::string(); + newString = newObject["artwork_url"].get(); if (newString.size() > 0) { results.thumbnailUrl = utf8MakeValid(newString); } - results.viewUrl = newObject["permalink_url"].operator jsonifier::string(); - results.duration = time_stamp::convertMsToDurationString(static_cast(newObject["duration"].operator uint64_t())); + results.viewUrl = newObject["permalink_url"].get(); + results.duration = time_stamp::convertMsToDurationString(static_cast(newObject["duration"].get())); results.firstDownloadUrl += - "?client_id=" + sound_cloud_request_builder::clientId + "&track_authorization=" + newObject["track_authorization"].operator jsonifier::string(); - if (newObject["artwork_url"].operator jsonifier::string().find("-") != jsonifier::string::npos) { + "?client_id=" + sound_cloud_request_builder::clientId + "&track_authorization=" + newObject["track_authorization"].get(); + if (newObject["artwork_url"].get().find("-") != jsonifier::string::npos) { jsonifier::string newerString = - newObject["artwork_url"].operator jsonifier::string().substr(0, newObject["artwork_url"].operator jsonifier::string().findLastOf("-") + 1); + newObject["artwork_url"].get().substr(0, newObject["artwork_url"].get().findLastOf("-") + 1); newerString += "t500x500.jpg"; results.thumbnailUrl = newerString; } else if (avatarUrl.find("-") != jsonifier::string::npos) { @@ -325,7 +324,7 @@ namespace discord_core_api { dataPackage.workloadClass = https_workload_class::Get; https_response_data returnData = submitWorkloadAndGetResult(std::move(dataPackage)); sound_cloud_search_results resultsNew{}; - parser.parseJson(resultsNew, returnData.responseData); + parser.parseJson(resultsNew, returnData.responseData); for (auto& value: resultsNew.collection) { song songNew{}; if (value.title == "") { @@ -396,7 +395,7 @@ namespace discord_core_api { https_response_data results = submitWorkloadAndGetResult(std::move(dataPackage01)); second_download_url downloadUrl{}; song newerSong{ songNew }; - parser.parseJson(downloadUrl, results.responseData); + parser.parseJson(downloadUrl, results.responseData); newerSong.secondDownloadUrl = downloadUrl.url; if (newerSong.secondDownloadUrl.find("/playlist") != jsonifier::string::npos) { https_workload_data dataPackage{ https_workload_type::SoundCloud_Get_Download_Links }; diff --git a/Source/VoiceConnection.cpp b/Source/VoiceConnection.cpp index 569a48749..ccaeecbd1 100644 --- a/Source/VoiceConnection.cpp +++ b/Source/VoiceConnection.cpp @@ -410,11 +410,11 @@ namespace discord_core_api { bool voice_connection::onMessageReceived(jsonifier::string_view_base data) { discord_core_internal::websocket_message message{}; message_printer::printSuccess("message received from voice websocket: " + jsonifier::string{ data }); - parser.parseJson(message, data); + parser.parseJson(message, data); switch (static_cast(message.op)) { case voice_socket_op_codes::Ready_Server: { discord_core_internal::websocket_message_data dataNew{}; - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); audioSSRC = dataNew.d.ssrc; voiceIp = dataNew.d.ip; port = dataNew.d.port; @@ -429,7 +429,7 @@ namespace discord_core_api { case voice_socket_op_codes::Session_Description: { discord_core_internal::websocket_message_data dataNew{}; encryptionKey.clear(); - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); for (auto& value: dataNew.d.secretKey) { encryptionKey.emplace_back(static_cast(value)); } @@ -439,7 +439,7 @@ namespace discord_core_api { } case voice_socket_op_codes::speaking: { discord_core_internal::websocket_message_data dataNew{}; - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); const uint32_t ssrc = dataNew.d.ssrc; auto userId = dataNew.d.userId; unique_ptr user{ makeUnique(userId) }; @@ -457,7 +457,7 @@ namespace discord_core_api { } case voice_socket_op_codes::hello: { discord_core_internal::websocket_message_data dataNew{}; - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); heartBeatStopWatch = stop_watch{ dataNew.d.heartBeatInterval }; heartBeatStopWatch.reset(); areWeHeartBeating = true; @@ -472,7 +472,7 @@ namespace discord_core_api { } case voice_socket_op_codes::Client_Disconnect: { discord_core_internal::websocket_message_data dataNew{}; - parser.parseJson(dataNew, data); + parser.parseJson(dataNew, data); const auto userId = dataNew.d.userId; for (auto& [key, value]: voiceUsers) { if (userId == value->getUserId()) { diff --git a/Source/WebSocketClient.cpp b/Source/WebSocketClient.cpp index dfbb6cdaf..fa856071a 100644 --- a/Source/WebSocketClient.cpp +++ b/Source/WebSocketClient.cpp @@ -460,12 +460,15 @@ namespace discord_core_api { bool websocket_client::onMessageReceived(jsonifier::string_view_base dataNew) { try { + std::string newString{}; + newString.resize(dataNew.size()); + std::memcpy(newString.data(), dataNew.data(), dataNew.size()); if (areWeConnected() && currentMessage.size() > 0 && dataNew.size() > 0) { websocket_message message{}; if (configManager->getTextFormat() == text_format::etf) { try { dataNew = etfParser.parseEtfToJson(dataNew); - parser.parseJson(message, dataNew); + parser.parseJson(message, dataNew); for (auto& valueNew: parser.getErrors()) { message_printer::printError(valueNew.reportError() + ", for data:" + dataNew); } @@ -476,7 +479,7 @@ namespace discord_core_api { return false; } } else { - parser.parseJson(message, dataNew); + parser.parseJson(message, dataNew); if (auto result = parser.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError() + ", for data:" + dataNew); @@ -484,453 +487,465 @@ namespace discord_core_api { } } - if (message.s != 0) { - lastNumberReceived = static_cast(message.s); + if (message.s.has_value()) { + if (message.s.value() != 0) { + std::cout << "CURRENT TYPE: " << message.s.value() << std::endl; + lastNumberReceived = static_cast(message.s.value()); + } } + + std::cout << "CURRENT TYPE: " << message.op << std::endl; + message_printer::printSuccess("Message received from websocket [" + jsonifier::toString(shard.at(0)) + "," + jsonifier::toString(shard.at(1)) + jsonifier::string("]: ") + jsonifier::string{ dataNew }); switch (static_cast(message.op)) { case websocket_op_codes::dispatch: { - if (message.t != "") { - switch (event_converter{ message.t }) { - case 1: { - websocket_message_data data{}; - if (dataOpCode == websocket_op_code::Op_Text) { - data.d.jsonifierExcludedKeys.emplace("shard"); - } - currentState.store(websocket_state::authenticated, std::memory_order_release); - parser.parseJson(data, dataNew); - if (auto result = parser.getErrors(); result.size() > 0) { - for (auto& valueNew: result) { - message_printer::printError(valueNew.reportError()); + if (message.t.has_value()) { + if (message.t.value() != "") { + std::cout << "CURRENT TYPE: " << message.t.value() << std::endl; + switch (event_converter{ message.t.value() }) { + case 1: { + websocket_message_data data{}; + if (dataOpCode == websocket_op_code::Op_Text) { + data.d.jsonifierExcludedKeys.emplace("shard"); } + currentState.store(websocket_state::authenticated, std::memory_order_release); + parser.parseJson(data, dataNew); + if (auto result = parser.getErrors(); result.size() > 0) { + for (auto& valueNew: result) { + message_printer::printError(valueNew.reportError()); + } + } + sessionId = data.d.sessionId; + if (data.d.resumeGatewayUrl.find("wss://") != jsonifier::string::npos) { + resumeUrl = data.d.resumeGatewayUrl.substr(data.d.resumeGatewayUrl.find("wss://") + jsonifier::string{ "wss://" }.size()); + } + discord_core_client::getInstance()->currentUser = bot_user{ data.d.user, + discord_core_client::getInstance() + ->baseSocketAgentsMap[static_cast(floor(static_cast(shard.at(0)) % + static_cast(discord_core_client::getInstance()->baseSocketAgentsMap.size())))] + .get() }; + users::insertUser(static_cast(std::move(data.d.user))); + currentReconnectTries = 0; + break; } - sessionId = data.d.sessionId; - if (data.d.resumeGatewayUrl.find("wss://") != jsonifier::string::npos) { - resumeUrl = data.d.resumeGatewayUrl.substr(data.d.resumeGatewayUrl.find("wss://") + jsonifier::string{ "wss://" }.size()); + case 2: { + currentState.store(websocket_state::authenticated, std::memory_order_release); + currentReconnectTries = 0; + break; } - discord_core_client::getInstance()->currentUser = bot_user{ data.d.user, - discord_core_client::getInstance() - ->baseSocketAgentsMap[static_cast(floor( - static_cast(shard.at(0)) % static_cast(discord_core_client::getInstance()->baseSocketAgentsMap.size())))] - .get() }; - users::insertUser(static_cast(std::move(data.d.user))); - currentReconnectTries = 0; - break; - } - case 2: { - currentState.store(websocket_state::authenticated, std::memory_order_release); - currentReconnectTries = 0; - break; - } - case 3: { - if (discord_core_client::getInstance()->eventManager.onApplicationCommandPermissionsUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique( - parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onApplicationCommandPermissionsUpdateEvent(*dataPackage); + case 3: { + if (discord_core_client::getInstance()->eventManager.onApplicationCommandPermissionsUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique( + parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onApplicationCommandPermissionsUpdateEvent(*dataPackage); + } + break; } - break; - } - case 4: { - if (discord_core_client::getInstance()->eventManager.onAutoModerationRuleCreationEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onAutoModerationRuleCreationEvent(*dataPackage); + case 4: { + if (discord_core_client::getInstance()->eventManager.onAutoModerationRuleCreationEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onAutoModerationRuleCreationEvent(*dataPackage); + } + break; } - break; - } - case 5: { - if (discord_core_client::getInstance()->eventManager.onAutoModerationRuleUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onAutoModerationRuleUpdateEvent(*dataPackage); + case 5: { + if (discord_core_client::getInstance()->eventManager.onAutoModerationRuleUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onAutoModerationRuleUpdateEvent(*dataPackage); + } + break; } - break; - } - case 6: { - if (discord_core_client::getInstance()->eventManager.onAutoModerationRuleDeletionEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onAutoModerationRuleDeletionEvent(*dataPackage); + case 6: { + if (discord_core_client::getInstance()->eventManager.onAutoModerationRuleDeletionEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onAutoModerationRuleDeletionEvent(*dataPackage); + } + break; } - break; - } - case 7: { - if (discord_core_client::getInstance()->eventManager.onAutoModerationActionExecutionEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, - dataNew) }; - discord_core_client::getInstance()->eventManager.onAutoModerationActionExecutionEvent(*dataPackage); + case 7: { + if (discord_core_client::getInstance()->eventManager.onAutoModerationActionExecutionEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, + dataNew) }; + discord_core_client::getInstance()->eventManager.onAutoModerationActionExecutionEvent(*dataPackage); + } + break; } - break; - } - case 8: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onChannelCreationEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onChannelCreationEvent(*dataPackage); + case 8: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onChannelCreationEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onChannelCreationEvent(*dataPackage); + } + break; } - break; - } - case 9: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onChannelUpdateEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onChannelUpdateEvent(*dataPackage); + case 9: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onChannelUpdateEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onChannelUpdateEvent(*dataPackage); + } + break; } - break; - } - case 10: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onChannelDeletionEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onChannelDeletionEvent(*dataPackage); + case 10: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onChannelDeletionEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onChannelDeletionEvent(*dataPackage); + } + break; } - break; - } - case 11: { - if (discord_core_client::getInstance()->eventManager.onChannelPinsUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onChannelPinsUpdateEvent(*dataPackage); + case 11: { + if (discord_core_client::getInstance()->eventManager.onChannelPinsUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onChannelPinsUpdateEvent(*dataPackage); + } + break; } - break; - } - case 12: { - if (discord_core_client::getInstance()->eventManager.onThreadCreationEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onThreadCreationEvent(*dataPackage); + case 12: { + if (discord_core_client::getInstance()->eventManager.onThreadCreationEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onThreadCreationEvent(*dataPackage); + } + break; } - break; - } - case 13: { - if (discord_core_client::getInstance()->eventManager.onThreadUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onThreadUpdateEvent(*dataPackage); + case 13: { + if (discord_core_client::getInstance()->eventManager.onThreadUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onThreadUpdateEvent(*dataPackage); + } + break; } - break; - } - case 14: { - if (discord_core_client::getInstance()->eventManager.onThreadDeletionEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onThreadDeletionEvent(*dataPackage); + case 14: { + if (discord_core_client::getInstance()->eventManager.onThreadDeletionEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onThreadDeletionEvent(*dataPackage); + } + break; } - break; - } - case 15: { - if (discord_core_client::getInstance()->eventManager.onThreadListSyncEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onThreadListSyncEvent(*dataPackage); + case 15: { + if (discord_core_client::getInstance()->eventManager.onThreadListSyncEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onThreadListSyncEvent(*dataPackage); + } + break; } - break; - } - case 16: { - if (discord_core_client::getInstance()->eventManager.onThreadMemberUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onThreadMemberUpdateEvent(*dataPackage); + case 16: { + if (discord_core_client::getInstance()->eventManager.onThreadMemberUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onThreadMemberUpdateEvent(*dataPackage); + } + break; } - break; - } - case 17: { - if (discord_core_client::getInstance()->eventManager.onThreadMembersUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onThreadMembersUpdateEvent(*dataPackage); + case 17: { + if (discord_core_client::getInstance()->eventManager.onThreadMembersUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onThreadMembersUpdateEvent(*dataPackage); + } + break; } - break; - } - case 18: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onGuildCreationEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onGuildCreationEvent(*dataPackage); + case 18: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onGuildCreationEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onGuildCreationEvent(*dataPackage); + } + break; } - break; - } - case 19: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onGuildUpdateEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onGuildUpdateEvent(*dataPackage); + case 19: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onGuildUpdateEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onGuildUpdateEvent(*dataPackage); + } + break; } - break; - } - case 20: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onGuildDeletionEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onGuildDeletionEvent(*dataPackage); + case 20: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onGuildDeletionEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onGuildDeletionEvent(*dataPackage); + } + break; } - break; - } - case 21: { - if (discord_core_client::getInstance()->eventManager.onGuildBanAddEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildBanAddEvent(*dataPackage); + case 21: { + if (discord_core_client::getInstance()->eventManager.onGuildBanAddEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildBanAddEvent(*dataPackage); + } + break; } - break; - } - case 22: { - if (discord_core_client::getInstance()->eventManager.onGuildBanRemoveEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildBanRemoveEvent(*dataPackage); + case 22: { + if (discord_core_client::getInstance()->eventManager.onGuildBanRemoveEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildBanRemoveEvent(*dataPackage); + } + break; } - break; - } - case 23: { - if (discord_core_client::getInstance()->eventManager.onGuildEmojisUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildEmojisUpdateEvent(*dataPackage); + case 23: { + if (discord_core_client::getInstance()->eventManager.onGuildEmojisUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildEmojisUpdateEvent(*dataPackage); + } + break; } - break; - } - case 24: { - if (discord_core_client::getInstance()->eventManager.onGuildStickersUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildStickersUpdateEvent(*dataPackage); + case 24: { + if (discord_core_client::getInstance()->eventManager.onGuildStickersUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildStickersUpdateEvent(*dataPackage); + } + break; } - break; - } - case 25: { - if (discord_core_client::getInstance()->eventManager.onGuildIntegrationsUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildIntegrationsUpdateEvent(*dataPackage); + case 25: { + if (discord_core_client::getInstance()->eventManager.onGuildIntegrationsUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildIntegrationsUpdateEvent(*dataPackage); + } + break; } - break; - } - case 26: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onGuildMemberAddEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onGuildMemberAddEvent(*dataPackage); + case 26: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onGuildMemberAddEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onGuildMemberAddEvent(*dataPackage); + } + break; } - break; - } - case 27: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onGuildMemberRemoveEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onGuildMemberRemoveEvent(*dataPackage); + case 27: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onGuildMemberRemoveEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onGuildMemberRemoveEvent(*dataPackage); + } + break; } - break; - } - case 28: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onGuildMemberUpdateEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onGuildMemberUpdateEvent(*dataPackage); + case 28: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onGuildMemberUpdateEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onGuildMemberUpdateEvent(*dataPackage); + } + break; } - break; - } - case 29: { - if (discord_core_client::getInstance()->eventManager.onGuildMembersChunkEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildMembersChunkEvent(*dataPackage); + case 29: { + if (discord_core_client::getInstance()->eventManager.onGuildMembersChunkEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildMembersChunkEvent(*dataPackage); + } + break; } - break; - } - case 30: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onRoleCreationEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onRoleCreationEvent(*dataPackage); + case 30: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onRoleCreationEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onRoleCreationEvent(*dataPackage); + } + break; } - break; - } - case 31: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onRoleUpdateEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onRoleUpdateEvent(*dataPackage); + case 31: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onRoleUpdateEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onRoleUpdateEvent(*dataPackage); + } + break; } - break; - } - case 32: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onRoleDeletionEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onRoleDeletionEvent(*dataPackage); + case 32: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onRoleDeletionEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onRoleDeletionEvent(*dataPackage); + } + break; } - break; - } - case 33: { - if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventCreationEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildScheduledEventCreationEvent(*dataPackage); + case 33: { + if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventCreationEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, + dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildScheduledEventCreationEvent(*dataPackage); + } + break; } - break; - } - case 34: { - if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildScheduledEventUpdateEvent(*dataPackage); + case 34: { + if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildScheduledEventUpdateEvent(*dataPackage); + } + break; } - break; - } - case 35: { - if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventDeletionEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildScheduledEventDeletionEvent(*dataPackage); + case 35: { + if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventDeletionEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, + dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildScheduledEventDeletionEvent(*dataPackage); + } + break; } - break; - } - case 36: { - if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventUserAddEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildScheduledEventUserAddEvent(*dataPackage); + case 36: { + if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventUserAddEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, + dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildScheduledEventUserAddEvent(*dataPackage); + } + break; } - break; - } - case 37: { - if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventUserRemoveEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, - dataNew) }; - discord_core_client::getInstance()->eventManager.onGuildScheduledEventUserRemoveEvent(*dataPackage); + case 37: { + if (discord_core_client::getInstance()->eventManager.onGuildScheduledEventUserRemoveEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, + dataNew) }; + discord_core_client::getInstance()->eventManager.onGuildScheduledEventUserRemoveEvent(*dataPackage); + } + break; } - break; - } - case 38: { - if (discord_core_client::getInstance()->eventManager.onIntegrationCreationEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onIntegrationCreationEvent(*dataPackage); + case 38: { + if (discord_core_client::getInstance()->eventManager.onIntegrationCreationEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onIntegrationCreationEvent(*dataPackage); + } + break; } - break; - } - case 39: { - if (discord_core_client::getInstance()->eventManager.onIntegrationUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onIntegrationUpdateEvent(*dataPackage); + case 39: { + if (discord_core_client::getInstance()->eventManager.onIntegrationUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onIntegrationUpdateEvent(*dataPackage); + } + break; } - break; - } - case 40: { - if (discord_core_client::getInstance()->eventManager.onIntegrationDeletionEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onIntegrationDeletionEvent(*dataPackage); + case 40: { + if (discord_core_client::getInstance()->eventManager.onIntegrationDeletionEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onIntegrationDeletionEvent(*dataPackage); + } + break; } - break; - } - case 41: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onInteractionCreationEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onInteractionCreationEvent(*dataPackage); + case 41: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onInteractionCreationEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onInteractionCreationEvent(*dataPackage); + } + break; } - break; - } - case 42: { - if (discord_core_client::getInstance()->eventManager.onInviteCreationEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onInviteCreationEvent(*dataPackage); + case 42: { + if (discord_core_client::getInstance()->eventManager.onInviteCreationEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onInviteCreationEvent(*dataPackage); + } + break; } - break; - } - case 43: { - if (discord_core_client::getInstance()->eventManager.onInviteDeletionEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onInviteDeletionEvent(*dataPackage); + case 43: { + if (discord_core_client::getInstance()->eventManager.onInviteDeletionEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onInviteDeletionEvent(*dataPackage); + } + break; } - break; - } - case 44: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onMessageCreationEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onMessageCreationEvent(*dataPackage); + case 44: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onMessageCreationEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onMessageCreationEvent(*dataPackage); + } + break; } - break; - } - case 45: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onMessageUpdateEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onMessageUpdateEvent(*dataPackage); + case 45: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onMessageUpdateEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onMessageUpdateEvent(*dataPackage); + } + break; } - break; - } - case 46: { - if (discord_core_client::getInstance()->eventManager.onMessageDeletionEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onMessageDeletionEvent(*dataPackage); + case 46: { + if (discord_core_client::getInstance()->eventManager.onMessageDeletionEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onMessageDeletionEvent(*dataPackage); + } + break; } - break; - } - case 47: { - if (discord_core_client::getInstance()->eventManager.onMessageDeleteBulkEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onMessageDeleteBulkEvent(*dataPackage); + case 47: { + if (discord_core_client::getInstance()->eventManager.onMessageDeleteBulkEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onMessageDeleteBulkEvent(*dataPackage); + } + break; } - break; - } - case 48: { - if (discord_core_client::getInstance()->eventManager.onReactionAddEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onReactionAddEvent(*dataPackage); + case 48: { + if (discord_core_client::getInstance()->eventManager.onReactionAddEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onReactionAddEvent(*dataPackage); + } + break; } - break; - } - case 49: { - if (discord_core_client::getInstance()->eventManager.onReactionRemoveEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onReactionRemoveEvent(*dataPackage); + case 49: { + if (discord_core_client::getInstance()->eventManager.onReactionRemoveEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onReactionRemoveEvent(*dataPackage); + } + break; } - break; - } - case 50: { - if (discord_core_client::getInstance()->eventManager.onReactionRemoveAllEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onReactionRemoveAllEvent(*dataPackage); + case 50: { + if (discord_core_client::getInstance()->eventManager.onReactionRemoveAllEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onReactionRemoveAllEvent(*dataPackage); + } + break; } - break; - } - case 51: { - if (discord_core_client::getInstance()->eventManager.onReactionRemoveEmojiEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onReactionRemoveEmojiEvent(*dataPackage); + case 51: { + if (discord_core_client::getInstance()->eventManager.onReactionRemoveEmojiEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onReactionRemoveEmojiEvent(*dataPackage); + } + break; } - break; - } - case 52: { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - if (discord_core_client::getInstance()->eventManager.onPresenceUpdateEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onPresenceUpdateEvent(*dataPackage); + case 52: { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + if (discord_core_client::getInstance()->eventManager.onPresenceUpdateEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onPresenceUpdateEvent(*dataPackage); + } + break; } - break; - } - case 53: { - if (discord_core_client::getInstance()->eventManager.onStageInstanceCreationEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onStageInstanceCreationEvent(*dataPackage); + case 53: { + if (discord_core_client::getInstance()->eventManager.onStageInstanceCreationEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onStageInstanceCreationEvent(*dataPackage); + } + break; } - break; - } - case 54: { - if (discord_core_client::getInstance()->eventManager.onStageInstanceUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onStageInstanceUpdateEvent(*dataPackage); + case 54: { + if (discord_core_client::getInstance()->eventManager.onStageInstanceUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onStageInstanceUpdateEvent(*dataPackage); + } + break; } - break; - } - case 55: { - if (discord_core_client::getInstance()->eventManager.onStageInstanceDeletionEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onStageInstanceDeletionEvent(*dataPackage); + case 55: { + if (discord_core_client::getInstance()->eventManager.onStageInstanceDeletionEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onStageInstanceDeletionEvent(*dataPackage); + } + break; } - break; - } - case 56: { - if (discord_core_client::getInstance()->eventManager.onTypingStartEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onTypingStartEvent(*dataPackage); + case 56: { + if (discord_core_client::getInstance()->eventManager.onTypingStartEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onTypingStartEvent(*dataPackage); + } + break; } - break; - } - case 57: { - if (discord_core_client::getInstance()->eventManager.onUserUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onUserUpdateEvent(*dataPackage); + case 57: { + if (discord_core_client::getInstance()->eventManager.onUserUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onUserUpdateEvent(*dataPackage); + } + break; } - break; - } - case 58: { - unique_ptr dataPackage{ makeUnique(parser, dataNew, this) }; - if (discord_core_client::getInstance()->eventManager.onVoiceStateUpdateEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onVoiceStateUpdateEvent(*dataPackage); + case 58: { + unique_ptr dataPackage{ makeUnique(parser, dataNew, this) }; + if (discord_core_client::getInstance()->eventManager.onVoiceStateUpdateEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onVoiceStateUpdateEvent(*dataPackage); + } + break; } - break; - } - case 59: { - unique_ptr dataPackage{ makeUnique(parser, dataNew, this) }; - if (discord_core_client::getInstance()->eventManager.onVoiceServerUpdateEvent.functions.size() > 0) { - discord_core_client::getInstance()->eventManager.onVoiceServerUpdateEvent(*dataPackage); + case 59: { + unique_ptr dataPackage{ makeUnique(parser, dataNew, this) }; + if (discord_core_client::getInstance()->eventManager.onVoiceServerUpdateEvent.functions.size() > 0) { + discord_core_client::getInstance()->eventManager.onVoiceServerUpdateEvent(*dataPackage); + } + break; } - break; - } - case 60: { - if (discord_core_client::getInstance()->eventManager.onWebhookUpdateEvent.functions.size() > 0) { - unique_ptr dataPackage{ makeUnique(parser, dataNew) }; - discord_core_client::getInstance()->eventManager.onWebhookUpdateEvent(*dataPackage); + case 60: { + if (discord_core_client::getInstance()->eventManager.onWebhookUpdateEvent.functions.size() > 0) { + unique_ptr dataPackage{ makeUnique(parser, dataNew) }; + discord_core_client::getInstance()->eventManager.onWebhookUpdateEvent(*dataPackage); + } + break; } - break; } } } @@ -951,7 +966,7 @@ namespace discord_core_api { } case websocket_op_codes::Invalid_Session: { websocket_message_data data{}; - parser.parseJson(data, dataNew); + parser.parseJson(data, dataNew); if (auto result = parser.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -975,7 +990,7 @@ namespace discord_core_api { } case websocket_op_codes::hello: { websocket_message_data data{}; - parser.parseJson(data, dataNew); + parser.parseJson(data, dataNew); if (auto result = parser.getErrors(); result.size() > 0) { for (auto& valueNew: result) { message_printer::printError(valueNew.reportError()); @@ -1178,6 +1193,7 @@ namespace discord_core_api { } } - base_socket_agent::~base_socket_agent(){} + base_socket_agent::~base_socket_agent() { + } }// namespace discord_core_internal }// namespace discord_core_api diff --git a/Source/YouTubeAPI.cpp b/Source/YouTubeAPI.cpp index 117fa80a7..b1c28c86e 100644 --- a/Source/YouTubeAPI.cpp +++ b/Source/YouTubeAPI.cpp @@ -197,7 +197,7 @@ namespace discord_core_api { jsonifier::string stringSequence = ";