Skip to content

Commit

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

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

jobs:
Build:
runs-on: windows-latest

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

steps:
- uses: actions/checkout@v4

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

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

is_numeric("${DCA_CPU_INSTRUCTIONS_NEW}" is_numeric_result)

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

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

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

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

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

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

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

# Documentation/Examples
\ref documentation_examples

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

# Bot Template
[A template for utilizing this library.](https://github.com/RealTimeChris/Bot-Template-for-DiscordCoreAPI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ namespace discord_core_api {
if (trackNumber >= song_api::getPlaylist(guild_data.id).songQueue.size()) {
unique_ptr<embed_data> newEmbed{ makeUnique<embed_data>() };
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);
Expand Down
34 changes: 21 additions & 13 deletions Include/discordcoreapi/FoundationEntities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#pragma once

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

namespace discord_core_api {

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

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

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

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

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

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

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


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

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

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

Expand All @@ -80,21 +80,21 @@ namespace jsonifier_internal {
jsonifier::raw_json_data newString{};
parse<minified, options>::impl(newString, context);
if (newString.getType() == jsonifier::json_type::String) {
value = newString.operator jsonifier::string();
value = newString.get<jsonifier::string>();
} else {
value = newString.operator uint64_t();
value = newString.get<uint64_t>();
}
}
};

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

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

Expand All @@ -104,9 +104,9 @@ namespace jsonifier_internal {
jsonifier::raw_json_data newString{};
parse<minified, options>::impl(newString, context);
if (newString.getType() == jsonifier::json_type::String) {
value = newString.operator jsonifier::string();
value = newString.get<jsonifier::string>();
} else {
value = newString.operator uint64_t();
value = newString.get<uint64_t>();
}
}
};
Expand Down
45 changes: 23 additions & 22 deletions Include/discordcoreapi/Utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -534,7 +536,6 @@ namespace discord_core_api {
/// @brief Permissions_base class, for representing and manipulating permission values.
template<typename value_type> 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.
Expand Down
Loading

0 comments on commit 65da963

Please sign in to comment.