mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Update WIP discord and some vendors.
CPR has features disabled and PCRE is fully disabled until updated to new code.
This commit is contained in:
parent
e0761bf3b9
commit
9298065cef
@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(SqMod)
|
||||
|
||||
# This plug-in only works on 64-bit
|
||||
@ -7,8 +7,7 @@ if(CMAKE_SIZEOF_VOID_P EQUAL 4)
|
||||
endif()
|
||||
|
||||
# Tell CMake where to find our scripts
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/vendor/POCO/cmake)
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ${PROJECT_SOURCE_DIR}/vendor/POCO/cmake)
|
||||
|
||||
# Several plugin options
|
||||
option(ENABLE_API21 "Build for 2.1 API." OFF)
|
||||
@ -20,85 +19,12 @@ option(ENABLE_BUILTIN_MYSQL_C "Enable built-in MySQL connector library" OFF)
|
||||
if(WIN32 AND MINGW)
|
||||
option(COPY_DEPENDENCIES "Copy dependent DLLs into the deps folder." OFF)
|
||||
endif()
|
||||
# Discord suppport
|
||||
option(ENABLE_DISCORD "Enable built-in Discord support." ON)
|
||||
|
||||
# C++14 is mandatory
|
||||
set(CPP_STD_NUMBER 14)
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
# C++ standard availability check
|
||||
if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU)+")
|
||||
# Specific flags
|
||||
set(CPP_STD_COMPILER_FLAG "-std=c++14")
|
||||
# Don't even bother with previous version
|
||||
if(CPP_STD_NUMBER LESS 20 AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
|
||||
check_cxx_compiler_flag(-std=c++20 HAVE_FLAG_STD_CXX20)
|
||||
check_cxx_compiler_flag(-std=c++2a HAVE_FLAG_STD_CXX2A)
|
||||
if(HAVE_FLAG_STD_CXX20 OR HAVE_FLAG_STD_CXX2A)
|
||||
# We can use C++20
|
||||
set(CPP_STD_NUMBER 20)
|
||||
# Specific flags
|
||||
if (HAVE_FLAG_STD_CXX2A AND NOT HAVE_FLAG_STD_CXX20)
|
||||
set(CPP_STD_COMPILER_FLAG "-std=c++2a")
|
||||
else()
|
||||
set(CPP_STD_COMPILER_FLAG "-std=c++20")
|
||||
endif()
|
||||
# Need these workarounds for older CMake
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
|
||||
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
|
||||
set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++20")
|
||||
set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++20")
|
||||
elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
|
||||
set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++2a")
|
||||
set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++2a")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
# Don't even bother with previous version
|
||||
if(CPP_STD_NUMBER LESS 17 AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
|
||||
check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17)
|
||||
check_cxx_compiler_flag(-std=c++1z HAVE_FLAG_STD_CXX1Z)
|
||||
if(HAVE_FLAG_STD_CXX17 OR HAVE_FLAG_STD_CXX1Z)
|
||||
# We can use C++17
|
||||
set(CPP_STD_NUMBER 17)
|
||||
# Specific flags
|
||||
if (HAVE_FLAG_STD_CXX1Z AND NOT HAVE_FLAG_STD_CXX17)
|
||||
set(CPP_STD_COMPILER_FLAG "-std=c++1z")
|
||||
else()
|
||||
set(CPP_STD_COMPILER_FLAG "-std=c++17")
|
||||
endif()
|
||||
# Need these workarounds for older CMake
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
|
||||
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
|
||||
set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++17")
|
||||
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17")
|
||||
elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
|
||||
set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z")
|
||||
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
# C++14 is mandatory
|
||||
set(CPP_STD_NUMBER 14)
|
||||
endif()
|
||||
|
||||
message(STATUS "SqMod: Using C++${CPP_STD_NUMBER} standard.")
|
||||
|
||||
# Default to the identified standard
|
||||
if(CMAKE_VERSION VERSION_LESS "3.1")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPP_STD_COMPILER_FLAG}")
|
||||
else()
|
||||
# Apparently the above does not work with cmake from on debian 8
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPP_STD_COMPILER_FLAG}")
|
||||
# F* you too Debian. What can I say.
|
||||
if(CMAKE_VERSION VERSION_LESS "3.8.0" AND CPP_STD_NUMBER LESS 17)
|
||||
# Try the standard method as well
|
||||
set(CMAKE_CXX_STANDARD ${CPP_STD_NUMBER})
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
endif()
|
||||
endif()
|
||||
# C++17 is mandatory (globally)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Strip binary
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s -g")
|
||||
|
92
cmake/_FindOpus.cmake
Normal file
92
cmake/_FindOpus.cmake
Normal file
@ -0,0 +1,92 @@
|
||||
############################################################################
|
||||
# FindOpus.cmake
|
||||
# Copyright (C) 2014-2023 Belledonne Communications, Grenoble France
|
||||
#
|
||||
############################################################################
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
############################################################################
|
||||
#
|
||||
# Find the opus library.
|
||||
#
|
||||
# Targets
|
||||
# ^^^^^^^
|
||||
#
|
||||
# The following targets may be defined:
|
||||
#
|
||||
# opus - If the opus library has been found
|
||||
#
|
||||
#
|
||||
# Result variables
|
||||
# ^^^^^^^^^^^^^^^^
|
||||
#
|
||||
# This module will set the following variables in your project:
|
||||
#
|
||||
# Opus_FOUND - The opus library has been found
|
||||
# Opus_TARGET - The name of the CMake target for the opus library
|
||||
#
|
||||
# This module may set the following variable:
|
||||
#
|
||||
# Opus_USE_BUILD_INTERFACE - If the opus library is used from its build directory
|
||||
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
set(_Opus_REQUIRED_VARS Opus_TARGET)
|
||||
set(_Opus_CACHE_VARS ${_Opus_REQUIRED_VARS})
|
||||
|
||||
if(TARGET opus)
|
||||
|
||||
set(Opus_TARGET opus)
|
||||
set(Opus_USE_BUILD_INTERFACE TRUE)
|
||||
|
||||
else()
|
||||
|
||||
find_path(_Opus_INCLUDE_DIRS
|
||||
NAMES opus/opus.h
|
||||
PATH_SUFFIXES include
|
||||
)
|
||||
|
||||
find_library(_Opus_LIBRARY NAMES opus)
|
||||
if(_Opus_LIBRARY)
|
||||
find_library(_m_LIBRARY NAMES m)
|
||||
endif()
|
||||
|
||||
if(_Opus_INCLUDE_DIRS AND _Opus_LIBRARY)
|
||||
add_library(opus UNKNOWN IMPORTED)
|
||||
if(WIN32)
|
||||
set_target_properties(opus PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_Opus_INCLUDE_DIRS}"
|
||||
IMPORTED_IMPLIB "${_Opus_LIBRARY}"
|
||||
IMPORTED_LINK_INTERFACE_LIBRARIES "${_m_LIBRARY}"
|
||||
)
|
||||
else()
|
||||
set_target_properties(opus PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${_Opus_INCLUDE_DIRS}"
|
||||
IMPORTED_LOCATION "${_Opus_LIBRARY}"
|
||||
IMPORTED_LINK_INTERFACE_LIBRARIES "${_m_LIBRARY}"
|
||||
)
|
||||
endif()
|
||||
|
||||
set(Opus_TARGET opus)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
find_package_handle_standard_args(Opus
|
||||
REQUIRED_VARS ${_Opus_REQUIRED_VARS}
|
||||
)
|
||||
mark_as_advanced(${_Opus_CACHE_VARS})
|
@ -92,6 +92,7 @@ add_library(SqModule MODULE SqBase.hpp Main.cpp
|
||||
Library/Utils.cpp Library/Utils.hpp
|
||||
Library/Utils/Announce.cpp Library/Utils/Announce.hpp
|
||||
Library/Utils/String.cpp Library/Utils/String.hpp
|
||||
Library/Utils/Template.cpp Library/Utils/Template.hpp
|
||||
Library/Utils/Vector.cpp Library/Utils/Vector.hpp
|
||||
Library/XML.cpp Library/XML.hpp
|
||||
Library/ZMQ.cpp Library/ZMQ.hpp
|
||||
@ -118,6 +119,8 @@ add_library(SqModule MODULE SqBase.hpp Main.cpp
|
||||
Register.cpp
|
||||
Exports.cpp
|
||||
)
|
||||
# The module requires C++ 17
|
||||
set_property(TARGET SqModule PROPERTY CXX_STANDARD 17)
|
||||
# Various definitions required by the plug-in
|
||||
target_compile_definitions(SqModule PRIVATE SCRAT_USE_EXCEPTIONS=1)
|
||||
# SDK targeting
|
||||
@ -135,7 +138,7 @@ if(WIN32 OR MINGW)
|
||||
target_link_libraries(SqModule wsock32 ws2_32 shlwapi)
|
||||
endif()
|
||||
# Link to base libraries
|
||||
target_link_libraries(SqModule RPMalloc Squirrel fmt::fmt SimpleINI TinyDir xxHash ConcurrentQueue SAJSON CPR UTF8Lib PUGIXML CivetWeb maxminddb libzmq-static)
|
||||
target_link_libraries(SqModule RPMalloc Squirrel fmt::fmt SimpleINI TinyDir xxHash ConcurrentQueue SAJSON CPR UTF8Lib PUGIXML CivetWeb inja maxminddb libzmq-static)
|
||||
# Link to POCO libraries
|
||||
target_link_libraries(SqModule Poco::Foundation Poco::Crypto Poco::Data Poco::Net)
|
||||
# Does POCO have SQLite support?
|
||||
@ -174,6 +177,31 @@ if(POSTGRESQL_FOUND)
|
||||
# Inform the plug-in that it can make use of this library
|
||||
target_compile_definitions(SqModule PRIVATE SQMOD_POCO_HAS_POSTGRESQL=1)
|
||||
endif()
|
||||
# Is Discord support enabled?
|
||||
if(ENABLE_DISCORD)
|
||||
target_link_libraries(SqModule dpp)
|
||||
target_sources(SqModule PRIVATE
|
||||
Library/Discord.cpp Library/Discord.hpp
|
||||
Library/Discord/Application.hpp Library/Discord/Application.cpp
|
||||
Library/Discord/Automod.hpp Library/Discord/Automod.cpp
|
||||
Library/Discord/Channel.hpp Library/Discord/Channel.cpp
|
||||
Library/Discord/Client.hpp Library/Discord/Client.cpp
|
||||
Library/Discord/Cluster.hpp Library/Discord/Cluster.cpp
|
||||
Library/Discord/Command.hpp Library/Discord/Command.cpp
|
||||
Library/Discord/Constants.hpp Library/Discord/Constants.cpp
|
||||
Library/Discord/Events.hpp Library/Discord/Events.cpp
|
||||
Library/Discord/Guild.hpp Library/Discord/Guild.cpp
|
||||
Library/Discord/Integration.hpp Library/Discord/Integration.cpp
|
||||
Library/Discord/Message.hpp Library/Discord/Message.cpp
|
||||
Library/Discord/Misc.hpp Library/Discord/Misc.cpp
|
||||
Library/Discord/Presence.hpp Library/Discord/Presence.cpp
|
||||
Library/Discord/Role.hpp Library/Discord/Role.cpp
|
||||
Library/Discord/User.hpp Library/Discord/User.cpp
|
||||
Library/Discord/Utilities.hpp Library/Discord/Utilities.cpp
|
||||
)
|
||||
# Inform the plug-in that discord is enabled
|
||||
target_compile_definitions(SqModule PRIVATE SQMOD_DISCORD=1)
|
||||
endif()
|
||||
# Determine if build mode
|
||||
if(${CMAKE_BUILD_TYPE} MATCHES "(Release)+")
|
||||
target_compile_definitions(SqModule PRIVATE NDEBUG=1)
|
||||
@ -218,6 +246,7 @@ else()
|
||||
endif()
|
||||
# Copy module into the plug-ins folder
|
||||
add_custom_command(TARGET SqModule POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:SqModule> "${PROJECT_SOURCE_DIR}/bin/plugins")
|
||||
|
||||
# Copy several dependent DLLs on windows to make distribution easier (used mainly by people that distribute builds)
|
||||
if(WIN32 AND MINGW AND COPY_DEPENDENCIES)
|
||||
get_filename_component(MINGW_BIN_PATH ${CMAKE_C_COMPILER} DIRECTORY REALPATH)
|
||||
|
@ -49,6 +49,9 @@ extern void TerminateRoutines();
|
||||
extern void TerminateCommands();
|
||||
extern void TerminateSignals();
|
||||
extern void TerminateNet();
|
||||
#ifdef SQMOD_DISCORD
|
||||
extern void TerminateDiscord();
|
||||
#endif
|
||||
extern void TerminatePocoNet();
|
||||
extern void TerminatePocoData();
|
||||
|
||||
@ -553,6 +556,11 @@ void Core::Terminate(bool shutdown)
|
||||
// Release network
|
||||
TerminateNet();
|
||||
cLogDbg(m_Verbosity >= 1, "Network terminated");
|
||||
// Release DPP
|
||||
#ifdef SQMOD_DISCORD
|
||||
TerminateDiscord();
|
||||
cLogDbg(m_Verbosity >= 1, "Discord terminated");
|
||||
#endif
|
||||
// Release Poco statement results
|
||||
TerminatePocoNet();
|
||||
TerminatePocoData();
|
||||
|
@ -19,6 +19,19 @@ SQMOD_DECL_TYPENAME(SqCpProxies, _SC("SqCprProxies"))
|
||||
SQMOD_DECL_TYPENAME(SqCpRedirect, _SC("SqCprRedirect"))
|
||||
SQMOD_DECL_TYPENAME(SqCpSession, _SC("SqCprSession"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
struct CurlInit
|
||||
{
|
||||
CurlInit()
|
||||
{
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
}
|
||||
~CurlInit()
|
||||
{
|
||||
curl_global_cleanup();
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Common session action implementation.
|
||||
*/
|
||||
@ -658,13 +671,11 @@ void Register_CURL(HSQUIRRELVM vm)
|
||||
.Func(_SC("SetTimeout"), &CpSession::SetTimeout_)
|
||||
.Func(_SC("SetConnectTimeout"), &CpSession::SetConnectTimeout_)
|
||||
.FmtFunc(_SC("SetAuth"), &CpSession::SetAuth_)
|
||||
.FmtFunc(_SC("SetDigest"), &CpSession::SetDigest_)
|
||||
.FmtFunc(_SC("SetUserAgent"), &CpSession::SetUserAgent_)
|
||||
.Func(_SC("SetPayload"), &CpSession::SetPayload_)
|
||||
.Func(_SC("YieldPayload"), &CpSession::YieldPayload)
|
||||
.Func(_SC("SetProxies"), &CpSession::SetProxies_)
|
||||
.Func(_SC("YieldProxies"), &CpSession::YieldProxies)
|
||||
.FmtFunc(_SC("SetNTLM"), &CpSession::SetNTLM_)
|
||||
.Func(_SC("SetRedirect"), &CpSession::SetRedirect_)
|
||||
.Func(_SC("SetCookies"), &CpSession::SetCookies_)
|
||||
.FmtFunc(_SC("SetBody"), &CpSession::SetBody_)
|
||||
|
@ -538,7 +538,7 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger Size() const
|
||||
{
|
||||
return static_cast< SQInteger >(cpr::Cookies::map_.size());
|
||||
return static_cast< SQInteger >(cpr::Cookies::cookies_.size());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -546,7 +546,7 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
SQMOD_NODISCARD bool Empty() const
|
||||
{
|
||||
return cpr::Cookies::map_.empty();
|
||||
return cpr::Cookies::cookies_.empty();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -554,7 +554,7 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
void Clear()
|
||||
{
|
||||
cpr::Cookies::map_.clear();
|
||||
cpr::Cookies::cookies_.clear();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -562,7 +562,12 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger Count(StackStrF & key) const
|
||||
{
|
||||
return static_cast< SQInteger >(cpr::Cookies::map_.count(key.ToStr()));
|
||||
SQInteger cnt = 0;
|
||||
for (const auto & c : cpr::Cookies::cookies_)
|
||||
{
|
||||
if (c.GetName().compare(0, static_cast<size_t>(key.mLen), key.mPtr) == 0) ++cnt;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -570,14 +575,14 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
bool Erase(StackStrF & key)
|
||||
{
|
||||
auto itr = cpr::Cookies::map_.find(key.ToStr());
|
||||
// Does it exist?
|
||||
if (itr == cpr::Cookies::map_.end())
|
||||
{
|
||||
return false; // Nope
|
||||
}
|
||||
// Erase it
|
||||
cpr::Cookies::map_.erase(itr);
|
||||
// auto itr = cpr::Cookies::cookies_.find(key.ToStr());
|
||||
// // Does it exist?
|
||||
// if (itr == cpr::Cookies::cookies_.end())
|
||||
// {
|
||||
// return false; // Nope
|
||||
// }
|
||||
// // Erase it
|
||||
// cpr::Cookies::cookies_.erase(itr);
|
||||
// Erased
|
||||
return true;
|
||||
}
|
||||
@ -587,7 +592,7 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
SQMOD_NODISCARD bool Has(StackStrF & key) const
|
||||
{
|
||||
return cpr::Cookies::map_.find(key.ToStr()) != cpr::Cookies::map_.end();
|
||||
return false;//cpr::Cookies::cookies_.find(key.ToStr()) != cpr::Cookies::cookies_.end()
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -595,14 +600,15 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
SQMOD_NODISCARD std::string & Get(StackStrF & key)
|
||||
{
|
||||
auto itr = cpr::Cookies::map_.find(key.ToStr());
|
||||
// Does it exist?
|
||||
if (itr == cpr::Cookies::map_.end())
|
||||
{
|
||||
STHROWF("No cookie named: %s", key.mPtr);
|
||||
}
|
||||
// auto itr = cpr::Cookies::cookies_.find(key.ToStr());
|
||||
// // Does it exist?
|
||||
// if (itr == cpr::Cookies::cookies_.end())
|
||||
// {
|
||||
// STHROWF("No cookie named: %s", key.mPtr);
|
||||
// }
|
||||
static std::string s;
|
||||
// Return it
|
||||
return itr->second;
|
||||
return s;// itr->second;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -610,7 +616,7 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
void Set(StackStrF & key, StackStrF & val)
|
||||
{
|
||||
cpr::Cookies::map_[key.ToStr()] = val.ToStr();
|
||||
//cpr::Cookies::cookies_[key.ToStr()] = val.ToStr();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -618,9 +624,9 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
void Each(Function & fn) const
|
||||
{
|
||||
for (const auto & p : cpr::Cookies::map_)
|
||||
for (const auto & c : cpr::Cookies::cookies_)
|
||||
{
|
||||
fn.Execute(p.first, p.second);
|
||||
fn.Execute(c);
|
||||
}
|
||||
}
|
||||
|
||||
@ -629,9 +635,9 @@ struct CpCookies : public cpr::Cookies
|
||||
*/
|
||||
void While(Function & fn) const
|
||||
{
|
||||
for (const auto & p : cpr::Cookies::map_)
|
||||
for (const auto & c : cpr::Cookies::cookies_)
|
||||
{
|
||||
auto ret = fn.Eval(p.first, p.second);
|
||||
auto ret = fn.Eval(c);
|
||||
// (null || true) == continue & false == break
|
||||
if (!ret.IsNull() || !ret.Cast< bool >())
|
||||
{
|
||||
@ -863,7 +869,7 @@ struct CpResponse : public cpr::Response
|
||||
STHROWF("Invalid response instance");
|
||||
}
|
||||
// Retrieve the info vector
|
||||
auto vec = cpr::Response::GetCertInfo();
|
||||
auto vec = cpr::Response::GetCertInfos();
|
||||
// Create a script array
|
||||
Array arr(SqVM(), static_cast< SQInteger >(vec.size()));
|
||||
// Populate the array with vector elements
|
||||
@ -1619,7 +1625,7 @@ struct CpRedirect : public cpr::Redirect
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit CpRedirect(SQInteger maximum)
|
||||
: cpr::Redirect(static_cast< long >(maximum), true, cpr::PostRedirectFlags::POST_ALL)
|
||||
: cpr::Redirect(static_cast< long >(maximum), true, false, cpr::PostRedirectFlags::POST_ALL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -1627,15 +1633,23 @@ struct CpRedirect : public cpr::Redirect
|
||||
* Explicit constructor.
|
||||
*/
|
||||
CpRedirect(SQInteger maximum, bool follow)
|
||||
: cpr::Redirect(static_cast< long >(maximum), follow, cpr::PostRedirectFlags::POST_ALL)
|
||||
: cpr::Redirect(static_cast< long >(maximum), follow, false, cpr::PostRedirectFlags::POST_ALL)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
CpRedirect(SQInteger maximum, bool follow, SQInteger post_flags)
|
||||
: cpr::Redirect(static_cast< long >(maximum), follow, static_cast< cpr::PostRedirectFlags >(post_flags))
|
||||
CpRedirect(SQInteger maximum, bool follow, bool cont_send_cred)
|
||||
: cpr::Redirect(static_cast< long >(maximum), follow, cont_send_cred, cpr::PostRedirectFlags::POST_ALL)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
CpRedirect(SQInteger maximum, bool follow, bool cont_send_cred, SQInteger post_flags)
|
||||
: cpr::Redirect(static_cast< long >(maximum), follow, cont_send_cred, static_cast< cpr::PostRedirectFlags >(post_flags))
|
||||
{
|
||||
}
|
||||
|
||||
@ -1879,20 +1893,10 @@ struct CpSession : public cpr::Session
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify auth option.
|
||||
*/
|
||||
CpSession & SetAuth_(StackStrF & username, StackStrF & password)
|
||||
CpSession & SetAuth_(StackStrF & username, StackStrF & password, SQInteger mode)
|
||||
{
|
||||
LockCheck();
|
||||
cpr::Session::SetAuth(cpr::Authentication(username.ToStr(), password.ToStr()));
|
||||
return *this; // Allow chaining
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify digest option.
|
||||
*/
|
||||
CpSession & SetDigest_(StackStrF & username, StackStrF & password)
|
||||
{
|
||||
LockCheck();
|
||||
cpr::Session::SetAuth(cpr::Digest(username.ToStr(), password.ToStr()));
|
||||
cpr::Session::SetAuth(cpr::Authentication(username.ToStr(), password.ToStr(), static_cast<cpr::AuthMode>(mode)));
|
||||
return *this; // Allow chaining
|
||||
}
|
||||
|
||||
@ -1960,16 +1964,6 @@ struct CpSession : public cpr::Session
|
||||
//{
|
||||
//}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify NTLM option.
|
||||
*/
|
||||
CpSession & SetNTLM_(StackStrF & username, StackStrF & password)
|
||||
{
|
||||
LockCheck();
|
||||
cpr::Session::SetNTLM(cpr::NTLM(username.ToStr(), password.ToStr()));
|
||||
return *this; // Allow chaining
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify redirect option.
|
||||
*/
|
||||
|
51
module/Library/Discord.cpp
Normal file
51
module/Library/Discord.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord.hpp"
|
||||
#include "Library/Discord/Cluster.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void TerminateDiscord()
|
||||
{
|
||||
// Go over all clusters and try to terminate them
|
||||
for (DpCluster * inst = DpCluster::sHead; inst && inst->mNext != DpCluster::sHead; inst = inst->mNext)
|
||||
{
|
||||
inst->Terminate(); // Terminate the cluster
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void ProcessDiscord()
|
||||
{
|
||||
// Go over all clusters and allow them to process data
|
||||
for (DpCluster * inst = DpCluster::sHead; inst && inst->mNext != DpCluster::sHead; inst = inst->mNext)
|
||||
{
|
||||
inst->Process();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern void Register_Discord_Constants(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_Discord_Events(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_Discord_Misc(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_Discord_Cluster(HSQUIRRELVM vm, Table & ns);
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Discord(HSQUIRRELVM vm)
|
||||
{
|
||||
Table ns(vm);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Register_Discord_Constants(vm, ns);
|
||||
{
|
||||
Table ens(vm);
|
||||
Register_Discord_Events(vm, ens);
|
||||
ns.Bind(_SC("Event"), ens);
|
||||
}
|
||||
Register_Discord_Misc(vm, ns);
|
||||
Register_Discord_Cluster(vm, ns);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
RootTable(vm).Bind(_SC("SqDiscord"), ns);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
17
module/Library/Discord.hpp
Normal file
17
module/Library/Discord.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/IO/Buffer.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <atomic>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqratFunction.h>
|
||||
#include <concurrentqueue.h>
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/Application.cpp
Normal file
9
module/Library/Discord/Application.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Application.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
13
module/Library/Discord/Application.hpp
Normal file
13
module/Library/Discord/Application.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/Automod.cpp
Normal file
9
module/Library/Discord/Automod.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Automod.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
13
module/Library/Discord/Automod.hpp
Normal file
13
module/Library/Discord/Automod.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/Channel.cpp
Normal file
9
module/Library/Discord/Channel.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Channel.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
13
module/Library/Discord/Channel.hpp
Normal file
13
module/Library/Discord/Channel.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/Client.cpp
Normal file
9
module/Library/Discord/Client.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Client.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
13
module/Library/Discord/Client.hpp
Normal file
13
module/Library/Discord/Client.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
496
module/Library/Discord/Cluster.cpp
Normal file
496
module/Library/Discord/Cluster.cpp
Normal file
@ -0,0 +1,496 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Cluster.hpp"
|
||||
#include "Library/Discord/Events.hpp"
|
||||
#include "Logger.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDpClusterTypename, _SC("SqDiscordCluster"))
|
||||
SQMOD_DECL_TYPENAME(SqDpClusterOptionsTypename, _SC("SqDiscordClusterOptions"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
DpCluster::DpCluster(DpClusterOptions & o)
|
||||
: Base(), mQueue(4096)
|
||||
, mC(std::make_unique< dpp::cluster >(o.mToken, o.mIntents, o.mShards, o.mClusterID, o.mMaxClusters, o.mCompressed, o.mPolicy, o.mRequestThreads, o.mRequestThreadsRaw))
|
||||
, mSqEvents(), mEvents(), mEventsHandle()
|
||||
{
|
||||
// Make sure all event handles are not valid
|
||||
mEventsHandle.fill(0);
|
||||
// Initialize event signals
|
||||
InitEvents();
|
||||
// Proxy library logging to our logger
|
||||
if (!o.mCustomLogging)
|
||||
{
|
||||
mC->on_log([](const dpp::log_t& event) {
|
||||
switch (event.severity)
|
||||
{
|
||||
case dpp::ll_trace: Logger::Get().Send(LOGL_DBG, true, event.message.c_str(), event.message.size()); break;
|
||||
case dpp::ll_debug: Logger::Get().Send(LOGL_DBG, true, event.message.c_str(), event.message.size()); break;
|
||||
case dpp::ll_info: Logger::Get().Send(LOGL_INF, true, event.message.c_str(), event.message.size()); break;
|
||||
case dpp::ll_warning: Logger::Get().Send(LOGL_WRN, true, event.message.c_str(), event.message.size()); break;
|
||||
case dpp::ll_error: Logger::Get().Send(LOGL_ERR, true, event.message.c_str(), event.message.size()); break;
|
||||
case dpp::ll_critical: Logger::Get().Send(LOGL_FTL, true, event.message.c_str(), event.message.size()); break;
|
||||
default: break;
|
||||
}
|
||||
});
|
||||
}
|
||||
// Remember this instance
|
||||
ChainInstance();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD LightObj EventToScriptObject(uint8_t type, uintptr_t data);
|
||||
void EventInvokeCleanup(uint8_t type, uintptr_t data);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::Process(bool force)
|
||||
{
|
||||
// Is there a valid connection?
|
||||
if (!mC && !force)
|
||||
{
|
||||
return; // No point in going forward
|
||||
}
|
||||
EventItem event;
|
||||
// Retrieve each event individually and process it
|
||||
for (size_t count = mQueue.size_approx(), n = 0; n <= count; ++n)
|
||||
{
|
||||
// Try to get an event from the queue
|
||||
if (mQueue.try_dequeue(event))
|
||||
{
|
||||
// Fetch the type of event
|
||||
const auto id = static_cast< size_t >(event->GetEventID());
|
||||
// Is this a valid event and is anyone listening to it?
|
||||
if (!(event->mFrom) || !(mEvents[id].first) || mEvents[id].first->IsEmpty())
|
||||
{
|
||||
continue; // Move on
|
||||
}
|
||||
// Transform the event instance into a script object
|
||||
LightObj obj = event->ToScriptObject();
|
||||
// Allow the script to take ownership of the event instance now
|
||||
[[maybe_unused]] auto p = event.release();
|
||||
// Don't abort everything down the line for an error caused by a discord event handler
|
||||
try {
|
||||
(*mEvents[id].first)(obj); // Forward the call to the associated signal
|
||||
} catch (const std::exception & e) {
|
||||
LogErr("Squirrel exception caught in (%s) discord event", p->GetEventName().data());
|
||||
LogSInf("Message: %s", e.what());
|
||||
}
|
||||
// Allow the event instance to clean itself (i.e. invalidate itself)
|
||||
// User should not keep this event object for later use!
|
||||
// Event data is accessible only during the event signal
|
||||
p->Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::Terminate()
|
||||
{
|
||||
// Stop the cluster connection
|
||||
if (mC) mC->shutdown();
|
||||
// Release associated script objects
|
||||
mSqEvents.Release();
|
||||
// Release event signal objects
|
||||
DropEvents();
|
||||
// Delete the cluster instance
|
||||
mC.reset();
|
||||
}
|
||||
|
||||
// ================================================================================================
|
||||
void Register_Discord_Cluster(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
ns.Bind(_SC("ClusterOptions"),
|
||||
Class< DpClusterOptions >(vm, SqDpClusterOptionsTypename::Str)
|
||||
// Constructors
|
||||
.Ctor< StackStrF & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpClusterOptionsTypename::Fn)
|
||||
);
|
||||
|
||||
ns.Bind(_SC("Cluster"),
|
||||
Class< DpCluster, NoCopy< DpCluster > >(vm, SqDpClusterTypename::Str)
|
||||
// Constructors
|
||||
.Ctor< DpClusterOptions & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpClusterTypename::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("On"), &DpCluster::GetEvents)
|
||||
// Member Methods
|
||||
.Func(_SC("Start"), &DpCluster::Start)
|
||||
.Func(_SC("Stop"), &DpCluster::Stop)
|
||||
.Func(_SC("EnableEvent"), &DpCluster::EnableEvent)
|
||||
.Func(_SC("DisableEvent"), &DpCluster::DisableEvent)
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
DpCluster & DpCluster::EnableEvent(SQInteger id)
|
||||
{
|
||||
// Retrieve managed cluster instance
|
||||
auto & c = Valid("enable event on a");
|
||||
// Assigned event handle
|
||||
dpp::event_handle eh = 0;
|
||||
// Make sure the specified event handle is valid
|
||||
if (id >= 0 && id < static_cast< SQInteger >(DpEventID::Max))
|
||||
{
|
||||
eh = mEventsHandle[static_cast< size_t >(id)]; // Get the real handle
|
||||
}
|
||||
// Is this event already enabled?
|
||||
if (eh != 0)
|
||||
{
|
||||
return *this; // Job already done
|
||||
}
|
||||
// Identify event type
|
||||
switch (id)
|
||||
{
|
||||
case DpEventID::VoiceStateUpdate: eh = c.on_voice_state_update.attach([this](const dpp::voice_state_update_t & e) { OnVoiceStateUpdate(e); }); break;
|
||||
case DpEventID::VoiceClientDisconnect: eh = c.on_voice_client_disconnect.attach([this](const dpp::voice_client_disconnect_t & e) { OnVoiceClientDisconnect(e); }); break;
|
||||
case DpEventID::VoiceClientSpeaking: eh = c.on_voice_client_speaking.attach([this](const dpp::voice_client_speaking_t & e) { OnVoiceClientSpeaking(e); }); break;
|
||||
case DpEventID::Log: eh = c.on_log.attach([this](const dpp::log_t & e) { OnLog(e); }); break;
|
||||
case DpEventID::GuildJoinRequestDelete: eh = c.on_guild_join_request_delete.attach([this](const dpp::guild_join_request_delete_t & e) { OnGuildJoinRequestDelete(e); }); break;
|
||||
case DpEventID::InteractionCreate: eh = c.on_interaction_create.attach([this](const dpp::interaction_create_t & e) { OnInteractionCreate(e); }); break;
|
||||
case DpEventID::SlashCommand: eh = c.on_slashcommand.attach([this](const dpp::slashcommand_t & e) { OnSlashCommand(e); }); break;
|
||||
case DpEventID::ButtonClick: eh = c.on_button_click.attach([this](const dpp::button_click_t & e) { OnButtonClick(e); }); break;
|
||||
case DpEventID::AutoComplete: eh = c.on_autocomplete.attach([this](const dpp::autocomplete_t & e) { OnAutoComplete(e); }); break;
|
||||
case DpEventID::SelectClick: eh = c.on_select_click.attach([this](const dpp::select_click_t & e) { OnSelectClick(e); }); break;
|
||||
case DpEventID::MessageContextMenu: eh = c.on_message_context_menu.attach([this](const dpp::message_context_menu_t & e) { OnMessageContextMenu(e); }); break;
|
||||
case DpEventID::UserContextMenu: eh = c.on_user_context_menu.attach([this](const dpp::user_context_menu_t & e) { OnUserContextMenu(e); }); break;
|
||||
case DpEventID::FormSubmit: eh = c.on_form_submit.attach([this](const dpp::form_submit_t & e) { OnFormSubmit(e); }); break;
|
||||
case DpEventID::GuildDelete: eh = c.on_guild_delete.attach([this](const dpp::guild_delete_t & e) { OnGuildDelete(e); }); break;
|
||||
case DpEventID::ChannelDelete: eh = c.on_channel_delete.attach([this](const dpp::channel_delete_t & e) { OnChannelDelete(e); }); break;
|
||||
case DpEventID::ChannelUpdate: eh = c.on_channel_update.attach([this](const dpp::channel_update_t & e) { OnChannelUpdate(e); }); break;
|
||||
case DpEventID::Ready: eh = c.on_ready.attach([this](const dpp::ready_t & e) { OnReady(e); }); break;
|
||||
case DpEventID::MessageDelete: eh = c.on_message_delete.attach([this](const dpp::message_delete_t & e) { OnMessageDelete(e); }); break;
|
||||
case DpEventID::GuildMemberRemove: eh = c.on_guild_member_remove.attach([this](const dpp::guild_member_remove_t & e) { OnGuildMemberRemove(e); }); break;
|
||||
case DpEventID::Resumed: eh = c.on_resumed.attach([this](const dpp::resumed_t & e) { OnResumed(e); }); break;
|
||||
case DpEventID::GuildRoleCreate: eh = c.on_guild_role_create.attach([this](const dpp::guild_role_create_t & e) { OnGuildRoleCreate(e); }); break;
|
||||
case DpEventID::TypingStart: eh = c.on_typing_start.attach([this](const dpp::typing_start_t & e) { OnTypingStart(e); }); break;
|
||||
case DpEventID::MessageReactionAdd: eh = c.on_message_reaction_add.attach([this](const dpp::message_reaction_add_t & e) { OnMessageReactionAdd(e); }); break;
|
||||
case DpEventID::GuildMembersChunk: eh = c.on_guild_members_chunk.attach([this](const dpp::guild_members_chunk_t & e) { OnGuildMembersChunk(e); }); break;
|
||||
case DpEventID::MessageReactionRemove: eh = c.on_message_reaction_remove.attach([this](const dpp::message_reaction_remove_t & e) { OnMessageReactionRemove(e); }); break;
|
||||
case DpEventID::GuildCreate: eh = c.on_guild_create.attach([this](const dpp::guild_create_t & e) { OnGuildCreate(e); }); break;
|
||||
case DpEventID::ChannelCreate: eh = c.on_channel_create.attach([this](const dpp::channel_create_t & e) { OnChannelCreate(e); }); break;
|
||||
case DpEventID::MessageReactionRemoveEmoji: eh = c.on_message_reaction_remove_emoji.attach([this](const dpp::message_reaction_remove_emoji_t & e) { OnMessageReactionRemoveEmoji(e); }); break;
|
||||
case DpEventID::MessageDeleteDulk: eh = c.on_message_delete_bulk.attach([this](const dpp::message_delete_bulk_t & e) { OnMessageDeleteDulk(e); }); break;
|
||||
case DpEventID::GuildRoleUpdate: eh = c.on_guild_role_update.attach([this](const dpp::guild_role_update_t & e) { OnGuildRoleUpdate(e); }); break;
|
||||
case DpEventID::GuildRoleDelete: eh = c.on_guild_role_delete.attach([this](const dpp::guild_role_delete_t & e) { OnGuildRoleDelete(e); }); break;
|
||||
case DpEventID::ChannelPinsUpdate: eh = c.on_channel_pins_update.attach([this](const dpp::channel_pins_update_t & e) { OnChannelPinsUpdate(e); }); break;
|
||||
case DpEventID::MessageReactionRemoveAll: eh = c.on_message_reaction_remove_all.attach([this](const dpp::message_reaction_remove_all_t & e) { OnMessageReactionRemoveAll(e); }); break;
|
||||
case DpEventID::VoiceServerUpdate: eh = c.on_voice_server_update.attach([this](const dpp::voice_server_update_t & e) { OnVoiceServerUpdate(e); }); break;
|
||||
case DpEventID::GuildEmojisUpdate: eh = c.on_guild_emojis_update.attach([this](const dpp::guild_emojis_update_t & e) { OnGuildEmojisUpdate(e); }); break;
|
||||
case DpEventID::GuildStickersUpdate: eh = c.on_guild_stickers_update.attach([this](const dpp::guild_stickers_update_t & e) { OnGuildStickersUpdate(e); }); break;
|
||||
case DpEventID::PresenceUpdate: eh = c.on_presence_update.attach([this](const dpp::presence_update_t & e) { OnPresenceUpdate(e); }); break;
|
||||
case DpEventID::WebhooksUpdate: eh = c.on_webhooks_update.attach([this](const dpp::webhooks_update_t & e) { OnWebhooksUpdate(e); }); break;
|
||||
case DpEventID::AutomodRuleCreate: eh = c.on_automod_rule_create.attach([this](const dpp::automod_rule_create_t & e) { OnAutomodRuleCreate(e); }); break;
|
||||
case DpEventID::AutomodRuleUpdate: eh = c.on_automod_rule_update.attach([this](const dpp::automod_rule_update_t & e) { OnAutomodRuleUpdate(e); }); break;
|
||||
case DpEventID::AutomodRuleDelete: eh = c.on_automod_rule_delete.attach([this](const dpp::automod_rule_delete_t & e) { OnAutomodRuleDelete(e); }); break;
|
||||
case DpEventID::AutomodRuleExecute: eh = c.on_automod_rule_execute.attach([this](const dpp::automod_rule_execute_t & e) { OnAutomodRuleExecute(e); }); break;
|
||||
case DpEventID::GuildMemberAdd: eh = c.on_guild_member_add.attach([this](const dpp::guild_member_add_t & e) { OnGuildMemberAdd(e); }); break;
|
||||
case DpEventID::InviteDelete: eh = c.on_invite_delete.attach([this](const dpp::invite_delete_t & e) { OnInviteDelete(e); }); break;
|
||||
case DpEventID::GuildUpdate: eh = c.on_guild_update.attach([this](const dpp::guild_update_t & e) { OnGuildUpdate(e); }); break;
|
||||
case DpEventID::GuildIntegrationsUpdate: eh = c.on_guild_integrations_update.attach([this](const dpp::guild_integrations_update_t & e) { OnGuildIntegrationsUpdate(e); }); break;
|
||||
case DpEventID::GuildMemberUpdate: eh = c.on_guild_member_update.attach([this](const dpp::guild_member_update_t & e) { OnGuildMemberUpdate(e); }); break;
|
||||
case DpEventID::InviteCreate: eh = c.on_invite_create.attach([this](const dpp::invite_create_t & e) { OnInviteCreate(e); }); break;
|
||||
case DpEventID::MessageUpdate: eh = c.on_message_update.attach([this](const dpp::message_update_t & e) { OnMessageUpdate(e); }); break;
|
||||
case DpEventID::UserUpdate: eh = c.on_user_update.attach([this](const dpp::user_update_t & e) { OnUserUpdate(e); }); break;
|
||||
case DpEventID::MessageCreate: eh = c.on_message_create.attach([this](const dpp::message_create_t & e) { OnMessageCreate(e); }); break;
|
||||
case DpEventID::GuildAuditLogEntryCreate: eh = c.on_guild_audit_log_entry_create.attach([this](const dpp::guild_audit_log_entry_create_t & e) { OnGuildAuditLogEntryCreate(e); }); break;
|
||||
case DpEventID::GuildBanAdd: eh = c.on_guild_ban_add.attach([this](const dpp::guild_ban_add_t & e) { OnGuildBanAdd(e); }); break;
|
||||
case DpEventID::GuildBanRemove: eh = c.on_guild_ban_remove.attach([this](const dpp::guild_ban_remove_t & e) { OnGuildBanRemove(e); }); break;
|
||||
case DpEventID::IntegrationCreate: eh = c.on_integration_create.attach([this](const dpp::integration_create_t & e) { OnIntegrationCreate(e); }); break;
|
||||
case DpEventID::IntegrationUpdate: eh = c.on_integration_update.attach([this](const dpp::integration_update_t & e) { OnIntegrationUpdate(e); }); break;
|
||||
case DpEventID::IntegrationDelete: eh = c.on_integration_delete.attach([this](const dpp::integration_delete_t & e) { OnIntegrationDelete(e); }); break;
|
||||
case DpEventID::ThreadCreate: eh = c.on_thread_create.attach([this](const dpp::thread_create_t & e) { OnThreadCreate(e); }); break;
|
||||
case DpEventID::ThreadUpdate: eh = c.on_thread_update.attach([this](const dpp::thread_update_t & e) { OnThreadUpdate(e); }); break;
|
||||
case DpEventID::ThreadDelete: eh = c.on_thread_delete.attach([this](const dpp::thread_delete_t & e) { OnThreadDelete(e); }); break;
|
||||
case DpEventID::ThreadListSync: eh = c.on_thread_list_sync.attach([this](const dpp::thread_list_sync_t & e) { OnThreadListSync(e); }); break;
|
||||
case DpEventID::ThreadMemberUpdate: eh = c.on_thread_member_update.attach([this](const dpp::thread_member_update_t & e) { OnThreadMemberUpdate(e); }); break;
|
||||
case DpEventID::ThreadMembersUpdate: eh = c.on_thread_members_update.attach([this](const dpp::thread_members_update_t & e) { OnThreadMembersUpdate(e); }); break;
|
||||
case DpEventID::GuildScheduledEventCreate: eh = c.on_guild_scheduled_event_create.attach([this](const dpp::guild_scheduled_event_create_t & e) { OnGuildScheduledEventCreate(e); }); break;
|
||||
case DpEventID::GuildScheduledEventUpdate: eh = c.on_guild_scheduled_event_update.attach([this](const dpp::guild_scheduled_event_update_t & e) { OnGuildScheduledEventUpdate(e); }); break;
|
||||
case DpEventID::GuildScheduledEventDelete: eh = c.on_guild_scheduled_event_delete.attach([this](const dpp::guild_scheduled_event_delete_t & e) { OnGuildScheduledEventDelete(e); }); break;
|
||||
case DpEventID::GuildScheduledEventUserAdd: eh = c.on_guild_scheduled_event_user_add.attach([this](const dpp::guild_scheduled_event_user_add_t & e) { OnGuildScheduledEventUserAdd(e); }); break;
|
||||
case DpEventID::GuildScheduledEventUserRemove: eh = c.on_guild_scheduled_event_user_remove.attach([this](const dpp::guild_scheduled_event_user_remove_t & e) { OnGuildScheduledEventUserRemove(e); }); break;
|
||||
case DpEventID::VoiceBufferSend: eh = c.on_voice_buffer_send.attach([this](const dpp::voice_buffer_send_t & e) { OnVoiceBufferSend(e); }); break;
|
||||
case DpEventID::VoiceUserTalking: eh = c.on_voice_user_talking.attach([this](const dpp::voice_user_talking_t & e) { OnVoiceUserTalking(e); }); break;
|
||||
case DpEventID::VoiceReady: eh = c.on_voice_ready.attach([this](const dpp::voice_ready_t & e) { OnVoiceReady(e); }); break;
|
||||
case DpEventID::VoiceReceive: eh = c.on_voice_receive.attach([this](const dpp::voice_receive_t & e) { OnVoiceReceive(e); }); break;
|
||||
case DpEventID::VoiceReceiveCombined: eh = c.on_voice_receive_combined.attach([this](const dpp::voice_receive_t & e) { OnVoiceReceiveCombined(e); }); break;
|
||||
case DpEventID::VoiceTrackMarker: eh = c.on_voice_track_marker.attach([this](const dpp::voice_track_marker_t & e) { OnVoiceTrackMarker(e); }); break;
|
||||
case DpEventID::StageInstanceCreate: eh = c.on_stage_instance_create.attach([this](const dpp::stage_instance_create_t & e) { OnStageInstanceCreate(e); }); break;
|
||||
case DpEventID::StageInstanceUpdate: eh = c.on_stage_instance_update.attach([this](const dpp::stage_instance_update_t & e) { OnStageInstanceUpdate(e); }); break;
|
||||
case DpEventID::StageInstanceDelete: eh = c.on_stage_instance_delete.attach([this](const dpp::stage_instance_delete_t & e) { OnStageInstanceDelete(e); }); break;
|
||||
case DpEventID::Max: // Fall through
|
||||
default: STHROWF("Invalid discord event identifier {}", id);
|
||||
}
|
||||
// Remember the designated event handle
|
||||
mEventsHandle[static_cast< size_t >(id)] = eh;
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
DpCluster & DpCluster::DisableEvent(SQInteger id)
|
||||
{
|
||||
// Retrieve managed cluster instance
|
||||
auto & c = Valid("disable event on a");
|
||||
// Assigned event handle
|
||||
dpp::event_handle eh = 0;
|
||||
// Make sure the specified event handle is valid
|
||||
if (id >= 0 && id < static_cast< SQInteger >(DpEventID::Max))
|
||||
{
|
||||
eh = mEventsHandle[static_cast< size_t >(id)]; // Get the real handle
|
||||
}
|
||||
// Is there anything attached to event dispatched?
|
||||
if (eh == 0)
|
||||
{
|
||||
return *this; // Nothing to detach
|
||||
}
|
||||
// Identify event type
|
||||
switch (id)
|
||||
{
|
||||
case DpEventID::VoiceStateUpdate: c.on_voice_state_update.detach(eh); break;
|
||||
case DpEventID::VoiceClientDisconnect: c.on_voice_client_disconnect.detach(eh); break;
|
||||
case DpEventID::VoiceClientSpeaking: c.on_voice_client_speaking.detach(eh); break;
|
||||
case DpEventID::Log: c.on_log.detach(eh); break;
|
||||
case DpEventID::GuildJoinRequestDelete: c.on_guild_join_request_delete.detach(eh); break;
|
||||
case DpEventID::InteractionCreate: c.on_interaction_create.detach(eh); break;
|
||||
case DpEventID::SlashCommand: c.on_slashcommand.detach(eh); break;
|
||||
case DpEventID::ButtonClick: c.on_button_click.detach(eh); break;
|
||||
case DpEventID::AutoComplete: c.on_autocomplete.detach(eh); break;
|
||||
case DpEventID::SelectClick: c.on_select_click.detach(eh); break;
|
||||
case DpEventID::MessageContextMenu: c.on_message_context_menu.detach(eh); break;
|
||||
case DpEventID::UserContextMenu: c.on_user_context_menu.detach(eh); break;
|
||||
case DpEventID::FormSubmit: c.on_form_submit.detach(eh); break;
|
||||
case DpEventID::GuildDelete: c.on_guild_delete.detach(eh); break;
|
||||
case DpEventID::ChannelDelete: c.on_channel_delete.detach(eh); break;
|
||||
case DpEventID::ChannelUpdate: c.on_channel_update.detach(eh); break;
|
||||
case DpEventID::Ready: c.on_ready.detach(eh); break;
|
||||
case DpEventID::MessageDelete: c.on_message_delete.detach(eh); break;
|
||||
case DpEventID::GuildMemberRemove: c.on_guild_member_remove.detach(eh); break;
|
||||
case DpEventID::Resumed: c.on_resumed.detach(eh); break;
|
||||
case DpEventID::GuildRoleCreate: c.on_guild_role_create.detach(eh); break;
|
||||
case DpEventID::TypingStart: c.on_typing_start.detach(eh); break;
|
||||
case DpEventID::MessageReactionAdd: c.on_message_reaction_add.detach(eh); break;
|
||||
case DpEventID::GuildMembersChunk: c.on_guild_members_chunk.detach(eh); break;
|
||||
case DpEventID::MessageReactionRemove: c.on_message_reaction_remove.detach(eh); break;
|
||||
case DpEventID::GuildCreate: c.on_guild_create.detach(eh); break;
|
||||
case DpEventID::ChannelCreate: c.on_channel_create.detach(eh); break;
|
||||
case DpEventID::MessageReactionRemoveEmoji: c.on_message_reaction_remove_emoji.detach(eh); break;
|
||||
case DpEventID::MessageDeleteDulk: c.on_message_delete_bulk.detach(eh); break;
|
||||
case DpEventID::GuildRoleUpdate: c.on_guild_role_update.detach(eh); break;
|
||||
case DpEventID::GuildRoleDelete: c.on_guild_role_delete.detach(eh); break;
|
||||
case DpEventID::ChannelPinsUpdate: c.on_channel_pins_update.detach(eh); break;
|
||||
case DpEventID::MessageReactionRemoveAll: c.on_message_reaction_remove_all.detach(eh); break;
|
||||
case DpEventID::VoiceServerUpdate: c.on_voice_server_update.detach(eh); break;
|
||||
case DpEventID::GuildEmojisUpdate: c.on_guild_emojis_update.detach(eh); break;
|
||||
case DpEventID::GuildStickersUpdate: c.on_guild_stickers_update.detach(eh); break;
|
||||
case DpEventID::PresenceUpdate: c.on_presence_update.detach(eh); break;
|
||||
case DpEventID::WebhooksUpdate: c.on_webhooks_update.detach(eh); break;
|
||||
case DpEventID::AutomodRuleCreate: c.on_automod_rule_create.detach(eh); break;
|
||||
case DpEventID::AutomodRuleUpdate: c.on_automod_rule_update.detach(eh); break;
|
||||
case DpEventID::AutomodRuleDelete: c.on_automod_rule_delete.detach(eh); break;
|
||||
case DpEventID::AutomodRuleExecute: c.on_automod_rule_execute.detach(eh); break;
|
||||
case DpEventID::GuildMemberAdd: c.on_guild_member_add.detach(eh); break;
|
||||
case DpEventID::InviteDelete: c.on_invite_delete.detach(eh); break;
|
||||
case DpEventID::GuildUpdate: c.on_guild_update.detach(eh); break;
|
||||
case DpEventID::GuildIntegrationsUpdate: c.on_guild_integrations_update.detach(eh); break;
|
||||
case DpEventID::GuildMemberUpdate: c.on_guild_member_update.detach(eh); break;
|
||||
case DpEventID::InviteCreate: c.on_invite_create.detach(eh); break;
|
||||
case DpEventID::MessageUpdate: c.on_message_update.detach(eh); break;
|
||||
case DpEventID::UserUpdate: c.on_user_update.detach(eh); break;
|
||||
case DpEventID::MessageCreate: c.on_message_create.detach(eh); break;
|
||||
case DpEventID::GuildAuditLogEntryCreate: c.on_guild_audit_log_entry_create.detach(eh); break;
|
||||
case DpEventID::GuildBanAdd: c.on_guild_ban_add.detach(eh); break;
|
||||
case DpEventID::GuildBanRemove: c.on_guild_ban_remove.detach(eh); break;
|
||||
case DpEventID::IntegrationCreate: c.on_integration_create.detach(eh); break;
|
||||
case DpEventID::IntegrationUpdate: c.on_integration_update.detach(eh); break;
|
||||
case DpEventID::IntegrationDelete: c.on_integration_delete.detach(eh); break;
|
||||
case DpEventID::ThreadCreate: c.on_thread_create.detach(eh); break;
|
||||
case DpEventID::ThreadUpdate: c.on_thread_update.detach(eh); break;
|
||||
case DpEventID::ThreadDelete: c.on_thread_delete.detach(eh); break;
|
||||
case DpEventID::ThreadListSync: c.on_thread_list_sync.detach(eh); break;
|
||||
case DpEventID::ThreadMemberUpdate: c.on_thread_member_update.detach(eh); break;
|
||||
case DpEventID::ThreadMembersUpdate: c.on_thread_members_update.detach(eh); break;
|
||||
case DpEventID::GuildScheduledEventCreate: c.on_guild_scheduled_event_create.detach(eh); break;
|
||||
case DpEventID::GuildScheduledEventUpdate: c.on_guild_scheduled_event_update.detach(eh); break;
|
||||
case DpEventID::GuildScheduledEventDelete: c.on_guild_scheduled_event_delete.detach(eh); break;
|
||||
case DpEventID::GuildScheduledEventUserAdd: c.on_guild_scheduled_event_user_add.detach(eh); break;
|
||||
case DpEventID::GuildScheduledEventUserRemove: c.on_guild_scheduled_event_user_remove.detach(eh); break;
|
||||
case DpEventID::VoiceBufferSend: c.on_voice_buffer_send.detach(eh); break;
|
||||
case DpEventID::VoiceUserTalking: c.on_voice_user_talking.detach(eh); break;
|
||||
case DpEventID::VoiceReady: c.on_voice_ready.detach(eh); break;
|
||||
case DpEventID::VoiceReceive: c.on_voice_receive.detach(eh); break;
|
||||
case DpEventID::VoiceReceiveCombined: c.on_voice_receive_combined.detach(eh); break;
|
||||
case DpEventID::VoiceTrackMarker: c.on_voice_track_marker.detach(eh); break;
|
||||
case DpEventID::StageInstanceCreate: c.on_stage_instance_create.detach(eh); break;
|
||||
case DpEventID::StageInstanceUpdate: c.on_stage_instance_update.detach(eh); break;
|
||||
case DpEventID::StageInstanceDelete: c.on_stage_instance_delete.detach(eh); break;
|
||||
case DpEventID::Max: // Fall through
|
||||
default: STHROWF("Invalid discord event identifier {}", id);
|
||||
}
|
||||
// Forget about this event handler
|
||||
mEventsHandle[static_cast< size_t >(id)] = 0;
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnVoiceStateUpdate(const dpp::voice_state_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceStateUpdateEvent(ev))); }
|
||||
void DpCluster::OnVoiceClientDisconnect(const dpp::voice_client_disconnect_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceClientDisconnectEvent(ev))); }
|
||||
void DpCluster::OnVoiceClientSpeaking(const dpp::voice_client_speaking_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceClientSpeakingEvent(ev))); }
|
||||
void DpCluster::OnLog(const dpp::log_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpLogEvent(ev))); }
|
||||
void DpCluster::OnGuildJoinRequestDelete(const dpp::guild_join_request_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildJoinRequestDeleteEvent(ev))); }
|
||||
void DpCluster::OnInteractionCreate(const dpp::interaction_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpInteractionCreateEvent(ev))); }
|
||||
void DpCluster::OnSlashCommand(const dpp::slashcommand_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpSlashCommandEvent(ev))); }
|
||||
void DpCluster::OnButtonClick(const dpp::button_click_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpButtonClickEvent(ev))); }
|
||||
void DpCluster::OnAutoComplete(const dpp::autocomplete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpAutoCompleteEvent(ev))); }
|
||||
void DpCluster::OnSelectClick(const dpp::select_click_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpSelectClickEvent(ev))); }
|
||||
void DpCluster::OnMessageContextMenu(const dpp::message_context_menu_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpMessageContextMenuEvent(ev))); }
|
||||
void DpCluster::OnUserContextMenu(const dpp::user_context_menu_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpUserContextMenuEvent(ev))); }
|
||||
void DpCluster::OnFormSubmit(const dpp::form_submit_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpFormSubmitEvent(ev))); }
|
||||
void DpCluster::OnGuildDelete(const dpp::guild_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildDeleteEvent(ev))); }
|
||||
void DpCluster::OnChannelDelete(const dpp::channel_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpChannelDeleteEvent(ev))); }
|
||||
void DpCluster::OnChannelUpdate(const dpp::channel_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpChannelUpdateEvent(ev))); }
|
||||
void DpCluster::OnReady(const dpp::ready_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpReadyEvent(ev))); }
|
||||
void DpCluster::OnMessageDelete(const dpp::message_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpMessageDeleteEvent(ev))); }
|
||||
void DpCluster::OnGuildMemberRemove(const dpp::guild_member_remove_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildMemberRemoveEvent(ev))); }
|
||||
void DpCluster::OnResumed(const dpp::resumed_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpResumedEvent(ev))); }
|
||||
void DpCluster::OnGuildRoleCreate(const dpp::guild_role_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildRoleCreateEvent(ev))); }
|
||||
void DpCluster::OnTypingStart(const dpp::typing_start_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpTypingStartEvent(ev))); }
|
||||
void DpCluster::OnMessageReactionAdd(const dpp::message_reaction_add_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpMessageReactionAddEvent(ev))); }
|
||||
void DpCluster::OnGuildMembersChunk(const dpp::guild_members_chunk_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildMembersChunkEvent(ev))); }
|
||||
void DpCluster::OnMessageReactionRemove(const dpp::message_reaction_remove_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpMessageReactionRemoveEvent(ev))); }
|
||||
void DpCluster::OnGuildCreate(const dpp::guild_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildCreateEvent(ev))); }
|
||||
void DpCluster::OnChannelCreate(const dpp::channel_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpChannelCreateEvent(ev))); }
|
||||
void DpCluster::OnMessageReactionRemoveEmoji(const dpp::message_reaction_remove_emoji_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpMessageReactionRemoveEmojiEvent(ev))); }
|
||||
void DpCluster::OnMessageDeleteDulk(const dpp::message_delete_bulk_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpMessageDeleteDulkEvent(ev))); }
|
||||
void DpCluster::OnGuildRoleUpdate(const dpp::guild_role_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildRoleUpdateEvent(ev))); }
|
||||
void DpCluster::OnGuildRoleDelete(const dpp::guild_role_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildRoleDeleteEvent(ev))); }
|
||||
void DpCluster::OnChannelPinsUpdate(const dpp::channel_pins_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpChannelPinsUpdateEvent(ev))); }
|
||||
void DpCluster::OnMessageReactionRemoveAll(const dpp::message_reaction_remove_all_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpMessageReactionRemoveAllEvent(ev))); }
|
||||
void DpCluster::OnVoiceServerUpdate(const dpp::voice_server_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceServerUpdateEvent(ev))); }
|
||||
void DpCluster::OnGuildEmojisUpdate(const dpp::guild_emojis_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildEmojisUpdateEvent(ev))); }
|
||||
void DpCluster::OnGuildStickersUpdate(const dpp::guild_stickers_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildStickersUpdateEvent(ev))); }
|
||||
void DpCluster::OnPresenceUpdate(const dpp::presence_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpPresenceUpdateEvent(ev))); }
|
||||
void DpCluster::OnWebhooksUpdate(const dpp::webhooks_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpWebhooksUpdateEvent(ev))); }
|
||||
void DpCluster::OnAutomodRuleCreate(const dpp::automod_rule_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpAutomodRuleCreateEvent(ev))); }
|
||||
void DpCluster::OnAutomodRuleUpdate(const dpp::automod_rule_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpAutomodRuleUpdateEvent(ev))); }
|
||||
void DpCluster::OnAutomodRuleDelete(const dpp::automod_rule_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpAutomodRuleDeleteEvent(ev))); }
|
||||
void DpCluster::OnAutomodRuleExecute(const dpp::automod_rule_execute_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpAutomodRuleExecuteEvent(ev))); }
|
||||
void DpCluster::OnGuildMemberAdd(const dpp::guild_member_add_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildMemberAddEvent(ev))); }
|
||||
void DpCluster::OnInviteDelete(const dpp::invite_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpInviteDeleteEvent(ev))); }
|
||||
void DpCluster::OnGuildUpdate(const dpp::guild_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildUpdateEvent(ev))); }
|
||||
void DpCluster::OnGuildIntegrationsUpdate(const dpp::guild_integrations_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildIntegrationsUpdateEvent(ev))); }
|
||||
void DpCluster::OnGuildMemberUpdate(const dpp::guild_member_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildMemberUpdateEvent(ev))); }
|
||||
void DpCluster::OnInviteCreate(const dpp::invite_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpInviteCreateEvent(ev))); }
|
||||
void DpCluster::OnMessageUpdate(const dpp::message_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpMessageUpdateEvent(ev))); }
|
||||
void DpCluster::OnUserUpdate(const dpp::user_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpUserUpdateEvent(ev))); }
|
||||
void DpCluster::OnMessageCreate(const dpp::message_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpMessageCreateEvent(ev))); }
|
||||
void DpCluster::OnGuildAuditLogEntryCreate(const dpp::guild_audit_log_entry_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildAuditLogEntryCreateEvent(ev))); }
|
||||
void DpCluster::OnGuildBanAdd(const dpp::guild_ban_add_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildBanAddEvent(ev))); }
|
||||
void DpCluster::OnGuildBanRemove(const dpp::guild_ban_remove_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildBanRemoveEvent(ev))); }
|
||||
void DpCluster::OnIntegrationCreate(const dpp::integration_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpIntegrationCreateEvent(ev))); }
|
||||
void DpCluster::OnIntegrationUpdate(const dpp::integration_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpIntegrationUpdateEvent(ev))); }
|
||||
void DpCluster::OnIntegrationDelete(const dpp::integration_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpIntegrationDeleteEvent(ev))); }
|
||||
void DpCluster::OnThreadCreate(const dpp::thread_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpThreadCreateEvent(ev))); }
|
||||
void DpCluster::OnThreadUpdate(const dpp::thread_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpThreadUpdateEvent(ev))); }
|
||||
void DpCluster::OnThreadDelete(const dpp::thread_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpThreadDeleteEvent(ev))); }
|
||||
void DpCluster::OnThreadListSync(const dpp::thread_list_sync_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpThreadListSyncEvent(ev))); }
|
||||
void DpCluster::OnThreadMemberUpdate(const dpp::thread_member_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpThreadMemberUpdateEvent(ev))); }
|
||||
void DpCluster::OnThreadMembersUpdate(const dpp::thread_members_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpThreadMembersUpdateEvent(ev))); }
|
||||
void DpCluster::OnGuildScheduledEventCreate(const dpp::guild_scheduled_event_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildScheduledEventCreateEvent(ev))); }
|
||||
void DpCluster::OnGuildScheduledEventUpdate(const dpp::guild_scheduled_event_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildScheduledEventUpdateEvent(ev))); }
|
||||
void DpCluster::OnGuildScheduledEventDelete(const dpp::guild_scheduled_event_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildScheduledEventDeleteEvent(ev))); }
|
||||
void DpCluster::OnGuildScheduledEventUserAdd(const dpp::guild_scheduled_event_user_add_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildScheduledEventUserAddEvent(ev))); }
|
||||
void DpCluster::OnGuildScheduledEventUserRemove(const dpp::guild_scheduled_event_user_remove_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpGuildScheduledEventUserRemoveEvent(ev))); }
|
||||
void DpCluster::OnVoiceBufferSend(const dpp::voice_buffer_send_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceBufferSendEvent(ev))); }
|
||||
void DpCluster::OnVoiceUserTalking(const dpp::voice_user_talking_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceUserTalkingEvent(ev))); }
|
||||
void DpCluster::OnVoiceReady(const dpp::voice_ready_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceReadyEvent(ev))); }
|
||||
void DpCluster::OnVoiceReceive(const dpp::voice_receive_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceReceiveEvent(ev))); }
|
||||
void DpCluster::OnVoiceReceiveCombined(const dpp::voice_receive_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceReceiveCombinedEvent(ev))); }
|
||||
void DpCluster::OnVoiceTrackMarker(const dpp::voice_track_marker_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpVoiceTrackMarkerEvent(ev))); }
|
||||
void DpCluster::OnStageInstanceCreate(const dpp::stage_instance_create_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpStageInstanceCreateEvent(ev))); }
|
||||
void DpCluster::OnStageInstanceUpdate(const dpp::stage_instance_update_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpStageInstanceUpdateEvent(ev))); }
|
||||
void DpCluster::OnStageInstanceDelete(const dpp::stage_instance_delete_t & ev)
|
||||
{ mQueue.enqueue(EventItem(new DpStageInstanceDeleteEvent(ev))); }
|
||||
|
||||
} // Namespace:: SqMod
|
338
module/Library/Discord/Cluster.hpp
Normal file
338
module/Library/Discord/Cluster.hpp
Normal file
@ -0,0 +1,338 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
#include "Core/Signal.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Constants.hpp"
|
||||
#include "Library/Discord/Misc.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
#include <string_view>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <concurrentqueue.h>
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
struct DpEventBase;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
struct DpClusterOptions
|
||||
{
|
||||
// The bot token to use for all HTTP commands and websocket connections.
|
||||
std::string mToken{};
|
||||
// A bitmask of dpd::intents values for all shards on this cluster. This is required to be sent for all bots with over 100 servers.
|
||||
uint32_t mIntents{dpp::i_default_intents};
|
||||
// The total number of shards on this bot. If there are multiple clusters, then (shards / clusters) actual shards will run on this cluster.
|
||||
// If you omit this value, the library will attempt to query the Discord API for the correct number of shards to start.
|
||||
uint32_t mShards{0};
|
||||
// The ID of this cluster, should be between 0 and MAXCLUSTERS-1
|
||||
uint32_t mClusterID{0};
|
||||
// The total number of clusters that are active, which may be on separate processes or even separate machines.
|
||||
uint32_t mMaxClusters{1};
|
||||
// Whether or not to use compression for shards on this cluster. Saves a ton of bandwidth at the cost of some CPU
|
||||
bool mCompressed{true};
|
||||
// Set the user caching policy for the cluster, either lazy (only cache users/members when they message the bot) or aggressive (request whole member lists on seeing new guilds too)
|
||||
dpp::cache_policy_t mPolicy{dpp::cp_aggressive, dpp::cp_aggressive, dpp::cp_aggressive};
|
||||
// The number of threads to allocate for making HTTP requests to Discord. This defaults to 12. You can increase this at runtime via the object returned from get_rest().
|
||||
uint32_t mRequestThreads{12};
|
||||
// The number of threads to allocate for making HTTP requests to sites outside of Discord. This defaults to 1. You can increase this at runtime via the object returned from get_raw_rest().
|
||||
uint32_t mRequestThreadsRaw{1};
|
||||
// Disable automatic forwarding of logged messages to internal logging. Allows to handle logging manually without risking duplicate output (at the cost of some performance, ofc).
|
||||
bool mCustomLogging{false};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructors.
|
||||
*/
|
||||
DpClusterOptions(StackStrF & token)
|
||||
: mToken(token.ToStr())
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy/Move constructors.
|
||||
*/
|
||||
DpClusterOptions(const DpClusterOptions &) noexcept = default;
|
||||
DpClusterOptions(DpClusterOptions &&) noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy/Move assignment operators.
|
||||
*/
|
||||
DpClusterOptions & operator = (const DpClusterOptions &) noexcept = default;
|
||||
DpClusterOptions & operator = (DpClusterOptions &&) noexcept = default;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Primitive implementation of a discord client with basic functionality.
|
||||
*/
|
||||
struct DpCluster : public SqChainedInstances< DpCluster >
|
||||
{
|
||||
using Base = SqChainedInstances< DpCluster >;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Queue of events generated from other threads.
|
||||
*/
|
||||
using EventItem = std::unique_ptr< DpEventBase >;
|
||||
using EventQueue = moodycamel::ConcurrentQueue< EventItem >;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Type of container for cluster signals.
|
||||
*/
|
||||
using Signals = std::array< SignalPair, static_cast< size_t >(DpEventID::Max) >;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Type of container for event handles.
|
||||
*/
|
||||
using EventHandle = std::array< dpp::event_handle, static_cast< size_t >(DpEventID::Max) >;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Event queue.
|
||||
*/
|
||||
EventQueue mQueue{4096};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Managed cluster instance.
|
||||
*/
|
||||
std::unique_ptr< dpp::cluster > mC;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Table containing the emitted cluster events.
|
||||
*/
|
||||
LightObj mSqEvents{};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Cluster signals.
|
||||
*/
|
||||
Signals mEvents{};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Event handles for bound event event handlers so they can be stopped at any time.
|
||||
*/
|
||||
EventHandle mEventsHandle{};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructors.
|
||||
*/
|
||||
DpCluster(DpClusterOptions & o);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy/Move constructors (disabled).
|
||||
*/
|
||||
DpCluster(const DpCluster &) noexcept = delete;
|
||||
DpCluster(DpCluster &&) noexcept = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpCluster()
|
||||
{
|
||||
if (mC) Stop();
|
||||
// Forget about this instance
|
||||
UnchainInstance();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy/Move assignment operators (disabled).
|
||||
*/
|
||||
DpCluster & operator = (const DpCluster &) noexcept = delete;
|
||||
DpCluster & operator = (DpCluster &&) noexcept = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the managed cluster instance is valid and throw an exception otherwise.
|
||||
*/
|
||||
void Validate() const
|
||||
{
|
||||
if (!mC)
|
||||
{
|
||||
STHROWF("Discord cluster instance is not valid anymore.");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the managed cluster instance is valid and throw an exception otherwise.
|
||||
*/
|
||||
void Validate(const char * m) const
|
||||
{
|
||||
if (!mC)
|
||||
{
|
||||
STHROWF("Cannot {} a cluster instance that is not valid anymore.", fmt::detail::to_string_view(m));
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the managed cluster instance is valid and throw an exception otherwise.
|
||||
*/
|
||||
dpp::cluster & Valid() const { Validate(); return *mC; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the managed cluster instance is valid and throw an exception otherwise.
|
||||
*/
|
||||
dpp::cluster & Valid(const char * m) const { Validate(m); return *mC; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process the cluster. This is used internally on each server frame.
|
||||
*/
|
||||
void Process(bool force = false);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Terminate the cluster. This is used internally when the VM is shutting down.
|
||||
*/
|
||||
void Terminate();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Start the cluster.
|
||||
*/
|
||||
DpCluster & Start() { Valid("start").start(dpp::st_return); return *this; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Stop the cluster.
|
||||
*/
|
||||
void Stop() { Valid("stop").shutdown(); }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the events table of this cluster.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetEvents()
|
||||
{
|
||||
return mSqEvents;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Enable a certain event for the cluster.
|
||||
*/
|
||||
DpCluster & EnableEvent(SQInteger id);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Disable a certain event for the cluster.
|
||||
*/
|
||||
DpCluster & DisableEvent(SQInteger id);
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Signal initialization.
|
||||
*/
|
||||
void InitEvents()
|
||||
{
|
||||
// Ignore the call if already initialized
|
||||
if (!mSqEvents.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Create a new table on the stack with enough space pre-allocated
|
||||
sq_newtableex(SqVM(), static_cast< SQInteger >(DpEventID::Max + 1));
|
||||
// Grab the table object from the stack
|
||||
mSqEvents = LightObj(-1, SqVM());
|
||||
// Pop the table object from the stack
|
||||
sq_pop(SqVM(), 1);
|
||||
// Proceed to initializing the events
|
||||
for (size_t i = 0; i < mEvents.size(); ++i)
|
||||
{
|
||||
InitSignalPair(mEvents[i], mSqEvents, DpEventID::NAME[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Signal termination.
|
||||
*/
|
||||
void DropEvents()
|
||||
{
|
||||
for (auto & e : mEvents)
|
||||
{
|
||||
ResetSignalPair(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Event handlers.
|
||||
*/
|
||||
void OnVoiceStateUpdate(const dpp::voice_state_update_t & ev);
|
||||
void OnVoiceClientDisconnect(const dpp::voice_client_disconnect_t & ev);
|
||||
void OnVoiceClientSpeaking(const dpp::voice_client_speaking_t & ev);
|
||||
void OnLog(const dpp::log_t & ev);
|
||||
void OnGuildJoinRequestDelete(const dpp::guild_join_request_delete_t & ev);
|
||||
void OnInteractionCreate(const dpp::interaction_create_t & ev);
|
||||
void OnSlashCommand(const dpp::slashcommand_t & ev);
|
||||
void OnButtonClick(const dpp::button_click_t & ev);
|
||||
void OnAutoComplete(const dpp::autocomplete_t & ev);
|
||||
void OnSelectClick(const dpp::select_click_t & ev);
|
||||
void OnMessageContextMenu(const dpp::message_context_menu_t & ev);
|
||||
void OnUserContextMenu(const dpp::user_context_menu_t & ev);
|
||||
void OnFormSubmit(const dpp::form_submit_t & ev);
|
||||
void OnGuildDelete(const dpp::guild_delete_t & ev);
|
||||
void OnChannelDelete(const dpp::channel_delete_t & ev);
|
||||
void OnChannelUpdate(const dpp::channel_update_t & ev);
|
||||
void OnReady(const dpp::ready_t & ev);
|
||||
void OnMessageDelete(const dpp::message_delete_t & ev);
|
||||
void OnGuildMemberRemove(const dpp::guild_member_remove_t & ev);
|
||||
void OnResumed(const dpp::resumed_t & ev);
|
||||
void OnGuildRoleCreate(const dpp::guild_role_create_t & ev);
|
||||
void OnTypingStart(const dpp::typing_start_t & ev);
|
||||
void OnMessageReactionAdd(const dpp::message_reaction_add_t & ev);
|
||||
void OnGuildMembersChunk(const dpp::guild_members_chunk_t & ev);
|
||||
void OnMessageReactionRemove(const dpp::message_reaction_remove_t & ev);
|
||||
void OnGuildCreate(const dpp::guild_create_t & ev);
|
||||
void OnChannelCreate(const dpp::channel_create_t & ev);
|
||||
void OnMessageReactionRemoveEmoji(const dpp::message_reaction_remove_emoji_t & ev);
|
||||
void OnMessageDeleteDulk(const dpp::message_delete_bulk_t & ev);
|
||||
void OnGuildRoleUpdate(const dpp::guild_role_update_t & ev);
|
||||
void OnGuildRoleDelete(const dpp::guild_role_delete_t & ev);
|
||||
void OnChannelPinsUpdate(const dpp::channel_pins_update_t & ev);
|
||||
void OnMessageReactionRemoveAll(const dpp::message_reaction_remove_all_t & ev);
|
||||
void OnVoiceServerUpdate(const dpp::voice_server_update_t & ev);
|
||||
void OnGuildEmojisUpdate(const dpp::guild_emojis_update_t & ev);
|
||||
void OnGuildStickersUpdate(const dpp::guild_stickers_update_t & ev);
|
||||
void OnPresenceUpdate(const dpp::presence_update_t & ev);
|
||||
void OnWebhooksUpdate(const dpp::webhooks_update_t & ev);
|
||||
void OnAutomodRuleCreate(const dpp::automod_rule_create_t & ev);
|
||||
void OnAutomodRuleUpdate(const dpp::automod_rule_update_t & ev);
|
||||
void OnAutomodRuleDelete(const dpp::automod_rule_delete_t & ev);
|
||||
void OnAutomodRuleExecute(const dpp::automod_rule_execute_t & ev);
|
||||
void OnGuildMemberAdd(const dpp::guild_member_add_t & ev);
|
||||
void OnInviteDelete(const dpp::invite_delete_t & ev);
|
||||
void OnGuildUpdate(const dpp::guild_update_t & ev);
|
||||
void OnGuildIntegrationsUpdate(const dpp::guild_integrations_update_t & ev);
|
||||
void OnGuildMemberUpdate(const dpp::guild_member_update_t & ev);
|
||||
void OnInviteCreate(const dpp::invite_create_t & ev);
|
||||
void OnMessageUpdate(const dpp::message_update_t & ev);
|
||||
void OnUserUpdate(const dpp::user_update_t & ev);
|
||||
void OnMessageCreate(const dpp::message_create_t & ev);
|
||||
void OnGuildAuditLogEntryCreate(const dpp::guild_audit_log_entry_create_t & ev);
|
||||
void OnGuildBanAdd(const dpp::guild_ban_add_t & ev);
|
||||
void OnGuildBanRemove(const dpp::guild_ban_remove_t & ev);
|
||||
void OnIntegrationCreate(const dpp::integration_create_t & ev);
|
||||
void OnIntegrationUpdate(const dpp::integration_update_t & ev);
|
||||
void OnIntegrationDelete(const dpp::integration_delete_t & ev);
|
||||
void OnThreadCreate(const dpp::thread_create_t & ev);
|
||||
void OnThreadUpdate(const dpp::thread_update_t & ev);
|
||||
void OnThreadDelete(const dpp::thread_delete_t & ev);
|
||||
void OnThreadListSync(const dpp::thread_list_sync_t & ev);
|
||||
void OnThreadMemberUpdate(const dpp::thread_member_update_t & ev);
|
||||
void OnThreadMembersUpdate(const dpp::thread_members_update_t & ev);
|
||||
void OnGuildScheduledEventCreate(const dpp::guild_scheduled_event_create_t & ev);
|
||||
void OnGuildScheduledEventUpdate(const dpp::guild_scheduled_event_update_t & ev);
|
||||
void OnGuildScheduledEventDelete(const dpp::guild_scheduled_event_delete_t & ev);
|
||||
void OnGuildScheduledEventUserAdd(const dpp::guild_scheduled_event_user_add_t & ev);
|
||||
void OnGuildScheduledEventUserRemove(const dpp::guild_scheduled_event_user_remove_t & ev);
|
||||
void OnVoiceBufferSend(const dpp::voice_buffer_send_t & ev);
|
||||
void OnVoiceUserTalking(const dpp::voice_user_talking_t & ev);
|
||||
void OnVoiceReady(const dpp::voice_ready_t & ev);
|
||||
void OnVoiceReceive(const dpp::voice_receive_t & ev);
|
||||
void OnVoiceReceiveCombined(const dpp::voice_receive_t & ev);
|
||||
void OnVoiceTrackMarker(const dpp::voice_track_marker_t & ev);
|
||||
void OnStageInstanceCreate(const dpp::stage_instance_create_t & ev);
|
||||
void OnStageInstanceUpdate(const dpp::stage_instance_update_t & ev);
|
||||
void OnStageInstanceDelete(const dpp::stage_instance_delete_t & ev);
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/Command.cpp
Normal file
9
module/Library/Discord/Command.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Command.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
13
module/Library/Discord/Command.hpp
Normal file
13
module/Library/Discord/Command.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
283
module/Library/Discord/Constants.cpp
Normal file
283
module/Library/Discord/Constants.cpp
Normal file
@ -0,0 +1,283 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Constants.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqratConst.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const std::array< const char *, static_cast< size_t >(DpEventID::Max) > DpEventID::NAME{
|
||||
"VoiceStateUpdate",
|
||||
"VoiceClientDisconnect",
|
||||
"VoiceClientSpeaking",
|
||||
"Log",
|
||||
"GuildJoinRequestDelete",
|
||||
"InteractionCreate",
|
||||
"SlashCommand",
|
||||
"ButtonClick",
|
||||
"AutoComplete",
|
||||
"SelectClick",
|
||||
"MessageContextMenu",
|
||||
"UserContextMenu",
|
||||
"FormSubmit",
|
||||
"GuildDelete",
|
||||
"ChannelDelete",
|
||||
"ChannelUpdate",
|
||||
"Ready",
|
||||
"MessageDelete",
|
||||
"GuildMemberRemove",
|
||||
"Resumed",
|
||||
"GuildRoleCreate",
|
||||
"TypingStart",
|
||||
"MessageReactionAdd",
|
||||
"GuildMembersChunk",
|
||||
"MessageReactionRemove",
|
||||
"GuildCreate",
|
||||
"ChannelCreate",
|
||||
"MessageReactionRemoveEmoji",
|
||||
"MessageDeleteDulk",
|
||||
"GuildRoleUpdate",
|
||||
"GuildRoleDelete",
|
||||
"ChannelPinsUpdate",
|
||||
"MessageReactionRemoveAll",
|
||||
"VoiceServerUpdate",
|
||||
"GuildEmojisUpdate",
|
||||
"GuildStickersUpdate",
|
||||
"PresenceUpdate",
|
||||
"WebhooksUpdate",
|
||||
"AutomodRuleCreate",
|
||||
"AutomodRuleUpdate",
|
||||
"AutomodRuleDelete",
|
||||
"AutomodRuleExecute",
|
||||
"GuildMemberAdd",
|
||||
"InviteDelete",
|
||||
"GuildUpdate",
|
||||
"GuildIntegrationsUpdate",
|
||||
"GuildMemberUpdate",
|
||||
"InviteCreate",
|
||||
"MessageUpdate",
|
||||
"UserUpdate",
|
||||
"MessageCreate",
|
||||
"GuildAuditLogEntryCreate",
|
||||
"GuildBanAdd",
|
||||
"GuildBanRemove",
|
||||
"IntegrationCreate",
|
||||
"IntegrationUpdate",
|
||||
"IntegrationDelete",
|
||||
"ThreadCreate",
|
||||
"ThreadUpdate",
|
||||
"ThreadDelete",
|
||||
"ThreadListSync",
|
||||
"ThreadMemberUpdate",
|
||||
"ThreadMembersUpdate",
|
||||
"GuildScheduledEventCreate",
|
||||
"GuildScheduledEventUpdate",
|
||||
"GuildScheduledEventDelete",
|
||||
"GuildScheduledEventUserAdd",
|
||||
"GuildScheduledEventUserRemove",
|
||||
"VoiceBufferSend",
|
||||
"VoiceUserTalking",
|
||||
"VoiceReady",
|
||||
"VoiceReceive",
|
||||
"VoiceReceiveCombined",
|
||||
"VoiceTrackMarker",
|
||||
"StageInstanceCreate",
|
||||
"StageInstanceUpdate",
|
||||
"StageInstanceDelete",
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpLogLevelEnum[] = {
|
||||
{_SC("Trace"), static_cast< SQInteger >(dpp::ll_trace)},
|
||||
{_SC("Debug"), static_cast< SQInteger >(dpp::ll_debug)},
|
||||
{_SC("Info"), static_cast< SQInteger >(dpp::ll_info)},
|
||||
{_SC("Warning"), static_cast< SQInteger >(dpp::ll_warning)},
|
||||
{_SC("Error"), static_cast< SQInteger >(dpp::ll_error)},
|
||||
{_SC("Critical"), static_cast< SQInteger >(dpp::ll_critical)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpVoiceStateFlagsEnum[] = {
|
||||
{_SC("Deaf"), static_cast< SQInteger >(dpp::vs_deaf)},
|
||||
{_SC("Mute"), static_cast< SQInteger >(dpp::vs_mute)},
|
||||
{_SC("SelfMute"), static_cast< SQInteger >(dpp::vs_self_mute)},
|
||||
{_SC("SelfDeaf"), static_cast< SQInteger >(dpp::vs_self_deaf)},
|
||||
{_SC("SelfStream"), static_cast< SQInteger >(dpp::vs_self_stream)},
|
||||
{_SC("SelfVideo"), static_cast< SQInteger >(dpp::vs_self_video)},
|
||||
{_SC("Suppress"), static_cast< SQInteger >(dpp::vs_suppress)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpEmojiFlagsEnum[] = {
|
||||
{_SC("RequireColons"), static_cast< SQInteger >(dpp::e_require_colons)},
|
||||
{_SC("Managed"), static_cast< SQInteger >(dpp::e_managed)},
|
||||
{_SC("Animated"), static_cast< SQInteger >(dpp::e_animated)},
|
||||
{_SC("Available"), static_cast< SQInteger >(dpp::e_available)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpPresenceFlagsEnum[] = {
|
||||
{_SC("DesktopOnline"), static_cast< SQInteger >(dpp::p_desktop_online)},
|
||||
{_SC("DesktopDND"), static_cast< SQInteger >(dpp::p_desktop_dnd)},
|
||||
{_SC("DesktopIdle"), static_cast< SQInteger >(dpp::p_desktop_idle)},
|
||||
{_SC("WebOnline"), static_cast< SQInteger >(dpp::p_web_online)},
|
||||
{_SC("WebDND"), static_cast< SQInteger >(dpp::p_web_dnd)},
|
||||
{_SC("WebIdle"), static_cast< SQInteger >(dpp::p_web_idle)},
|
||||
{_SC("MobileOnline"), static_cast< SQInteger >(dpp::p_mobile_online)},
|
||||
{_SC("MobileDND"), static_cast< SQInteger >(dpp::p_mobile_dnd)},
|
||||
{_SC("MobileIdle"), static_cast< SQInteger >(dpp::p_mobile_idle)},
|
||||
{_SC("StatusOnline"), static_cast< SQInteger >(dpp::p_status_online)},
|
||||
{_SC("StatusDND"), static_cast< SQInteger >(dpp::p_status_dnd)},
|
||||
{_SC("StatusIdle"), static_cast< SQInteger >(dpp::p_status_idle)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpPresenceStatusEnum[] = {
|
||||
{_SC("Offline"), static_cast< SQInteger >(dpp::ps_offline)},
|
||||
{_SC("Online"), static_cast< SQInteger >(dpp::ps_online)},
|
||||
{_SC("DND"), static_cast< SQInteger >(dpp::ps_dnd)},
|
||||
{_SC("Idle"), static_cast< SQInteger >(dpp::ps_idle)},
|
||||
// Bit shift for desktop status
|
||||
{_SC("ShiftDesktop"), static_cast< SQInteger >(PF_SHIFT_DESKTOP)},
|
||||
{_SC("ShiftWeb"), static_cast< SQInteger >(PF_SHIFT_WEB)},
|
||||
{_SC("ShiftMobile"), static_cast< SQInteger >(PF_SHIFT_MOBILE)},
|
||||
{_SC("ShiftMain"), static_cast< SQInteger >(PF_SHIFT_MAIN)},
|
||||
{_SC("StatusMask"), static_cast< SQInteger >(PF_STATUS_MASK)},
|
||||
{_SC("ClearDesktop"), static_cast< SQInteger >(PF_CLEAR_DESKTOP)},
|
||||
{_SC("ClearWeb"), static_cast< SQInteger >(PF_CLEAR_WEB)},
|
||||
{_SC("ClearMobile"), static_cast< SQInteger >(PF_CLEAR_MOBILE)},
|
||||
{_SC("ClearStatus"), static_cast< SQInteger >(PF_CLEAR_STATUS)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpActivityTypeEnum[] = {
|
||||
{_SC("Game"), static_cast< SQInteger >(dpp::at_game)},
|
||||
{_SC("Streaming"), static_cast< SQInteger >(dpp::at_streaming)},
|
||||
{_SC("Listening"), static_cast< SQInteger >(dpp::at_listening)},
|
||||
{_SC("Watching"), static_cast< SQInteger >(dpp::at_watching)},
|
||||
{_SC("Custom"), static_cast< SQInteger >(dpp::at_custom)},
|
||||
{_SC("Competing"), static_cast< SQInteger >(dpp::at_competing)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpActivityFlagsEnum[] = {
|
||||
{_SC("Instance"), static_cast< SQInteger >(dpp::af_instance)},
|
||||
{_SC("Join"), static_cast< SQInteger >(dpp::af_join)},
|
||||
{_SC("Spectate"), static_cast< SQInteger >(dpp::af_spectate)},
|
||||
{_SC("JoinRequest"), static_cast< SQInteger >(dpp::af_join_request)},
|
||||
{_SC("Sync"), static_cast< SQInteger >(dpp::af_sync)},
|
||||
{_SC("Play"), static_cast< SQInteger >(dpp::af_play)},
|
||||
{_SC("PartyPrivacyFriends"), static_cast< SQInteger >(dpp::af_party_privacy_friends)},
|
||||
{_SC("PartyPrivacyVoiceChannel"), static_cast< SQInteger >(dpp::af_party_privacy_voice_channel)},
|
||||
{_SC("Embedded"), static_cast< SQInteger >(dpp::af_embedded)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpRegionEnum[] = {
|
||||
{_SC("Brazil"), static_cast< SQInteger >(dpp::r_brazil)},
|
||||
{_SC("CentralEurope"), static_cast< SQInteger >(dpp::r_central_europe)},
|
||||
{_SC("HongKong"), static_cast< SQInteger >(dpp::r_hong_kong)},
|
||||
{_SC("India"), static_cast< SQInteger >(dpp::r_india)},
|
||||
{_SC("Japan"), static_cast< SQInteger >(dpp::r_japan)},
|
||||
{_SC("Russia"), static_cast< SQInteger >(dpp::r_russia)},
|
||||
{_SC("Singapore"), static_cast< SQInteger >(dpp::r_singapore)},
|
||||
{_SC("SouthAfrica"), static_cast< SQInteger >(dpp::r_south_africa)},
|
||||
{_SC("Sydney"), static_cast< SQInteger >(dpp::r_sydney)},
|
||||
{_SC("UsCentral"), static_cast< SQInteger >(dpp::r_us_central)},
|
||||
{_SC("UsEast"), static_cast< SQInteger >(dpp::r_us_east)},
|
||||
{_SC("UsSouth"), static_cast< SQInteger >(dpp::r_us_south)},
|
||||
{_SC("UsWest"), static_cast< SQInteger >(dpp::r_us_west)},
|
||||
{_SC("WesternEurope"), static_cast< SQInteger >(dpp::r_western_europe)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpGuildFlagsEnum[] = {
|
||||
{_SC("Large"), static_cast< SQInteger >(dpp::g_large)},
|
||||
{_SC("Unavailable"), static_cast< SQInteger >(dpp::g_unavailable)},
|
||||
{_SC("WidgetEnabled"), static_cast< SQInteger >(dpp::g_widget_enabled)},
|
||||
{_SC("InviteSplash"), static_cast< SQInteger >(dpp::g_invite_splash)},
|
||||
{_SC("VipRegions"), static_cast< SQInteger >(dpp::g_vip_regions)},
|
||||
{_SC("VanityURL"), static_cast< SQInteger >(dpp::g_vanity_url)},
|
||||
{_SC("Verified"), static_cast< SQInteger >(dpp::g_verified)},
|
||||
{_SC("Partnered"), static_cast< SQInteger >(dpp::g_partnered)},
|
||||
{_SC("Community"), static_cast< SQInteger >(dpp::g_community)},
|
||||
{_SC("RoleSubscriptionEnabled"), static_cast< SQInteger >(dpp::g_role_subscription_enabled)},
|
||||
{_SC("News"), static_cast< SQInteger >(dpp::g_news)},
|
||||
{_SC("Discoverable"), static_cast< SQInteger >(dpp::g_discoverable)},
|
||||
{_SC("Featureable"), static_cast< SQInteger >(dpp::g_featureable)},
|
||||
{_SC("AnimatedIcon"), static_cast< SQInteger >(dpp::g_animated_icon)},
|
||||
{_SC("Banner"), static_cast< SQInteger >(dpp::g_banner)},
|
||||
{_SC("WelcomeScreenEnabled"), static_cast< SQInteger >(dpp::g_welcome_screen_enabled)},
|
||||
{_SC("MemberVerificationGate"), static_cast< SQInteger >(dpp::g_member_verification_gate)},
|
||||
{_SC("PreviewEnabled"), static_cast< SQInteger >(dpp::g_preview_enabled)},
|
||||
{_SC("NoJoinNotifications"), static_cast< SQInteger >(dpp::g_no_join_notifications)},
|
||||
{_SC("NoBoostNotifications"), static_cast< SQInteger >(dpp::g_no_boost_notifications)},
|
||||
{_SC("HasAnimatedIcon"), static_cast< SQInteger >(dpp::g_has_animated_icon)},
|
||||
{_SC("HasAnimatedBanner"), static_cast< SQInteger >(dpp::g_has_animated_banner)},
|
||||
{_SC("NoSetupTips"), static_cast< SQInteger >(dpp::g_no_setup_tips)},
|
||||
{_SC("NoStickerGreeting"), static_cast< SQInteger >(dpp::g_no_sticker_greeting)},
|
||||
{_SC("MonetizationEnabled"), static_cast< SQInteger >(dpp::g_monetization_enabled)},
|
||||
{_SC("MoreStickers"), static_cast< SQInteger >(dpp::g_more_stickers)},
|
||||
{_SC("CreatorStorePageEnabled"), static_cast< SQInteger >(dpp::g_creator_store_page_enabled)},
|
||||
{_SC("RoleIcons"), static_cast< SQInteger >(dpp::g_role_icons)},
|
||||
{_SC("SevenDayThreadArchive"), static_cast< SQInteger >(dpp::g_seven_day_thread_archive)},
|
||||
{_SC("ThreeDayThreadArchive"), static_cast< SQInteger >(dpp::g_three_day_thread_archive)},
|
||||
{_SC("TicketedEvents"), static_cast< SQInteger >(dpp::g_ticketed_events)},
|
||||
{_SC("ChannelBanners"), static_cast< SQInteger >(dpp::g_channel_banners)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpGuildFlagsExtraEnum[] = {
|
||||
{_SC("PremiumProgressBarEnabled"), static_cast< SQInteger >(dpp::g_premium_progress_bar_enabled)},
|
||||
{_SC("AnimatedBanner"), static_cast< SQInteger >(dpp::g_animated_banner)},
|
||||
{_SC("AutoModeration"), static_cast< SQInteger >(dpp::g_auto_moderation)},
|
||||
{_SC("InvitesDisabled"), static_cast< SQInteger >(dpp::g_invites_disabled)},
|
||||
{_SC("DeveloperSupportServer"), static_cast< SQInteger >(dpp::g_developer_support_server)},
|
||||
{_SC("NoRoleSubscriptionNotifications"), static_cast< SQInteger >(dpp::g_no_role_subscription_notifications)},
|
||||
{_SC("NoRoleSubscriptionNotificationReplies"), static_cast< SQInteger >(dpp::g_no_role_subscription_notification_replies)},
|
||||
{_SC("RoleSubscriptionsAvailableForPurchase"), static_cast< SQInteger >(dpp::g_role_subscriptions_available_for_purchase)},
|
||||
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpGuildMemberFlagsEnum[] = {
|
||||
{_SC("Deaf"), static_cast< SQInteger >(dpp::gm_deaf)},
|
||||
{_SC("Mute"), static_cast< SQInteger >(dpp::gm_mute)},
|
||||
{_SC("Pending"), static_cast< SQInteger >(dpp::gm_pending)},
|
||||
{_SC("AnimatedAvatar"), static_cast< SQInteger >(dpp::gm_animated_avatar)},
|
||||
{_SC("VoiceAction"), static_cast< SQInteger >(dpp::gm_voice_action)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElements g_EnumList[] = {
|
||||
{_SC("SqDiscordLogLevel"), g_DpLogLevelEnum},
|
||||
{_SC("SqDiscordVoiceStateFlags"), g_DpVoiceStateFlagsEnum},
|
||||
{_SC("SqDiscordEmojiFlags"), g_DpEmojiFlagsEnum},
|
||||
{_SC("SqDiscordPresenceFlags"), g_DpPresenceFlagsEnum},
|
||||
{_SC("SqDiscordPresenceStatus"), g_DpPresenceStatusEnum},
|
||||
{_SC("SqDiscordActivityType"), g_DpActivityTypeEnum},
|
||||
{_SC("SqDiscordActivityFlags"), g_DpActivityFlagsEnum},
|
||||
{_SC("SqDiscordRegion"), g_DpRegionEnum},
|
||||
{_SC("SqDiscordGuildFlags"), g_DpGuildFlagsEnum},
|
||||
{_SC("SqDiscordGuildFlagsExtra"), g_DpGuildFlagsExtraEnum},
|
||||
{_SC("SqDiscordGuildMemberFlags"), g_DpGuildMemberFlagsEnum},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_Discord_Constants(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
RegisterEnumerations(vm, g_EnumList);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Enumeration e(vm);
|
||||
// Bind all events using their associated name
|
||||
for (SQInteger i = 0; i < static_cast< SQInteger >(DpEventID::Max); ++i)
|
||||
{
|
||||
e.Const(DpEventID::NAME[i], i);
|
||||
}
|
||||
// Expose the constants
|
||||
ConstTable(vm).Enum(_SC("SqDiscordEvent"), e);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
663
module/Library/Discord/Constants.hpp
Normal file
663
module/Library/Discord/Constants.hpp
Normal file
@ -0,0 +1,663 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <array>
|
||||
#include <string_view>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Unique ID for each event.
|
||||
*/
|
||||
struct DpEventID
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ID enumeration.
|
||||
*/
|
||||
enum Type
|
||||
{
|
||||
VoiceStateUpdate=0,
|
||||
VoiceClientDisconnect,
|
||||
VoiceClientSpeaking,
|
||||
Log,
|
||||
GuildJoinRequestDelete,
|
||||
InteractionCreate,
|
||||
SlashCommand,
|
||||
ButtonClick,
|
||||
AutoComplete,
|
||||
SelectClick,
|
||||
MessageContextMenu,
|
||||
UserContextMenu,
|
||||
FormSubmit,
|
||||
GuildDelete,
|
||||
ChannelDelete,
|
||||
ChannelUpdate,
|
||||
Ready,
|
||||
MessageDelete,
|
||||
GuildMemberRemove,
|
||||
Resumed,
|
||||
GuildRoleCreate,
|
||||
TypingStart,
|
||||
MessageReactionAdd,
|
||||
GuildMembersChunk,
|
||||
MessageReactionRemove,
|
||||
GuildCreate,
|
||||
ChannelCreate,
|
||||
MessageReactionRemoveEmoji,
|
||||
MessageDeleteDulk,
|
||||
GuildRoleUpdate,
|
||||
GuildRoleDelete,
|
||||
ChannelPinsUpdate,
|
||||
MessageReactionRemoveAll,
|
||||
VoiceServerUpdate,
|
||||
GuildEmojisUpdate,
|
||||
GuildStickersUpdate,
|
||||
PresenceUpdate,
|
||||
WebhooksUpdate,
|
||||
AutomodRuleCreate,
|
||||
AutomodRuleUpdate,
|
||||
AutomodRuleDelete,
|
||||
AutomodRuleExecute,
|
||||
GuildMemberAdd,
|
||||
InviteDelete,
|
||||
GuildUpdate,
|
||||
GuildIntegrationsUpdate,
|
||||
GuildMemberUpdate,
|
||||
InviteCreate,
|
||||
MessageUpdate,
|
||||
UserUpdate,
|
||||
MessageCreate,
|
||||
GuildAuditLogEntryCreate,
|
||||
GuildBanAdd,
|
||||
GuildBanRemove,
|
||||
IntegrationCreate,
|
||||
IntegrationUpdate,
|
||||
IntegrationDelete,
|
||||
ThreadCreate,
|
||||
ThreadUpdate,
|
||||
ThreadDelete,
|
||||
ThreadListSync,
|
||||
ThreadMemberUpdate,
|
||||
ThreadMembersUpdate,
|
||||
GuildScheduledEventCreate,
|
||||
GuildScheduledEventUpdate,
|
||||
GuildScheduledEventDelete,
|
||||
GuildScheduledEventUserAdd,
|
||||
GuildScheduledEventUserRemove,
|
||||
VoiceBufferSend,
|
||||
VoiceUserTalking,
|
||||
VoiceReady,
|
||||
VoiceReceive,
|
||||
VoiceReceiveCombined,
|
||||
VoiceTrackMarker,
|
||||
StageInstanceCreate,
|
||||
StageInstanceUpdate,
|
||||
StageInstanceDelete,
|
||||
Max
|
||||
};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* String identification for each event ID.
|
||||
*/
|
||||
static const std::array< const char *, static_cast< size_t >(Max) > NAME;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Structures that hold compile-time type information for events.
|
||||
*/
|
||||
struct DpVoiceStateUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::voice_state_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceStateUpdate;
|
||||
static inline constexpr std::string_view Name = "VoiceStateUpdate";
|
||||
};
|
||||
struct DpVoiceClientDisconnectEventInfo
|
||||
{
|
||||
using Type = dpp::voice_client_disconnect_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceClientDisconnect;
|
||||
static inline constexpr std::string_view Name = "VoiceClientDisconnect";
|
||||
};
|
||||
struct DpVoiceClientSpeakingEventInfo
|
||||
{
|
||||
using Type = dpp::voice_client_speaking_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceClientSpeaking;
|
||||
static inline constexpr std::string_view Name = "VoiceClientSpeaking";
|
||||
};
|
||||
struct DpLogEventInfo
|
||||
{
|
||||
using Type = dpp::log_t;
|
||||
static inline constexpr size_t ID = DpEventID::Log;
|
||||
static inline constexpr std::string_view Name = "Log";
|
||||
};
|
||||
struct DpGuildJoinRequestDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::guild_join_request_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildJoinRequestDelete;
|
||||
static inline constexpr std::string_view Name = "GuildJoinRequestDelete";
|
||||
};
|
||||
struct DpInteractionCreateEventInfo
|
||||
{
|
||||
using Type = dpp::interaction_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::InteractionCreate;
|
||||
static inline constexpr std::string_view Name = "InteractionCreate";
|
||||
};
|
||||
struct DpSlashCommandEventInfo
|
||||
{
|
||||
using Type = dpp::slashcommand_t;
|
||||
static inline constexpr size_t ID = DpEventID::SlashCommand;
|
||||
static inline constexpr std::string_view Name = "SlashCommand";
|
||||
};
|
||||
struct DpButtonClickEventInfo
|
||||
{
|
||||
using Type = dpp::button_click_t;
|
||||
static inline constexpr size_t ID = DpEventID::ButtonClick;
|
||||
static inline constexpr std::string_view Name = "ButtonClick";
|
||||
};
|
||||
struct DpAutoCompleteEventInfo
|
||||
{
|
||||
using Type = dpp::autocomplete_t;
|
||||
static inline constexpr size_t ID = DpEventID::AutoComplete;
|
||||
static inline constexpr std::string_view Name = "AutoComplete";
|
||||
};
|
||||
struct DpSelectClickEventInfo
|
||||
{
|
||||
using Type = dpp::select_click_t;
|
||||
static inline constexpr size_t ID = DpEventID::SelectClick;
|
||||
static inline constexpr std::string_view Name = "SelectClick";
|
||||
};
|
||||
struct DpMessageContextMenuEventInfo
|
||||
{
|
||||
using Type = dpp::message_context_menu_t;
|
||||
static inline constexpr size_t ID = DpEventID::MessageContextMenu;
|
||||
static inline constexpr std::string_view Name = "MessageContextMenu";
|
||||
};
|
||||
struct DpUserContextMenuEventInfo
|
||||
{
|
||||
using Type = dpp::user_context_menu_t;
|
||||
static inline constexpr size_t ID = DpEventID::UserContextMenu;
|
||||
static inline constexpr std::string_view Name = "UserContextMenu";
|
||||
};
|
||||
struct DpFormSubmitEventInfo
|
||||
{
|
||||
using Type = dpp::form_submit_t;
|
||||
static inline constexpr size_t ID = DpEventID::FormSubmit;
|
||||
static inline constexpr std::string_view Name = "FormSubmit";
|
||||
};
|
||||
struct DpGuildDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::guild_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildDelete;
|
||||
static inline constexpr std::string_view Name = "GuildDelete";
|
||||
};
|
||||
struct DpChannelDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::channel_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::ChannelDelete;
|
||||
static inline constexpr std::string_view Name = "ChannelDelete";
|
||||
};
|
||||
struct DpChannelUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::channel_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::ChannelUpdate;
|
||||
static inline constexpr std::string_view Name = "ChannelUpdate";
|
||||
};
|
||||
struct DpReadyEventInfo
|
||||
{
|
||||
using Type = dpp::ready_t;
|
||||
static inline constexpr size_t ID = DpEventID::Ready;
|
||||
static inline constexpr std::string_view Name = "Ready";
|
||||
};
|
||||
struct DpMessageDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::message_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::MessageDelete;
|
||||
static inline constexpr std::string_view Name = "MessageDelete";
|
||||
};
|
||||
struct DpGuildMemberRemoveEventInfo
|
||||
{
|
||||
using Type = dpp::guild_member_remove_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildMemberRemove;
|
||||
static inline constexpr std::string_view Name = "GuildMemberRemove";
|
||||
};
|
||||
struct DpResumedEventInfo
|
||||
{
|
||||
using Type = dpp::resumed_t;
|
||||
static inline constexpr size_t ID = DpEventID::Resumed;
|
||||
static inline constexpr std::string_view Name = "Resumed";
|
||||
};
|
||||
struct DpGuildRoleCreateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_role_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildRoleCreate;
|
||||
static inline constexpr std::string_view Name = "GuildRoleCreate";
|
||||
};
|
||||
struct DpTypingStartEventInfo
|
||||
{
|
||||
using Type = dpp::typing_start_t;
|
||||
static inline constexpr size_t ID = DpEventID::TypingStart;
|
||||
static inline constexpr std::string_view Name = "TypingStart";
|
||||
};
|
||||
struct DpMessageReactionAddEventInfo
|
||||
{
|
||||
using Type = dpp::message_reaction_add_t;
|
||||
static inline constexpr size_t ID = DpEventID::MessageReactionAdd;
|
||||
static inline constexpr std::string_view Name = "MessageReactionAdd";
|
||||
};
|
||||
struct DpGuildMembersChunkEventInfo
|
||||
{
|
||||
using Type = dpp::guild_members_chunk_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildMembersChunk;
|
||||
static inline constexpr std::string_view Name = "GuildMembersChunk";
|
||||
};
|
||||
struct DpMessageReactionRemoveEventInfo
|
||||
{
|
||||
using Type = dpp::message_reaction_remove_t;
|
||||
static inline constexpr size_t ID = DpEventID::MessageReactionRemove;
|
||||
static inline constexpr std::string_view Name = "MessageReactionRemove";
|
||||
};
|
||||
struct DpGuildCreateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildCreate;
|
||||
static inline constexpr std::string_view Name = "GuildCreate";
|
||||
};
|
||||
struct DpChannelCreateEventInfo
|
||||
{
|
||||
using Type = dpp::channel_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::ChannelCreate;
|
||||
static inline constexpr std::string_view Name = "ChannelCreate";
|
||||
};
|
||||
struct DpMessageReactionRemoveEmojiEventInfo
|
||||
{
|
||||
using Type = dpp::message_reaction_remove_emoji_t;
|
||||
static inline constexpr size_t ID = DpEventID::MessageReactionRemoveEmoji;
|
||||
static inline constexpr std::string_view Name = "MessageReactionRemoveEmoji";
|
||||
};
|
||||
struct DpMessageDeleteDulkEventInfo
|
||||
{
|
||||
using Type = dpp::message_delete_bulk_t;
|
||||
static inline constexpr size_t ID = DpEventID::MessageDeleteDulk;
|
||||
static inline constexpr std::string_view Name = "MessageDeleteDulk";
|
||||
};
|
||||
struct DpGuildRoleUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_role_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildRoleUpdate;
|
||||
static inline constexpr std::string_view Name = "GuildRoleUpdate";
|
||||
};
|
||||
struct DpGuildRoleDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::guild_role_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildRoleDelete;
|
||||
static inline constexpr std::string_view Name = "GuildRoleDelete";
|
||||
};
|
||||
struct DpChannelPinsUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::channel_pins_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::ChannelPinsUpdate;
|
||||
static inline constexpr std::string_view Name = "ChannelPinsUpdate";
|
||||
};
|
||||
struct DpMessageReactionRemoveAllEventInfo
|
||||
{
|
||||
using Type = dpp::message_reaction_remove_all_t;
|
||||
static inline constexpr size_t ID = DpEventID::MessageReactionRemoveAll;
|
||||
static inline constexpr std::string_view Name = "MessageReactionRemoveAll";
|
||||
};
|
||||
struct DpVoiceServerUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::voice_server_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceServerUpdate;
|
||||
static inline constexpr std::string_view Name = "VoiceServerUpdate";
|
||||
};
|
||||
struct DpGuildEmojisUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_emojis_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildEmojisUpdate;
|
||||
static inline constexpr std::string_view Name = "GuildEmojisUpdate";
|
||||
};
|
||||
struct DpGuildStickersUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_stickers_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildStickersUpdate;
|
||||
static inline constexpr std::string_view Name = "GuildStickersUpdate";
|
||||
};
|
||||
struct DpPresenceUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::presence_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::PresenceUpdate;
|
||||
static inline constexpr std::string_view Name = "PresenceUpdate";
|
||||
};
|
||||
struct DpWebhooksUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::webhooks_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::WebhooksUpdate;
|
||||
static inline constexpr std::string_view Name = "WebhooksUpdate";
|
||||
};
|
||||
struct DpAutomodRuleCreateEventInfo
|
||||
{
|
||||
using Type = dpp::automod_rule_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::AutomodRuleCreate;
|
||||
static inline constexpr std::string_view Name = "AutomodRuleCreate";
|
||||
};
|
||||
struct DpAutomodRuleUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::automod_rule_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::AutomodRuleUpdate;
|
||||
static inline constexpr std::string_view Name = "AutomodRuleUpdate";
|
||||
};
|
||||
struct DpAutomodRuleDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::automod_rule_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::AutomodRuleDelete;
|
||||
static inline constexpr std::string_view Name = "AutomodRuleDelete";
|
||||
};
|
||||
struct DpAutomodRuleExecuteEventInfo
|
||||
{
|
||||
using Type = dpp::automod_rule_execute_t;
|
||||
static inline constexpr size_t ID = DpEventID::AutomodRuleExecute;
|
||||
static inline constexpr std::string_view Name = "AutomodRuleExecute";
|
||||
};
|
||||
struct DpGuildMemberAddEventInfo
|
||||
{
|
||||
using Type = dpp::guild_member_add_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildMemberAdd;
|
||||
static inline constexpr std::string_view Name = "GuildMemberAdd";
|
||||
};
|
||||
struct DpInviteDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::invite_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::InviteDelete;
|
||||
static inline constexpr std::string_view Name = "InviteDelete";
|
||||
};
|
||||
struct DpGuildUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildUpdate;
|
||||
static inline constexpr std::string_view Name = "GuildUpdate";
|
||||
};
|
||||
struct DpGuildIntegrationsUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_integrations_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildIntegrationsUpdate;
|
||||
static inline constexpr std::string_view Name = "GuildIntegrationsUpdate";
|
||||
};
|
||||
struct DpGuildMemberUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_member_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildMemberUpdate;
|
||||
static inline constexpr std::string_view Name = "GuildMemberUpdate";
|
||||
};
|
||||
struct DpInviteCreateEventInfo
|
||||
{
|
||||
using Type = dpp::invite_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::InviteCreate;
|
||||
static inline constexpr std::string_view Name = "InviteCreate";
|
||||
};
|
||||
struct DpMessageUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::message_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::MessageUpdate;
|
||||
static inline constexpr std::string_view Name = "MessageUpdate";
|
||||
};
|
||||
struct DpUserUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::user_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::UserUpdate;
|
||||
static inline constexpr std::string_view Name = "UserUpdate";
|
||||
};
|
||||
struct DpMessageCreateEventInfo
|
||||
{
|
||||
using Type = dpp::message_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::MessageCreate;
|
||||
static inline constexpr std::string_view Name = "MessageCreate";
|
||||
};
|
||||
struct DpGuildAuditLogEntryCreateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_audit_log_entry_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildAuditLogEntryCreate;
|
||||
static inline constexpr std::string_view Name = "GuildAuditLogEntryCreate";
|
||||
};
|
||||
struct DpGuildBanAddEventInfo
|
||||
{
|
||||
using Type = dpp::guild_ban_add_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildBanAdd;
|
||||
static inline constexpr std::string_view Name = "GuildBanAdd";
|
||||
};
|
||||
struct DpGuildBanRemoveEventInfo
|
||||
{
|
||||
using Type = dpp::guild_ban_remove_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildBanRemove;
|
||||
static inline constexpr std::string_view Name = "GuildBanRemove";
|
||||
};
|
||||
struct DpIntegrationCreateEventInfo
|
||||
{
|
||||
using Type = dpp::integration_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::IntegrationCreate;
|
||||
static inline constexpr std::string_view Name = "IntegrationCreate";
|
||||
};
|
||||
struct DpIntegrationUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::integration_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::IntegrationUpdate;
|
||||
static inline constexpr std::string_view Name = "IntegrationUpdate";
|
||||
};
|
||||
struct DpIntegrationDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::integration_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::IntegrationDelete;
|
||||
static inline constexpr std::string_view Name = "IntegrationDelete";
|
||||
};
|
||||
struct DpThreadCreateEventInfo
|
||||
{
|
||||
using Type = dpp::thread_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::ThreadCreate;
|
||||
static inline constexpr std::string_view Name = "ThreadCreate";
|
||||
};
|
||||
struct DpThreadUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::thread_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::ThreadUpdate;
|
||||
static inline constexpr std::string_view Name = "ThreadUpdate";
|
||||
};
|
||||
struct DpThreadDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::thread_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::ThreadDelete;
|
||||
static inline constexpr std::string_view Name = "ThreadDelete";
|
||||
};
|
||||
struct DpThreadListSyncEventInfo
|
||||
{
|
||||
using Type = dpp::thread_list_sync_t;
|
||||
static inline constexpr size_t ID = DpEventID::ThreadListSync;
|
||||
static inline constexpr std::string_view Name = "ThreadListSync";
|
||||
};
|
||||
struct DpThreadMemberUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::thread_member_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::ThreadMemberUpdate;
|
||||
static inline constexpr std::string_view Name = "ThreadMemberUpdate";
|
||||
};
|
||||
struct DpThreadMembersUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::thread_members_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::ThreadMembersUpdate;
|
||||
static inline constexpr std::string_view Name = "ThreadMembersUpdate";
|
||||
};
|
||||
struct DpGuildScheduledEventCreateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_scheduled_event_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildScheduledEventCreate;
|
||||
static inline constexpr std::string_view Name = "GuildScheduledEventCreate";
|
||||
};
|
||||
struct DpGuildScheduledEventUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::guild_scheduled_event_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildScheduledEventUpdate;
|
||||
static inline constexpr std::string_view Name = "GuildScheduledEventUpdate";
|
||||
};
|
||||
struct DpGuildScheduledEventDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::guild_scheduled_event_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildScheduledEventDelete;
|
||||
static inline constexpr std::string_view Name = "GuildScheduledEventDelete";
|
||||
};
|
||||
struct DpGuildScheduledEventUserAddEventInfo
|
||||
{
|
||||
using Type = dpp::guild_scheduled_event_user_add_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildScheduledEventUserAdd;
|
||||
static inline constexpr std::string_view Name = "GuildScheduledEventUserAdd";
|
||||
};
|
||||
struct DpGuildScheduledEventUserRemoveEventInfo
|
||||
{
|
||||
using Type = dpp::guild_scheduled_event_user_remove_t;
|
||||
static inline constexpr size_t ID = DpEventID::GuildScheduledEventUserRemove;
|
||||
static inline constexpr std::string_view Name = "GuildScheduledEventUserRemove";
|
||||
};
|
||||
struct DpVoiceBufferSendEventInfo
|
||||
{
|
||||
using Type = dpp::voice_buffer_send_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceBufferSend;
|
||||
static inline constexpr std::string_view Name = "VoiceBufferSend";
|
||||
};
|
||||
struct DpVoiceUserTalkingEventInfo
|
||||
{
|
||||
using Type = dpp::voice_user_talking_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceUserTalking;
|
||||
static inline constexpr std::string_view Name = "VoiceUserTalking";
|
||||
};
|
||||
struct DpVoiceReadyEventInfo
|
||||
{
|
||||
using Type = dpp::voice_ready_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceReady;
|
||||
static inline constexpr std::string_view Name = "VoiceReady";
|
||||
};
|
||||
struct DpVoiceReceiveEventInfo
|
||||
{
|
||||
using Type = dpp::voice_receive_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceReceive;
|
||||
static inline constexpr std::string_view Name = "VoiceReceive";
|
||||
};
|
||||
struct DpVoiceReceiveCombinedEventInfo
|
||||
{
|
||||
using Type = dpp::voice_receive_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceReceiveCombined;
|
||||
static inline constexpr std::string_view Name = "VoiceReceiveCombined";
|
||||
};
|
||||
struct DpVoiceTrackMarkerEventInfo
|
||||
{
|
||||
using Type = dpp::voice_track_marker_t;
|
||||
static inline constexpr size_t ID = DpEventID::VoiceTrackMarker;
|
||||
static inline constexpr std::string_view Name = "VoiceTrackMarker";
|
||||
};
|
||||
struct DpStageInstanceCreateEventInfo
|
||||
{
|
||||
using Type = dpp::stage_instance_create_t;
|
||||
static inline constexpr size_t ID = DpEventID::StageInstanceCreate;
|
||||
static inline constexpr std::string_view Name = "StageInstanceCreate";
|
||||
};
|
||||
struct DpStageInstanceUpdateEventInfo
|
||||
{
|
||||
using Type = dpp::stage_instance_update_t;
|
||||
static inline constexpr size_t ID = DpEventID::StageInstanceUpdate;
|
||||
static inline constexpr std::string_view Name = "StageInstanceUpdate";
|
||||
};
|
||||
struct DpStageInstanceDeleteEventInfo
|
||||
{
|
||||
using Type = dpp::stage_instance_delete_t;
|
||||
static inline constexpr size_t ID = DpEventID::StageInstanceDelete;
|
||||
static inline constexpr std::string_view Name = "StageInstanceDelete";
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Utility used to acquire event information at compile time.
|
||||
*/
|
||||
template < int > struct EventInfoID;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Implementation.
|
||||
*/
|
||||
template < > struct EventInfoID< DpEventID::VoiceStateUpdate > : public DpVoiceStateUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::VoiceClientDisconnect > : public DpVoiceClientDisconnectEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::VoiceClientSpeaking > : public DpVoiceClientSpeakingEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::Log > : public DpLogEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildJoinRequestDelete > : public DpGuildJoinRequestDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::InteractionCreate > : public DpInteractionCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::SlashCommand > : public DpSlashCommandEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ButtonClick > : public DpButtonClickEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::AutoComplete > : public DpAutoCompleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::SelectClick > : public DpSelectClickEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::MessageContextMenu > : public DpMessageContextMenuEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::UserContextMenu > : public DpUserContextMenuEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::FormSubmit > : public DpFormSubmitEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildDelete > : public DpGuildDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ChannelDelete > : public DpChannelDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ChannelUpdate > : public DpChannelUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::Ready > : public DpReadyEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::MessageDelete > : public DpMessageDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildMemberRemove > : public DpGuildMemberRemoveEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::Resumed > : public DpResumedEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildRoleCreate > : public DpGuildRoleCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::TypingStart > : public DpTypingStartEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::MessageReactionAdd > : public DpMessageReactionAddEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildMembersChunk > : public DpGuildMembersChunkEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::MessageReactionRemove > : public DpMessageReactionRemoveEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildCreate > : public DpGuildCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ChannelCreate > : public DpChannelCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::MessageReactionRemoveEmoji > : public DpMessageReactionRemoveEmojiEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::MessageDeleteDulk > : public DpMessageDeleteDulkEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildRoleUpdate > : public DpGuildRoleUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildRoleDelete > : public DpGuildRoleDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ChannelPinsUpdate > : public DpChannelPinsUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::MessageReactionRemoveAll > : public DpMessageReactionRemoveAllEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::VoiceServerUpdate > : public DpVoiceServerUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildEmojisUpdate > : public DpGuildEmojisUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildStickersUpdate > : public DpGuildStickersUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::PresenceUpdate > : public DpPresenceUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::WebhooksUpdate > : public DpWebhooksUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::AutomodRuleCreate > : public DpAutomodRuleCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::AutomodRuleUpdate > : public DpAutomodRuleUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::AutomodRuleDelete > : public DpAutomodRuleDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::AutomodRuleExecute > : public DpAutomodRuleExecuteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildMemberAdd > : public DpGuildMemberAddEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::InviteDelete > : public DpInviteDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildUpdate > : public DpGuildUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildIntegrationsUpdate > : public DpGuildIntegrationsUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildMemberUpdate > : public DpGuildMemberUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::InviteCreate > : public DpInviteCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::MessageUpdate > : public DpMessageUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::UserUpdate > : public DpUserUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::MessageCreate > : public DpMessageCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildAuditLogEntryCreate > : public DpGuildAuditLogEntryCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildBanAdd > : public DpGuildBanAddEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildBanRemove > : public DpGuildBanRemoveEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::IntegrationCreate > : public DpIntegrationCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::IntegrationUpdate > : public DpIntegrationUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::IntegrationDelete > : public DpIntegrationDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ThreadCreate > : public DpThreadCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ThreadUpdate > : public DpThreadUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ThreadDelete > : public DpThreadDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ThreadListSync > : public DpThreadListSyncEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ThreadMemberUpdate > : public DpThreadMemberUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::ThreadMembersUpdate > : public DpThreadMembersUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildScheduledEventCreate > : public DpGuildScheduledEventCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildScheduledEventUpdate > : public DpGuildScheduledEventUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildScheduledEventDelete > : public DpGuildScheduledEventDeleteEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildScheduledEventUserAdd > : public DpGuildScheduledEventUserAddEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::GuildScheduledEventUserRemove > : public DpGuildScheduledEventUserRemoveEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::VoiceBufferSend > : public DpVoiceBufferSendEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::VoiceUserTalking > : public DpVoiceUserTalkingEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::VoiceReady > : public DpVoiceReadyEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::VoiceReceive > : public DpVoiceReceiveEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::VoiceReceiveCombined > : public DpVoiceReceiveCombinedEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::VoiceTrackMarker > : public DpVoiceTrackMarkerEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::StageInstanceCreate > : public DpStageInstanceCreateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::StageInstanceUpdate > : public DpStageInstanceUpdateEventInfo { };
|
||||
template < > struct EventInfoID< DpEventID::StageInstanceDelete > : public DpStageInstanceDeleteEventInfo { };
|
||||
|
||||
} // Namespace:: SqMod
|
787
module/Library/Discord/Events.cpp
Normal file
787
module/Library/Discord/Events.cpp
Normal file
@ -0,0 +1,787 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Events.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceStateUpdateEvent, _SC("SqDiscordVoiceStateUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceClientDisconnectEvent, _SC("SqDiscordVoiceClientDisconnectEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceClientSpeakingEvent, _SC("SqDiscordVoiceClientSpeakingEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpLogEvent, _SC("SqDiscordLogEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildJoinRequestDeleteEvent, _SC("SqDiscordGuildJoinRequestDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpInteractionCreateEvent, _SC("SqDiscordInteractionCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpSlashCommandEvent, _SC("SqDiscordSlashCommandEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpButtonClickEvent, _SC("SqDiscordButtonClickEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpAutoCompleteEvent, _SC("SqDiscordAutoCompleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpSelectClickEvent, _SC("SqDiscordSelectClickEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpMessageContextMenuEvent, _SC("SqDiscordMessageContextMenuEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpUserContextMenuEvent, _SC("SqDiscordUserContextMenuEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpFormSubmitEvent, _SC("SqDiscordFormSubmitEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildDeleteEvent, _SC("SqDiscordGuildDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpChannelDeleteEvent, _SC("SqDiscordChannelDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpChannelUpdateEvent, _SC("SqDiscordChannelUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpReadyEvent, _SC("SqDiscordReadyEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpMessageDeleteEvent, _SC("SqDiscordMessageDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildMemberRemoveEvent, _SC("SqDiscordGuildMemberRemoveEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpResumedEvent, _SC("SqDiscordResumedEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildRoleCreateEvent, _SC("SqDiscordGuildRoleCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpTypingStartEvent, _SC("SqDiscordTypingStartEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpMessageReactionAddEvent, _SC("SqDiscordMessageReactionAddEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildMembersChunkEvent, _SC("SqDiscordGuildMembersChunkEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpMessageReactionRemoveEvent, _SC("SqDiscordMessageReactionRemoveEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildCreateEvent, _SC("SqDiscordGuildCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpChannelCreateEvent, _SC("SqDiscordChannelCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpMessageReactionRemoveEmojiEvent, _SC("SqDiscordMessageReactionRemoveEmojiEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpMessageDeleteDulkEvent, _SC("SqDiscordMessageDeleteDulkEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildRoleUpdateEvent, _SC("SqDiscordGuildRoleUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildRoleDeleteEvent, _SC("SqDiscordGuildRoleDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpChannelPinsUpdateEvent, _SC("SqDiscordChannelPinsUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpMessageReactionRemoveAllEvent, _SC("SqDiscordMessageReactionRemoveAllEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceServerUpdateEvent, _SC("SqDiscordVoiceServerUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildEmojisUpdateEvent, _SC("SqDiscordGuildEmojisUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildStickersUpdateEvent, _SC("SqDiscordGuildStickersUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpPresenceUpdateEvent, _SC("SqDiscordPresenceUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpWebhooksUpdateEvent, _SC("SqDiscordWebhooksUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpAutomodRuleCreateEvent, _SC("SqDiscordAutomodRuleCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpAutomodRuleUpdateEvent, _SC("SqDiscordAutomodRuleUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpAutomodRuleDeleteEvent, _SC("SqDiscordAutomodRuleDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpAutomodRuleExecuteEvent, _SC("SqDiscordAutomodRuleExecuteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildMemberAddEvent, _SC("SqDiscordGuildMemberAddEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpInviteDeleteEvent, _SC("SqDiscordInviteDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildUpdateEvent, _SC("SqDiscordGuildUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildIntegrationsUpdateEvent, _SC("SqDiscordGuildIntegrationsUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildMemberUpdateEvent, _SC("SqDiscordGuildMemberUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpInviteCreateEvent, _SC("SqDiscordInviteCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpMessageUpdateEvent, _SC("SqDiscordMessageUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpUserUpdateEvent, _SC("SqDiscordUserUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpMessageCreateEvent, _SC("SqDiscordMessageCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildAuditLogEntryCreateEvent, _SC("SqDiscordGuildAuditLogEntryCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildBanAddEvent, _SC("SqDiscordGuildBanAddEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildBanRemoveEvent, _SC("SqDiscordGuildBanRemoveEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpIntegrationCreateEvent, _SC("SqDiscordIntegrationCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpIntegrationUpdateEvent, _SC("SqDiscordIntegrationUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpIntegrationDeleteEvent, _SC("SqDiscordIntegrationDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpThreadCreateEvent, _SC("SqDiscordThreadCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpThreadUpdateEvent, _SC("SqDiscordThreadUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpThreadDeleteEvent, _SC("SqDiscordThreadDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpThreadListSyncEvent, _SC("SqDiscordThreadListSyncEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpThreadMemberUpdateEvent, _SC("SqDiscordThreadMemberUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpThreadMembersUpdateEvent, _SC("SqDiscordThreadMembersUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildScheduledEventCreateEvent, _SC("SqDiscordGuildScheduledEventCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildScheduledEventUpdateEvent, _SC("SqDiscordGuildScheduledEventUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildScheduledEventDeleteEvent, _SC("SqDiscordGuildScheduledEventDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildScheduledEventUserAddEvent, _SC("SqDiscordGuildScheduledEventUserAddEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildScheduledEventUserRemoveEvent, _SC("SqDiscordGuildScheduledEventUserRemoveEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceBufferSendEvent, _SC("SqDiscordVoiceBufferSendEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceUserTalkingEvent, _SC("SqDiscordVoiceUserTalkingEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceReadyEvent, _SC("SqDiscordVoiceReadyEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceReceiveEvent, _SC("SqDiscordVoiceReceiveEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceReceiveCombinedEvent, _SC("SqDiscordVoiceReceiveCombinedEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceTrackMarkerEvent, _SC("SqDiscordVoiceTrackMarkerEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpStageInstanceCreateEvent, _SC("SqDiscordStageInstanceCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpStageInstanceUpdateEvent, _SC("SqDiscordStageInstanceUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDpStageInstanceDeleteEvent, _SC("SqDiscordStageInstanceDeleteEvent"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_Discord_Events(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceStateUpdate"),
|
||||
Class< DpVoiceStateUpdateEvent, NoConstructor< DpVoiceStateUpdateEvent > >(vm, SqDpVoiceStateUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceStateUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceStateUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceStateUpdateEvent::GetRawEvent)
|
||||
.Prop(_SC("State"), &DpVoiceStateUpdateEvent::GetState)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceClientDisconnect"),
|
||||
Class< DpVoiceClientDisconnectEvent, NoConstructor< DpVoiceClientDisconnectEvent > >(vm, SqDpVoiceClientDisconnectEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceClientDisconnectEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceClientDisconnectEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceClientDisconnectEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceClientSpeaking"),
|
||||
Class< DpVoiceClientSpeakingEvent, NoConstructor< DpVoiceClientSpeakingEvent > >(vm, SqDpVoiceClientSpeakingEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceClientSpeakingEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceClientSpeakingEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceClientSpeakingEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Log"),
|
||||
Class< DpLogEvent, NoConstructor< DpLogEvent > >(vm, SqDpLogEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpLogEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpLogEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpLogEvent::GetRawEvent)
|
||||
.Prop(_SC("Severity"), &DpLogEvent::GetSeverity)
|
||||
.Prop(_SC("Message"), &DpLogEvent::GetMessage)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildJoinRequestDelete"),
|
||||
Class< DpGuildJoinRequestDeleteEvent, NoConstructor< DpGuildJoinRequestDeleteEvent > >(vm, SqDpGuildJoinRequestDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildJoinRequestDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildJoinRequestDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildJoinRequestDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("InteractionCreate"),
|
||||
Class< DpInteractionCreateEvent, NoConstructor< DpInteractionCreateEvent > >(vm, SqDpInteractionCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpInteractionCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpInteractionCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpInteractionCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("SlashCommand"),
|
||||
Class< DpSlashCommandEvent, NoConstructor< DpSlashCommandEvent > >(vm, SqDpSlashCommandEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpSlashCommandEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpSlashCommandEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpSlashCommandEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ButtonClick"),
|
||||
Class< DpButtonClickEvent, NoConstructor< DpButtonClickEvent > >(vm, SqDpButtonClickEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpButtonClickEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpButtonClickEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpButtonClickEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("AutoComplete"),
|
||||
Class< DpAutoCompleteEvent, NoConstructor< DpAutoCompleteEvent > >(vm, SqDpAutoCompleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpAutoCompleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpAutoCompleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpAutoCompleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("SelectClick"),
|
||||
Class< DpSelectClickEvent, NoConstructor< DpSelectClickEvent > >(vm, SqDpSelectClickEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpSelectClickEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpSelectClickEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpSelectClickEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageContextMenu"),
|
||||
Class< DpMessageContextMenuEvent, NoConstructor< DpMessageContextMenuEvent > >(vm, SqDpMessageContextMenuEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpMessageContextMenuEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageContextMenuEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpMessageContextMenuEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("UserContextMenu"),
|
||||
Class< DpUserContextMenuEvent, NoConstructor< DpUserContextMenuEvent > >(vm, SqDpUserContextMenuEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpUserContextMenuEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpUserContextMenuEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpUserContextMenuEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("FormSubmit"),
|
||||
Class< DpFormSubmitEvent, NoConstructor< DpFormSubmitEvent > >(vm, SqDpFormSubmitEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpFormSubmitEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpFormSubmitEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpFormSubmitEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildDelete"),
|
||||
Class< DpGuildDeleteEvent, NoConstructor< DpGuildDeleteEvent > >(vm, SqDpGuildDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ChannelDelete"),
|
||||
Class< DpChannelDeleteEvent, NoConstructor< DpChannelDeleteEvent > >(vm, SqDpChannelDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpChannelDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpChannelDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpChannelDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ChannelUpdate"),
|
||||
Class< DpChannelUpdateEvent, NoConstructor< DpChannelUpdateEvent > >(vm, SqDpChannelUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpChannelUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpChannelUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpChannelUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Ready"),
|
||||
Class< DpReadyEvent, NoConstructor< DpReadyEvent > >(vm, SqDpReadyEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpReadyEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpReadyEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpReadyEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageDelete"),
|
||||
Class< DpMessageDeleteEvent, NoConstructor< DpMessageDeleteEvent > >(vm, SqDpMessageDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpMessageDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpMessageDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildMemberRemove"),
|
||||
Class< DpGuildMemberRemoveEvent, NoConstructor< DpGuildMemberRemoveEvent > >(vm, SqDpGuildMemberRemoveEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildMemberRemoveEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildMemberRemoveEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildMemberRemoveEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Resumed"),
|
||||
Class< DpResumedEvent, NoConstructor< DpResumedEvent > >(vm, SqDpResumedEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpResumedEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpResumedEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpResumedEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildRoleCreate"),
|
||||
Class< DpGuildRoleCreateEvent, NoConstructor< DpGuildRoleCreateEvent > >(vm, SqDpGuildRoleCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildRoleCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildRoleCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildRoleCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("TypingStart"),
|
||||
Class< DpTypingStartEvent, NoConstructor< DpTypingStartEvent > >(vm, SqDpTypingStartEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpTypingStartEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpTypingStartEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpTypingStartEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageReactionAdd"),
|
||||
Class< DpMessageReactionAddEvent, NoConstructor< DpMessageReactionAddEvent > >(vm, SqDpMessageReactionAddEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpMessageReactionAddEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageReactionAddEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpMessageReactionAddEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildMembersChunk"),
|
||||
Class< DpGuildMembersChunkEvent, NoConstructor< DpGuildMembersChunkEvent > >(vm, SqDpGuildMembersChunkEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildMembersChunkEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildMembersChunkEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildMembersChunkEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageReactionRemove"),
|
||||
Class< DpMessageReactionRemoveEvent, NoConstructor< DpMessageReactionRemoveEvent > >(vm, SqDpMessageReactionRemoveEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpMessageReactionRemoveEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageReactionRemoveEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpMessageReactionRemoveEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildCreate"),
|
||||
Class< DpGuildCreateEvent, NoConstructor< DpGuildCreateEvent > >(vm, SqDpGuildCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ChannelCreate"),
|
||||
Class< DpChannelCreateEvent, NoConstructor< DpChannelCreateEvent > >(vm, SqDpChannelCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpChannelCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpChannelCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpChannelCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageReactionRemoveEmoji"),
|
||||
Class< DpMessageReactionRemoveEmojiEvent, NoConstructor< DpMessageReactionRemoveEmojiEvent > >(vm, SqDpMessageReactionRemoveEmojiEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpMessageReactionRemoveEmojiEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageReactionRemoveEmojiEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpMessageReactionRemoveEmojiEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageDeleteDulk"),
|
||||
Class< DpMessageDeleteDulkEvent, NoConstructor< DpMessageDeleteDulkEvent > >(vm, SqDpMessageDeleteDulkEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpMessageDeleteDulkEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageDeleteDulkEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpMessageDeleteDulkEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildRoleUpdate"),
|
||||
Class< DpGuildRoleUpdateEvent, NoConstructor< DpGuildRoleUpdateEvent > >(vm, SqDpGuildRoleUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildRoleUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildRoleUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildRoleUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildRoleDelete"),
|
||||
Class< DpGuildRoleDeleteEvent, NoConstructor< DpGuildRoleDeleteEvent > >(vm, SqDpGuildRoleDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildRoleDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildRoleDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildRoleDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ChannelPinsUpdate"),
|
||||
Class< DpChannelPinsUpdateEvent, NoConstructor< DpChannelPinsUpdateEvent > >(vm, SqDpChannelPinsUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpChannelPinsUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpChannelPinsUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpChannelPinsUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageReactionRemoveAll"),
|
||||
Class< DpMessageReactionRemoveAllEvent, NoConstructor< DpMessageReactionRemoveAllEvent > >(vm, SqDpMessageReactionRemoveAllEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpMessageReactionRemoveAllEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageReactionRemoveAllEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpMessageReactionRemoveAllEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceServerUpdate"),
|
||||
Class< DpVoiceServerUpdateEvent, NoConstructor< DpVoiceServerUpdateEvent > >(vm, SqDpVoiceServerUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceServerUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceServerUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceServerUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildEmojisUpdate"),
|
||||
Class< DpGuildEmojisUpdateEvent, NoConstructor< DpGuildEmojisUpdateEvent > >(vm, SqDpGuildEmojisUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildEmojisUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildEmojisUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildEmojisUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildStickersUpdate"),
|
||||
Class< DpGuildStickersUpdateEvent, NoConstructor< DpGuildStickersUpdateEvent > >(vm, SqDpGuildStickersUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildStickersUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildStickersUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildStickersUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("PresenceUpdate"),
|
||||
Class< DpPresenceUpdateEvent, NoConstructor< DpPresenceUpdateEvent > >(vm, SqDpPresenceUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpPresenceUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpPresenceUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpPresenceUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("WebhooksUpdate"),
|
||||
Class< DpWebhooksUpdateEvent, NoConstructor< DpWebhooksUpdateEvent > >(vm, SqDpWebhooksUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpWebhooksUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpWebhooksUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpWebhooksUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("AutomodRuleCreate"),
|
||||
Class< DpAutomodRuleCreateEvent, NoConstructor< DpAutomodRuleCreateEvent > >(vm, SqDpAutomodRuleCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpAutomodRuleCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpAutomodRuleCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpAutomodRuleCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("AutomodRuleUpdate"),
|
||||
Class< DpAutomodRuleUpdateEvent, NoConstructor< DpAutomodRuleUpdateEvent > >(vm, SqDpAutomodRuleUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpAutomodRuleUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpAutomodRuleUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpAutomodRuleUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("AutomodRuleDelete"),
|
||||
Class< DpAutomodRuleDeleteEvent, NoConstructor< DpAutomodRuleDeleteEvent > >(vm, SqDpAutomodRuleDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpAutomodRuleDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpAutomodRuleDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpAutomodRuleDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("AutomodRuleExecute"),
|
||||
Class< DpAutomodRuleExecuteEvent, NoConstructor< DpAutomodRuleExecuteEvent > >(vm, SqDpAutomodRuleExecuteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpAutomodRuleExecuteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpAutomodRuleExecuteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpAutomodRuleExecuteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildMemberAdd"),
|
||||
Class< DpGuildMemberAddEvent, NoConstructor< DpGuildMemberAddEvent > >(vm, SqDpGuildMemberAddEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildMemberAddEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildMemberAddEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildMemberAddEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("InviteDelete"),
|
||||
Class< DpInviteDeleteEvent, NoConstructor< DpInviteDeleteEvent > >(vm, SqDpInviteDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpInviteDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpInviteDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpInviteDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildUpdate"),
|
||||
Class< DpGuildUpdateEvent, NoConstructor< DpGuildUpdateEvent > >(vm, SqDpGuildUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildIntegrationsUpdate"),
|
||||
Class< DpGuildIntegrationsUpdateEvent, NoConstructor< DpGuildIntegrationsUpdateEvent > >(vm, SqDpGuildIntegrationsUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildIntegrationsUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildIntegrationsUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildIntegrationsUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildMemberUpdate"),
|
||||
Class< DpGuildMemberUpdateEvent, NoConstructor< DpGuildMemberUpdateEvent > >(vm, SqDpGuildMemberUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildMemberUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildMemberUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildMemberUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("InviteCreate"),
|
||||
Class< DpInviteCreateEvent, NoConstructor< DpInviteCreateEvent > >(vm, SqDpInviteCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpInviteCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpInviteCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpInviteCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageUpdate"),
|
||||
Class< DpMessageUpdateEvent, NoConstructor< DpMessageUpdateEvent > >(vm, SqDpMessageUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpMessageUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpMessageUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("UserUpdate"),
|
||||
Class< DpUserUpdateEvent, NoConstructor< DpUserUpdateEvent > >(vm, SqDpUserUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpUserUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpUserUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpUserUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageCreate"),
|
||||
Class< DpMessageCreateEvent, NoConstructor< DpMessageCreateEvent > >(vm, SqDpMessageCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpMessageCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpMessageCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildAuditLogEntryCreate"),
|
||||
Class< DpGuildAuditLogEntryCreateEvent, NoConstructor< DpGuildAuditLogEntryCreateEvent > >(vm, SqDpGuildAuditLogEntryCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildAuditLogEntryCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildAuditLogEntryCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildAuditLogEntryCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildBanAdd"),
|
||||
Class< DpGuildBanAddEvent, NoConstructor< DpGuildBanAddEvent > >(vm, SqDpGuildBanAddEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildBanAddEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildBanAddEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildBanAddEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildBanRemove"),
|
||||
Class< DpGuildBanRemoveEvent, NoConstructor< DpGuildBanRemoveEvent > >(vm, SqDpGuildBanRemoveEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildBanRemoveEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildBanRemoveEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildBanRemoveEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("IntegrationCreate"),
|
||||
Class< DpIntegrationCreateEvent, NoConstructor< DpIntegrationCreateEvent > >(vm, SqDpIntegrationCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpIntegrationCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpIntegrationCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpIntegrationCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("IntegrationUpdate"),
|
||||
Class< DpIntegrationUpdateEvent, NoConstructor< DpIntegrationUpdateEvent > >(vm, SqDpIntegrationUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpIntegrationUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpIntegrationUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpIntegrationUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("IntegrationDelete"),
|
||||
Class< DpIntegrationDeleteEvent, NoConstructor< DpIntegrationDeleteEvent > >(vm, SqDpIntegrationDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpIntegrationDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpIntegrationDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpIntegrationDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadCreate"),
|
||||
Class< DpThreadCreateEvent, NoConstructor< DpThreadCreateEvent > >(vm, SqDpThreadCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpThreadCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpThreadCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadUpdate"),
|
||||
Class< DpThreadUpdateEvent, NoConstructor< DpThreadUpdateEvent > >(vm, SqDpThreadUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpThreadUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpThreadUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadDelete"),
|
||||
Class< DpThreadDeleteEvent, NoConstructor< DpThreadDeleteEvent > >(vm, SqDpThreadDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpThreadDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpThreadDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadListSync"),
|
||||
Class< DpThreadListSyncEvent, NoConstructor< DpThreadListSyncEvent > >(vm, SqDpThreadListSyncEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpThreadListSyncEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadListSyncEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpThreadListSyncEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadMemberUpdate"),
|
||||
Class< DpThreadMemberUpdateEvent, NoConstructor< DpThreadMemberUpdateEvent > >(vm, SqDpThreadMemberUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpThreadMemberUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadMemberUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpThreadMemberUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadMembersUpdate"),
|
||||
Class< DpThreadMembersUpdateEvent, NoConstructor< DpThreadMembersUpdateEvent > >(vm, SqDpThreadMembersUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpThreadMembersUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadMembersUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpThreadMembersUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildScheduledEventCreate"),
|
||||
Class< DpGuildScheduledEventCreateEvent, NoConstructor< DpGuildScheduledEventCreateEvent > >(vm, SqDpGuildScheduledEventCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildScheduledEventCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildScheduledEventCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildScheduledEventCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildScheduledEventUpdate"),
|
||||
Class< DpGuildScheduledEventUpdateEvent, NoConstructor< DpGuildScheduledEventUpdateEvent > >(vm, SqDpGuildScheduledEventUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildScheduledEventUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildScheduledEventUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildScheduledEventUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildScheduledEventDelete"),
|
||||
Class< DpGuildScheduledEventDeleteEvent, NoConstructor< DpGuildScheduledEventDeleteEvent > >(vm, SqDpGuildScheduledEventDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildScheduledEventDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildScheduledEventDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildScheduledEventDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildScheduledEventUserAdd"),
|
||||
Class< DpGuildScheduledEventUserAddEvent, NoConstructor< DpGuildScheduledEventUserAddEvent > >(vm, SqDpGuildScheduledEventUserAddEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildScheduledEventUserAddEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildScheduledEventUserAddEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildScheduledEventUserAddEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildScheduledEventUserRemove"),
|
||||
Class< DpGuildScheduledEventUserRemoveEvent, NoConstructor< DpGuildScheduledEventUserRemoveEvent > >(vm, SqDpGuildScheduledEventUserRemoveEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildScheduledEventUserRemoveEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildScheduledEventUserRemoveEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpGuildScheduledEventUserRemoveEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceBufferSend"),
|
||||
Class< DpVoiceBufferSendEvent, NoConstructor< DpVoiceBufferSendEvent > >(vm, SqDpVoiceBufferSendEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceBufferSendEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceBufferSendEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceBufferSendEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceUserTalking"),
|
||||
Class< DpVoiceUserTalkingEvent, NoConstructor< DpVoiceUserTalkingEvent > >(vm, SqDpVoiceUserTalkingEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceUserTalkingEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceUserTalkingEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceUserTalkingEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceReady"),
|
||||
Class< DpVoiceReadyEvent, NoConstructor< DpVoiceReadyEvent > >(vm, SqDpVoiceReadyEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceReadyEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceReadyEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceReadyEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceReceive"),
|
||||
Class< DpVoiceReceiveEvent, NoConstructor< DpVoiceReceiveEvent > >(vm, SqDpVoiceReceiveEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceReceiveEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceReceiveEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceReceiveEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceReceive"),
|
||||
Class< DpVoiceReceiveCombinedEvent, NoConstructor< DpVoiceReceiveCombinedEvent > >(vm, SqDpVoiceReceiveCombinedEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceReceiveCombinedEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceReceiveCombinedEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceReceiveCombinedEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceTrackMarker"),
|
||||
Class< DpVoiceTrackMarkerEvent, NoConstructor< DpVoiceTrackMarkerEvent > >(vm, SqDpVoiceTrackMarkerEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceTrackMarkerEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceTrackMarkerEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpVoiceTrackMarkerEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("StageInstanceCreate"),
|
||||
Class< DpStageInstanceCreateEvent, NoConstructor< DpStageInstanceCreateEvent > >(vm, SqDpStageInstanceCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpStageInstanceCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpStageInstanceCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpStageInstanceCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("StageInstanceUpdate"),
|
||||
Class< DpStageInstanceUpdateEvent, NoConstructor< DpStageInstanceUpdateEvent > >(vm, SqDpStageInstanceUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpStageInstanceUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpStageInstanceUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpStageInstanceUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("StageInstanceDelete"),
|
||||
Class< DpStageInstanceDeleteEvent, NoConstructor< DpStageInstanceDeleteEvent > >(vm, SqDpStageInstanceDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpStageInstanceDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpStageInstanceDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("Raw"), &DpStageInstanceDeleteEvent::GetRawEvent)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
2716
module/Library/Discord/Events.hpp
Normal file
2716
module/Library/Discord/Events.hpp
Normal file
File diff suppressed because it is too large
Load Diff
65
module/Library/Discord/Guild.cpp
Normal file
65
module/Library/Discord/Guild.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Guild.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDpGuildMember, _SC("SqDiscordGuildMember"))
|
||||
SQMOD_DECL_TYPENAME(SqDpGuild, _SC("SqDiscordGuild"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_Discord_Guild(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
ns.Bind(_SC("GuildMember"),
|
||||
Class< DpGuildMember, NoConstructor< DpGuildMember > >(vm, SqDpGuildMember::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuildMember::Fn)
|
||||
.Func(_SC("_cmp"), &DpGuildMember::SqCmp)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpGuildMember::IsValid)
|
||||
.Prop(_SC("JSON"), &DpGuildMember::BuildJSON)
|
||||
.Prop(_SC("Nickname"), &DpGuildMember::GetNickname, &DpGuildMember::SetNickname)
|
||||
.Prop(_SC("Roles"), &DpGuildMember::GetRoles)
|
||||
.Prop(_SC("RolesCount"), &DpGuildMember::RolesCount)
|
||||
.Prop(_SC("GuildID"), &DpGuildMember::GetGuildID, &DpGuildMember::SetGuildID)
|
||||
.Prop(_SC("UserID"), &DpGuildMember::GetUserID, &DpGuildMember::SetUserID)
|
||||
.Prop(_SC("Avatar"), &DpGuildMember::GetAvatar, &DpGuildMember::SetAvatar)
|
||||
.Prop(_SC("CommunicationDisabledUntil"), &DpGuildMember::GetCommunicationDisabledUntil, &DpGuildMember::SetCommunicationDisabledUntil)
|
||||
.Prop(_SC("JoinedAt"), &DpGuildMember::GetJoinedAt)
|
||||
.Prop(_SC("PremiumSince"), &DpGuildMember::GetPremiumSince)
|
||||
.Prop(_SC("Flags"), &DpGuildMember::GetFlags, &DpGuildMember::SetFlags)
|
||||
.Prop(_SC("CommunicationDisabled"), &DpGuildMember::IsCommunicationDisabled)
|
||||
.Prop(_SC("Deaf"), &DpGuildMember::GetDeaf, &DpGuildMember::SetDeaf)
|
||||
.Prop(_SC("Muted"), &DpGuildMember::GetMuted, &DpGuildMember::SetMuted)
|
||||
.Prop(_SC("IsPending"), &DpGuildMember::IsPending)
|
||||
.Prop(_SC("HasAnimatedGuildAvatar"), &DpGuildMember::HasAnimatedGuildAvatar)
|
||||
.Prop(_SC("Mention"), &DpGuildMember::GetMention)
|
||||
// Member Methods
|
||||
.Func(_SC("BuildJSON"), &DpGuildMember::BuildJSON_)
|
||||
.Func(_SC("GetNickname"), &DpGuildMember::ApplyNickname)
|
||||
.Func(_SC("AddRole"), &DpGuildMember::AddRole)
|
||||
.Func(_SC("EachRole"), &DpGuildMember::EachRole)
|
||||
.Func(_SC("ClearRoles"), &DpGuildMember::ClearRoles)
|
||||
.Func(_SC("FilterRoles"), &DpGuildMember::FilterRoles)
|
||||
.Func(_SC("GetFlags"), &DpGuildMember::ApplyFlags)
|
||||
.Func(_SC("GetAvatarURL"), &DpGuildMember::GetAvatarURL)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Guild"),
|
||||
Class< DpGuild, NoConstructor< DpGuild > >(vm, SqDpGuild::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpGuild::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpGuild::IsValid)
|
||||
.Prop(_SC("JSON"), &DpGuild::BuildJSON)
|
||||
.Prop(_SC("Name"), &DpGuild::GetName, &DpGuild::SetName)
|
||||
.Prop(_SC("Description"), &DpGuild::GetDescription, &DpGuild::SetDescription)
|
||||
// Member Methods
|
||||
.Func(_SC("BuildJSON"), &DpGuild::BuildJSON_)
|
||||
.Func(_SC("GetName"), &DpGuild::ApplyName)
|
||||
.Func(_SC("GetDescription"), &DpGuild::ApplyDescription)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
421
module/Library/Discord/Guild.hpp
Normal file
421
module/Library/Discord/Guild.hpp
Normal file
@ -0,0 +1,421 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Represents a guild on Discord (AKA a server).
|
||||
*/
|
||||
struct DpGuildMember
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::guild_member >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced guild member instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpGuildMember() noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpGuildMember(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
explicit DpGuildMember(const Ptr::element_type & o) noexcept
|
||||
: DpGuildMember(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpGuildMember(Ptr::element_type && o) noexcept
|
||||
: DpGuildMember(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpGuildMember(const DpGuildMember & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpGuildMember(DpGuildMember && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpGuildMember() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpGuildMember & operator = (const DpGuildMember & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpGuildMember & operator = (DpGuildMember && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord voice state handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build json representation of the object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
SQMOD_NODISCARD std::string BuildJSON_(bool with_id) const { return Valid().build_json(with_id); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if this member is equal to another member object.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger SqCmp(const DpGuildMember & o) const
|
||||
{
|
||||
if (Valid() == o.Valid()) {
|
||||
return 0;
|
||||
// Nonsense...
|
||||
} else if (Valid().user_id > o.Valid().user_id) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the nickname, or empty string if they don't have a nickname on this guild.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetNickname() const { return Valid().nickname; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the nickname.
|
||||
*/
|
||||
void SetNickname(StackStrF & name) const { Valid().set_nickname(name.ToStr()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the nickname.
|
||||
*/
|
||||
DpGuildMember & ApplyNickname(StackStrF & name) { SetNickname(name); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the list of roles this user has on this guild.
|
||||
*/
|
||||
SQMOD_NODISCARD Array GetRoles() const
|
||||
{
|
||||
return Array(SqVM()).Reserve(static_cast< SQInteger >(Valid().roles.size()))
|
||||
.AppendFromVector(Valid().roles);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of roles.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger RolesCount() const { return static_cast< SQInteger >(Valid().roles.size()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Add a new role.
|
||||
*/
|
||||
DpGuildMember & AddRole(dpp::snowflake role) { Valid().roles.push_back(role); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate all roles.
|
||||
*/
|
||||
DpGuildMember & EachRole(Function & fn)
|
||||
{
|
||||
for (const auto & a : Valid().roles)
|
||||
{
|
||||
fn.Execute(a);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of roles.
|
||||
*/
|
||||
DpGuildMember & ClearRoles(dpp::snowflake role) { Valid().roles.clear(); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Filter roles.
|
||||
*/
|
||||
DpGuildMember & FilterRoles(Function & fn)
|
||||
{
|
||||
std::vector< dpp::snowflake > list;
|
||||
// Reserve memory in advance
|
||||
list.reserve(Valid().roles.size());
|
||||
// Process each role individually
|
||||
for (const auto & role : Valid().roles)
|
||||
{
|
||||
auto ret = fn.Eval(role);
|
||||
// (null || true) == keep & false == skip
|
||||
if (!ret.IsNull() || !ret.template Cast< bool >())
|
||||
{
|
||||
list.push_back(role); // Keep this role
|
||||
}
|
||||
}
|
||||
// Use filtered roles
|
||||
Valid().roles.swap(list);
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild id.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetGuildID() const { return Valid().guild_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the guild id.
|
||||
*/
|
||||
void SetGuildID(dpp::snowflake id) { Valid().guild_id = id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the user id.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetUserID() const { return Valid().user_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the guild id.
|
||||
*/
|
||||
void SetUserID(dpp::snowflake id) { Valid().guild_id = id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the user avatar (per-server avatar is a nitro only feature).
|
||||
*/
|
||||
SQMOD_NODISCARD const dpp::utility::iconhash & GetAvatar() const { return Valid().avatar; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the user avatar (per-server avatar is a nitro only feature).
|
||||
*/
|
||||
void SetAvatar(const dpp::utility::iconhash & a) const { Valid().avatar = a; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the date and time when the time out will be removed; until then, they cannot interact with the guild.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetCommunicationDisabledUntil() const
|
||||
{
|
||||
return std::chrono::time_point_cast< std::chrono::seconds >(
|
||||
std::chrono::system_clock::from_time_t(Valid().communication_disabled_until)
|
||||
).time_since_epoch().count();
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assign a timestamp until communication is disabled.
|
||||
*/
|
||||
void SetCommunicationDisabledUntil(SQInteger ts) const
|
||||
{
|
||||
Valid().set_communication_disabled_until(
|
||||
std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >(std::chrono::seconds(ts)))
|
||||
);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the date and time the user joined the guild.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetJoinedAt() const
|
||||
{
|
||||
return std::chrono::time_point_cast< std::chrono::seconds >(
|
||||
std::chrono::system_clock::from_time_t(Valid().joined_at)
|
||||
).time_since_epoch().count();
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the date and time since the user is boosting.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetPremiumSince() const
|
||||
{
|
||||
return std::chrono::time_point_cast< std::chrono::seconds >(
|
||||
std::chrono::system_clock::from_time_t(Valid().premium_since)
|
||||
).time_since_epoch().count();
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild flags. Built from the bitmask defined by SqDiscordGuildMemberFlags.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return static_cast< SQInteger >(Valid().flags); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the guild flags.
|
||||
*/
|
||||
void SetFlags(SQInteger f) const { Valid().flags = static_cast< uint8_t >(f); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the guild flags.
|
||||
*/
|
||||
DpGuildMember & ApplyFlags(SQInteger f) { SetFlags(f); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is in time-out (communication disabled).
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsCommunicationDisabled() const { return Valid().is_communication_disabled(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is deafened.
|
||||
*/
|
||||
SQMOD_NODISCARD bool GetDeaf() const { return Valid().is_deaf(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is deafened.
|
||||
*/
|
||||
void SetDeaf(bool is_deafened) const { Valid().set_deaf(is_deafened); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is muted.
|
||||
*/
|
||||
SQMOD_NODISCARD bool GetMuted() const { return Valid().is_muted(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is muted.
|
||||
*/
|
||||
void SetMuted(bool is_muted) const { Valid().set_mute(is_muted); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is pending verification by membership screening.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsPending() const { return Valid().is_pending(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the the user's per-guild custom avatar is animated.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasAnimatedGuildAvatar() const { return Valid().has_animated_guild_avatar(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the the user's per-guild custom avatar is animated.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string GetAvatarURL(SQInteger size, SQInteger format, bool animated) const
|
||||
{ return Valid().get_avatar_url(static_cast< uint16_t >(size), static_cast< dpp::image_type >(format), animated); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a ping/mention for the user by nickname.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string GetMention() const { return Valid().get_mention(); }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Represents a guild on Discord (AKA a server)
|
||||
*/
|
||||
struct DpGuild
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::guild >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced guild instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpGuild() noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpGuild(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
explicit DpGuild(const Ptr::element_type & o) noexcept
|
||||
: DpGuild(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpGuild(Ptr::element_type && o) noexcept
|
||||
: DpGuild(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpGuild(const DpGuild & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpGuild(DpGuild && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpGuild() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpGuild & operator = (const DpGuild & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpGuild & operator = (DpGuild && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord guild handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build json representation of the object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
SQMOD_NODISCARD std::string BuildJSON_(bool with_id) const { return Valid().build_json(with_id); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild name. Min length: 2, Max length: 100 (not including leading/trailing spaces)
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetName() const { return Valid().name; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the guild name. Min length: 2, Max length: 100 (not including leading/trailing spaces)
|
||||
*/
|
||||
void SetName(StackStrF & name) const { Valid().set_name(name.ToStr()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the guild name. Min length: 2, Max length: 100 (not including leading/trailing spaces)
|
||||
*/
|
||||
DpGuild & ApplyName(StackStrF & name) { SetName(name); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the server description.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetDescription() const { return Valid().description; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the server description.
|
||||
*/
|
||||
void SetDescription(StackStrF & description) const { Valid().description = description.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the server description.
|
||||
*/
|
||||
DpGuild & ApplyDescription(StackStrF & description) { SetDescription(description); return *this; }
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/Integration.cpp
Normal file
9
module/Library/Discord/Integration.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Integration.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
13
module/Library/Discord/Integration.hpp
Normal file
13
module/Library/Discord/Integration.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/Message.cpp
Normal file
9
module/Library/Discord/Message.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Message.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
13
module/Library/Discord/Message.hpp
Normal file
13
module/Library/Discord/Message.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
117
module/Library/Discord/Misc.cpp
Normal file
117
module/Library/Discord/Misc.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Misc.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDpCachePolicy, _SC("SqDiscordCachePolicy"))
|
||||
SQMOD_DECL_TYPENAME(SqDpUptime, _SC("SqDiscordUptime"))
|
||||
SQMOD_DECL_TYPENAME(SqDpIconHash, _SC("SqDiscordIconHash"))
|
||||
SQMOD_DECL_TYPENAME(SqDpVoiceState, _SC("SqDiscordVoiceState"))
|
||||
SQMOD_DECL_TYPENAME(SqDpEmoji, _SC("SqDiscordEmoji"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_Discord_Misc(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Uptime"),
|
||||
Class< dpp::utility::uptime >(vm, SqDpUptime::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< double >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpUptime::Fn)
|
||||
.Func(_SC("_tostring"), &dpp::utility::uptime::to_string)
|
||||
// Member Variables
|
||||
.Var(_SC("Days"), &dpp::utility::uptime::days)
|
||||
.Var(_SC("Hours"), &dpp::utility::uptime::hours)
|
||||
.Var(_SC("Minutes"), &dpp::utility::uptime::mins)
|
||||
.Var(_SC("Seconds"), &dpp::utility::uptime::secs)
|
||||
// Member Methods
|
||||
.Func(_SC("ToSeconds"), &dpp::utility::uptime::to_secs)
|
||||
.Func(_SC("ToMilliseconds"), &dpp::utility::uptime::to_msecs)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("IconHash"),
|
||||
Class< dpp::utility::iconhash >(vm, SqDpIconHash::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const std::string & >()
|
||||
.Ctor< uint64_t, uint64_t >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpIconHash::Fn)
|
||||
.Func(_SC("_tostring"), &dpp::utility::iconhash::to_string)
|
||||
// Member Variables
|
||||
.Var(_SC("High"), &dpp::utility::iconhash::first)
|
||||
.Var(_SC("Low"), &dpp::utility::iconhash::second)
|
||||
// Member Methods
|
||||
.Func(_SC("Set"), &dpp::utility::iconhash::set)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("CachePolicy"),
|
||||
Class< DpCachePolicy >(vm, SqDpCachePolicy::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< SQInteger >()
|
||||
.Ctor< SQInteger, SQInteger >()
|
||||
.Ctor< SQInteger, SQInteger, SQInteger >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpCachePolicy::Fn)
|
||||
// Member Variables
|
||||
.Var(_SC("UserPolicy"), &DpCachePolicy::mUserPolicy)
|
||||
.Var(_SC("EmojiPolicy"), &DpCachePolicy::mEmojiPolicy)
|
||||
.Var(_SC("RolePolicy"), &DpCachePolicy::mRolePolicy)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceState"),
|
||||
Class< DpVoiceState, NoConstructor< DpVoiceState > >(vm, SqDpVoiceState::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpVoiceState::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpVoiceState::IsValid)
|
||||
.Prop(_SC("JSON"), &DpVoiceState::BuildJSON)
|
||||
.Prop(_SC("GuildID"), &DpVoiceState::GetGuildID)
|
||||
.Prop(_SC("ChannelID"), &DpVoiceState::GetChannelID)
|
||||
.Prop(_SC("UserID"), &DpVoiceState::GetUserID)
|
||||
.Prop(_SC("SessionID"), &DpVoiceState::GetSessionID)
|
||||
.Prop(_SC("Flags"), &DpVoiceState::GetFlags, &DpVoiceState::SetFlags)
|
||||
.Prop(_SC("RequestToSpeak"), &DpVoiceState::GetRequestToSpeak)
|
||||
.Prop(_SC("IsDeaf"), &DpVoiceState::IsDeaf)
|
||||
.Prop(_SC("IsMute"), &DpVoiceState::IsMute)
|
||||
.Prop(_SC("IsSelfMute"), &DpVoiceState::IsSelfMute)
|
||||
.Prop(_SC("IsSelfDeaf"), &DpVoiceState::IsSelfDeaf)
|
||||
.Prop(_SC("SelfStream"), &DpVoiceState::SelfStream)
|
||||
.Prop(_SC("SelfVideo"), &DpVoiceState::SelfVideo)
|
||||
.Prop(_SC("IsSuppressed"), &DpVoiceState::IsSuppressed)
|
||||
// Member Methods
|
||||
.Func(_SC("BuildJSON"), &DpVoiceState::BuildJSON_)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Emoji"),
|
||||
Class< DpEmoji, NoCopy< DpEmoji > >(vm, SqDpEmoji::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< StackStrF &, dpp::snowflake, SQInteger >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpEmoji::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmoji::IsValid)
|
||||
.Prop(_SC("JSON"), &DpEmoji::BuildJSON)
|
||||
.Prop(_SC("Name"), &DpEmoji::GetName, &DpEmoji::SetName)
|
||||
.Prop(_SC("ImageData"), &DpEmoji::GetImageData)
|
||||
.Prop(_SC("RequiresColons"), &DpEmoji::GetRequiresColons)
|
||||
.Prop(_SC("IsManaged"), &DpEmoji::GetIsManaged)
|
||||
.Prop(_SC("IsAnimated"), &DpEmoji::GetIsAnimated)
|
||||
.Prop(_SC("IsAvailable"), &DpEmoji::GetIsAvailable)
|
||||
.Prop(_SC("Format"), &DpEmoji::Format)
|
||||
.Prop(_SC("Mention"), &DpEmoji::GetMention)
|
||||
// Member Methods
|
||||
.Func(_SC("SetName"), &DpEmoji::ApplyName)
|
||||
.Func(_SC("GetMention"), &DpEmoji::GetMention_)
|
||||
.Func(_SC("BuildJSON"), &DpEmoji::BuildJSON_)
|
||||
.Func(_SC("LoadImage"), &DpEmoji::LoadImage)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
393
module/Library/Discord/Misc.hpp
Normal file
393
module/Library/Discord/Misc.hpp
Normal file
@ -0,0 +1,393 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Utilities.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Represents the caching policy of the cluster.
|
||||
*/
|
||||
struct DpCachePolicy
|
||||
{
|
||||
SQInteger mUserPolicy{dpp::cp_aggressive};
|
||||
SQInteger mEmojiPolicy{dpp::cp_aggressive};
|
||||
SQInteger mRolePolicy{dpp::cp_aggressive};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpCachePolicy() noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpCachePolicy(SQInteger user) noexcept
|
||||
: mUserPolicy(user), mEmojiPolicy(dpp::cp_aggressive), mRolePolicy(dpp::cp_aggressive)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpCachePolicy(SQInteger user, SQInteger emoji) noexcept
|
||||
: mUserPolicy(user), mEmojiPolicy(emoji), mRolePolicy(dpp::cp_aggressive)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpCachePolicy(SQInteger user, SQInteger emoji, SQInteger role) noexcept
|
||||
: mUserPolicy(user), mEmojiPolicy(emoji), mRolePolicy(role)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
DpCachePolicy(const DpCachePolicy &) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Convert to native cache policy type.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::cache_policy_t ToNative() const noexcept
|
||||
{
|
||||
return dpp::cache_policy_t{
|
||||
static_cast< dpp::cache_policy_setting_t >(mUserPolicy),
|
||||
static_cast< dpp::cache_policy_setting_t >(mEmojiPolicy),
|
||||
static_cast< dpp::cache_policy_setting_t >(mRolePolicy)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Represents the voice state of a user on a guild.
|
||||
* These are stored in the DpGuild object, and accessible there, or via DpChannel::GetVoiceMembers.
|
||||
*/
|
||||
struct DpVoiceState
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::voicestate >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced voice state instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpVoiceState() noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpVoiceState(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpVoiceState(const Ptr::element_type & o) noexcept
|
||||
: DpVoiceState(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpVoiceState(Ptr::element_type && o) noexcept
|
||||
: DpVoiceState(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpVoiceState(const DpVoiceState & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpVoiceState(DpVoiceState && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpVoiceState() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpVoiceState & operator = (const DpVoiceState & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpVoiceState & operator = (DpVoiceState && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord voice state handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild id this voice state is for (optional).
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetGuildID() const { return Valid().guild_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the channel id this user is connected to (may be empty).
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetChannelID() const { return Valid().channel_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the user id this voice state is for.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetUserID() const { return Valid().user_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the session id for this voice state.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetSessionID() const { return Valid().session_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the voice state flags (see SqDiscordVoiceStateFlags).
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return Valid().flags; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the voice state flags (see SqDiscordVoiceStateFlags).
|
||||
*/
|
||||
void SetFlags(SQInteger flags) const { Valid().flags = flags; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the time at which the user requested to speak, or 0.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetRequestToSpeak() const {
|
||||
return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(
|
||||
std::chrono::system_clock::from_time_t(Valid().request_to_speak).time_since_epoch()
|
||||
).count());
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build json representation of the object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
SQMOD_NODISCARD std::string BuildJSON_(bool with_id) const { return Valid().build_json(with_id); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the user is deafened by the server.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsDeaf() const { return Valid().is_deaf(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the user is muted by the server.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsMute() const { return Valid().is_mute(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the user muted themselves.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsSelfMute() const { return Valid().is_self_mute(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the user deafened themselves.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsSelfDeaf() const { return Valid().is_self_deaf(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the user is streaming using "Go Live".
|
||||
*/
|
||||
SQMOD_NODISCARD bool SelfStream() const { return Valid().self_stream(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the user's camera is enabled.
|
||||
*/
|
||||
SQMOD_NODISCARD bool SelfVideo() const { return Valid().self_video(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if user is suppressed. "HELP HELP I'M BEING SUPPRESSED!"
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsSuppressed() const { return Valid().is_suppressed(); }
|
||||
};
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Represents the voice state of a user on a guild.
|
||||
*/
|
||||
struct DpEmoji
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::emoji >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced voice state instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpEmoji() noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpEmoji(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpEmoji(const Ptr::element_type & o) noexcept
|
||||
: DpEmoji(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpEmoji(Ptr::element_type && o) noexcept
|
||||
: DpEmoji(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpEmoji(StackStrF & name, dpp::snowflake id, SQInteger flags)
|
||||
: DpEmoji(new Ptr::element_type(name.ToStr(), id, static_cast< uint8_t >(flags)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpEmoji(const DpEmoji & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpEmoji(DpEmoji && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpEmoji() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpEmoji & operator = (const DpEmoji & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpEmoji & operator = (DpEmoji && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord voice state handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the name of the emoji.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetName() const { return Valid().name; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the name of the emoji.
|
||||
*/
|
||||
void SetName(StackStrF & name) const { Valid().name = name.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the name of the emoji.
|
||||
*/
|
||||
DpEmoji & ApplyName(StackStrF & name) { SetName(name); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the user who uploaded the emoji.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetUserID() const { return Valid().user_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the user who uploaded the emoji.
|
||||
*/
|
||||
void SetUserID(dpp::snowflake id) const { Valid().user_id = id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the user who uploaded the emoji.
|
||||
*/
|
||||
DpEmoji & ApplyUserID(dpp::snowflake id) { SetUserID(id); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the flags for the emoji from SqDiscordEmojiFlags.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return Valid().flags; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the flags for the emoji from SqDiscordEmojiFlags.
|
||||
*/
|
||||
void SetFlags(SQInteger flags) const { Valid().flags = static_cast< uint8_t >(flags); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the flags for the emoji from SqDiscordEmojiFlags.
|
||||
*/
|
||||
DpEmoji & ApplyFlags(SQInteger flags) { SetFlags(flags); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the image data for the emoji if uploading.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj GetImageData() const { return !Valid().image_data ? LightObj{} : LightObj(*Valid().image_data); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create a mentionable emoji.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string GetMention_(StackStrF & name, dpp::snowflake id, bool is_animated = false) const
|
||||
{ return Valid().get_mention(name.ToStr(), id, is_animated); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build json representation of the object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
SQMOD_NODISCARD std::string BuildJSON_(bool with_id) const { return Valid().build_json(with_id); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve whether the Emoji requires colons.
|
||||
*/
|
||||
SQMOD_NODISCARD bool GetRequiresColons() const { return Valid().requires_colons(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve whether the Emoji is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool GetIsManaged() const { return Valid().is_managed(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve whether the Emoji is animated.
|
||||
*/
|
||||
SQMOD_NODISCARD bool GetIsAnimated() const { return Valid().is_animated(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve whether the Emoji is available.
|
||||
*/
|
||||
SQMOD_NODISCARD bool GetIsAvailable() const { return Valid().is_available(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Load an image into the object as base64.
|
||||
*/
|
||||
DpEmoji & LoadImage(StackStrF & data, SQInteger type) { Valid().load_image(data.ToStr(), static_cast< dpp::image_type >(type)); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Format to name if unicode, name:id if has id or a:name:id if animated.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string Format() const { return Valid().format(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the mention/ping for the emoji.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string GetMention() const { return Valid().get_mention(); }
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
143
module/Library/Discord/Presence.cpp
Normal file
143
module/Library/Discord/Presence.cpp
Normal file
@ -0,0 +1,143 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Presence.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDpActivityButton, _SC("SqDiscordActivityButton"))
|
||||
SQMOD_DECL_TYPENAME(SqDpActivityButtons, _SC("SqDiscordActivityButtons"))
|
||||
SQMOD_DECL_TYPENAME(SqDpActivityAssets, _SC("SqDiscordActivityAssets"))
|
||||
SQMOD_DECL_TYPENAME(SqDpActivitySecrets, _SC("SqDiscordActivitySecrets"))
|
||||
SQMOD_DECL_TYPENAME(SqDpActivity, _SC("SqDiscordActivity"))
|
||||
SQMOD_DECL_TYPENAME(SqDpActivities, _SC("SqDiscordActivities"))
|
||||
SQMOD_DECL_TYPENAME(SqDpPresence, _SC("SqDiscordPresence"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_Discord_Presence(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ActivityButton"),
|
||||
Class< DpActivityButton, NoCopy< DpActivityButton > >(vm, SqDpActivityButton::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpActivityButton::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpActivityButton::IsValid)
|
||||
.Prop(_SC("Label"), &DpActivityButton::GetLabel, &DpActivityButton::SetLabel)
|
||||
.Prop(_SC("URL"), &DpActivityButton::GetURL, &DpActivityButton::SetURL)
|
||||
// Member Methods
|
||||
.Func(_SC("SetLabel"), &DpActivityButton::ApplyLabel)
|
||||
.Func(_SC("SetURL"), &DpActivityButton::ApplyURL)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Register_Discord_VectorProxy< dpp::activity_button, DpActivityButton, SqDpActivityButton >(vm, ns, _SC("ActivityButtons"));
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ActivityAssets"),
|
||||
Class< DpActivityAssets, NoCopy< DpActivityAssets > >(vm, SqDpActivityAssets::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpActivityAssets::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpActivityAssets::IsValid)
|
||||
.Prop(_SC("LargeImage"), &DpActivityAssets::GetLargeImage, &DpActivityAssets::SetLargeImage)
|
||||
.Prop(_SC("LargeText"), &DpActivityAssets::GetLargeText, &DpActivityAssets::SetLargeText)
|
||||
.Prop(_SC("SmallImage"), &DpActivityAssets::GetSmallImage, &DpActivityAssets::SetSmallImage)
|
||||
.Prop(_SC("SmallText"), &DpActivityAssets::GetSmallText, &DpActivityAssets::SetSmallText)
|
||||
// Member Methods
|
||||
.Func(_SC("SetLargeImage"), &DpActivityAssets::ApplyLargeImage)
|
||||
.Func(_SC("SetLargeText"), &DpActivityAssets::ApplyLargeText)
|
||||
.Func(_SC("SetSmallImage"), &DpActivityAssets::ApplySmallImage)
|
||||
.Func(_SC("SetSmallText"), &DpActivityAssets::ApplySmallText)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ActivitySecrets"),
|
||||
Class< DpActivitySecrets, NoCopy< DpActivitySecrets > >(vm, SqDpActivitySecrets::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpActivitySecrets::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpActivitySecrets::IsValid)
|
||||
.Prop(_SC("Join"), &DpActivitySecrets::GetJoin, &DpActivitySecrets::SetJoin)
|
||||
.Prop(_SC("Spectate"), &DpActivitySecrets::GetSpectate, &DpActivitySecrets::SetSpectate)
|
||||
.Prop(_SC("Match"), &DpActivitySecrets::GetMatch, &DpActivitySecrets::SetMatch)
|
||||
// Member Methods
|
||||
.Func(_SC("SetJoin"), &DpActivitySecrets::ApplyJoin)
|
||||
.Func(_SC("SetSpectate"), &DpActivitySecrets::ApplySpectate)
|
||||
.Func(_SC("SetMatch"), &DpActivitySecrets::ApplyMatch)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Activity"),
|
||||
Class< DpActivity, NoCopy< DpActivity > >(vm, SqDpActivity::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< SQInteger, StackStrF &, StackStrF &, StackStrF & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpActivity::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpActivity::IsValid)
|
||||
.Prop(_SC("Name"), &DpActivity::GetName, &DpActivity::SetName)
|
||||
.Prop(_SC("State"), &DpActivity::GetState, &DpActivity::SetState)
|
||||
.Prop(_SC("Details"), &DpActivity::GetDetails, &DpActivity::SetDetails)
|
||||
.Prop(_SC("Assets"), &DpActivity::GetAssets)
|
||||
.Prop(_SC("Buttons"), &DpActivity::GetButtons)
|
||||
.Prop(_SC("Emoji"), &DpActivity::GetEmoji)
|
||||
.Prop(_SC("PartyID"), &DpActivity::GetPartyID)
|
||||
.Prop(_SC("CurrentPartySize"), &DpActivity::GetCurrentPartySize)
|
||||
.Prop(_SC("MaxPartySize"), &DpActivity::GetMaxPartySize)
|
||||
.Prop(_SC("Secrets"), &DpActivity::GetSecrets)
|
||||
.Prop(_SC("URL"), &DpActivity::GetURL, &DpActivity::SetURL)
|
||||
.Prop(_SC("Type"), &DpActivity::GetType, &DpActivity::SetType)
|
||||
.Prop(_SC("CreatedAt"), &DpActivity::GetCreatedAt, &DpActivity::SetCreatedAt)
|
||||
.Prop(_SC("Start"), &DpActivity::GetStart, &DpActivity::SetStart)
|
||||
.Prop(_SC("End"), &DpActivity::GetEnd, &DpActivity::SetEnd)
|
||||
.Prop(_SC("ApplicationID"), &DpActivity::GetApplicationID)
|
||||
.Prop(_SC("Flags"), &DpActivity::GetFlags, &DpActivity::SetFlags)
|
||||
.Prop(_SC("Instance"), &DpActivity::IsInstance)
|
||||
// Member Methods
|
||||
.Func(_SC("SetName"), &DpActivity::ApplyName)
|
||||
.Func(_SC("SetState"), &DpActivity::ApplyState)
|
||||
.Func(_SC("SetDetails"), &DpActivity::ApplyDetails)
|
||||
.Func(_SC("SetURL"), &DpActivity::ApplyURL)
|
||||
.Func(_SC("SetType"), &DpActivity::ApplyType)
|
||||
.Func(_SC("SetCreatedAt"), &DpActivity::ApplyCreatedAt)
|
||||
.Func(_SC("SetStart"), &DpActivity::ApplyStart)
|
||||
.Func(_SC("SetEnd"), &DpActivity::ApplyEnd)
|
||||
.Func(_SC("SetFlags"), &DpActivity::ApplyFlags)
|
||||
.Func(_SC("GetLargeAssetURL"), &DpActivity::GetLargeAssetURL)
|
||||
.Func(_SC("GetSmallAssetURL"), &DpActivity::GetSmallAssetURL)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Register_Discord_VectorProxy< dpp::activity, DpActivity, SqDpActivities >(vm, ns, _SC("Activities"));
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Presence"),
|
||||
Class< DpPresence, NoCopy< DpPresence > >(vm, SqDpPresence::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< SQInteger, DpActivity & >()
|
||||
.Ctor< SQInteger, SQInteger, StackStrF & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDpPresence::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpPresence::IsValid)
|
||||
.Prop(_SC("JSON"), &DpPresence::BuildJSON)
|
||||
.Prop(_SC("UserID"), &DpPresence::GetUserID, &DpPresence::SetUserID)
|
||||
.Prop(_SC("GuildID"), &DpPresence::GetGuildID, &DpPresence::SetGuildID)
|
||||
.Prop(_SC("Flags"), &DpPresence::GetFlags, &DpPresence::SetFlags)
|
||||
.Prop(_SC("Activities"), &DpPresence::GetActivities)
|
||||
.Prop(_SC("DesktopStatus"), &DpPresence::GetDesktopStatus)
|
||||
.Prop(_SC("WebStatus"), &DpPresence::GetWebStatus)
|
||||
.Prop(_SC("MobileStatus"), &DpPresence::GetMobileStatus)
|
||||
.Prop(_SC("Status"), &DpPresence::GetStatus)
|
||||
// Member Methods
|
||||
.Func(_SC("SetUserID"), &DpPresence::ApplyUserID)
|
||||
.Func(_SC("SetGuildID"), &DpPresence::ApplyGuildID)
|
||||
.Func(_SC("SetFlags"), &DpPresence::ApplyFlags)
|
||||
.Func(_SC("BuildJSON"), &DpVoiceState::BuildJSON_)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
928
module/Library/Discord/Presence.hpp
Normal file
928
module/Library/Discord/Presence.hpp
Normal file
@ -0,0 +1,928 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Misc.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* An activity button is a custom button shown in the rich presence. Can be to join a game or whatever.
|
||||
*/
|
||||
struct DpActivityButton
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::activity_button >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced activity instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpActivityButton() noexcept
|
||||
: DpActivityButton(new Ptr::element_type(), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpActivityButton(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
explicit DpActivityButton(const Ptr::element_type & o) noexcept
|
||||
: DpActivityButton(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpActivityButton(Ptr::element_type && o) noexcept
|
||||
: DpActivityButton(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpActivityButton(const DpActivityButton & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpActivityButton(DpActivityButton && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpActivityButton() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpActivityButton & operator = (const DpActivityButton & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpActivityButton & operator = (DpActivityButton && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord activity button handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the text shown on the button (1-32 characters).
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetLabel() const { return Valid().label; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the text shown on the button (1-32 characters).
|
||||
*/
|
||||
void SetLabel(StackStrF & label) const { Valid().label = label.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the text shown on the button (1-32 characters).
|
||||
*/
|
||||
DpActivityButton & ApplyLabel(StackStrF & label) { SetLabel(label); return *this; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the url opened when clicking the button (1-512 characters). It's may be empty.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetURL() const { return Valid().url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the url opened when clicking the button (1-512 characters).
|
||||
*/
|
||||
void SetURL(StackStrF & url) const { Valid().url = url.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the url opened when clicking the button (1-512 characters).
|
||||
*/
|
||||
DpActivityButton & ApplyURL(StackStrF & url) { SetURL(url); return *this; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* An activity asset are the images and the hover text displayed in the rich presence.
|
||||
*/
|
||||
struct DpActivityAssets
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::activity_assets >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced activity instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpActivityAssets() noexcept
|
||||
: DpActivityAssets(new Ptr::element_type(), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpActivityAssets(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
explicit DpActivityAssets(const Ptr::element_type & o) noexcept
|
||||
: DpActivityAssets(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpActivityAssets(Ptr::element_type && o) noexcept
|
||||
: DpActivityAssets(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpActivityAssets(const DpActivityAssets & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpActivityAssets(DpActivityAssets && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpActivityAssets() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpActivityAssets & operator = (const DpActivityAssets & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpActivityAssets & operator = (DpActivityAssets && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord activity assets handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the large asset image which usually contain snowflake ID or prefixed image ID.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetLargeImage() const { return Valid().large_image; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the large asset image.
|
||||
*/
|
||||
void SetLargeImage(StackStrF & large_image) const { Valid().large_image = large_image.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the large asset image.
|
||||
*/
|
||||
DpActivityAssets & ApplyLargeImage(StackStrF & large_image) { SetLargeImage(large_image); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the text displayed when hovering over the large image of the activity.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetLargeText() const { return Valid().large_text; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the text displayed when hovering over the large image of the activity.
|
||||
*/
|
||||
void SetLargeText(StackStrF & large_text) const { Valid().large_text = large_text.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the text displayed when hovering over the large image of the activity.
|
||||
*/
|
||||
DpActivityAssets & ApplyLargeText(StackStrF & large_text) { SetLargeText(large_text); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the small asset image which usually contain snowflake ID or prefixed image ID.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetSmallImage() const { return Valid().small_image; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the small asset image.
|
||||
*/
|
||||
void SetSmallImage(StackStrF & small_image) const { Valid().small_image = small_image.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the small asset image.
|
||||
*/
|
||||
DpActivityAssets & ApplySmallImage(StackStrF & small_image) { SetSmallImage(small_image); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the text displayed when hovering over the small image of the activity.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetSmallText() const { return Valid().small_text; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the text displayed when hovering over the small image of the activity.
|
||||
*/
|
||||
void SetSmallText(StackStrF & small_text) const { Valid().small_text = small_text.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the text displayed when hovering over the small image of the activity.
|
||||
*/
|
||||
DpActivityAssets & ApplySmallText(StackStrF & small_text) { SetSmallText(small_text); return *this; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Secrets for Rich Presence joining and spectating.
|
||||
*/
|
||||
struct DpActivitySecrets
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::activity_secrets >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced activity instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpActivitySecrets() noexcept
|
||||
: DpActivitySecrets(new Ptr::element_type(), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpActivitySecrets(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
explicit DpActivitySecrets(const Ptr::element_type & o) noexcept
|
||||
: DpActivitySecrets(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpActivitySecrets(Ptr::element_type && o) noexcept
|
||||
: DpActivitySecrets(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpActivitySecrets(const DpActivitySecrets & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpActivitySecrets(DpActivitySecrets && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpActivitySecrets() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpActivitySecrets & operator = (const DpActivitySecrets & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpActivitySecrets & operator = (DpActivitySecrets && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord activity secrets handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the secret for joining a party.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetJoin() const { return Valid().join; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the secret for joining a party.
|
||||
*/
|
||||
void SetJoin(StackStrF & join) const { Valid().join = join.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the secret for joining a party.
|
||||
*/
|
||||
DpActivitySecrets & ApplyJoin(StackStrF & join) { SetJoin(join); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the secret for spectating a game.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetSpectate() const { return Valid().spectate; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the secret for spectating a game.
|
||||
*/
|
||||
void SetSpectate(StackStrF & spectate) const { Valid().spectate = spectate.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the secret for spectating a game.
|
||||
*/
|
||||
DpActivitySecrets & ApplySpectate(StackStrF & spectate) { SetSpectate(spectate); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the secret for a specific instanced match.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetMatch() const { return Valid().match; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the secret for a specific instanced match.
|
||||
*/
|
||||
void SetMatch(StackStrF & match) const { Valid().match = match.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the secret for a specific instanced match.
|
||||
*/
|
||||
DpActivitySecrets & ApplyMatch(StackStrF & match) { SetMatch(match); return *this; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* An activity is a representation of what a user is doing. It might be a game, or a website, or a movie. Whatever.
|
||||
*/
|
||||
struct DpActivity
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::activity >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced activity instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
// --------------------------------------------------------------------------------------------
|
||||
using Buttons = DpVectorProxy< dpp::activity_button, DpActivityButton >;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
LightObj mSqAssets{};
|
||||
LightObj mSqButtons{};
|
||||
LightObj mSqEmoji{};
|
||||
LightObj mSqSecrets{};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpActivity() noexcept
|
||||
: DpActivity(new Ptr::element_type(), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpActivity(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
explicit DpActivity(const Ptr::element_type & o) noexcept
|
||||
: DpActivity(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpActivity(Ptr::element_type && o) noexcept
|
||||
: DpActivity(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpActivity(SQInteger type, StackStrF & name, StackStrF & state, StackStrF & url)
|
||||
: DpActivity(new Ptr::element_type(static_cast< dpp::activity_type >(type), name.ToStr(), state.ToStr(), url.ToStr()), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpActivity(const DpActivity & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpActivity(DpActivity && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpActivity() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpActivity & operator = (const DpActivity & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpActivity & operator = (DpActivity && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Cleanup activity assets, if any
|
||||
if (!mSqAssets.IsNull())
|
||||
{
|
||||
mSqAssets.CastI< DpActivityAssets >()->Cleanup();
|
||||
// Release script resources
|
||||
mSqAssets.Release();
|
||||
}
|
||||
// Cleanup activity buttons, if any
|
||||
if (!mSqButtons.IsNull())
|
||||
{
|
||||
mSqButtons.CastI< Buttons >()->Cleanup();
|
||||
// Release script resources
|
||||
mSqButtons.Release();
|
||||
}
|
||||
// Cleanup activity emoji, if any
|
||||
if (!mSqEmoji.IsNull())
|
||||
{
|
||||
mSqEmoji.CastI< DpEmoji >()->Cleanup();
|
||||
// Release script resources
|
||||
mSqEmoji.Release();
|
||||
}
|
||||
// Cleanup activity secrets, if any
|
||||
if (!mSqSecrets.IsNull())
|
||||
{
|
||||
mSqSecrets.CastI< DpActivitySecrets >()->Cleanup();
|
||||
// Release script resources
|
||||
mSqSecrets.Release();
|
||||
}
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord activity handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the name of the activity. e.g. "Vice City"
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetName() const { return Valid().name; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the name of the activity.
|
||||
*/
|
||||
void SetName(StackStrF & name) const { Valid().name = name.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the name of the activity.
|
||||
*/
|
||||
DpActivity & ApplyName(StackStrF & name) { SetName(name); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the state of the activity. e.g. "Waiting in lobby"
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetState() const { return Valid().state; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the state of the activity.
|
||||
*/
|
||||
void SetState(StackStrF & state) const { Valid().state = state.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the state of the activity.
|
||||
*/
|
||||
DpActivity & ApplyState(StackStrF & state) { SetState(state); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the details of the activity. What the player is currently doing.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetDetails() const { return Valid().details; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the details of the activity.
|
||||
*/
|
||||
void SetDetails(StackStrF & details) const { Valid().details = details.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the details of the activity.
|
||||
*/
|
||||
DpActivity & ApplyDetails(StackStrF & details) { SetDetails(details); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the images for the presence and their hover texts.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetAssets()
|
||||
{
|
||||
if (mSqAssets.IsNull())
|
||||
{
|
||||
mSqAssets = LightObj{SqTypeIdentity< DpActivityAssets >{}, SqVM(), &Valid().assets, false};
|
||||
}
|
||||
// Return the associated script object
|
||||
return mSqAssets;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the url of the activity. Only applicable for certain sites such a YouTube.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetURL() const { return Valid().url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the url of the activity.
|
||||
*/
|
||||
void SetURL(StackStrF & url) const { Valid().url = url.ToStr(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the url of the activity.
|
||||
*/
|
||||
DpActivity & ApplyURL(StackStrF & url) { SetURL(url); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the custom buttons shown in the Rich Presence (max 2).
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetButtons()
|
||||
{
|
||||
if (mSqButtons.IsNull())
|
||||
{
|
||||
mSqButtons = LightObj{SqTypeIdentity< Buttons >{}, SqVM(), &Valid().buttons, false};
|
||||
}
|
||||
// Return the associated script object
|
||||
return mSqButtons;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the emoji used for the custom status.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetEmoji()
|
||||
{
|
||||
if (mSqEmoji.IsNull())
|
||||
{
|
||||
mSqEmoji = LightObj{SqTypeIdentity< DpEmoji >{}, SqVM(), &Valid().emoji, false};
|
||||
}
|
||||
// Return the associated script object
|
||||
return mSqEmoji;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the ID of the party.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetPartyID() const { return Valid().party.id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the party's current size. Used to show the party's current size.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetCurrentPartySize() const { return Valid().party.current_size; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the party's maximum size. Used to show the party's maximum size.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetMaxPartySize() const { return Valid().party.maximum_size; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the secrets for rich presence joining and spectating.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetSecrets()
|
||||
{
|
||||
if (mSqSecrets.IsNull())
|
||||
{
|
||||
mSqSecrets = LightObj{SqTypeIdentity< DpActivitySecrets >{}, SqVM(), &Valid().secrets, false};
|
||||
}
|
||||
// Return the associated script object
|
||||
return mSqSecrets;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the type for the activity from SqDiscordActivityType.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetType() const { return Valid().type; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the type for the activity from SqDiscordActivityType.
|
||||
*/
|
||||
void SetType(SQInteger type) const { Valid().type = static_cast< dpp::activity_type >(type); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the type for the activity from SqDiscordActivityType.
|
||||
*/
|
||||
DpActivity & ApplyType(SQInteger type) { SetType(type); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve when the activity was created.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetCreatedAt() const
|
||||
{
|
||||
return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::from_time_t(Valid().created_at).time_since_epoch()).count());
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify when the activity was created.
|
||||
*/
|
||||
void SetCreatedAt(SQInteger s) const
|
||||
{
|
||||
Valid().created_at = std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >{std::chrono::seconds{s}});
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify when the activity was created.
|
||||
*/
|
||||
DpActivity & ApplyCreatedAt(SQInteger s) { SetCreatedAt(s); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve when the activity was started.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetStart() const
|
||||
{
|
||||
return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::from_time_t(Valid().start).time_since_epoch()).count());
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify when the activity was started.
|
||||
*/
|
||||
void SetStart(SQInteger s) const
|
||||
{
|
||||
Valid().start = std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >{std::chrono::seconds{s}});
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify when the activity was started.
|
||||
*/
|
||||
DpActivity & ApplyStart(SQInteger s) { SetStart(s); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve when the activity was stopped.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetEnd() const
|
||||
{
|
||||
return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::from_time_t(Valid().end).time_since_epoch()).count());
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify when the activity was stopped.
|
||||
*/
|
||||
void SetEnd(SQInteger s) const
|
||||
{
|
||||
Valid().end = std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >{std::chrono::seconds{s}});
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify when the activity was stopped.
|
||||
*/
|
||||
DpActivity & ApplyEnd(SQInteger s) { SetEnd(s); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the creating application (e.g. a linked account on the user's client)
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetApplicationID() const { return Valid().application_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the flags for the activity from SqDiscordActivityFlags.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return Valid().flags; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the flags for the activity from SqDiscordActivityFlags.
|
||||
*/
|
||||
void SetFlags(SQInteger flags) const { Valid().flags = static_cast< uint8_t >(flags); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the flags for the activity from SqDiscordActivityFlags.
|
||||
*/
|
||||
DpActivity & ApplyFlags(SQInteger flags) { SetFlags(flags); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve whether or not the activity is an instanced game session.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsInstance() const { return Valid().is_instance; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Get the assets large image url if they have one, otherwise returns an empty string.
|
||||
* In case of prefixed image IDs (mp:{image_id}) it returns an empty string.
|
||||
* See: https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-asset-image
|
||||
*/
|
||||
SQMOD_NODISCARD std::string GetLargeAssetURL(SQInteger size, SQInteger format) const
|
||||
{ return Valid().get_large_asset_url(static_cast< uint16_t >(size), static_cast< dpp::image_type >(format)); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Get the assets small image url if they have one, otherwise returns an empty string.
|
||||
* In case of prefixed image IDs (mp:{image_id}) it returns an empty string.
|
||||
* See: https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-asset-image
|
||||
*/
|
||||
SQMOD_NODISCARD std::string GetSmallAssetURL(SQInteger size, SQInteger format) const
|
||||
{ return Valid().get_small_asset_url(static_cast< uint16_t >(size), static_cast< dpp::image_type >(format)); }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Represents user presence, e.g. what game they are playing and if they are online.
|
||||
*/
|
||||
struct DpPresence
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::presence >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced presence instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
// --------------------------------------------------------------------------------------------
|
||||
using Activities = DpVectorProxy< dpp::activity, DpActivity >;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
LightObj mSqActivities{};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpPresence() noexcept
|
||||
: DpPresence(new Ptr::element_type(), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpPresence(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
explicit DpPresence(const Ptr::element_type & o) noexcept
|
||||
: DpPresence(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpPresence(Ptr::element_type && o) noexcept
|
||||
: DpPresence(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpPresence(SQInteger status, DpActivity & activity)
|
||||
: DpPresence(new Ptr::element_type(static_cast< dpp::presence_status >(status), activity.Valid()), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpPresence(SQInteger status, SQInteger type, StackStrF & description)
|
||||
: DpPresence(new Ptr::element_type(static_cast< dpp::presence_status >(status), static_cast< dpp::activity_type >(status), description.ToStr()), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpPresence(const DpPresence & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpPresence(DpPresence && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpPresence() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpPresence & operator = (const DpPresence & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpPresence & operator = (DpPresence && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Cleanup presence activities, if any
|
||||
if (!mSqActivities.IsNull())
|
||||
{
|
||||
mSqActivities.CastI< Activities >()->Cleanup();
|
||||
// Release script resources
|
||||
mSqActivities.Release();
|
||||
}
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord presence handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the user that the presence applies to.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetUserID() const { return Valid().user_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the user that the presence applies to.
|
||||
*/
|
||||
void SetUserID(dpp::snowflake id) const { Valid().user_id = id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the user that the presence applies to.
|
||||
*/
|
||||
DpPresence & ApplyUserID(dpp::snowflake id) { SetUserID(id); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild that the presence applies to.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetGuildID() const { return Valid().guild_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the guild that the presence applies to.
|
||||
*/
|
||||
void SetGuildID(dpp::snowflake id) const { Valid().guild_id = id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the guild that the presence applies to.
|
||||
*/
|
||||
DpPresence & ApplyGuildID(dpp::snowflake id) { SetGuildID(id); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the presence bit-mask.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return static_cast< SQInteger >(Valid().flags); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the presence bit-mask.
|
||||
*/
|
||||
void SetFlags(SQInteger f) const { Valid().flags = static_cast< uint8_t >(f); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the presence bit-mask.
|
||||
*/
|
||||
DpPresence & ApplyFlags(SQInteger f) { SetFlags(f); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the list of activities.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetActivities()
|
||||
{
|
||||
if (mSqActivities.IsNull())
|
||||
{
|
||||
mSqActivities = LightObj{SqTypeIdentity< Activities >{}, SqVM(), &Valid().activities, false};
|
||||
}
|
||||
// Return the associated script object
|
||||
return mSqActivities;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build JSON string from this object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
SQMOD_NODISCARD std::string BuildJSON_(bool with_id) const { return Valid().build_json(with_id); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the users status on desktop.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetDesktopStatus() const { return static_cast< SQInteger >(Valid().desktop_status()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the user's status on web.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetWebStatus() const { return static_cast< SQInteger >(Valid().web_status()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the user's status on mobile.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetMobileStatus() const { return static_cast< SQInteger >(Valid().mobile_status()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the user's status as shown to other users.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetStatus() const { return static_cast< SQInteger >(Valid().status()); }
|
||||
};
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/Role.cpp
Normal file
9
module/Library/Discord/Role.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Role.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
13
module/Library/Discord/Role.hpp
Normal file
13
module/Library/Discord/Role.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/User.cpp
Normal file
9
module/Library/Discord/User.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/User.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
13
module/Library/Discord/User.hpp
Normal file
13
module/Library/Discord/User.hpp
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
9
module/Library/Discord/Utilities.cpp
Normal file
9
module/Library/Discord/Utilities.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/Discord/Utilities.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
462
module/Library/Discord/Utilities.hpp
Normal file
462
module/Library/Discord/Utilities.hpp
Normal file
@ -0,0 +1,462 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <memory>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace Sqrat {
|
||||
|
||||
// Allow the VM to treat the dpp::snowflake type as a integer.
|
||||
template<> struct Var<dpp::snowflake>
|
||||
{
|
||||
dpp::snowflake value;
|
||||
Var(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
sq_getinteger(vm, idx, reinterpret_cast<SQInteger*>(&static_cast<uint64_t&>(value)));
|
||||
}
|
||||
inline static void push(HSQUIRRELVM vm, const dpp::snowflake& value) noexcept
|
||||
{
|
||||
sq_pushinteger(vm, static_cast<SQInteger>(static_cast<uint64_t>(value)));
|
||||
}
|
||||
};
|
||||
|
||||
// Allow the VM to treat the dpp::snowflake type as a integer.
|
||||
template<> struct Var<const dpp::snowflake&>
|
||||
{
|
||||
dpp::snowflake value;
|
||||
Var(HSQUIRRELVM vm, SQInteger idx)
|
||||
{
|
||||
sq_getinteger(vm, idx, reinterpret_cast<SQInteger*>(&static_cast<uint64_t&>(value)));
|
||||
}
|
||||
inline static void push(HSQUIRRELVM vm, const dpp::snowflake& value) noexcept
|
||||
{
|
||||
sq_pushinteger(vm, static_cast<SQInteger>(static_cast<uint64_t>(value)));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Wrapper around a std::vector of DPP values.
|
||||
*/
|
||||
template < class T, class W > struct DpVectorProxy
|
||||
{
|
||||
using Ptr = std::unique_ptr< std::vector< T > >;
|
||||
using Vec = std::vector< std::pair< LightObj, W * > >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced vector instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Cached script objects vector.
|
||||
*/
|
||||
Vec mVec{};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpVectorProxy() noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpVectorProxy(typename Ptr::pointer ptr, bool owned = false)
|
||||
: mPtr(ptr), mVec(), mOwned(owned)
|
||||
{ if (mPtr) mVec.resize(mPtr->size()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpVectorProxy(const typename Ptr::element_type & o) noexcept
|
||||
: DpVectorProxy(new typename Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpVectorProxy(typename Ptr::element_type && o) noexcept
|
||||
: DpVectorProxy(new typename Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpVectorProxy(const DpVectorProxy & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpVectorProxy(DpVectorProxy && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpVectorProxy() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpVectorProxy & operator = (const DpVectorProxy & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpVectorProxy & operator = (DpVectorProxy && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mVec = std::move(o.mVec);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Invalidate cached instances
|
||||
ClearCache();
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
void Validate() const { if (!mPtr) STHROWF("Invalid discord vector handle"); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle and retrieve a const reference to it.
|
||||
*/
|
||||
SQMOD_NODISCARD typename Ptr::element_type & Valid() const { Validate(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure an index is within range and return the container. Container must exist.
|
||||
*/
|
||||
void ValidIdx_(SQInteger i)
|
||||
{
|
||||
if (static_cast< size_t >(i) >= Valid().size())
|
||||
{
|
||||
STHROWF("Invalid vector container index({})", i);
|
||||
}
|
||||
}
|
||||
typename Ptr::element_type & ValidIdx(SQInteger i) { ValidIdx_(i); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure an index is within range and return the container. Container must exist.
|
||||
*/
|
||||
void ValidIdx_(SQInteger i) const
|
||||
{
|
||||
if (static_cast< size_t >(i) >= Valid().size())
|
||||
{
|
||||
STHROWF("Invalid vector container index({})", i);
|
||||
}
|
||||
}
|
||||
const typename Ptr::element_type & ValidIdx(SQInteger i) const { ValidIdx_(i); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure a container instance is referenced and is populated, then return it.
|
||||
*/
|
||||
void ValidPop_()
|
||||
{
|
||||
if (Valid().empty())
|
||||
{
|
||||
STHROWF("Vector container is empty");
|
||||
}
|
||||
}
|
||||
typename Ptr::element_type & ValidPop() { ValidPop_(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure a container instance is referenced and is populated, then return it.
|
||||
*/
|
||||
void ValidPop_() const
|
||||
{
|
||||
if (Valid().empty())
|
||||
{
|
||||
STHROWF("Vector container is empty");
|
||||
}
|
||||
}
|
||||
const typename Ptr::element_type & ValidPop() const { ValidPop_(); return *mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if a container instance is referenced.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsNull() const { return !mPtr; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a value from the container.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & Get_(SQInteger i)
|
||||
{
|
||||
// Is the element cached?
|
||||
if (mVec[static_cast< size_t >(i)].first.IsNull())
|
||||
{
|
||||
mVec[static_cast< size_t >(i)] = Obj(&mPtr->at(static_cast< size_t >(i)));
|
||||
}
|
||||
// Return the object from the cache
|
||||
return mVec[static_cast< size_t >(i)].first;
|
||||
}
|
||||
SQMOD_NODISCARD LightObj & Get(SQInteger i)
|
||||
{
|
||||
// Was the referenced vector modified?
|
||||
if (mVec.size() < Valid().size())
|
||||
{
|
||||
// Synchronize the size
|
||||
mVec.resize(mPtr->size());
|
||||
// Synchronize the cache
|
||||
CacheSync();
|
||||
}
|
||||
// Validate index
|
||||
ValidIdx_(i);
|
||||
// Perform the request
|
||||
return Get_(i);
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify a value from the container.
|
||||
*/
|
||||
void Set(SQInteger i, const W & v) { ValidIdx(i)[static_cast< size_t >(i)] = v.Valid(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the container has no elements.
|
||||
*/
|
||||
SQMOD_NODISCARD bool Empty() const { return Valid().empty(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of elements in the container.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger Size() const { return static_cast< SQInteger >(Valid().size()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of elements that the container has currently allocated space for.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger Capacity() const { return static_cast< SQInteger >(Valid().capacity()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Synchronize cache container instances.
|
||||
*/
|
||||
void CacheSync()
|
||||
{
|
||||
// Invalidate cached instances, if any
|
||||
for (size_t i = 0; i < mVec.size(); ++i)
|
||||
{
|
||||
// Is this element cached?
|
||||
if (mVec[i].second != nullptr)
|
||||
{
|
||||
// Discard previous instance, if any
|
||||
[[maybe_unused]] auto _ = mVec[i].second->mPtr.release();
|
||||
// Sync to new instance
|
||||
mVec[i].second->mPtr.reset(&mPtr->at(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Increase the capacity of the container to a value that's greater or equal to the one specified.
|
||||
*/
|
||||
DpVectorProxy & Reserve(SQInteger n)
|
||||
{
|
||||
Valid().reserve(ClampL< SQInteger, size_t >(n));
|
||||
mVec.reserve(mPtr->size());
|
||||
CacheSync();
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Request the removal of unused capacity.
|
||||
*/
|
||||
void Compact() { Valid().shrink_to_fit(); CacheSync(); mVec.shrink_to_fit(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Erase all elements from the cache container.
|
||||
*/
|
||||
void ClearCache()
|
||||
{
|
||||
// Invalidate cached instances, if any
|
||||
for (auto & e : mVec)
|
||||
{
|
||||
// Is this element cached?
|
||||
if (e.second != nullptr)
|
||||
{
|
||||
// Invalidate the instance
|
||||
e.second->Cleanup();
|
||||
// Forget about it
|
||||
e.second = nullptr;
|
||||
// Release script object
|
||||
e.first.Release();
|
||||
}
|
||||
}
|
||||
// Clear the cache vector
|
||||
mVec.clear();
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Erase all elements from the container.
|
||||
*/
|
||||
void Clear() { Validate(); ClearCache(); mPtr->clear(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Push a value at the back of the container.
|
||||
*/
|
||||
void Push(const W & v)
|
||||
{
|
||||
Valid().push_back(v.Valid());
|
||||
mVec.emplace_back();
|
||||
CacheSync();
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extends the Container by appending all the items in the given container.
|
||||
*/
|
||||
void Extend(DpVectorProxy & v)
|
||||
{
|
||||
Valid().insert(Valid().end(), v.Valid().begin(), v.Valid().end());
|
||||
mVec.resize(mPtr->size());
|
||||
CacheSync();
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Pop the last element in the container.
|
||||
*/
|
||||
void Pop()
|
||||
{
|
||||
Validate();
|
||||
// Is this element cached?
|
||||
if (mVec.back().second != nullptr)
|
||||
{
|
||||
// Invalidate the instance
|
||||
mVec.back().second->Cleanup();
|
||||
mVec.back().first.Release();
|
||||
}
|
||||
// Safe to remove
|
||||
mPtr->pop_back();
|
||||
mVec.pop_back();
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Erase the element at a certain position.
|
||||
*/
|
||||
void EraseAt(SQInteger i)
|
||||
{
|
||||
ValidIdx_(i);
|
||||
// Is this element cached?
|
||||
if (mVec[static_cast< size_t >(i)].second != nullptr)
|
||||
{
|
||||
// Invalidate the instance
|
||||
mVec[static_cast< size_t >(i)].second->Cleanup();
|
||||
mVec[static_cast< size_t >(i)].first.Release();
|
||||
}
|
||||
// Safe to remove
|
||||
mPtr->erase(mPtr->begin() + static_cast< size_t >(i));
|
||||
mVec.erase(mVec.begin() + static_cast< size_t >(i));
|
||||
// Synchronize cache
|
||||
CacheSync();
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate all values through a functor.
|
||||
*/
|
||||
void Each(Function & fn)
|
||||
{
|
||||
Validate();
|
||||
// Iterate referenced vector elements
|
||||
for (size_t i = 0; i < mVec.size(); ++i)
|
||||
{
|
||||
fn.Execute(Get(static_cast< SQInteger >(i)));
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate values in range through a functor.
|
||||
*/
|
||||
void EachRange(SQInteger p, SQInteger n, Function & fn)
|
||||
{
|
||||
ValidIdx_(p);
|
||||
ValidIdx_(p + n);
|
||||
// Iterate specified range
|
||||
for (n += p; p < n; ++p)
|
||||
{
|
||||
fn.Execute(Get(static_cast< SQInteger >(p)));
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate all values through a functor until stopped (i.e false is returned).
|
||||
*/
|
||||
void While(Function & fn)
|
||||
{
|
||||
Validate();
|
||||
// Iterate referenced vector elements
|
||||
for (size_t i = 0; i < mVec.size(); ++i)
|
||||
{
|
||||
auto ret = fn.Eval(Get(static_cast< SQInteger >(i)));
|
||||
// (null || true) == continue & false == break
|
||||
if (!ret.IsNull() || !ret.template Cast< bool >())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate values in range through a functor until stopped (i.e false is returned).
|
||||
*/
|
||||
void WhileRange(SQInteger p, SQInteger n, Function & fn)
|
||||
{
|
||||
ValidIdx_(p);
|
||||
ValidIdx_(p + n);
|
||||
// Iterate specified range
|
||||
for (n += p; p < n; ++p)
|
||||
{
|
||||
auto ret = fn.Eval(Get(static_cast< SQInteger >(p)));
|
||||
// (null || true) == continue & false == break
|
||||
if (!ret.IsNull() || !ret.template Cast< bool >())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a wrapped instance as a script object.
|
||||
*/
|
||||
SQMOD_NODISCARD static std::pair< LightObj, W * > Obj(T * ptr, bool owned = false)
|
||||
{
|
||||
// Create the wrapper instance for given pointer
|
||||
auto wp = std::make_unique< W >(ptr, false);
|
||||
// Create script object for wrapper instance
|
||||
std::pair< LightObj, W * > p{LightObj{wp.get()}, wp.get()};
|
||||
// Release ownership of the wrapper instance
|
||||
[[maybe_unused]] auto _ = wp.release();
|
||||
// Return the script object and wrapper instance
|
||||
return p;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a wrapped instance as a script object.
|
||||
*/
|
||||
SQMOD_NODISCARD static std::pair< LightObj, W * > Obj(const T * ptr, bool owned = false)
|
||||
{
|
||||
return Obj(const_cast< T * >(ptr), owned);
|
||||
}
|
||||
};
|
||||
|
||||
template < class T, class W, class U > inline void Register_Discord_VectorProxy(HSQUIRRELVM vm, Table & ns, const SQChar * name)
|
||||
{
|
||||
using Container = DpVectorProxy< T, W >;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(name,
|
||||
Class< Container, NoConstructor< Container > >(vm, U::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &U::Fn)
|
||||
// Properties
|
||||
.Prop(_SC("Null"), &Container::IsNull)
|
||||
.Prop(_SC("Empty"), &Container::Empty)
|
||||
.Prop(_SC("Size"), &Container::Size)
|
||||
.Prop(_SC("Capacity"), &Container::Capacity, &Container::Reserve)
|
||||
// Member Methods
|
||||
.Func(_SC("Get"), &Container::Get)
|
||||
.Func(_SC("Set"), &Container::Set)
|
||||
.Func(_SC("Reserve"), &Container::Reserve)
|
||||
.Func(_SC("Compact"), &Container::Compact)
|
||||
.Func(_SC("Clear"), &Container::Clear)
|
||||
.Func(_SC("Push"), &Container::Push)
|
||||
.Func(_SC("Append"), &Container::Push)
|
||||
.Func(_SC("Extend"), &Container::Extend)
|
||||
.Func(_SC("Pop"), &Container::Pop)
|
||||
.Func(_SC("EraseAt"), &Container::EraseAt)
|
||||
.Func(_SC("Each"), &Container::Each)
|
||||
.Func(_SC("EachRange"), &Container::EachRange)
|
||||
.Func(_SC("While"), &Container::While)
|
||||
.Func(_SC("WhileRange"), &Container::WhileRange)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -88,6 +88,7 @@ static SQInteger SqExtractIPv4(HSQUIRRELVM vm)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern void Register_IdPool(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_Vector(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_Template(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_Native_String(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_ServerAnnouncer(HSQUIRRELVM vm, Table & ns);
|
||||
|
||||
@ -99,6 +100,7 @@ void Register_Utils(HSQUIRRELVM vm)
|
||||
|
||||
Register_IdPool(vm, ns);
|
||||
Register_Vector(vm, ns);
|
||||
Register_Template(vm, ns);
|
||||
Register_Native_String(vm, ns);
|
||||
Register_ServerAnnouncer(vm, ns);
|
||||
|
||||
@ -110,7 +112,6 @@ void Register_Utils(HSQUIRRELVM vm)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_IdPool(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("IdPool"),
|
||||
Class< SqIdPool, NoCopy< SqIdPool > >(vm, SqIdPoolTypename::Str)
|
||||
// Constructors
|
||||
|
@ -10,6 +10,10 @@
|
||||
#include <winsock2.h>
|
||||
#endif // SQMOD_OS_WINDOWS
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <curl/curl.h>
|
||||
#include <civetweb.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
@ -24,6 +28,9 @@ extern void ProcessRoutines();
|
||||
extern void ProcessTasks();
|
||||
extern void ProcessThreads();
|
||||
extern void ProcessNet();
|
||||
#ifdef SQMOD_DISCORD
|
||||
extern void ProcessDiscord();
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Will the scripts be reloaded at the end of the current event?
|
||||
@ -147,6 +154,7 @@ static void OnServerShutdown()
|
||||
Core::Get().EmitServerShutdown();
|
||||
// Deallocate and release everything obtained at startup
|
||||
Core::Get().Terminate(true);
|
||||
curl_global_cleanup();
|
||||
SQMOD_SV_EV_TRACEBACK("[TRACE>] OnServerShutdown")
|
||||
}
|
||||
SQMOD_CATCH_EVENT_EXCEPTION(OnServerShutdown)
|
||||
@ -172,6 +180,10 @@ static void OnServerFrame(float elapsed_time)
|
||||
ProcessThreads();
|
||||
// Process network
|
||||
ProcessNet();
|
||||
// Process Discord
|
||||
#ifdef SQMOD_DISCORD
|
||||
ProcessDiscord();
|
||||
#endif
|
||||
// Process log messages from other threads
|
||||
Logger::Get().ProcessQueue();
|
||||
// See if a reload was requested
|
||||
@ -994,6 +1006,8 @@ SQMOD_API_EXPORT unsigned int VcmpPluginInit(PluginFuncs * funcs, PluginCallback
|
||||
_Info->apiMinorVersion = PLUGIN_API_MINOR;
|
||||
// Assign the plug-in name
|
||||
std::snprintf(_Info->name, sizeof(_Info->name), "%s", SQMOD_HOST_NAME);
|
||||
// Initialize CURL
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
// Initialize third-party allocator
|
||||
gsRPMallocInit = std::make_unique< RPMallocInit >();
|
||||
// Attempt to initialize the logger before anything else
|
||||
|
@ -30,6 +30,9 @@ extern void Register_CVehicle(HSQUIRRELVM vm);
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern void Register_Chrono(HSQUIRRELVM vm);
|
||||
extern void Register_CURL(HSQUIRRELVM vm);
|
||||
#ifdef SQMOD_DISCORD
|
||||
extern void Register_Discord(HSQUIRRELVM vm);
|
||||
#endif
|
||||
extern void Register_Format(HSQUIRRELVM vm);
|
||||
extern void Register_IO(HSQUIRRELVM vm);
|
||||
extern void Register_JSON(HSQUIRRELVM vm);
|
||||
@ -98,6 +101,9 @@ bool RegisterAPI(HSQUIRRELVM vm)
|
||||
|
||||
Register_Chrono(vm);
|
||||
Register_CURL(vm);
|
||||
#ifdef SQMOD_DISCORD
|
||||
Register_Discord(vm);
|
||||
#endif
|
||||
Register_Format(vm);
|
||||
Register_IO(vm);
|
||||
Register_JSON(vm);
|
||||
|
27
vendor/CMakeLists.txt
vendored
27
vendor/CMakeLists.txt
vendored
@ -8,6 +8,8 @@ add_subdirectory(TinyDir)
|
||||
add_subdirectory(SAJSON)
|
||||
add_subdirectory(CPR)
|
||||
add_subdirectory(UTF8)
|
||||
add_subdirectory(JSON)
|
||||
add_subdirectory(Inja)
|
||||
add_subdirectory(PUGIXML)
|
||||
add_subdirectory(CivetWeb)
|
||||
if (ENABLE_BUILTIN_MYSQL_C)
|
||||
@ -70,4 +72,29 @@ set(BUILD_STATIC ON CACHE INTERNAL "" FORCE)
|
||||
if (WIN32 OR MINGW)
|
||||
set(ZMQ_HAVE_IPC OFF CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
set(ENABLE_CURVE OFF CACHE INTERNAL "" FORCE)
|
||||
set(WITH_LIBSODIUM OFF CACHE INTERNAL "" FORCE)
|
||||
add_subdirectory(ZMQ)
|
||||
if(ENABLE_DISCORD)
|
||||
set(BUILD_TESTING OFF CACHE INTERNAL "" FORCE)
|
||||
set(BUILD_VOICE_SUPPORT OFF CACHE INTERNAL "" FORCE)
|
||||
set(DPP_INSTALL OFF CACHE INTERNAL "" FORCE)
|
||||
set(DPP_BUILD_TEST OFF CACHE INTERNAL "" FORCE)
|
||||
set(DPP_NO_VCPKG ON CACHE INTERNAL "" FORCE)
|
||||
set(DPP_CORO OFF CACHE INTERNAL "" FORCE)
|
||||
set(DPP_USE_EXTERNAL_JSON ON CACHE INTERNAL "" FORCE)
|
||||
if (WIN32 OR MINGW)
|
||||
set(BUILD_SHARED_LIBS ON CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
add_subdirectory(DPP)
|
||||
target_link_libraries(dpp PRIVATE nlohmann_json)
|
||||
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "" FORCE)
|
||||
# We don't care about DPP warnings
|
||||
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
|
||||
target_compile_options(dpp PRIVATE -w)
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
target_compile_options(dpp PRIVATE -w)
|
||||
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
target_compile_options(dpp PRIVATE /w)
|
||||
endif()
|
||||
endif()
|
||||
|
60
vendor/CPR/CMakeLists.txt
vendored
60
vendor/CPR/CMakeLists.txt
vendored
@ -1,52 +1,84 @@
|
||||
# Create the CPR library
|
||||
add_library(CPR STATIC
|
||||
# Source files
|
||||
cpr/auth.cpp
|
||||
cpr/bearer.cpp
|
||||
cpr/cookies.cpp
|
||||
cpr/cprtypes.cpp
|
||||
cpr/curl_container.cpp
|
||||
cpr/curlholder.cpp
|
||||
cpr/error.cpp
|
||||
cpr/file.cpp
|
||||
cpr/interceptor.cpp
|
||||
cpr/multipart.cpp
|
||||
cpr/multiperform.cpp
|
||||
cpr/parameters.cpp
|
||||
cpr/payload.cpp
|
||||
cpr/proxies.cpp
|
||||
cpr/proxyauth.cpp
|
||||
cpr/redirect.cpp
|
||||
cpr/response.cpp
|
||||
cpr/session.cpp
|
||||
cpr/ssl_ctx.cpp
|
||||
cpr/threadpool.cpp
|
||||
cpr/timeout.cpp
|
||||
cpr/unix_socket.cpp
|
||||
cpr/util.cpp
|
||||
cpr/response.cpp
|
||||
# Header files
|
||||
include/cpr/api.h
|
||||
include/cpr/auth.h
|
||||
cpr/accept_encoding.cpp
|
||||
cpr/async.cpp
|
||||
cpr/auth.cpp
|
||||
cpr/bearer.cpp
|
||||
cpr/callback.cpp
|
||||
cpr/cert_info.cpp
|
||||
cpr/cookies.cpp
|
||||
cpr/cprtypes.cpp
|
||||
cpr/curl_container.cpp
|
||||
cpr/curlholder.cpp
|
||||
cpr/curlmultiholder.cpp
|
||||
# Header Files
|
||||
include/cpr/bearer.h
|
||||
include/cpr/body.h
|
||||
include/cpr/buffer.h
|
||||
include/cpr/callback.h
|
||||
include/cpr/cert_info.h
|
||||
include/cpr/connect_timeout.h
|
||||
include/cpr/cookies.h
|
||||
include/cpr/cpr.h
|
||||
include/cpr/cprtypes.h
|
||||
include/cpr/curl_container.h
|
||||
include/cpr/curlholder.h
|
||||
include/cpr/curlholder.h
|
||||
include/cpr/digest.h
|
||||
include/cpr/curlmultiholder.h
|
||||
include/cpr/error.h
|
||||
include/cpr/file.h
|
||||
include/cpr/filesystem.h
|
||||
include/cpr/http_version.h
|
||||
include/cpr/interceptor.h
|
||||
include/cpr/interface.h
|
||||
include/cpr/limit_rate.h
|
||||
include/cpr/local_port.h
|
||||
include/cpr/local_port_range.h
|
||||
include/cpr/low_speed.h
|
||||
include/cpr/multipart.h
|
||||
include/cpr/ntlm.h
|
||||
include/cpr/multiperform.h
|
||||
include/cpr/parameters.h
|
||||
include/cpr/payload.h
|
||||
include/cpr/proxies.h
|
||||
include/cpr/proxyauth.h
|
||||
include/cpr/range.h
|
||||
include/cpr/redirect.h
|
||||
include/cpr/reserve_size.h
|
||||
include/cpr/resolve.h
|
||||
include/cpr/response.h
|
||||
include/cpr/session.h
|
||||
include/cpr/singleton.h
|
||||
include/cpr/ssl_ctx.h
|
||||
include/cpr/ssl_options.h
|
||||
include/cpr/status_codes.h
|
||||
include/cpr/threadpool.h
|
||||
include/cpr/timeout.h
|
||||
include/cpr/unix_socket.h
|
||||
include/cpr/user_agent.h
|
||||
include/cpr/util.h
|
||||
include/cpr/verbose.h
|
||||
include/cpr/accept_encoding.h
|
||||
include/cpr/api.h
|
||||
include/cpr/async.h
|
||||
include/cpr/async_wrapper.h
|
||||
include/cpr/auth.h
|
||||
)
|
||||
# Library includes
|
||||
target_include_directories(CPR PRIVATE ${CMAKE_CURRENT_LIST_DIR}/cpr)
|
||||
@ -55,7 +87,7 @@ target_include_directories(CPR PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
|
||||
if (NOT MSVC)
|
||||
target_compile_options(CPR PRIVATE -Wno-deprecated-declarations)
|
||||
endif()
|
||||
# Find CURK
|
||||
# Find CURL
|
||||
find_package(CURL REQUIRED)
|
||||
if (CURL_FOUND)
|
||||
set(SSL_ENABLED ON CACHE INTERNAL "" FORCE)
|
||||
|
37
vendor/CPR/cpr/accept_encoding.cpp
vendored
Normal file
37
vendor/CPR/cpr/accept_encoding.cpp
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
#include "cpr/accept_encoding.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
AcceptEncoding::AcceptEncoding(const std::initializer_list<AcceptEncodingMethods>& methods) {
|
||||
methods_.clear();
|
||||
std::transform(methods.begin(), methods.end(), std::inserter(methods_, methods_.begin()), [&](cpr::AcceptEncodingMethods method) { return cpr::AcceptEncodingMethodsStringMap.at(method); });
|
||||
}
|
||||
|
||||
AcceptEncoding::AcceptEncoding(const std::initializer_list<std::string>& string_methods) : methods_{string_methods} {}
|
||||
|
||||
bool AcceptEncoding::empty() const noexcept {
|
||||
return methods_.empty();
|
||||
}
|
||||
|
||||
const std::string AcceptEncoding::getString() const {
|
||||
return std::accumulate(std::next(methods_.begin()), methods_.end(), *methods_.begin(), [](std::string a, std::string b) { return std::move(a) + ", " + std::move(b); });
|
||||
}
|
||||
|
||||
[[nodiscard]] bool AcceptEncoding::disabled() const {
|
||||
if (methods_.find(cpr::AcceptEncodingMethodsStringMap.at(AcceptEncodingMethods::disabled)) != methods_.end()) {
|
||||
if (methods_.size() != 1) {
|
||||
throw std::invalid_argument("AcceptEncoding does not accept any other values if 'disabled' is present. You set the following encodings: " + getString());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace cpr
|
8
vendor/CPR/cpr/async.cpp
vendored
Normal file
8
vendor/CPR/cpr/async.cpp
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
#include "cpr/async.h"
|
||||
|
||||
namespace cpr {
|
||||
|
||||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||
CPR_SINGLETON_IMPL(GlobalThreadPool)
|
||||
|
||||
} // namespace cpr
|
9
vendor/CPR/cpr/auth.cpp
vendored
9
vendor/CPR/cpr/auth.cpp
vendored
@ -1,7 +1,16 @@
|
||||
#include "cpr/auth.h"
|
||||
#include "cpr/util.h"
|
||||
|
||||
namespace cpr {
|
||||
Authentication::~Authentication() noexcept {
|
||||
util::secureStringClear(auth_string_);
|
||||
}
|
||||
|
||||
const char* Authentication::GetAuthString() const noexcept {
|
||||
return auth_string_.c_str();
|
||||
}
|
||||
|
||||
AuthMode Authentication::GetAuthMode() const noexcept {
|
||||
return auth_mode_;
|
||||
}
|
||||
} // namespace cpr
|
||||
|
5
vendor/CPR/cpr/bearer.cpp
vendored
5
vendor/CPR/cpr/bearer.cpp
vendored
@ -1,9 +1,14 @@
|
||||
#include "cpr/bearer.h"
|
||||
#include "cpr/util.h"
|
||||
|
||||
namespace cpr {
|
||||
// Only supported with libcurl >= 7.61.0.
|
||||
// As an alternative use SetHeader and add the token manually.
|
||||
#if LIBCURL_VERSION_NUM >= 0x073D00
|
||||
Bearer::~Bearer() noexcept {
|
||||
util::secureStringClear(token_string_);
|
||||
}
|
||||
|
||||
const char* Bearer::GetToken() const noexcept {
|
||||
return token_string_.c_str();
|
||||
}
|
||||
|
14
vendor/CPR/cpr/callback.cpp
vendored
Normal file
14
vendor/CPR/cpr/callback.cpp
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
#include <cpr/callback.h>
|
||||
#include <curl/curl.h>
|
||||
#include <functional>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
void CancellationCallback::SetProgressCallback(ProgressCallback& u_cb) {
|
||||
user_cb.emplace(std::reference_wrapper{u_cb});
|
||||
}
|
||||
bool CancellationCallback::operator()(cpr_pf_arg_t dltotal, cpr_pf_arg_t dlnow, cpr_pf_arg_t ultotal, cpr_pf_arg_t ulnow) const {
|
||||
const bool cont_operation{!cancellation_state->load()};
|
||||
return user_cb ? (cont_operation && (*user_cb)(dltotal, dlnow, ultotal, ulnow)) : cont_operation;
|
||||
}
|
||||
} // namespace cpr
|
43
vendor/CPR/cpr/cert_info.cpp
vendored
Normal file
43
vendor/CPR/cpr/cert_info.cpp
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
#include "cpr/cert_info.h"
|
||||
|
||||
namespace cpr {
|
||||
|
||||
std::string& CertInfo::operator[](const size_t& pos) {
|
||||
return cert_info_[pos];
|
||||
}
|
||||
|
||||
CertInfo::iterator CertInfo::begin() {
|
||||
return cert_info_.begin();
|
||||
}
|
||||
CertInfo::iterator CertInfo::end() {
|
||||
return cert_info_.end();
|
||||
}
|
||||
|
||||
CertInfo::const_iterator CertInfo::begin() const {
|
||||
return cert_info_.begin();
|
||||
}
|
||||
|
||||
CertInfo::const_iterator CertInfo::end() const {
|
||||
return cert_info_.end();
|
||||
}
|
||||
|
||||
CertInfo::const_iterator CertInfo::cbegin() const {
|
||||
return cert_info_.cbegin();
|
||||
}
|
||||
|
||||
CertInfo::const_iterator CertInfo::cend() const {
|
||||
return cert_info_.cend();
|
||||
}
|
||||
|
||||
void CertInfo::emplace_back(const std::string& str) {
|
||||
cert_info_.emplace_back(str);
|
||||
}
|
||||
|
||||
void CertInfo::push_back(const std::string& str) {
|
||||
cert_info_.push_back(str);
|
||||
}
|
||||
|
||||
void CertInfo::pop_back() {
|
||||
cert_info_.pop_back();
|
||||
}
|
||||
} // namespace cpr
|
83
vendor/CPR/cpr/cookies.cpp
vendored
83
vendor/CPR/cpr/cookies.cpp
vendored
@ -1,51 +1,106 @@
|
||||
#include "cpr/cookies.h"
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
|
||||
namespace cpr {
|
||||
std::string Cookies::GetEncoded(const CurlHolder& holder) const {
|
||||
const std::string Cookie::GetDomain() const {
|
||||
return domain_;
|
||||
}
|
||||
|
||||
bool Cookie::IsIncludingSubdomains() const {
|
||||
return includeSubdomains_;
|
||||
}
|
||||
|
||||
const std::string Cookie::GetPath() const {
|
||||
return path_;
|
||||
}
|
||||
|
||||
bool Cookie::IsHttpsOnly() const {
|
||||
return httpsOnly_;
|
||||
}
|
||||
|
||||
const std::chrono::system_clock::time_point Cookie::GetExpires() const {
|
||||
return expires_;
|
||||
}
|
||||
|
||||
const std::string Cookie::GetExpiresString() const {
|
||||
std::stringstream ss;
|
||||
std::tm tm{};
|
||||
const std::time_t tt = std::chrono::system_clock::to_time_t(expires_);
|
||||
#ifdef _WIN32
|
||||
gmtime_s(&tm, &tt);
|
||||
#else
|
||||
gmtime_r(&tt, &tm);
|
||||
#endif
|
||||
ss << std::put_time(&tm, "%a, %d %b %Y %H:%M:%S GMT");
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
const std::string Cookie::GetName() const {
|
||||
return name_;
|
||||
}
|
||||
|
||||
const std::string Cookie::GetValue() const {
|
||||
return value_;
|
||||
}
|
||||
|
||||
const std::string Cookies::GetEncoded(const CurlHolder& holder) const {
|
||||
std::stringstream stream;
|
||||
for (const std::pair<const std::string, std::string>& item : map_) {
|
||||
for (const cpr::Cookie& item : cookies_) {
|
||||
// Depending on if encoding is set to "true", we will URL-encode cookies
|
||||
stream << (encode ? holder.urlEncode(item.first) : item.first) << "=";
|
||||
stream << (encode ? holder.urlEncode(item.GetName()) : item.GetName()) << "=";
|
||||
|
||||
// special case version 1 cookies, which can be distinguished by
|
||||
// beginning and trailing quotes
|
||||
if (!item.second.empty() && item.second.front() == '"' && item.second.back() == '"') {
|
||||
stream << item.second;
|
||||
if (!item.GetValue().empty() && item.GetValue().front() == '"' && item.GetValue().back() == '"') {
|
||||
stream << item.GetValue();
|
||||
} else {
|
||||
// Depending on if encoding is set to "true", we will URL-encode cookies
|
||||
stream << (encode ? holder.urlEncode(item.second) : item.second);
|
||||
stream << (encode ? holder.urlEncode(item.GetValue()) : item.GetValue());
|
||||
}
|
||||
stream << "; ";
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string& Cookies::operator[](const std::string& key) {
|
||||
return map_[key];
|
||||
cpr::Cookie& Cookies::operator[](size_t pos) {
|
||||
return cookies_[pos];
|
||||
}
|
||||
|
||||
Cookies::iterator Cookies::begin() {
|
||||
return map_.begin();
|
||||
return cookies_.begin();
|
||||
}
|
||||
|
||||
Cookies::iterator Cookies::end() {
|
||||
return map_.end();
|
||||
return cookies_.end();
|
||||
}
|
||||
|
||||
Cookies::const_iterator Cookies::begin() const {
|
||||
return map_.begin();
|
||||
return cookies_.begin();
|
||||
}
|
||||
|
||||
Cookies::const_iterator Cookies::end() const {
|
||||
return map_.end();
|
||||
return cookies_.end();
|
||||
}
|
||||
|
||||
Cookies::const_iterator Cookies::cbegin() const {
|
||||
return map_.cbegin();
|
||||
return cookies_.cbegin();
|
||||
}
|
||||
|
||||
Cookies::const_iterator Cookies::cend() const {
|
||||
return map_.cend();
|
||||
return cookies_.cend();
|
||||
}
|
||||
|
||||
void Cookies::emplace_back(const Cookie& str) {
|
||||
cookies_.emplace_back(str);
|
||||
}
|
||||
|
||||
void Cookies::push_back(const Cookie& str) {
|
||||
cookies_.push_back(str);
|
||||
}
|
||||
|
||||
void Cookies::pop_back() {
|
||||
cookies_.pop_back();
|
||||
}
|
||||
|
||||
} // namespace cpr
|
||||
|
4
vendor/CPR/cpr/cprtypes.cpp
vendored
4
vendor/CPR/cpr/cprtypes.cpp
vendored
@ -5,8 +5,6 @@
|
||||
|
||||
namespace cpr {
|
||||
bool CaseInsensitiveCompare::operator()(const std::string& a, const std::string& b) const noexcept {
|
||||
return std::lexicographical_compare(
|
||||
a.begin(), a.end(), b.begin(), b.end(),
|
||||
[](unsigned char ac, unsigned char bc) { return std::tolower(ac) < std::tolower(bc); });
|
||||
return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), [](unsigned char ac, unsigned char bc) { return std::tolower(ac) < std::tolower(bc); });
|
||||
}
|
||||
} // namespace cpr
|
||||
|
17
vendor/CPR/cpr/curl_container.cpp
vendored
17
vendor/CPR/cpr/curl_container.cpp
vendored
@ -1,16 +1,15 @@
|
||||
#include "cpr/curl_container.h"
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
|
||||
|
||||
namespace cpr {
|
||||
template <class T>
|
||||
CurlContainer<T>::CurlContainer(const std::initializer_list<T>& containerList)
|
||||
: containerList_(containerList) {}
|
||||
CurlContainer<T>::CurlContainer(const std::initializer_list<T>& containerList) : containerList_(containerList) {}
|
||||
|
||||
template <class T>
|
||||
void CurlContainer<T>::Add(const std::initializer_list<T>& containerList) {
|
||||
for (const T& element : containerList) {
|
||||
containerList_.push_back(std::move(element));
|
||||
}
|
||||
std::transform(containerList.begin(), containerList.end(), std::back_inserter(containerList_), [](const T& elem) { return std::move(elem); });
|
||||
}
|
||||
|
||||
template <class T>
|
||||
@ -26,15 +25,15 @@ const std::string CurlContainer<Parameter>::GetContent(const CurlHolder& holder)
|
||||
content += "&";
|
||||
}
|
||||
|
||||
std::string escapedKey = encode ? holder.urlEncode(parameter.key) : parameter.key;
|
||||
const std::string escapedKey = encode ? holder.urlEncode(parameter.key) : parameter.key;
|
||||
if (parameter.value.empty()) {
|
||||
content += escapedKey;
|
||||
} else {
|
||||
std::string escapedValue = encode ? holder.urlEncode(parameter.value) : parameter.value;
|
||||
const std::string escapedValue = encode ? holder.urlEncode(parameter.value) : parameter.value;
|
||||
content += escapedKey + "=";
|
||||
content += escapedValue;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
@ -46,7 +45,7 @@ const std::string CurlContainer<Pair>::GetContent(const CurlHolder& holder) cons
|
||||
if (!content.empty()) {
|
||||
content += "&";
|
||||
}
|
||||
std::string escaped = encode ? holder.urlEncode(element.value) : element.value;
|
||||
const std::string escaped = encode ? holder.urlEncode(element.value) : element.value;
|
||||
content += element.key + "=" + escaped;
|
||||
}
|
||||
|
||||
|
16
vendor/CPR/cpr/curlholder.cpp
vendored
16
vendor/CPR/cpr/curlholder.cpp
vendored
@ -2,10 +2,6 @@
|
||||
#include <cassert>
|
||||
|
||||
namespace cpr {
|
||||
// It does not make sense to make a std::mutex const.
|
||||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||
std::mutex CurlHolder::curl_easy_init_mutex_{};
|
||||
|
||||
CurlHolder::CurlHolder() {
|
||||
/**
|
||||
* Allow multithreaded access to CPR by locking curl_easy_init().
|
||||
@ -14,22 +10,24 @@ CurlHolder::CurlHolder() {
|
||||
* https://curl.haxx.se/libcurl/c/curl_easy_init.html
|
||||
* https://curl.haxx.se/libcurl/c/threadsafe.html
|
||||
**/
|
||||
curl_easy_init_mutex_.lock();
|
||||
curl_easy_init_mutex_().lock();
|
||||
// NOLINTNEXTLINE (cppcoreguidelines-prefer-member-initializer) since we need it to happen inside the lock
|
||||
handle = curl_easy_init();
|
||||
curl_easy_init_mutex_.unlock();
|
||||
curl_easy_init_mutex_().unlock();
|
||||
|
||||
assert(handle);
|
||||
} // namespace cpr
|
||||
|
||||
CurlHolder::~CurlHolder() {
|
||||
curl_slist_free_all(chunk);
|
||||
curl_formfree(formpost);
|
||||
curl_slist_free_all(resolveCurlList);
|
||||
curl_mime_free(multipart);
|
||||
curl_easy_cleanup(handle);
|
||||
}
|
||||
|
||||
std::string CurlHolder::urlEncode(const std::string& s) const {
|
||||
assert(handle);
|
||||
char* output = curl_easy_escape(handle, s.c_str(), s.length());
|
||||
char* output = curl_easy_escape(handle, s.c_str(), static_cast<int>(s.length()));
|
||||
if (output) {
|
||||
std::string result = output;
|
||||
curl_free(output);
|
||||
@ -40,7 +38,7 @@ std::string CurlHolder::urlEncode(const std::string& s) const {
|
||||
|
||||
std::string CurlHolder::urlDecode(const std::string& s) const {
|
||||
assert(handle);
|
||||
char* output = curl_easy_unescape(handle, s.c_str(), s.length(), nullptr);
|
||||
char* output = curl_easy_unescape(handle, s.c_str(), static_cast<int>(s.length()), nullptr);
|
||||
if (output) {
|
||||
std::string result = output;
|
||||
curl_free(output);
|
||||
|
15
vendor/CPR/cpr/curlmultiholder.cpp
vendored
Normal file
15
vendor/CPR/cpr/curlmultiholder.cpp
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
#include "cpr/curlmultiholder.h"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
CurlMultiHolder::CurlMultiHolder() : handle{curl_multi_init()} {
|
||||
assert(handle);
|
||||
}
|
||||
|
||||
CurlMultiHolder::~CurlMultiHolder() {
|
||||
curl_multi_cleanup(handle);
|
||||
}
|
||||
|
||||
} // namespace cpr
|
2
vendor/CPR/cpr/error.cpp
vendored
2
vendor/CPR/cpr/error.cpp
vendored
@ -59,7 +59,7 @@ ErrorCode Error::getErrorCodeForCurlError(std::int32_t curl_code) {
|
||||
case CURLE_SSL_ISSUER_ERROR:
|
||||
return ErrorCode::SSL_CACERT_ERROR;
|
||||
case CURLE_TOO_MANY_REDIRECTS:
|
||||
return ErrorCode::OK;
|
||||
return ErrorCode::TOO_MANY_REDIRECTS;
|
||||
default:
|
||||
return ErrorCode::INTERNAL_ERROR;
|
||||
}
|
||||
|
60
vendor/CPR/cpr/file.cpp
vendored
Normal file
60
vendor/CPR/cpr/file.cpp
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
#include "cpr/file.h"
|
||||
|
||||
namespace cpr {
|
||||
|
||||
Files::Files(const std::initializer_list<std::string>& p_filepaths) {
|
||||
for (const std::string& filepath : p_filepaths) {
|
||||
files.emplace_back(filepath);
|
||||
}
|
||||
}
|
||||
|
||||
Files::iterator Files::begin() {
|
||||
return files.begin();
|
||||
}
|
||||
|
||||
Files::iterator Files::end() {
|
||||
return files.end();
|
||||
}
|
||||
|
||||
Files::const_iterator Files::begin() const {
|
||||
return files.begin();
|
||||
}
|
||||
|
||||
Files::const_iterator Files::end() const {
|
||||
return files.end();
|
||||
}
|
||||
|
||||
Files::const_iterator Files::cbegin() const {
|
||||
return files.cbegin();
|
||||
}
|
||||
|
||||
Files::const_iterator Files::cend() const {
|
||||
return files.cend();
|
||||
}
|
||||
|
||||
void Files::emplace_back(const File& file) {
|
||||
files.emplace_back(file);
|
||||
}
|
||||
|
||||
void Files::push_back(const File& file) {
|
||||
files.push_back(file);
|
||||
}
|
||||
|
||||
void Files::pop_back() {
|
||||
files.pop_back();
|
||||
}
|
||||
|
||||
Files& Files::operator=(const Files& other) {
|
||||
if (&other != this) {
|
||||
files = other.files;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
Files& Files::operator=(Files&& old) noexcept {
|
||||
if (&old != this) {
|
||||
files = std::move(old.files);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
} // namespace cpr
|
53
vendor/CPR/cpr/interceptor.cpp
vendored
Normal file
53
vendor/CPR/cpr/interceptor.cpp
vendored
Normal file
@ -0,0 +1,53 @@
|
||||
#include "cpr/interceptor.h"
|
||||
|
||||
#include <exception>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
Response Interceptor::proceed(Session& session) {
|
||||
return session.proceed();
|
||||
}
|
||||
|
||||
Response Interceptor::proceed(Session& session, ProceedHttpMethod httpMethod) {
|
||||
switch (httpMethod) {
|
||||
case ProceedHttpMethod::DELETE_REQUEST:
|
||||
return session.Delete();
|
||||
case ProceedHttpMethod::GET_REQUEST:
|
||||
return session.Get();
|
||||
case ProceedHttpMethod::HEAD_REQUEST:
|
||||
return session.Head();
|
||||
case ProceedHttpMethod::OPTIONS_REQUEST:
|
||||
return session.Options();
|
||||
case ProceedHttpMethod::PATCH_REQUEST:
|
||||
return session.Patch();
|
||||
case ProceedHttpMethod::POST_REQUEST:
|
||||
return session.Post();
|
||||
case ProceedHttpMethod::PUT_REQUEST:
|
||||
return session.Put();
|
||||
default:
|
||||
throw std::invalid_argument{"Can't proceed the session with the provided http method!"};
|
||||
}
|
||||
}
|
||||
|
||||
Response Interceptor::proceed(Session& session, ProceedHttpMethod httpMethod, std::ofstream& file) {
|
||||
if (httpMethod == ProceedHttpMethod::DOWNLOAD_FILE_REQUEST) {
|
||||
return session.Download(file);
|
||||
}
|
||||
throw std::invalid_argument{"std::ofstream argument is only valid for ProceedHttpMethod::DOWNLOAD_FILE!"};
|
||||
}
|
||||
|
||||
Response Interceptor::proceed(Session& session, ProceedHttpMethod httpMethod, const WriteCallback& write) {
|
||||
if (httpMethod == ProceedHttpMethod::DOWNLOAD_CALLBACK_REQUEST) {
|
||||
return session.Download(write);
|
||||
}
|
||||
throw std::invalid_argument{"WriteCallback argument is only valid for ProceedHttpMethod::DOWNLOAD_CALLBACK!"};
|
||||
}
|
||||
|
||||
std::vector<Response> InterceptorMulti::proceed(MultiPerform& multi) {
|
||||
return multi.proceed();
|
||||
}
|
||||
|
||||
void InterceptorMulti::PrepareDownloadSession(MultiPerform& multi, size_t sessions_index, const WriteCallback& write) {
|
||||
multi.PrepareDownloadSessions(sessions_index, write);
|
||||
}
|
||||
} // namespace cpr
|
2
vendor/CPR/cpr/multipart.cpp
vendored
2
vendor/CPR/cpr/multipart.cpp
vendored
@ -2,4 +2,6 @@
|
||||
|
||||
namespace cpr {
|
||||
Multipart::Multipart(const std::initializer_list<Part>& p_parts) : parts{p_parts} {}
|
||||
Multipart::Multipart(const std::vector<Part>& p_parts) : parts{p_parts} {}
|
||||
Multipart::Multipart(const std::vector<Part>&& p_parts) : parts{p_parts} {}
|
||||
} // namespace cpr
|
||||
|
323
vendor/CPR/cpr/multiperform.cpp
vendored
Normal file
323
vendor/CPR/cpr/multiperform.cpp
vendored
Normal file
@ -0,0 +1,323 @@
|
||||
#include "cpr/multiperform.h"
|
||||
|
||||
#include "cpr/interceptor.h"
|
||||
#include "cpr/response.h"
|
||||
#include "cpr/session.h"
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
MultiPerform::MultiPerform() : multicurl_(new CurlMultiHolder()) {}
|
||||
|
||||
MultiPerform::~MultiPerform() {
|
||||
// Unlock all sessions
|
||||
for (const std::pair<std::shared_ptr<Session>, HttpMethod>& pair : sessions_) {
|
||||
pair.first->isUsedInMultiPerform = false;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiPerform::AddSession(std::shared_ptr<Session>& session, HttpMethod method) {
|
||||
// Check if this multiperform is download only
|
||||
if (((method != HttpMethod::DOWNLOAD_REQUEST && is_download_multi_perform) && method != HttpMethod::UNDEFINED) || (method == HttpMethod::DOWNLOAD_REQUEST && !is_download_multi_perform && !sessions_.empty())) {
|
||||
// Currently it is not possible to mix download and non-download methods, as download needs additional parameters
|
||||
throw std::invalid_argument("Failed to add session: Cannot mix download and non-download methods!");
|
||||
}
|
||||
|
||||
// Set download only if neccessary
|
||||
if (method == HttpMethod::DOWNLOAD_REQUEST) {
|
||||
is_download_multi_perform = true;
|
||||
}
|
||||
|
||||
// Add easy handle to multi handle
|
||||
const CURLMcode error_code = curl_multi_add_handle(multicurl_->handle, session->curl_->handle);
|
||||
if (error_code) {
|
||||
std::cerr << "curl_multi_add_handle() failed, code " << static_cast<int>(error_code) << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Lock session to the multihandle
|
||||
session->isUsedInMultiPerform = true;
|
||||
|
||||
// Add session to sessions_
|
||||
sessions_.emplace_back(session, method);
|
||||
}
|
||||
|
||||
void MultiPerform::RemoveSession(const std::shared_ptr<Session>& session) {
|
||||
// Remove easy handle from multihandle
|
||||
const CURLMcode error_code = curl_multi_remove_handle(multicurl_->handle, session->curl_->handle);
|
||||
if (error_code) {
|
||||
std::cerr << "curl_multi_remove_handle() failed, code " << static_cast<int>(error_code) << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Unock session
|
||||
session->isUsedInMultiPerform = false;
|
||||
|
||||
// Remove session from sessions_
|
||||
auto it = std::find_if(sessions_.begin(), sessions_.end(), [&session](const std::pair<std::shared_ptr<Session>, HttpMethod>& pair) { return session->curl_->handle == pair.first->curl_->handle; });
|
||||
if (it == sessions_.end()) {
|
||||
throw std::invalid_argument("Failed to find session!");
|
||||
}
|
||||
sessions_.erase(it);
|
||||
|
||||
// Reset download only if empty
|
||||
if (sessions_.empty()) {
|
||||
is_download_multi_perform = false;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::shared_ptr<Session>, MultiPerform::HttpMethod>>& MultiPerform::GetSessions() {
|
||||
return sessions_;
|
||||
}
|
||||
|
||||
const std::vector<std::pair<std::shared_ptr<Session>, MultiPerform::HttpMethod>>& MultiPerform::GetSessions() const {
|
||||
return sessions_;
|
||||
}
|
||||
|
||||
void MultiPerform::DoMultiPerform() {
|
||||
// Do multi perform until every handle has finished
|
||||
int still_running{0};
|
||||
do {
|
||||
CURLMcode error_code = curl_multi_perform(multicurl_->handle, &still_running);
|
||||
if (error_code) {
|
||||
std::cerr << "curl_multi_perform() failed, code " << static_cast<int>(error_code) << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
if (still_running) {
|
||||
const int timeout_ms{250};
|
||||
error_code = curl_multi_poll(multicurl_->handle, nullptr, 0, timeout_ms, nullptr);
|
||||
if (error_code) {
|
||||
std::cerr << "curl_multi_poll() failed, code " << static_cast<int>(error_code) << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (still_running);
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::ReadMultiInfo(std::function<Response(Session&, CURLcode)>&& complete_function) {
|
||||
// Get infos and create Response objects
|
||||
std::vector<Response> responses;
|
||||
struct CURLMsg* info{nullptr};
|
||||
do {
|
||||
int msgq = 0;
|
||||
|
||||
// Read info from multihandle
|
||||
info = curl_multi_info_read(multicurl_->handle, &msgq);
|
||||
|
||||
if (info) {
|
||||
// Find current session
|
||||
auto it = std::find_if(sessions_.begin(), sessions_.end(), [&info](const std::pair<std::shared_ptr<Session>, HttpMethod>& pair) { return pair.first->curl_->handle == info->easy_handle; });
|
||||
if (it == sessions_.end()) {
|
||||
std::cerr << "Failed to find current session!" << std::endl;
|
||||
break;
|
||||
}
|
||||
const std::shared_ptr<Session> current_session = (*it).first;
|
||||
|
||||
// Add response object
|
||||
// NOLINTNEXTLINE (cppcoreguidelines-pro-type-union-access)
|
||||
responses.push_back(complete_function(*current_session, info->data.result));
|
||||
}
|
||||
} while (info);
|
||||
|
||||
// Sort response objects to match order of added sessions
|
||||
std::vector<Response> sorted_responses;
|
||||
for (const std::pair<std::shared_ptr<Session>, HttpMethod>& pair : sessions_) {
|
||||
Session& current_session = *(pair.first);
|
||||
auto it = std::find_if(responses.begin(), responses.end(), [¤t_session](const Response& response) { return current_session.curl_->handle == response.curl_->handle; });
|
||||
const Response current_response = *it;
|
||||
// Erase response from original vector to increase future search speed
|
||||
responses.erase(it);
|
||||
sorted_responses.push_back(current_response);
|
||||
}
|
||||
|
||||
return sorted_responses;
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::MakeRequest() {
|
||||
if (!interceptors_.empty()) {
|
||||
return intercept();
|
||||
}
|
||||
|
||||
DoMultiPerform();
|
||||
return ReadMultiInfo([](Session& session, CURLcode curl_error) -> Response { return session.Complete(curl_error); });
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::MakeDownloadRequest() {
|
||||
if (!interceptors_.empty()) {
|
||||
return intercept();
|
||||
}
|
||||
|
||||
DoMultiPerform();
|
||||
return ReadMultiInfo([](Session& session, CURLcode curl_error) -> Response { return session.CompleteDownload(curl_error); });
|
||||
}
|
||||
|
||||
void MultiPerform::PrepareSessions() {
|
||||
for (const std::pair<std::shared_ptr<Session>, HttpMethod>& pair : sessions_) {
|
||||
switch (pair.second) {
|
||||
case HttpMethod::GET_REQUEST:
|
||||
pair.first->PrepareGet();
|
||||
break;
|
||||
case HttpMethod::POST_REQUEST:
|
||||
pair.first->PreparePost();
|
||||
break;
|
||||
case HttpMethod::PUT_REQUEST:
|
||||
pair.first->PreparePut();
|
||||
break;
|
||||
case HttpMethod::DELETE_REQUEST:
|
||||
pair.first->PrepareDelete();
|
||||
break;
|
||||
case HttpMethod::PATCH_REQUEST:
|
||||
pair.first->PreparePatch();
|
||||
break;
|
||||
case HttpMethod::HEAD_REQUEST:
|
||||
pair.first->PrepareHead();
|
||||
break;
|
||||
case HttpMethod::OPTIONS_REQUEST:
|
||||
pair.first->PrepareOptions();
|
||||
break;
|
||||
default:
|
||||
std::cerr << "PrepareSessions failed: Undefined HttpMethod or download without arguments!" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MultiPerform::PrepareDownloadSession(size_t sessions_index, const WriteCallback& write) {
|
||||
const std::pair<std::shared_ptr<Session>, HttpMethod>& pair = sessions_[sessions_index];
|
||||
switch (pair.second) {
|
||||
case HttpMethod::DOWNLOAD_REQUEST:
|
||||
pair.first->PrepareDownload(write);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "PrepareSessions failed: Undefined HttpMethod or non download method with arguments!" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiPerform::PrepareDownloadSession(size_t sessions_index, std::ofstream& file) {
|
||||
const std::pair<std::shared_ptr<Session>, HttpMethod>& pair = sessions_[sessions_index];
|
||||
switch (pair.second) {
|
||||
case HttpMethod::DOWNLOAD_REQUEST:
|
||||
pair.first->PrepareDownload(file);
|
||||
break;
|
||||
default:
|
||||
std::cerr << "PrepareSessions failed: Undefined HttpMethod or non download method with arguments!" << std::endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiPerform::SetHttpMethod(HttpMethod method) {
|
||||
for (std::pair<std::shared_ptr<Session>, HttpMethod>& pair : sessions_) {
|
||||
pair.second = method;
|
||||
}
|
||||
}
|
||||
|
||||
void MultiPerform::PrepareGet() {
|
||||
SetHttpMethod(HttpMethod::GET_REQUEST);
|
||||
PrepareSessions();
|
||||
}
|
||||
|
||||
void MultiPerform::PrepareDelete() {
|
||||
SetHttpMethod(HttpMethod::DELETE_REQUEST);
|
||||
PrepareSessions();
|
||||
}
|
||||
|
||||
void MultiPerform::PreparePut() {
|
||||
SetHttpMethod(HttpMethod::PUT_REQUEST);
|
||||
PrepareSessions();
|
||||
}
|
||||
|
||||
void MultiPerform::PreparePatch() {
|
||||
SetHttpMethod(HttpMethod::PATCH_REQUEST);
|
||||
PrepareSessions();
|
||||
}
|
||||
|
||||
void MultiPerform::PrepareHead() {
|
||||
SetHttpMethod(HttpMethod::HEAD_REQUEST);
|
||||
PrepareSessions();
|
||||
}
|
||||
|
||||
void MultiPerform::PrepareOptions() {
|
||||
SetHttpMethod(HttpMethod::OPTIONS_REQUEST);
|
||||
PrepareSessions();
|
||||
}
|
||||
|
||||
void MultiPerform::PreparePost() {
|
||||
SetHttpMethod(HttpMethod::POST_REQUEST);
|
||||
PrepareSessions();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::Get() {
|
||||
PrepareGet();
|
||||
return MakeRequest();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::Delete() {
|
||||
PrepareDelete();
|
||||
return MakeRequest();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::Put() {
|
||||
PreparePut();
|
||||
return MakeRequest();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::Head() {
|
||||
PrepareHead();
|
||||
return MakeRequest();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::Options() {
|
||||
PrepareOptions();
|
||||
return MakeRequest();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::Patch() {
|
||||
PreparePatch();
|
||||
return MakeRequest();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::Post() {
|
||||
PreparePost();
|
||||
return MakeRequest();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::Perform() {
|
||||
PrepareSessions();
|
||||
return MakeRequest();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::proceed() {
|
||||
// Check if this multiperform mixes download and non download requests
|
||||
if (!sessions_.empty()) {
|
||||
const bool new_is_download_multi_perform = sessions_.front().second == HttpMethod::DOWNLOAD_REQUEST;
|
||||
|
||||
for (const std::pair<std::shared_ptr<Session>, HttpMethod>& s : sessions_) {
|
||||
const HttpMethod method = s.second;
|
||||
if ((new_is_download_multi_perform && method != HttpMethod::DOWNLOAD_REQUEST) || (!new_is_download_multi_perform && method == HttpMethod::DOWNLOAD_REQUEST)) {
|
||||
throw std::invalid_argument("Failed to proceed with session: Cannot mix download and non-download methods!");
|
||||
}
|
||||
}
|
||||
is_download_multi_perform = new_is_download_multi_perform;
|
||||
}
|
||||
|
||||
PrepareSessions();
|
||||
return MakeRequest();
|
||||
}
|
||||
|
||||
std::vector<Response> MultiPerform::intercept() {
|
||||
// At least one interceptor exists -> Execute its intercept function
|
||||
const std::shared_ptr<InterceptorMulti> interceptor = interceptors_.front();
|
||||
interceptors_.pop();
|
||||
return interceptor->intercept(*this);
|
||||
}
|
||||
|
||||
void MultiPerform::AddInterceptor(const std::shared_ptr<InterceptorMulti>& pinterceptor) {
|
||||
interceptors_.push(pinterceptor);
|
||||
}
|
||||
|
||||
} // namespace cpr
|
6
vendor/CPR/cpr/parameters.cpp
vendored
6
vendor/CPR/cpr/parameters.cpp
vendored
@ -1,10 +1,4 @@
|
||||
#include "cpr/parameters.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
||||
#include "cpr/util.h"
|
||||
|
||||
namespace cpr {
|
||||
Parameters::Parameters(const std::initializer_list<Parameter>& parameters) : CurlContainer<Parameter>(parameters) {}
|
||||
} // namespace cpr
|
||||
|
6
vendor/CPR/cpr/payload.cpp
vendored
6
vendor/CPR/cpr/payload.cpp
vendored
@ -1,10 +1,4 @@
|
||||
#include "cpr/payload.h"
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
|
||||
#include "cpr/util.h"
|
||||
|
||||
namespace cpr {
|
||||
Payload::Payload(const std::initializer_list<Pair>& pairs) : CurlContainer<Pair>(pairs) {}
|
||||
} // namespace cpr
|
||||
|
4
vendor/CPR/cpr/proxies.cpp
vendored
4
vendor/CPR/cpr/proxies.cpp
vendored
@ -7,8 +7,8 @@
|
||||
|
||||
namespace cpr {
|
||||
|
||||
Proxies::Proxies(const std::initializer_list<std::pair<const std::string, std::string>>& hosts)
|
||||
: hosts_{hosts} {}
|
||||
Proxies::Proxies(const std::initializer_list<std::pair<const std::string, std::string>>& hosts) : hosts_{hosts} {}
|
||||
Proxies::Proxies(const std::map<std::string, std::string>& hosts) : hosts_{hosts} {}
|
||||
|
||||
bool Proxies::has(const std::string& protocol) const {
|
||||
return hosts_.count(protocol) > 0;
|
||||
|
22
vendor/CPR/cpr/proxyauth.cpp
vendored
22
vendor/CPR/cpr/proxyauth.cpp
vendored
@ -1,16 +1,30 @@
|
||||
#include "cpr/proxyauth.h"
|
||||
#include "cpr/util.h"
|
||||
|
||||
namespace cpr {
|
||||
const char* EncodedAuthentication::GetAuthString() const noexcept {
|
||||
return auth_string_.c_str();
|
||||
EncodedAuthentication::~EncodedAuthentication() noexcept {
|
||||
util::secureStringClear(username);
|
||||
util::secureStringClear(password);
|
||||
}
|
||||
|
||||
const std::string& EncodedAuthentication::GetUsername() const {
|
||||
return username;
|
||||
}
|
||||
|
||||
const std::string& EncodedAuthentication::GetPassword() const {
|
||||
return password;
|
||||
}
|
||||
|
||||
bool ProxyAuthentication::has(const std::string& protocol) const {
|
||||
return proxyAuth_.count(protocol) > 0;
|
||||
}
|
||||
|
||||
const char* ProxyAuthentication::operator[](const std::string& protocol) {
|
||||
return proxyAuth_[protocol].GetAuthString();
|
||||
const char* ProxyAuthentication::GetUsername(const std::string& protocol) {
|
||||
return proxyAuth_[protocol].username.c_str();
|
||||
}
|
||||
|
||||
const char* ProxyAuthentication::GetPassword(const std::string& protocol) {
|
||||
return proxyAuth_[protocol].password.c_str();
|
||||
}
|
||||
|
||||
} // namespace cpr
|
||||
|
2
vendor/CPR/cpr/redirect.cpp
vendored
2
vendor/CPR/cpr/redirect.cpp
vendored
@ -19,7 +19,7 @@ PostRedirectFlags operator~(PostRedirectFlags flag) {
|
||||
|
||||
PostRedirectFlags& operator|=(PostRedirectFlags& lhs, PostRedirectFlags rhs) {
|
||||
lhs = static_cast<PostRedirectFlags>(static_cast<uint8_t>(lhs) | static_cast<uint8_t>(rhs));
|
||||
uint8_t tmp = static_cast<uint8_t>(lhs);
|
||||
const uint8_t tmp = static_cast<uint8_t>(lhs);
|
||||
lhs = static_cast<PostRedirectFlags>(tmp);
|
||||
return lhs;
|
||||
}
|
||||
|
26
vendor/CPR/cpr/response.cpp
vendored
26
vendor/CPR/cpr/response.cpp
vendored
@ -1,12 +1,9 @@
|
||||
#include "cpr/response.h"
|
||||
|
||||
namespace cpr {
|
||||
Response::Response(std::shared_ptr<CurlHolder> curl, std::string&& p_text,
|
||||
std::string&& p_header_string, Cookies&& p_cookies = Cookies{},
|
||||
Error&& p_error = Error{})
|
||||
: curl_(std::move(curl)), text(std::move(p_text)), cookies(std::move(p_cookies)),
|
||||
error(std::move(p_error)) {
|
||||
header = cpr::util::parseHeader(p_header_string, &status_line, &reason);
|
||||
|
||||
Response::Response(std::shared_ptr<CurlHolder> curl, std::string&& p_text, std::string&& p_header_string, Cookies&& p_cookies = Cookies{}, Error&& p_error = Error{}) : curl_(std::move(curl)), text(std::move(p_text)), cookies(std::move(p_cookies)), error(std::move(p_error)), raw_header(std::move(p_header_string)) {
|
||||
header = cpr::util::parseHeader(raw_header, &status_line, &reason);
|
||||
assert(curl_);
|
||||
assert(curl_->handle);
|
||||
curl_easy_getinfo(curl_->handle, CURLINFO_RESPONSE_CODE, &status_code);
|
||||
@ -14,7 +11,7 @@ Response::Response(std::shared_ptr<CurlHolder> curl, std::string&& p_text,
|
||||
char* url_string{nullptr};
|
||||
curl_easy_getinfo(curl_->handle, CURLINFO_EFFECTIVE_URL, &url_string);
|
||||
url = Url(url_string);
|
||||
#if LIBCURL_VERSION_NUM >= 0x073700
|
||||
#if LIBCURL_VERSION_NUM >= 0x073700 // 7.55.0
|
||||
curl_easy_getinfo(curl_->handle, CURLINFO_SIZE_DOWNLOAD_T, &downloaded_bytes);
|
||||
curl_easy_getinfo(curl_->handle, CURLINFO_SIZE_UPLOAD_T, &uploaded_bytes);
|
||||
#else
|
||||
@ -27,20 +24,21 @@ Response::Response(std::shared_ptr<CurlHolder> curl, std::string&& p_text,
|
||||
curl_easy_getinfo(curl_->handle, CURLINFO_REDIRECT_COUNT, &redirect_count);
|
||||
}
|
||||
|
||||
std::vector<std::string> Response::GetCertInfo() {
|
||||
std::vector<CertInfo> Response::GetCertInfos() {
|
||||
assert(curl_);
|
||||
assert(curl_->handle);
|
||||
curl_certinfo* ci{nullptr};
|
||||
curl_easy_getinfo(curl_->handle, CURLINFO_CERTINFO, &ci);
|
||||
|
||||
std::vector<std::string> info;
|
||||
info.resize(ci->num_of_certs);
|
||||
std::vector<CertInfo> cert_infos;
|
||||
for (int i = 0; i < ci->num_of_certs; i++) {
|
||||
// No way around here.
|
||||
CertInfo cert_info;
|
||||
// NOLINTNEXTLINE (cppcoreguidelines-pro-bounds-pointer-arithmetic)
|
||||
info[i] = std::string{ci->certinfo[i]->data};
|
||||
for (curl_slist* slist = ci->certinfo[i]; slist; slist = slist->next) {
|
||||
cert_info.emplace_back(std::string{slist->data});
|
||||
}
|
||||
|
||||
return info;
|
||||
cert_infos.emplace_back(cert_info);
|
||||
}
|
||||
return cert_infos;
|
||||
}
|
||||
} // namespace cpr
|
||||
|
1304
vendor/CPR/cpr/session.cpp
vendored
1304
vendor/CPR/cpr/session.cpp
vendored
File diff suppressed because it is too large
Load Diff
70
vendor/CPR/cpr/ssl_ctx.cpp
vendored
Normal file
70
vendor/CPR/cpr/ssl_ctx.cpp
vendored
Normal file
@ -0,0 +1,70 @@
|
||||
|
||||
#include "cpr/ssl_ctx.h"
|
||||
|
||||
#if SUPPORT_CURLOPT_SSL_CTX_FUNCTION
|
||||
|
||||
#ifdef OPENSSL_BACKEND_USED
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/safestack.h>
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
/**
|
||||
* The ssl_ctx parameter is actually a pointer to the SSL library's SSL_CTX for OpenSSL.
|
||||
* If an error is returned from the callback no attempt to establish a connection is made and
|
||||
* the perform operation will return the callback's error code.
|
||||
*
|
||||
* Sources: https://curl.se/libcurl/c/CURLOPT_SSL_CTX_FUNCTION.html
|
||||
* https://curl.se/libcurl/c/CURLOPT_SSL_CTX_DATA.html
|
||||
*/
|
||||
CURLcode sslctx_function_load_ca_cert_from_buffer(CURL* /*curl*/, void* sslctx, void* raw_cert_buf) {
|
||||
// Check arguments
|
||||
if (raw_cert_buf == nullptr || sslctx == nullptr) {
|
||||
printf("Invalid callback arguments\n");
|
||||
return CURLE_ABORTED_BY_CALLBACK;
|
||||
}
|
||||
|
||||
// Setup pointer
|
||||
X509_STORE* store = nullptr;
|
||||
X509* cert = nullptr;
|
||||
BIO* bio = nullptr;
|
||||
char* cert_buf = static_cast<char*>(raw_cert_buf);
|
||||
|
||||
// Create a memory BIO using the data of cert_buf.
|
||||
// Note: It is assumed, that cert_buf is nul terminated and its length is determined by strlen.
|
||||
bio = BIO_new_mem_buf(cert_buf, -1);
|
||||
|
||||
// Load the PEM formatted certicifate into an X509 structure which OpenSSL can use.
|
||||
PEM_read_bio_X509(bio, &cert, nullptr, nullptr);
|
||||
if (cert == nullptr) {
|
||||
printf("PEM_read_bio_X509 failed\n");
|
||||
return CURLE_ABORTED_BY_CALLBACK;
|
||||
}
|
||||
|
||||
// Get a pointer to the current certificate verification storage
|
||||
store = SSL_CTX_get_cert_store(static_cast<SSL_CTX*>(sslctx));
|
||||
|
||||
// Add the loaded certificate to the verification storage
|
||||
const int status = X509_STORE_add_cert(store, cert);
|
||||
if (status == 0) {
|
||||
printf("Error adding certificate\n");
|
||||
return CURLE_ABORTED_BY_CALLBACK;
|
||||
}
|
||||
|
||||
// Decrement the reference count of the X509 structure cert and frees it up
|
||||
X509_free(cert);
|
||||
|
||||
// Free the entire bio chain
|
||||
BIO_free(bio);
|
||||
|
||||
// The CA certificate was loaded successfully into the verification storage
|
||||
return CURLE_OK;
|
||||
}
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif // OPENSSL_BACKEND_USED
|
||||
|
||||
#endif // SUPPORT_CURLOPT_SSL_CTX_FUNCTION
|
148
vendor/CPR/cpr/threadpool.cpp
vendored
Normal file
148
vendor/CPR/cpr/threadpool.cpp
vendored
Normal file
@ -0,0 +1,148 @@
|
||||
#include "cpr/threadpool.h"
|
||||
|
||||
namespace cpr {
|
||||
|
||||
ThreadPool::ThreadPool(size_t min_threads, size_t max_threads, std::chrono::milliseconds max_idle_ms) : min_thread_num(min_threads), max_thread_num(max_threads), max_idle_time(max_idle_ms), status(STOP), cur_thread_num(0), idle_thread_num(0) {}
|
||||
|
||||
ThreadPool::~ThreadPool() {
|
||||
Stop();
|
||||
}
|
||||
|
||||
int ThreadPool::Start(size_t start_threads) {
|
||||
if (status != STOP) {
|
||||
return -1;
|
||||
}
|
||||
status = RUNNING;
|
||||
if (start_threads < min_thread_num) {
|
||||
start_threads = min_thread_num;
|
||||
}
|
||||
if (start_threads > max_thread_num) {
|
||||
start_threads = max_thread_num;
|
||||
}
|
||||
for (size_t i = 0; i < start_threads; ++i) {
|
||||
CreateThread();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ThreadPool::Stop() {
|
||||
if (status == STOP) {
|
||||
return -1;
|
||||
}
|
||||
status = STOP;
|
||||
task_cond.notify_all();
|
||||
for (auto& i : threads) {
|
||||
if (i.thread->joinable()) {
|
||||
i.thread->join();
|
||||
}
|
||||
}
|
||||
threads.clear();
|
||||
cur_thread_num = 0;
|
||||
idle_thread_num = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ThreadPool::Pause() {
|
||||
if (status == RUNNING) {
|
||||
status = PAUSE;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ThreadPool::Resume() {
|
||||
if (status == PAUSE) {
|
||||
status = RUNNING;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ThreadPool::Wait() {
|
||||
while (true) {
|
||||
if (status == STOP || (tasks.empty() && idle_thread_num == cur_thread_num)) {
|
||||
break;
|
||||
}
|
||||
std::this_thread::yield();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool ThreadPool::CreateThread() {
|
||||
if (cur_thread_num >= max_thread_num) {
|
||||
return false;
|
||||
}
|
||||
std::thread* thread = new std::thread([this] {
|
||||
bool initialRun = true;
|
||||
while (status != STOP) {
|
||||
while (status == PAUSE) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
|
||||
Task task;
|
||||
{
|
||||
std::unique_lock<std::mutex> locker(task_mutex);
|
||||
task_cond.wait_for(locker, std::chrono::milliseconds(max_idle_time), [this]() { return status == STOP || !tasks.empty(); });
|
||||
if (status == STOP) {
|
||||
return;
|
||||
}
|
||||
if (tasks.empty()) {
|
||||
if (cur_thread_num > min_thread_num) {
|
||||
DelThread(std::this_thread::get_id());
|
||||
return;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!initialRun) {
|
||||
--idle_thread_num;
|
||||
}
|
||||
task = std::move(tasks.front());
|
||||
tasks.pop();
|
||||
}
|
||||
if (task) {
|
||||
task();
|
||||
++idle_thread_num;
|
||||
if (initialRun) {
|
||||
initialRun = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
AddThread(thread);
|
||||
return true;
|
||||
}
|
||||
|
||||
void ThreadPool::AddThread(std::thread* thread) {
|
||||
thread_mutex.lock();
|
||||
++cur_thread_num;
|
||||
ThreadData data;
|
||||
data.thread = std::shared_ptr<std::thread>(thread);
|
||||
data.id = thread->get_id();
|
||||
data.status = RUNNING;
|
||||
data.start_time = time(nullptr);
|
||||
data.stop_time = 0;
|
||||
threads.emplace_back(data);
|
||||
thread_mutex.unlock();
|
||||
}
|
||||
|
||||
void ThreadPool::DelThread(std::thread::id id) {
|
||||
const time_t now = time(nullptr);
|
||||
thread_mutex.lock();
|
||||
--cur_thread_num;
|
||||
--idle_thread_num;
|
||||
auto iter = threads.begin();
|
||||
while (iter != threads.end()) {
|
||||
if (iter->status == STOP && now > iter->stop_time) {
|
||||
if (iter->thread->joinable()) {
|
||||
iter->thread->join();
|
||||
iter = threads.erase(iter);
|
||||
continue;
|
||||
}
|
||||
} else if (iter->id == id) {
|
||||
iter->status = STOP;
|
||||
iter->stop_time = time(nullptr);
|
||||
}
|
||||
++iter;
|
||||
}
|
||||
thread_mutex.unlock();
|
||||
}
|
||||
|
||||
} // namespace cpr
|
4
vendor/CPR/cpr/timeout.cpp
vendored
4
vendor/CPR/cpr/timeout.cpp
vendored
@ -14,12 +14,12 @@ long Timeout::Milliseconds() const {
|
||||
|
||||
// No way around since curl uses a long here.
|
||||
// NOLINTNEXTLINE(google-runtime-int)
|
||||
if (ms.count() > std::numeric_limits<long>::max()) {
|
||||
if (ms.count() > static_cast<std::chrono::milliseconds::rep>(std::numeric_limits<long>::max())) {
|
||||
throw std::overflow_error("cpr::Timeout: timeout value overflow: " + std::to_string(ms.count()) + " ms.");
|
||||
}
|
||||
// No way around since curl uses a long here.
|
||||
// NOLINTNEXTLINE(google-runtime-int)
|
||||
if (ms.count() < std::numeric_limits<long>::min()) {
|
||||
if (ms.count() < static_cast<std::chrono::milliseconds::rep>(std::numeric_limits<long>::min())) {
|
||||
throw std::underflow_error("cpr::Timeout: timeout value underflow: " + std::to_string(ms.count()) + " ms.");
|
||||
}
|
||||
|
||||
|
126
vendor/CPR/cpr/util.cpp
vendored
126
vendor/CPR/cpr/util.cpp
vendored
@ -3,23 +3,64 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <ios>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cpr {
|
||||
namespace util {
|
||||
#if defined(_Win32)
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
#if __has_warning("-Wreserved-macro-identifier") // Not all versions of clang support this flag like the one used on Ubuntu 18.04
|
||||
#pragma clang diagnostic ignored "-Wreserved-macro-identifier"
|
||||
#endif
|
||||
#pragma clang diagnostic ignored "-Wunused-macros"
|
||||
#endif
|
||||
// https://en.cppreference.com/w/c/string/byte/memset
|
||||
// NOLINTNEXTLINE(bugprone-reserved-identifier, cert-dcl37-c, cert-dcl51-cpp, cppcoreguidelines-macro-usage)
|
||||
#define __STDC_WANT_LIB_EXT1__ 1
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
#include <cstring>
|
||||
#endif
|
||||
|
||||
namespace cpr::util {
|
||||
|
||||
enum class CurlHTTPCookieField : size_t {
|
||||
Domain = 0,
|
||||
IncludeSubdomains,
|
||||
Path,
|
||||
HttpsOnly,
|
||||
Expires,
|
||||
Name,
|
||||
Value,
|
||||
};
|
||||
|
||||
Cookies parseCookies(curl_slist* raw_cookies) {
|
||||
const int CURL_HTTP_COOKIE_SIZE = static_cast<int>(CurlHTTPCookieField::Value) + 1;
|
||||
Cookies cookies;
|
||||
for (curl_slist* nc = raw_cookies; nc; nc = nc->next) {
|
||||
std::vector<std::string> tokens = cpr::util::split(nc->data, '\t');
|
||||
std::string value = tokens.back();
|
||||
tokens.pop_back();
|
||||
cookies[tokens.back()] = value;
|
||||
while (tokens.size() < CURL_HTTP_COOKIE_SIZE) {
|
||||
tokens.emplace_back("");
|
||||
}
|
||||
const std::time_t expires = static_cast<time_t>(std::stoul(tokens.at(static_cast<size_t>(CurlHTTPCookieField::Expires))));
|
||||
cookies.emplace_back(Cookie{
|
||||
tokens.at(static_cast<size_t>(CurlHTTPCookieField::Name)),
|
||||
tokens.at(static_cast<size_t>(CurlHTTPCookieField::Value)),
|
||||
tokens.at(static_cast<size_t>(CurlHTTPCookieField::Domain)),
|
||||
isTrue(tokens.at(static_cast<size_t>(CurlHTTPCookieField::IncludeSubdomains))),
|
||||
tokens.at(static_cast<size_t>(CurlHTTPCookieField::Path)),
|
||||
isTrue(tokens.at(static_cast<size_t>(CurlHTTPCookieField::HttpsOnly))),
|
||||
std::chrono::system_clock::from_time_t(expires),
|
||||
});
|
||||
}
|
||||
return cookies;
|
||||
}
|
||||
@ -36,7 +77,6 @@ Header parseHeader(const std::string& headers, std::string* status_line, std::st
|
||||
}
|
||||
|
||||
for (std::string& line : lines) {
|
||||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-magic-numbers)
|
||||
if (line.substr(0, 5) == "HTTP/") {
|
||||
// set the status_line if it was given
|
||||
if ((status_line != nullptr) || (reason != nullptr)) {
|
||||
@ -47,7 +87,7 @@ Header parseHeader(const std::string& headers, std::string* status_line, std::st
|
||||
|
||||
// set the reason if it was given
|
||||
if (reason != nullptr) {
|
||||
size_t pos1 = line.find_first_of("\t ");
|
||||
const size_t pos1 = line.find_first_of("\t ");
|
||||
size_t pos2 = std::string::npos;
|
||||
if (pos1 != std::string::npos) {
|
||||
pos2 = line.find_first_of("\t ", pos1 + 1);
|
||||
@ -62,7 +102,7 @@ Header parseHeader(const std::string& headers, std::string* status_line, std::st
|
||||
}
|
||||
|
||||
if (line.length() > 0) {
|
||||
size_t found = line.find(':');
|
||||
const size_t found = line.find(':');
|
||||
if (found != std::string::npos) {
|
||||
std::string value = line.substr(found + 1);
|
||||
value.erase(0, value.find_first_not_of("\t "));
|
||||
@ -105,7 +145,7 @@ size_t writeFunction(char* ptr, size_t size, size_t nmemb, std::string* data) {
|
||||
|
||||
size_t writeFileFunction(char* ptr, size_t size, size_t nmemb, std::ofstream* file) {
|
||||
size *= nmemb;
|
||||
file->write(ptr, size);
|
||||
file->write(ptr, static_cast<std::streamsize>(size));
|
||||
return size;
|
||||
}
|
||||
|
||||
@ -114,19 +154,8 @@ size_t writeUserFunction(char* ptr, size_t size, size_t nmemb, const WriteCallba
|
||||
return (*write)({ptr, size}) ? size : 0;
|
||||
}
|
||||
|
||||
#if LIBCURL_VERSION_NUM < 0x072000
|
||||
int progressUserFunction(const ProgressCallback* progress, double dltotal, double dlnow,
|
||||
double ultotal, double ulnow) {
|
||||
#else
|
||||
int progressUserFunction(const ProgressCallback* progress, curl_off_t dltotal, curl_off_t dlnow,
|
||||
curl_off_t ultotal, curl_off_t ulnow) {
|
||||
#endif
|
||||
return (*progress)(dltotal, dlnow, ultotal, ulnow) ? 0 : 1;
|
||||
}
|
||||
|
||||
int debugUserFunction(CURL* /*handle*/, curl_infotype type, char* data, size_t size,
|
||||
const DebugCallback* debug) {
|
||||
(*debug)(DebugCallback::InfoType(type), std::string(data, size));
|
||||
int debugUserFunction(CURL* /*handle*/, curl_infotype type, char* data, size_t size, const DebugCallback* debug) {
|
||||
(*debug)(static_cast<DebugCallback::InfoType>(type), std::string(data, size));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -141,7 +170,7 @@ int debugUserFunction(CURL* /*handle*/, curl_infotype type, char* data, size_t s
|
||||
* std::string result = holder.urlEncode(input);
|
||||
**/
|
||||
std::string urlEncode(const std::string& s) {
|
||||
CurlHolder holder; // Create a temporary new holder for URL encoding
|
||||
const CurlHolder holder; // Create a temporary new holder for URL encoding
|
||||
return holder.urlEncode(s);
|
||||
}
|
||||
|
||||
@ -156,9 +185,54 @@ std::string urlEncode(const std::string& s) {
|
||||
* std::string result = holder.urlDecode(input);
|
||||
**/
|
||||
std::string urlDecode(const std::string& s) {
|
||||
CurlHolder holder; // Create a temporary new holder for URL decoding
|
||||
const CurlHolder holder; // Create a temporary new holder for URL decoding
|
||||
return holder.urlDecode(s);
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace cpr
|
||||
#if defined(__STDC_LIB_EXT1__)
|
||||
void secureStringClear(std::string& s) {
|
||||
if (s.empty()) {
|
||||
return;
|
||||
}
|
||||
memset_s(&s.front(), s.length(), 0, s.length());
|
||||
s.clear();
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
void secureStringClear(std::string& s) {
|
||||
if (s.empty()) {
|
||||
return;
|
||||
}
|
||||
SecureZeroMemory(&s.front(), s.length());
|
||||
s.clear();
|
||||
}
|
||||
#else
|
||||
#if defined(__clang__)
|
||||
#pragma clang optimize off // clang
|
||||
#elif defined(__GNUC__) || defined(__MINGW32__) || defined(__MINGW32__) || defined(__MINGW64__)
|
||||
#pragma GCC push_options // g++
|
||||
#pragma GCC optimize("O0") // g++
|
||||
#endif
|
||||
void secureStringClear(std::string& s) {
|
||||
if (s.empty()) {
|
||||
return;
|
||||
}
|
||||
// NOLINTNEXTLINE (readability-container-data-pointer)
|
||||
char* ptr = &(s[0]);
|
||||
memset(ptr, '\0', s.length());
|
||||
s.clear();
|
||||
}
|
||||
|
||||
#if defined(__clang__)
|
||||
#pragma clang optimize on // clang
|
||||
#elif defined(__GNUC__) || defined(__MINGW32__) || defined(__MINGW32__) || defined(__MINGW64__)
|
||||
#pragma GCC pop_options // g++
|
||||
#endif
|
||||
#endif
|
||||
|
||||
bool isTrue(const std::string& s) {
|
||||
std::string temp_string{s};
|
||||
std::transform(temp_string.begin(), temp_string.end(), temp_string.begin(), [](unsigned char c) { return std::tolower(c); });
|
||||
return temp_string == "true";
|
||||
}
|
||||
|
||||
} // namespace cpr::util
|
||||
|
41
vendor/CPR/include/cpr/accept_encoding.h
vendored
Normal file
41
vendor/CPR/include/cpr/accept_encoding.h
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef CPR_ACCEPT_ENCODING_H
|
||||
#define CPR_ACCEPT_ENCODING_H
|
||||
|
||||
#include <curl/curlver.h>
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
enum class AcceptEncodingMethods {
|
||||
identity,
|
||||
deflate,
|
||||
zlib,
|
||||
gzip,
|
||||
disabled,
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(cert-err58-cpp)
|
||||
static const std::map<AcceptEncodingMethods, std::string> AcceptEncodingMethodsStringMap{{AcceptEncodingMethods::identity, "identity"}, {AcceptEncodingMethods::deflate, "deflate"}, {AcceptEncodingMethods::zlib, "zlib"}, {AcceptEncodingMethods::gzip, "gzip"}, {AcceptEncodingMethods::disabled, "disabled"}};
|
||||
|
||||
class AcceptEncoding {
|
||||
public:
|
||||
AcceptEncoding() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
AcceptEncoding(const std::initializer_list<AcceptEncodingMethods>& methods);
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
AcceptEncoding(const std::initializer_list<std::string>& methods);
|
||||
|
||||
[[nodiscard]] bool empty() const noexcept;
|
||||
[[nodiscard]] const std::string getString() const;
|
||||
[[nodiscard]] bool disabled() const;
|
||||
|
||||
private:
|
||||
std::unordered_set<std::string> methods_;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
270
vendor/CPR/include/cpr/api.h
vendored
270
vendor/CPR/include/cpr/api.h
vendored
@ -7,27 +7,108 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "cpr/async.h"
|
||||
#include "cpr/async_wrapper.h"
|
||||
#include "cpr/auth.h"
|
||||
#include "cpr/bearer.h"
|
||||
#include "cpr/cprtypes.h"
|
||||
#include "cpr/digest.h"
|
||||
#include "cpr/multipart.h"
|
||||
#include "cpr/ntlm.h"
|
||||
#include "cpr/multiperform.h"
|
||||
#include "cpr/payload.h"
|
||||
#include "cpr/response.h"
|
||||
#include "cpr/session.h"
|
||||
#include <utility>
|
||||
#include <cpr/filesystem.h>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
using AsyncResponse = std::future<Response>;
|
||||
using AsyncResponse = AsyncWrapper<Response>;
|
||||
|
||||
namespace priv {
|
||||
|
||||
template <bool processed_header, typename CurrentType>
|
||||
void set_option_internal(Session& session, CurrentType&& current_option) {
|
||||
session.SetOption(std::forward<CurrentType>(current_option));
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void set_option_internal<true, Header>(Session& session, Header&& current_option) {
|
||||
// Header option was already provided -> Update previous header
|
||||
session.UpdateHeader(std::forward<Header>(current_option));
|
||||
}
|
||||
|
||||
template <bool processed_header, typename CurrentType, typename... Ts>
|
||||
void set_option_internal(Session& session, CurrentType&& current_option, Ts&&... ts) {
|
||||
set_option_internal<processed_header, CurrentType>(session, std::forward<CurrentType>(current_option));
|
||||
|
||||
if (std::is_same<CurrentType, Header>::value) {
|
||||
set_option_internal<true, Ts...>(session, std::forward<Ts>(ts)...);
|
||||
} else {
|
||||
set_option_internal<processed_header, Ts...>(session, std::forward<Ts>(ts)...);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
void set_option(Session& session, Ts&&... ts) {
|
||||
std::initializer_list<int> ignore = { (session.SetOption(std::forward<Ts>(ts)), 0)... };
|
||||
(void)ignore;
|
||||
set_option_internal<false, Ts...>(session, std::forward<Ts>(ts)...);
|
||||
}
|
||||
|
||||
// Idea: https://stackoverflow.com/a/19060157
|
||||
template <typename Tuple, std::size_t... I>
|
||||
void apply_set_option_internal(Session& session, Tuple&& t, std::index_sequence<I...>) {
|
||||
set_option(session, std::get<I>(std::forward<Tuple>(t))...);
|
||||
}
|
||||
|
||||
// Idea: https://stackoverflow.com/a/19060157
|
||||
template <typename Tuple>
|
||||
void apply_set_option(Session& session, Tuple&& t) {
|
||||
using Indices = std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>;
|
||||
apply_set_option_internal(session, std::forward<Tuple>(t), Indices());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void setup_multiperform_internal(MultiPerform& multiperform, T&& t) {
|
||||
std::shared_ptr<Session> session = std::make_shared<Session>();
|
||||
apply_set_option(*session, t);
|
||||
multiperform.AddSession(session);
|
||||
}
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
void setup_multiperform_internal(MultiPerform& multiperform, T&& t, Ts&&... ts) {
|
||||
std::shared_ptr<Session> session = std::make_shared<Session>();
|
||||
apply_set_option(*session, t);
|
||||
multiperform.AddSession(session);
|
||||
setup_multiperform_internal<Ts...>(multiperform, std::forward<Ts>(ts)...);
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
void setup_multiperform(MultiPerform& multiperform, Ts&&... ts) {
|
||||
setup_multiperform_internal<Ts...>(multiperform, std::forward<Ts>(ts)...);
|
||||
}
|
||||
|
||||
using session_action_t = cpr::Response (cpr::Session::*)();
|
||||
|
||||
template <session_action_t SessionAction, typename T>
|
||||
void setup_multiasync(std::vector<AsyncWrapper<Response, true>>& responses, T&& parameters) {
|
||||
std::shared_ptr<std::atomic_bool> cancellation_state = std::make_shared<std::atomic_bool>(false);
|
||||
|
||||
std::function<Response(T)> execFn{[cancellation_state](T params) {
|
||||
if (cancellation_state->load()) {
|
||||
return Response{};
|
||||
}
|
||||
cpr::Session s{};
|
||||
s.SetCancellationParam(cancellation_state);
|
||||
apply_set_option(s, std::forward<T>(params));
|
||||
return std::invoke(SessionAction, s);
|
||||
}};
|
||||
responses.emplace_back(GlobalThreadPool::GetInstance()->Submit(std::move(execFn), std::forward<T>(parameters)), std::move(cancellation_state));
|
||||
}
|
||||
|
||||
template <session_action_t SessionAction, typename T, typename... Ts>
|
||||
void setup_multiasync(std::vector<AsyncWrapper<Response, true>>& responses, T&& head, Ts&&... tail) {
|
||||
setup_multiasync<SessionAction>(responses, std::forward<T>(head));
|
||||
if constexpr (sizeof...(Ts) > 0) {
|
||||
setup_multiasync<SessionAction>(responses, std::forward<Ts>(tail)...);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
@ -43,17 +124,14 @@ Response Get(Ts&&... ts) {
|
||||
// Get async methods
|
||||
template <typename... Ts>
|
||||
AsyncResponse GetAsync(Ts... ts) {
|
||||
return std::async(
|
||||
std::launch::async, [](Ts... ts_inner) { return Get(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
return cpr::async([](Ts... ts_inner) { return Get(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
}
|
||||
|
||||
// Get callback methods
|
||||
template <typename Then, typename... Ts>
|
||||
// NOLINTNEXTLINE(fuchsia-trailing-return)
|
||||
auto GetCallback(Then then, Ts... ts) -> std::future<decltype(then(Get(std::move(ts)...)))> {
|
||||
return std::async(
|
||||
std::launch::async, [](Then then_inner, Ts... ts_inner) { return then_inner(Get(std::move(ts_inner)...)); },
|
||||
std::move(then), std::move(ts)...);
|
||||
auto GetCallback(Then then, Ts... ts) {
|
||||
return cpr::async([](Then then_inner, Ts... ts_inner) { return then_inner(Get(std::move(ts_inner)...)); }, std::move(then), std::move(ts)...);
|
||||
}
|
||||
|
||||
// Post methods
|
||||
@ -67,17 +145,14 @@ Response Post(Ts&&... ts) {
|
||||
// Post async methods
|
||||
template <typename... Ts>
|
||||
AsyncResponse PostAsync(Ts... ts) {
|
||||
return std::async(
|
||||
std::launch::async, [](Ts... ts_inner) { return Post(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
return cpr::async([](Ts... ts_inner) { return Post(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
}
|
||||
|
||||
// Post callback methods
|
||||
template <typename Then, typename... Ts>
|
||||
// NOLINTNEXTLINE(fuchsia-trailing-return)
|
||||
auto PostCallback(Then then, Ts... ts) -> std::future<decltype(then(Post(std::move(ts)...)))> {
|
||||
return std::async(
|
||||
std::launch::async, [](Then then_inner, Ts... ts_inner) { return then_inner(Post(std::move(ts_inner)...)); },
|
||||
std::move(then), std::move(ts)...);
|
||||
auto PostCallback(Then then, Ts... ts) {
|
||||
return cpr::async([](Then then_inner, Ts... ts_inner) { return then_inner(Post(std::move(ts_inner)...)); }, std::move(then), std::move(ts)...);
|
||||
}
|
||||
|
||||
// Put methods
|
||||
@ -91,17 +166,14 @@ Response Put(Ts&&... ts) {
|
||||
// Put async methods
|
||||
template <typename... Ts>
|
||||
AsyncResponse PutAsync(Ts... ts) {
|
||||
return std::async(
|
||||
std::launch::async, [](Ts... ts_inner) { return Put(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
return cpr::async([](Ts... ts_inner) { return Put(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
}
|
||||
|
||||
// Put callback methods
|
||||
template <typename Then, typename... Ts>
|
||||
// NOLINTNEXTLINE(fuchsia-trailing-return)
|
||||
auto PutCallback(Then then, Ts... ts) -> std::future<decltype(then(Put(std::move(ts)...)))> {
|
||||
return std::async(
|
||||
std::launch::async, [](Then then_inner, Ts... ts_inner) { return then_inner(Put(std::move(ts_inner)...)); },
|
||||
std::move(then), std::move(ts)...);
|
||||
auto PutCallback(Then then, Ts... ts) {
|
||||
return cpr::async([](Then then_inner, Ts... ts_inner) { return then_inner(Put(std::move(ts_inner)...)); }, std::move(then), std::move(ts)...);
|
||||
}
|
||||
|
||||
// Head methods
|
||||
@ -115,17 +187,14 @@ Response Head(Ts&&... ts) {
|
||||
// Head async methods
|
||||
template <typename... Ts>
|
||||
AsyncResponse HeadAsync(Ts... ts) {
|
||||
return std::async(
|
||||
std::launch::async, [](Ts... ts_inner) { return Head(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
return cpr::async([](Ts... ts_inner) { return Head(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
}
|
||||
|
||||
// Head callback methods
|
||||
template <typename Then, typename... Ts>
|
||||
// NOLINTNEXTLINE(fuchsia-trailing-return)
|
||||
auto HeadCallback(Then then, Ts... ts) -> std::future<decltype(then(Head(std::move(ts)...)))> {
|
||||
return std::async(
|
||||
std::launch::async, [](Then then_inner, Ts... ts_inner) { return then_inner(Head(std::move(ts_inner)...)); },
|
||||
std::move(then), std::move(ts)...);
|
||||
auto HeadCallback(Then then, Ts... ts) {
|
||||
return cpr::async([](Then then_inner, Ts... ts_inner) { return then_inner(Head(std::move(ts_inner)...)); }, std::move(then), std::move(ts)...);
|
||||
}
|
||||
|
||||
// Delete methods
|
||||
@ -139,18 +208,14 @@ Response Delete(Ts&&... ts) {
|
||||
// Delete async methods
|
||||
template <typename... Ts>
|
||||
AsyncResponse DeleteAsync(Ts... ts) {
|
||||
return std::async(
|
||||
std::launch::async, [](Ts... ts_inner) { return Delete(std::move(ts_inner)...); },
|
||||
std::move(ts)...);
|
||||
return cpr::async([](Ts... ts_inner) { return Delete(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
}
|
||||
|
||||
// Delete callback methods
|
||||
template <typename Then, typename... Ts>
|
||||
// NOLINTNEXTLINE(fuchsia-trailing-return)
|
||||
auto DeleteCallback(Then then, Ts... ts) -> std::future<decltype(then(Delete(std::move(ts)...)))> {
|
||||
return std::async(
|
||||
std::launch::async, [](Then then_inner, Ts... ts_inner) { return then_inner(Delete(std::move(ts_inner)...)); },
|
||||
std::move(then), std::move(ts)...);
|
||||
auto DeleteCallback(Then then, Ts... ts) {
|
||||
return cpr::async([](Then then_inner, Ts... ts_inner) { return then_inner(Delete(std::move(ts_inner)...)); }, std::move(then), std::move(ts)...);
|
||||
}
|
||||
|
||||
// Options methods
|
||||
@ -164,19 +229,14 @@ Response Options(Ts&&... ts) {
|
||||
// Options async methods
|
||||
template <typename... Ts>
|
||||
AsyncResponse OptionsAsync(Ts... ts) {
|
||||
return std::async(
|
||||
std::launch::async, [](Ts... ts_inner) { return Options(std::move(ts_inner)...); },
|
||||
std::move(ts)...);
|
||||
return cpr::async([](Ts... ts_inner) { return Options(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
}
|
||||
|
||||
// Options callback methods
|
||||
template <typename Then, typename... Ts>
|
||||
// NOLINTNEXTLINE(fuchsia-trailing-return)
|
||||
auto OptionsCallback(Then then, Ts... ts)
|
||||
-> std::future<decltype(then(Options(std::move(ts)...)))> {
|
||||
return std::async(
|
||||
std::launch::async, [](Then then_inner, Ts... ts_inner) { return then_inner(Options(std::move(ts_inner)...)); },
|
||||
std::move(then), std::move(ts)...);
|
||||
auto OptionsCallback(Then then, Ts... ts) {
|
||||
return cpr::async([](Then then_inner, Ts... ts_inner) { return then_inner(Options(std::move(ts_inner)...)); }, std::move(then), std::move(ts)...);
|
||||
}
|
||||
|
||||
// Patch methods
|
||||
@ -190,17 +250,14 @@ Response Patch(Ts&&... ts) {
|
||||
// Patch async methods
|
||||
template <typename... Ts>
|
||||
AsyncResponse PatchAsync(Ts... ts) {
|
||||
return std::async(
|
||||
std::launch::async, [](Ts... ts_inner) { return Patch(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
return cpr::async([](Ts... ts_inner) { return Patch(std::move(ts_inner)...); }, std::move(ts)...);
|
||||
}
|
||||
|
||||
// Patch callback methods
|
||||
template <typename Then, typename... Ts>
|
||||
// NOLINTNEXTLINE(fuchsia-trailing-return)
|
||||
auto PatchCallback(Then then, Ts... ts) -> std::future<decltype(then(Patch(std::move(ts)...)))> {
|
||||
return std::async(
|
||||
std::launch::async, [](Then then_inner, Ts... ts_inner) { return then_inner(Patch(std::move(ts_inner)...)); },
|
||||
std::move(then), std::move(ts)...);
|
||||
auto PatchCallback(Then then, Ts... ts) {
|
||||
return cpr::async([](Then then_inner, Ts... ts_inner) { return then_inner(Patch(std::move(ts_inner)...)); }, std::move(then), std::move(ts)...);
|
||||
}
|
||||
|
||||
// Download methods
|
||||
@ -211,6 +268,18 @@ Response Download(std::ofstream& file, Ts&&... ts) {
|
||||
return session.Download(file);
|
||||
}
|
||||
|
||||
// Download async method
|
||||
template <typename... Ts>
|
||||
AsyncResponse DownloadAsync(fs::path local_path, Ts... ts) {
|
||||
return AsyncWrapper{std::async(
|
||||
std::launch::async,
|
||||
[](fs::path local_path_, Ts... ts_) {
|
||||
std::ofstream f(local_path_.c_str());
|
||||
return Download(f, std::move(ts_)...);
|
||||
},
|
||||
std::move(local_path), std::move(ts)...)};
|
||||
}
|
||||
|
||||
// Download with user callback
|
||||
template <typename... Ts>
|
||||
Response Download(const WriteCallback& write, Ts&&... ts) {
|
||||
@ -219,6 +288,105 @@ Response Download(const WriteCallback& write, Ts&&... ts) {
|
||||
return session.Download(write);
|
||||
}
|
||||
|
||||
// Multi requests
|
||||
template <typename... Ts>
|
||||
std::vector<Response> MultiGet(Ts&&... ts) {
|
||||
MultiPerform multiperform;
|
||||
priv::setup_multiperform<Ts...>(multiperform, std::forward<Ts>(ts)...);
|
||||
return multiperform.Get();
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<Response> MultiDelete(Ts&&... ts) {
|
||||
MultiPerform multiperform;
|
||||
priv::setup_multiperform<Ts...>(multiperform, std::forward<Ts>(ts)...);
|
||||
return multiperform.Delete();
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<Response> MultiPut(Ts&&... ts) {
|
||||
MultiPerform multiperform;
|
||||
priv::setup_multiperform<Ts...>(multiperform, std::forward<Ts>(ts)...);
|
||||
return multiperform.Put();
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<Response> MultiHead(Ts&&... ts) {
|
||||
MultiPerform multiperform;
|
||||
priv::setup_multiperform<Ts...>(multiperform, std::forward<Ts>(ts)...);
|
||||
return multiperform.Head();
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<Response> MultiOptions(Ts&&... ts) {
|
||||
MultiPerform multiperform;
|
||||
priv::setup_multiperform<Ts...>(multiperform, std::forward<Ts>(ts)...);
|
||||
return multiperform.Options();
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<Response> MultiPatch(Ts&&... ts) {
|
||||
MultiPerform multiperform;
|
||||
priv::setup_multiperform<Ts...>(multiperform, std::forward<Ts>(ts)...);
|
||||
return multiperform.Patch();
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<Response> MultiPost(Ts&&... ts) {
|
||||
MultiPerform multiperform;
|
||||
priv::setup_multiperform<Ts...>(multiperform, std::forward<Ts>(ts)...);
|
||||
return multiperform.Post();
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<AsyncWrapper<Response, true>> MultiGetAsync(Ts&&... ts) {
|
||||
std::vector<AsyncWrapper<Response, true>> ret{};
|
||||
priv::setup_multiasync<&cpr::Session::Get>(ret, std::forward<Ts>(ts)...);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<AsyncWrapper<Response, true>> MultiDeleteAsync(Ts&&... ts) {
|
||||
std::vector<AsyncWrapper<Response, true>> ret{};
|
||||
priv::setup_multiasync<&cpr::Session::Delete>(ret, std::forward<Ts>(ts)...);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<AsyncWrapper<Response, true>> MultiHeadAsync(Ts&&... ts) {
|
||||
std::vector<AsyncWrapper<Response, true>> ret{};
|
||||
priv::setup_multiasync<&cpr::Session::Head>(ret, std::forward<Ts>(ts)...);
|
||||
return ret;
|
||||
}
|
||||
template <typename... Ts>
|
||||
std::vector<AsyncWrapper<Response, true>> MultiOptionsAsync(Ts&&... ts) {
|
||||
std::vector<AsyncWrapper<Response, true>> ret{};
|
||||
priv::setup_multiasync<&cpr::Session::Options>(ret, std::forward<Ts>(ts)...);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<AsyncWrapper<Response, true>> MultiPatchAsync(Ts&&... ts) {
|
||||
std::vector<AsyncWrapper<Response, true>> ret{};
|
||||
priv::setup_multiasync<&cpr::Session::Patch>(ret, std::forward<Ts>(ts)...);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<AsyncWrapper<Response, true>> MultiPostAsync(Ts&&... ts) {
|
||||
std::vector<AsyncWrapper<Response, true>> ret{};
|
||||
priv::setup_multiasync<&cpr::Session::Post>(ret, std::forward<Ts>(ts)...);
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename... Ts>
|
||||
std::vector<AsyncWrapper<Response, true>> MultiPutAsync(Ts&&... ts) {
|
||||
std::vector<AsyncWrapper<Response, true>> ret{};
|
||||
priv::setup_multiasync<&cpr::Session::Put>(ret, std::forward<Ts>(ts)...);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
||||
|
50
vendor/CPR/include/cpr/async.h
vendored
Normal file
50
vendor/CPR/include/cpr/async.h
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
#ifndef CPR_ASYNC_H
|
||||
#define CPR_ASYNC_H
|
||||
|
||||
#include "async_wrapper.h"
|
||||
#include "singleton.h"
|
||||
#include "threadpool.h"
|
||||
|
||||
namespace cpr {
|
||||
|
||||
class GlobalThreadPool : public ThreadPool {
|
||||
CPR_SINGLETON_DECL(GlobalThreadPool)
|
||||
protected:
|
||||
GlobalThreadPool() = default;
|
||||
|
||||
public:
|
||||
~GlobalThreadPool() override = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* Return a wrapper for a future, calling future.get() will wait until the task is done and return RetType.
|
||||
* async(fn, args...)
|
||||
* async(std::bind(&Class::mem_fn, &obj))
|
||||
* async(std::mem_fn(&Class::mem_fn, &obj))
|
||||
**/
|
||||
template <class Fn, class... Args>
|
||||
auto async(Fn&& fn, Args&&... args) {
|
||||
return AsyncWrapper{GlobalThreadPool::GetInstance()->Submit(std::forward<Fn>(fn), std::forward<Args>(args)...)};
|
||||
}
|
||||
|
||||
class async {
|
||||
public:
|
||||
static void startup(size_t min_threads = CPR_DEFAULT_THREAD_POOL_MIN_THREAD_NUM, size_t max_threads = CPR_DEFAULT_THREAD_POOL_MAX_THREAD_NUM, std::chrono::milliseconds max_idle_ms = CPR_DEFAULT_THREAD_POOL_MAX_IDLE_TIME) {
|
||||
GlobalThreadPool* gtp = GlobalThreadPool::GetInstance();
|
||||
if (gtp->IsStarted()) {
|
||||
return;
|
||||
}
|
||||
gtp->SetMinThreadNum(min_threads);
|
||||
gtp->SetMaxThreadNum(max_threads);
|
||||
gtp->SetMaxIdleTime(max_idle_ms);
|
||||
gtp->Start();
|
||||
}
|
||||
|
||||
static void cleanup() {
|
||||
GlobalThreadPool::ExitInstance();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
140
vendor/CPR/include/cpr/async_wrapper.h
vendored
Normal file
140
vendor/CPR/include/cpr/async_wrapper.h
vendored
Normal file
@ -0,0 +1,140 @@
|
||||
#ifndef CPR_ASYNC_WRAPPER_H
|
||||
#define CPR_ASYNC_WRAPPER_H
|
||||
|
||||
#include <atomic>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
|
||||
#include "cpr/response.h"
|
||||
|
||||
namespace cpr {
|
||||
enum class [[nodiscard]] CancellationResult { failure, success, invalid_operation };
|
||||
|
||||
/**
|
||||
* A class template intended to wrap results of async operations (instances of std::future<T>)
|
||||
* and also provide extended capablilities relaed to these requests, for example cancellation.
|
||||
*
|
||||
* The RAII semantics are the same as std::future<T> - moveable, not copyable.
|
||||
*/
|
||||
template <typename T, bool isCancellable = false>
|
||||
class AsyncWrapper {
|
||||
private:
|
||||
std::future<T> future;
|
||||
std::shared_ptr<std::atomic_bool> is_cancelled;
|
||||
|
||||
public:
|
||||
// Constructors
|
||||
explicit AsyncWrapper(std::future<T>&& f) : future{std::move(f)} {}
|
||||
AsyncWrapper(std::future<T>&& f, std::shared_ptr<std::atomic_bool>&& cancelledState) : future{std::move(f)}, is_cancelled{std::move(cancelledState)} {}
|
||||
|
||||
// Copy Semantics
|
||||
AsyncWrapper(const AsyncWrapper&) = delete;
|
||||
AsyncWrapper& operator=(const AsyncWrapper&) = delete;
|
||||
|
||||
// Move Semantics
|
||||
AsyncWrapper(AsyncWrapper&&) noexcept = default;
|
||||
AsyncWrapper& operator=(AsyncWrapper&&) noexcept = default;
|
||||
|
||||
// Destructor
|
||||
~AsyncWrapper() {
|
||||
if constexpr (isCancellable) {
|
||||
if(is_cancelled) {
|
||||
is_cancelled->store(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// These methods replicate the behaviour of std::future<T>
|
||||
[[nodiscard]] T get() {
|
||||
if constexpr (isCancellable) {
|
||||
if (IsCancelled()) {
|
||||
throw std::logic_error{"Calling AsyncWrapper::get on a cancelled request!"};
|
||||
}
|
||||
}
|
||||
if (!future.valid()) {
|
||||
throw std::logic_error{"Calling AsyncWrapper::get when the associated future instance is invalid!"};
|
||||
}
|
||||
return future.get();
|
||||
}
|
||||
|
||||
[[nodiscard]] bool valid() const noexcept {
|
||||
if constexpr (isCancellable) {
|
||||
return !is_cancelled->load() && future.valid();
|
||||
} else {
|
||||
return future.valid();
|
||||
}
|
||||
}
|
||||
|
||||
void wait() const {
|
||||
if constexpr (isCancellable) {
|
||||
if (is_cancelled->load()) {
|
||||
throw std::logic_error{"Calling AsyncWrapper::wait when the associated future is invalid or cancelled!"};
|
||||
}
|
||||
}
|
||||
if (!future.valid()) {
|
||||
throw std::logic_error{"Calling AsyncWrapper::wait_until when the associated future is invalid!"};
|
||||
}
|
||||
future.wait();
|
||||
}
|
||||
|
||||
template <class Rep, class Period>
|
||||
std::future_status wait_for(const std::chrono::duration<Rep, Period>& timeout_duration) const {
|
||||
if constexpr (isCancellable) {
|
||||
if (IsCancelled()) {
|
||||
throw std::logic_error{"Calling AsyncWrapper::wait_for when the associated future is cancelled!"};
|
||||
}
|
||||
}
|
||||
if (!future.valid()) {
|
||||
throw std::logic_error{"Calling AsyncWrapper::wait_until when the associated future is invalid!"};
|
||||
}
|
||||
return future.wait_for(timeout_duration);
|
||||
}
|
||||
|
||||
template <class Clock, class Duration>
|
||||
std::future_status wait_until(const std::chrono::time_point<Clock, Duration>& timeout_time) const {
|
||||
if constexpr (isCancellable) {
|
||||
if (IsCancelled()) {
|
||||
throw std::logic_error{"Calling AsyncWrapper::wait_until when the associated future is cancelled!"};
|
||||
}
|
||||
}
|
||||
if (!future.valid()) {
|
||||
throw std::logic_error{"Calling AsyncWrapper::wait_until when the associated future is invalid!"};
|
||||
}
|
||||
return future.wait_until(timeout_time);
|
||||
}
|
||||
|
||||
std::shared_future<T> share() noexcept {
|
||||
return future.share();
|
||||
}
|
||||
|
||||
// Cancellation-related methods
|
||||
CancellationResult Cancel() {
|
||||
if constexpr (!isCancellable) {
|
||||
return CancellationResult::invalid_operation;
|
||||
}
|
||||
if (!future.valid() || is_cancelled->load()) {
|
||||
return CancellationResult::invalid_operation;
|
||||
}
|
||||
is_cancelled->store(true);
|
||||
return CancellationResult::success;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsCancelled() const {
|
||||
if constexpr (isCancellable) {
|
||||
return is_cancelled->load();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Deduction guides
|
||||
template <typename T>
|
||||
AsyncWrapper(std::future<T>&&) -> AsyncWrapper<T, false>;
|
||||
|
||||
template <typename T>
|
||||
AsyncWrapper(std::future<T>&&, std::shared_ptr<std::atomic_bool>&&) -> AsyncWrapper<T, true>;
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
|
||||
#endif
|
15
vendor/CPR/include/cpr/auth.h
vendored
15
vendor/CPR/include/cpr/auth.h
vendored
@ -7,23 +7,24 @@
|
||||
|
||||
namespace cpr {
|
||||
|
||||
enum class AuthMode { BASIC, DIGEST, NTLM };
|
||||
|
||||
class Authentication {
|
||||
public:
|
||||
Authentication(const std::string& username, const std::string& password)
|
||||
: auth_string_{username + ":" + password} {}
|
||||
Authentication(std::string&& username, std::string&& password)
|
||||
: auth_string_{std::move(username) + ":" + std::move(password)} {}
|
||||
Authentication(std::string username, std::string password, AuthMode auth_mode) : auth_string_{std::move(username) + ":" + std::move(password)}, auth_mode_{std::move(auth_mode)} {}
|
||||
Authentication(const Authentication& other) = default;
|
||||
Authentication(Authentication&& old) noexcept = default;
|
||||
virtual ~Authentication() noexcept = default;
|
||||
~Authentication() noexcept;
|
||||
|
||||
Authentication& operator=(Authentication&& old) noexcept = default;
|
||||
Authentication& operator=(const Authentication& other) = default;
|
||||
|
||||
virtual const char* GetAuthString() const noexcept;
|
||||
const char* GetAuthString() const noexcept;
|
||||
AuthMode GetAuthMode() const noexcept;
|
||||
|
||||
protected:
|
||||
private:
|
||||
std::string auth_string_;
|
||||
AuthMode auth_mode_;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
8
vendor/CPR/include/cpr/bearer.h
vendored
8
vendor/CPR/include/cpr/bearer.h
vendored
@ -1,8 +1,8 @@
|
||||
#ifndef CPR_BEARER_H
|
||||
#define CPR_BEARER_H
|
||||
|
||||
#include <string>
|
||||
#include <curl/curlver.h>
|
||||
#include <string>
|
||||
|
||||
#include <utility>
|
||||
|
||||
@ -14,12 +14,10 @@ namespace cpr {
|
||||
class Bearer {
|
||||
public:
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Bearer(const std::string& token) : token_string_{token} {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Bearer(std::string&& token) : token_string_{std::move(token)} {}
|
||||
Bearer(std::string token) : token_string_{std::move(token)} {}
|
||||
Bearer(const Bearer& other) = default;
|
||||
Bearer(Bearer&& old) noexcept = default;
|
||||
virtual ~Bearer() noexcept = default;
|
||||
virtual ~Bearer() noexcept;
|
||||
|
||||
Bearer& operator=(Bearer&& old) noexcept = default;
|
||||
Bearer& operator=(const Bearer& other) = default;
|
||||
|
28
vendor/CPR/include/cpr/body.h
vendored
28
vendor/CPR/include/cpr/body.h
vendored
@ -1,24 +1,46 @@
|
||||
#ifndef CPR_BODY_H
|
||||
#define CPR_BODY_H
|
||||
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "cpr/buffer.h"
|
||||
#include "cpr/cprtypes.h"
|
||||
#include "cpr/file.h"
|
||||
|
||||
namespace cpr {
|
||||
|
||||
class Body : public StringHolder<Body> {
|
||||
public:
|
||||
Body() : StringHolder<Body>() {}
|
||||
Body() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Body(const std::string& body) : StringHolder<Body>(body) {}
|
||||
Body(std::string body) : StringHolder<Body>(std::move(body)) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Body(std::string&& body) : StringHolder<Body>(std::move(body)) {}
|
||||
Body(std::string_view body) : StringHolder<Body>(body) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Body(const char* body) : StringHolder<Body>(body) {}
|
||||
Body(const char* str, size_t len) : StringHolder<Body>(str, len) {}
|
||||
Body(const std::initializer_list<std::string> args) : StringHolder<Body>(args) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, cppcoreguidelines-pro-type-reinterpret-cast)
|
||||
Body(const Buffer& buffer) : StringHolder<Body>(reinterpret_cast<const char*>(buffer.data), static_cast<size_t>(buffer.datalen)) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
Body(const File& file) {
|
||||
std::ifstream is(file.filepath, std::ifstream::binary);
|
||||
if (!is) {
|
||||
throw std::invalid_argument("Can't open the file for HTTP request body!");
|
||||
}
|
||||
|
||||
is.seekg(0, std::ios::end);
|
||||
const std::streampos length = is.tellg();
|
||||
is.seekg(0, std::ios::beg);
|
||||
std::string buffer;
|
||||
buffer.resize(static_cast<size_t>(length));
|
||||
is.read(buffer.data(), length);
|
||||
str_ = std::move(buffer);
|
||||
}
|
||||
Body(const Body& other) = default;
|
||||
Body(Body&& old) noexcept = default;
|
||||
~Body() override = default;
|
||||
|
33
vendor/CPR/include/cpr/buffer.h
vendored
Normal file
33
vendor/CPR/include/cpr/buffer.h
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef CPR_BUFFER_H
|
||||
#define CPR_BUFFER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <cpr/filesystem.h>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
struct Buffer {
|
||||
using data_t = const char*;
|
||||
|
||||
template <typename Iterator>
|
||||
Buffer(Iterator begin, Iterator end, fs::path&& p_filename)
|
||||
// Ignored here since libcurl reqires a long.
|
||||
// There is also no way around the reinterpret_cast.
|
||||
// NOLINTNEXTLINE(google-runtime-int, cppcoreguidelines-pro-type-reinterpret-cast)
|
||||
: data{reinterpret_cast<data_t>(&(*begin))}, datalen{static_cast<size_t>(std::distance(begin, end))}, filename(std::move(p_filename)) {
|
||||
is_random_access_iterator(begin, end);
|
||||
static_assert(sizeof(*begin) == 1, "Only byte buffers can be used");
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
typename std::enable_if<std::is_same<typename std::iterator_traits<Iterator>::iterator_category, std::random_access_iterator_tag>::value>::type is_random_access_iterator(Iterator /* begin */, Iterator /* end */) {}
|
||||
|
||||
data_t data;
|
||||
size_t datalen;
|
||||
const fs::path filename;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
42
vendor/CPR/include/cpr/callback.h
vendored
42
vendor/CPR/include/cpr/callback.h
vendored
@ -3,7 +3,9 @@
|
||||
|
||||
#include "cprtypes.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
namespace cpr {
|
||||
@ -14,11 +16,11 @@ class ReadCallback {
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
ReadCallback(std::function<bool(char* buffer, size_t& size, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), size{-1}, callback{std::move(p_callback)} {}
|
||||
ReadCallback(cpr_off_t p_size, std::function<bool(char* buffer, size_t& size, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), size{p_size}, callback{std::move(p_callback)} {}
|
||||
bool operator()(char* buffer, size_t& size) const {
|
||||
return callback(buffer, size, userdata);
|
||||
bool operator()(char* buffer, size_t& buffer_size) const {
|
||||
return callback(buffer, buffer_size, userdata);
|
||||
}
|
||||
|
||||
intptr_t userdata;
|
||||
intptr_t userdata{};
|
||||
cpr_off_t size{};
|
||||
std::function<bool(char* buffer, size_t& size, intptr_t userdata)> callback;
|
||||
};
|
||||
@ -32,7 +34,7 @@ class HeaderCallback {
|
||||
return callback(std::move(header), userdata);
|
||||
}
|
||||
|
||||
intptr_t userdata;
|
||||
intptr_t userdata{};
|
||||
std::function<bool(std::string header, intptr_t userdata)> callback;
|
||||
};
|
||||
|
||||
@ -45,7 +47,7 @@ class WriteCallback {
|
||||
return callback(std::move(data), userdata);
|
||||
}
|
||||
|
||||
intptr_t userdata;
|
||||
intptr_t userdata{};
|
||||
std::function<bool(std::string data, intptr_t userdata)> callback;
|
||||
};
|
||||
|
||||
@ -53,13 +55,13 @@ class ProgressCallback {
|
||||
public:
|
||||
ProgressCallback() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
ProgressCallback(std::function<bool(cpr_off_t downloadTotal, cpr_off_t downloadNow, cpr_off_t uploadTotal, cpr_off_t uploadNow, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
|
||||
bool operator()(cpr_off_t downloadTotal, cpr_off_t downloadNow, cpr_off_t uploadTotal, cpr_off_t uploadNow) const {
|
||||
ProgressCallback(std::function<bool(cpr_pf_arg_t downloadTotal, cpr_pf_arg_t downloadNow, cpr_pf_arg_t uploadTotal, cpr_pf_arg_t uploadNow, intptr_t userdata)> p_callback, intptr_t p_userdata = 0) : userdata(p_userdata), callback(std::move(p_callback)) {}
|
||||
bool operator()(cpr_pf_arg_t downloadTotal, cpr_pf_arg_t downloadNow, cpr_pf_arg_t uploadTotal, cpr_pf_arg_t uploadNow) const {
|
||||
return callback(downloadTotal, downloadNow, uploadTotal, uploadNow, userdata);
|
||||
}
|
||||
|
||||
intptr_t userdata;
|
||||
std::function<bool(size_t downloadTotal, size_t downloadNow, size_t uploadTotal, size_t uploadNow, intptr_t userdata)> callback;
|
||||
intptr_t userdata{};
|
||||
std::function<bool(cpr_pf_arg_t downloadTotal, cpr_pf_arg_t downloadNow, cpr_pf_arg_t uploadTotal, cpr_pf_arg_t uploadNow, intptr_t userdata)> callback;
|
||||
};
|
||||
|
||||
class DebugCallback {
|
||||
@ -80,10 +82,30 @@ class DebugCallback {
|
||||
callback(type, std::move(data), userdata);
|
||||
}
|
||||
|
||||
intptr_t userdata;
|
||||
intptr_t userdata{};
|
||||
std::function<void(InfoType type, std::string data, intptr_t userdata)> callback;
|
||||
};
|
||||
|
||||
/**
|
||||
* Functor class for progress functions that will be used in cancellable requests.
|
||||
*/
|
||||
class CancellationCallback {
|
||||
public:
|
||||
CancellationCallback() = default;
|
||||
explicit CancellationCallback(std::shared_ptr<std::atomic_bool>&& cs) : cancellation_state{std::move(cs)} {}
|
||||
|
||||
CancellationCallback(std::shared_ptr<std::atomic_bool>&& cs, ProgressCallback& u_cb) : cancellation_state{std::move(cs)}, user_cb{std::reference_wrapper{u_cb}} {}
|
||||
|
||||
bool operator()(cpr_pf_arg_t dltotal, cpr_pf_arg_t dlnow, cpr_pf_arg_t ultotal, cpr_pf_arg_t ulnow) const;
|
||||
|
||||
void SetProgressCallback(ProgressCallback& u_cb);
|
||||
|
||||
private:
|
||||
std::shared_ptr<std::atomic_bool> cancellation_state;
|
||||
std::optional<std::reference_wrapper<ProgressCallback>> user_cb;
|
||||
};
|
||||
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
||||
|
37
vendor/CPR/include/cpr/cert_info.h
vendored
Normal file
37
vendor/CPR/include/cpr/cert_info.h
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef CPR_CERT_INFO_H
|
||||
#define CPR_CERT_INFO_H
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
class CertInfo {
|
||||
private:
|
||||
std::vector<std::string> cert_info_;
|
||||
|
||||
public:
|
||||
CertInfo() = default;
|
||||
CertInfo(const CertInfo& other) = default;
|
||||
CertInfo(CertInfo&& old) = default;
|
||||
CertInfo(const std::initializer_list<std::string>& entry) : cert_info_{entry} {}
|
||||
~CertInfo() noexcept = default;
|
||||
|
||||
using iterator = std::vector<std::string>::iterator;
|
||||
using const_iterator = std::vector<std::string>::const_iterator;
|
||||
|
||||
std::string& operator[](const size_t& pos);
|
||||
iterator begin();
|
||||
iterator end();
|
||||
const_iterator begin() const;
|
||||
const_iterator end() const;
|
||||
const_iterator cbegin() const;
|
||||
const_iterator cend() const;
|
||||
void emplace_back(const std::string& str);
|
||||
void push_back(const std::string& str);
|
||||
void pop_back();
|
||||
};
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
61
vendor/CPR/include/cpr/cookies.h
vendored
61
vendor/CPR/include/cpr/cookies.h
vendored
@ -2,12 +2,49 @@
|
||||
#define CPR_COOKIES_H
|
||||
|
||||
#include "cpr/curlholder.h"
|
||||
#include <chrono>
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace cpr {
|
||||
/**
|
||||
* EXPIRES_STRING_SIZE is an explicitly static and const variable that could be only accessed within the same namespace and is immutable.
|
||||
* To be used for "std::array", the expression must have a constant value, so EXPIRES_STRING_SIZE must be a const value.
|
||||
**/
|
||||
static const std::size_t EXPIRES_STRING_SIZE = 100;
|
||||
|
||||
class Cookie {
|
||||
public:
|
||||
Cookie() = default;
|
||||
/**
|
||||
* Some notes for the default value used by expires:
|
||||
* std::chrono::system_clock::time_point::min() won't work on Windows due to the min, max clash there.
|
||||
* So we fall back to std::chrono::system_clock::from_time_t(0) for the minimum value here.
|
||||
**/
|
||||
Cookie(const std::string& name, const std::string& value, const std::string& domain = "", bool p_isIncludingSubdomains = false, const std::string& path = "/", bool p_isHttpsOnly = false, std::chrono::system_clock::time_point expires = std::chrono::system_clock::from_time_t(0)) : name_{name}, value_{value}, domain_{domain}, includeSubdomains_{p_isIncludingSubdomains}, path_{path}, httpsOnly_{p_isHttpsOnly}, expires_{expires} {}
|
||||
const std::string GetDomain() const;
|
||||
bool IsIncludingSubdomains() const;
|
||||
const std::string GetPath() const;
|
||||
bool IsHttpsOnly() const;
|
||||
const std::chrono::system_clock::time_point GetExpires() const;
|
||||
const std::string GetExpiresString() const;
|
||||
const std::string GetName() const;
|
||||
const std::string GetValue() const;
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
std::string value_;
|
||||
std::string domain_;
|
||||
bool includeSubdomains_{};
|
||||
std::string path_;
|
||||
bool httpsOnly_{};
|
||||
/**
|
||||
* TODO: Update the implementation using `std::chrono::utc_clock` of C++20
|
||||
**/
|
||||
std::chrono::system_clock::time_point expires_{};
|
||||
};
|
||||
|
||||
class Cookies {
|
||||
public:
|
||||
@ -25,19 +62,16 @@ class Cookies {
|
||||
bool encode{true};
|
||||
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Cookies(bool p_encode = true) : encode(p_encode) {}
|
||||
Cookies(const std::initializer_list<std::pair<const std::string, std::string>>& pairs,
|
||||
bool p_encode = true)
|
||||
: encode(p_encode), map_{pairs} {}
|
||||
Cookies(bool p_encode = true) : encode{p_encode} {}
|
||||
Cookies(const std::initializer_list<cpr::Cookie>& cookies, bool p_encode = true) : encode{p_encode}, cookies_{cookies} {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Cookies(const std::map<std::string, std::string>& map, bool p_encode = true)
|
||||
: encode(p_encode), map_{map} {}
|
||||
Cookies(const cpr::Cookie& cookie, bool p_encode = true) : encode{p_encode}, cookies_{cookie} {}
|
||||
|
||||
std::string& operator[](const std::string& key);
|
||||
std::string GetEncoded(const CurlHolder& holder) const;
|
||||
cpr::Cookie& operator[](size_t pos);
|
||||
const std::string GetEncoded(const CurlHolder& holder) const;
|
||||
|
||||
using iterator = std::map<std::string, std::string>::iterator;
|
||||
using const_iterator = std::map<std::string, std::string>::const_iterator;
|
||||
using iterator = std::vector<cpr::Cookie>::iterator;
|
||||
using const_iterator = std::vector<cpr::Cookie>::const_iterator;
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
@ -45,9 +79,12 @@ class Cookies {
|
||||
const_iterator end() const;
|
||||
const_iterator cbegin() const;
|
||||
const_iterator cend() const;
|
||||
void emplace_back(const Cookie& str);
|
||||
void push_back(const Cookie& str);
|
||||
void pop_back();
|
||||
|
||||
protected:
|
||||
std::map<std::string, std::string> map_;
|
||||
std::vector<cpr::Cookie> cookies_;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
31
vendor/CPR/include/cpr/cpr.h
vendored
31
vendor/CPR/include/cpr/cpr.h
vendored
@ -3,12 +3,43 @@
|
||||
|
||||
#include "cpr/api.h"
|
||||
#include "cpr/auth.h"
|
||||
#include "cpr/bearer.h"
|
||||
#include "cpr/callback.h"
|
||||
#include "cpr/cert_info.h"
|
||||
#include "cpr/connect_timeout.h"
|
||||
#include "cpr/cookies.h"
|
||||
#include "cpr/cprtypes.h"
|
||||
#include "cpr/cprver.h"
|
||||
#include "cpr/curl_container.h"
|
||||
#include "cpr/curlholder.h"
|
||||
#include "cpr/error.h"
|
||||
#include "cpr/http_version.h"
|
||||
#include "cpr/interceptor.h"
|
||||
#include "cpr/interface.h"
|
||||
#include "cpr/limit_rate.h"
|
||||
#include "cpr/local_port.h"
|
||||
#include "cpr/local_port_range.h"
|
||||
#include "cpr/low_speed.h"
|
||||
#include "cpr/multipart.h"
|
||||
#include "cpr/multiperform.h"
|
||||
#include "cpr/parameters.h"
|
||||
#include "cpr/payload.h"
|
||||
#include "cpr/proxies.h"
|
||||
#include "cpr/proxyauth.h"
|
||||
#include "cpr/range.h"
|
||||
#include "cpr/redirect.h"
|
||||
#include "cpr/reserve_size.h"
|
||||
#include "cpr/resolve.h"
|
||||
#include "cpr/response.h"
|
||||
#include "cpr/session.h"
|
||||
#include "cpr/ssl_ctx.h"
|
||||
#include "cpr/ssl_options.h"
|
||||
#include "cpr/status_codes.h"
|
||||
#include "cpr/timeout.h"
|
||||
#include "cpr/unix_socket.h"
|
||||
#include "cpr/user_agent.h"
|
||||
#include "cpr/util.h"
|
||||
#include "cpr/verbose.h"
|
||||
|
||||
#define CPR_LIBCURL_VERSION_NUM LIBCURL_VERSION_NUM
|
||||
|
||||
|
19
vendor/CPR/include/cpr/cprtypes.h
vendored
19
vendor/CPR/include/cpr/cprtypes.h
vendored
@ -2,11 +2,13 @@
|
||||
#define CPR_CPR_TYPES_H
|
||||
|
||||
#include <curl/curl.h>
|
||||
#include <curl/system.h>
|
||||
#include <initializer_list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <numeric>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
@ -15,12 +17,21 @@ namespace cpr {
|
||||
**/
|
||||
using cpr_off_t = curl_off_t;
|
||||
|
||||
/**
|
||||
* The argument type for progress functions, dependent on libcurl version
|
||||
**/
|
||||
#if LIBCURL_VERSION_NUM < 0x072000
|
||||
using cpr_pf_arg_t = double;
|
||||
#else
|
||||
using cpr_pf_arg_t = cpr_off_t;
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
class StringHolder {
|
||||
public:
|
||||
StringHolder() = default;
|
||||
explicit StringHolder(const std::string& str) : str_(str) {}
|
||||
explicit StringHolder(std::string&& str) : str_(std::move(str)) {}
|
||||
explicit StringHolder(std::string str) : str_(std::move(str)) {}
|
||||
explicit StringHolder(std::string_view str) : str_(str) {}
|
||||
explicit StringHolder(const char* str) : str_(str) {}
|
||||
StringHolder(const char* str, size_t len) : str_(str, len) {}
|
||||
StringHolder(const std::initializer_list<std::string> args) {
|
||||
@ -107,9 +118,9 @@ class Url : public StringHolder<Url> {
|
||||
public:
|
||||
Url() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Url(const std::string& url) : StringHolder<Url>(url) {}
|
||||
Url(std::string url) : StringHolder<Url>(std::move(url)) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Url(std::string&& url) : StringHolder<Url>(std::move(url)) {}
|
||||
Url(std::string_view url) : StringHolder<Url>(url) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Url(const char* url) : StringHolder<Url>(url) {}
|
||||
Url(const char* str, size_t len) : StringHolder<Url>(std::string(str, len)) {}
|
||||
|
30
vendor/CPR/include/cpr/cprver.h
vendored
Normal file
30
vendor/CPR/include/cpr/cprver.h
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#ifndef CPR_CPRVER_H
|
||||
#define CPR_CPRVER_H
|
||||
|
||||
/**
|
||||
* CPR version as a string.
|
||||
**/
|
||||
#define CPR_VERSION "1.10.4"
|
||||
|
||||
/**
|
||||
* CPR version split up into parts.
|
||||
**/
|
||||
#define CPR_VERSION_MAJOR 1
|
||||
#define CPR_VERSION_MINOR 10
|
||||
#define CPR_VERSION_PATCH 4
|
||||
|
||||
/**
|
||||
* CPR version as a single hex digit.
|
||||
* it can be split up into three parts:
|
||||
* 0xAABBCC
|
||||
* AA: The current CPR major version number in a hex format.
|
||||
* BB: The current CPR minor version number in a hex format.
|
||||
* CC: The current CPR patch version number in a hex format.
|
||||
*
|
||||
* Examples:
|
||||
* '0x010702' -> 01.07.02 -> CPR_VERSION: 1.7.2
|
||||
* '0xA13722' -> A1.37.22 -> CPR_VERSION: 161.55.34
|
||||
**/
|
||||
#define CPR_VERSION_NUM 0x011004
|
||||
|
||||
#endif
|
8
vendor/CPR/include/cpr/curl_container.h
vendored
8
vendor/CPR/include/cpr/curl_container.h
vendored
@ -12,18 +12,14 @@
|
||||
namespace cpr {
|
||||
|
||||
struct Parameter {
|
||||
Parameter(const std::string& p_key, const std::string& p_value) : key{p_key}, value{p_value} {}
|
||||
Parameter(std::string&& p_key, std::string&& p_value)
|
||||
: key{std::move(p_key)}, value{std::move(p_value)} {}
|
||||
Parameter(std::string p_key, std::string p_value) : key{std::move(p_key)}, value{std::move(p_value)} {}
|
||||
|
||||
std::string key;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
struct Pair {
|
||||
Pair(const std::string& p_key, const std::string& p_value) : key(p_key), value(p_value) {}
|
||||
Pair(std::string&& p_key, std::string&& p_value)
|
||||
: key(std::move(p_key)), value(std::move(p_value)) {}
|
||||
Pair(std::string p_key, std::string p_value) : key(std::move(p_key)), value(std::move(p_value)) {}
|
||||
|
||||
std::string key;
|
||||
std::string value;
|
||||
|
10
vendor/CPR/include/cpr/curlholder.h
vendored
10
vendor/CPR/include/cpr/curlholder.h
vendored
@ -17,14 +17,18 @@ struct CurlHolder {
|
||||
* https://curl.haxx.se/libcurl/c/curl_easy_init.html
|
||||
* https://curl.haxx.se/libcurl/c/threadsafe.html
|
||||
**/
|
||||
// It does not make sense to make a std::mutex const.
|
||||
// NOLINTNEXTLINE (cppcoreguidelines-avoid-non-const-global-variables)
|
||||
|
||||
// Avoids initalization order problems in a static build
|
||||
static std::mutex& curl_easy_init_mutex_() {
|
||||
static std::mutex curl_easy_init_mutex_;
|
||||
return curl_easy_init_mutex_;
|
||||
}
|
||||
|
||||
public:
|
||||
CURL* handle{nullptr};
|
||||
struct curl_slist* chunk{nullptr};
|
||||
struct curl_httppost* formpost{nullptr};
|
||||
struct curl_slist* resolveCurlList{nullptr};
|
||||
curl_mime* multipart{nullptr};
|
||||
std::array<char, CURL_ERROR_SIZE> error{};
|
||||
|
||||
CurlHolder();
|
||||
|
18
vendor/CPR/include/cpr/curlmultiholder.h
vendored
Normal file
18
vendor/CPR/include/cpr/curlmultiholder.h
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef CPR_CURLMULTIHOLDER_H
|
||||
#define CPR_CURLMULTIHOLDER_H
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
class CurlMultiHolder {
|
||||
public:
|
||||
CurlMultiHolder();
|
||||
~CurlMultiHolder();
|
||||
|
||||
CURLM* handle{nullptr};
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
15
vendor/CPR/include/cpr/digest.h
vendored
15
vendor/CPR/include/cpr/digest.h
vendored
@ -1,15 +0,0 @@
|
||||
#ifndef CPR_DIGEST_H
|
||||
#define CPR_DIGEST_H
|
||||
|
||||
#include "cpr/auth.h"
|
||||
|
||||
namespace cpr {
|
||||
class Digest : public Authentication {
|
||||
public:
|
||||
Digest(const std::string& username, const std::string& password)
|
||||
: Authentication{username, password} {}
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
5
vendor/CPR/include/cpr/error.h
vendored
5
vendor/CPR/include/cpr/error.h
vendored
@ -27,6 +27,7 @@ enum class ErrorCode {
|
||||
GENERIC_SSL_ERROR,
|
||||
UNSUPPORTED_PROTOCOL,
|
||||
REQUEST_CANCELLED,
|
||||
TOO_MANY_REDIRECTS,
|
||||
UNKNOWN_ERROR = 1000,
|
||||
};
|
||||
|
||||
@ -37,9 +38,7 @@ class Error {
|
||||
|
||||
Error() = default;
|
||||
|
||||
Error(const std::int32_t& curl_code, std::string&& p_error_message)
|
||||
: code{getErrorCodeForCurlError(curl_code)},
|
||||
message(std::move(p_error_message)) {}
|
||||
Error(const std::int32_t& curl_code, std::string&& p_error_message) : code{getErrorCodeForCurlError(curl_code)}, message(std::move(p_error_message)) {}
|
||||
|
||||
explicit operator bool() const {
|
||||
return code != ErrorCode::OK;
|
||||
|
59
vendor/CPR/include/cpr/file.h
vendored
Normal file
59
vendor/CPR/include/cpr/file.h
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
#ifndef CPR_FILE_H
|
||||
#define CPR_FILE_H
|
||||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cpr/filesystem.h>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
struct File {
|
||||
explicit File(std::string p_filepath, const std::string& p_overriden_filename = {}) : filepath(std::move(p_filepath)), overriden_filename(p_overriden_filename) {}
|
||||
|
||||
std::string filepath;
|
||||
std::string overriden_filename;
|
||||
|
||||
[[nodiscard]] bool hasOverridenFilename() const noexcept {
|
||||
return !overriden_filename.empty();
|
||||
}
|
||||
};
|
||||
|
||||
class Files {
|
||||
public:
|
||||
Files() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
Files(const File& p_file) : files{p_file} {}
|
||||
|
||||
Files(const Files& other) = default;
|
||||
Files(Files&& old) noexcept = default;
|
||||
|
||||
Files(const std::initializer_list<File>& p_files) : files{p_files} {}
|
||||
Files(const std::initializer_list<std::string>& p_filepaths);
|
||||
|
||||
~Files() noexcept = default;
|
||||
|
||||
Files& operator=(const Files& other);
|
||||
Files& operator=(Files&& old) noexcept;
|
||||
|
||||
using iterator = std::vector<File>::iterator;
|
||||
using const_iterator = std::vector<File>::const_iterator;
|
||||
|
||||
iterator begin();
|
||||
iterator end();
|
||||
[[nodiscard]] const_iterator begin() const;
|
||||
[[nodiscard]] const_iterator end() const;
|
||||
[[nodiscard]] const_iterator cbegin() const;
|
||||
[[nodiscard]] const_iterator cend() const;
|
||||
void emplace_back(const File& file);
|
||||
void push_back(const File& file);
|
||||
void pop_back();
|
||||
|
||||
private:
|
||||
std::vector<File> files;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
26
vendor/CPR/include/cpr/filesystem.h
vendored
Normal file
26
vendor/CPR/include/cpr/filesystem.h
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef CPR_FILESYSTEM_H
|
||||
#define CPR_FILESYSTEM_H
|
||||
|
||||
// Include filesystem into the namespace "fs" from either "filesystem" or "experimental/filesystem" or "boost/filesystem"
|
||||
#ifdef CPR_USE_BOOST_FILESYSTEM
|
||||
#define BOOST_FILESYSTEM_VERSION 4 // Use the latest, with the closest behavior to std::filesystem.
|
||||
#include <boost/filesystem.hpp>
|
||||
namespace cpr {
|
||||
namespace fs = boost::filesystem;
|
||||
}
|
||||
// cppcheck-suppress preprocessorErrorDirective
|
||||
#elif __has_include(<filesystem>)
|
||||
#include <filesystem>
|
||||
namespace cpr {
|
||||
namespace fs = std::filesystem;
|
||||
}
|
||||
#elif __has_include("experimental/filesystem")
|
||||
#include <experimental/filesystem>
|
||||
namespace cpr {
|
||||
namespace fs = std::experimental::filesystem;
|
||||
}
|
||||
#else
|
||||
#error "Failed to include <filesystem> header!"
|
||||
#endif
|
||||
|
||||
#endif
|
67
vendor/CPR/include/cpr/http_version.h
vendored
Normal file
67
vendor/CPR/include/cpr/http_version.h
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef CPR_HTTP_VERSION_H
|
||||
#define CPR_HTTP_VERSION_H
|
||||
|
||||
#include <curl/curlver.h>
|
||||
|
||||
namespace cpr {
|
||||
enum class HttpVersionCode {
|
||||
/**
|
||||
* Let libcurl decide which version is the best.
|
||||
**/
|
||||
VERSION_NONE,
|
||||
/**
|
||||
* Enforce HTTP 1.0 requests.
|
||||
**/
|
||||
VERSION_1_0,
|
||||
/**
|
||||
* Enforce HTTP 1.1 requests.
|
||||
**/
|
||||
VERSION_1_1,
|
||||
#if LIBCURL_VERSION_NUM >= 0x072100 // 7.33.0
|
||||
/**
|
||||
* Attempt HTTP 2.0 requests.
|
||||
* Fallback to HTTP 1.1 if negotiation fails.
|
||||
**/
|
||||
VERSION_2_0,
|
||||
#endif
|
||||
#if LIBCURL_VERSION_NUM >= 0x072F00 // 7.47.0
|
||||
/**
|
||||
* Attempt HTTP 2.0 for HTTPS requests only.
|
||||
* Fallback to HTTP 1.1 if negotiation fails.
|
||||
* HTTP 1.1 will be used for HTTP connections.
|
||||
**/
|
||||
VERSION_2_0_TLS,
|
||||
#endif
|
||||
#if LIBCURL_VERSION_NUM >= 0x073100 // 7.49.0
|
||||
/**
|
||||
* Start HTTP 2.0 for HTTP requests.
|
||||
* Requires prior knowledge that the server supports HTTP 2.0.
|
||||
* For HTTPS requests we will negotiate the protocol version in the TLS handshake.
|
||||
**/
|
||||
VERSION_2_0_PRIOR_KNOWLEDGE,
|
||||
#endif
|
||||
#if LIBCURL_VERSION_NUM >= 0x074200 // 7.66.0
|
||||
/**
|
||||
* Attempt HTTP 3.0 requests.
|
||||
* Requires prior knowledge that the server supports HTTP 3.0 since there is no gracefully downgrade.
|
||||
* Fallback to HTTP 1.1 if negotiation fails.
|
||||
**/
|
||||
VERSION_3_0
|
||||
#endif
|
||||
};
|
||||
|
||||
class HttpVersion {
|
||||
public:
|
||||
/**
|
||||
* The HTTP version that should be used by libcurl when initiating a HTTP(S) connection.
|
||||
* Default: HttpVersionCode::VERSION_NONE
|
||||
**/
|
||||
HttpVersionCode code = HttpVersionCode::VERSION_NONE;
|
||||
|
||||
HttpVersion() = default;
|
||||
explicit HttpVersion(HttpVersionCode _code) : code(_code) {}
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
74
vendor/CPR/include/cpr/interceptor.h
vendored
Normal file
74
vendor/CPR/include/cpr/interceptor.h
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
#ifndef CPR_INTERCEPTOR_H
|
||||
#define CPR_INTERCEPTOR_H
|
||||
|
||||
#include "cpr/multiperform.h"
|
||||
#include "cpr/response.h"
|
||||
#include "cpr/session.h"
|
||||
#include <vector>
|
||||
|
||||
namespace cpr {
|
||||
class Interceptor {
|
||||
public:
|
||||
enum class ProceedHttpMethod {
|
||||
GET_REQUEST = 0,
|
||||
POST_REQUEST,
|
||||
PUT_REQUEST,
|
||||
DELETE_REQUEST,
|
||||
PATCH_REQUEST,
|
||||
HEAD_REQUEST,
|
||||
OPTIONS_REQUEST,
|
||||
DOWNLOAD_CALLBACK_REQUEST,
|
||||
DOWNLOAD_FILE_REQUEST,
|
||||
};
|
||||
|
||||
Interceptor() = default;
|
||||
Interceptor(const Interceptor& other) = default;
|
||||
Interceptor(Interceptor&& old) = default;
|
||||
virtual ~Interceptor() = default;
|
||||
|
||||
Interceptor& operator=(const Interceptor& other) = default;
|
||||
Interceptor& operator=(Interceptor&& old) = default;
|
||||
|
||||
virtual Response intercept(Session& session) = 0;
|
||||
|
||||
protected:
|
||||
static Response proceed(Session& session);
|
||||
static Response proceed(Session& session, ProceedHttpMethod httpMethod);
|
||||
static Response proceed(Session& session, ProceedHttpMethod httpMethod, std::ofstream& file);
|
||||
static Response proceed(Session& session, ProceedHttpMethod httpMethod, const WriteCallback& write);
|
||||
};
|
||||
|
||||
class InterceptorMulti {
|
||||
public:
|
||||
enum class ProceedHttpMethod {
|
||||
GET_REQUEST = 0,
|
||||
POST_REQUEST,
|
||||
PUT_REQUEST,
|
||||
DELETE_REQUEST,
|
||||
PATCH_REQUEST,
|
||||
HEAD_REQUEST,
|
||||
OPTIONS_REQUEST,
|
||||
DOWNLOAD_CALLBACK_REQUEST,
|
||||
DOWNLOAD_FILE_REQUEST,
|
||||
};
|
||||
|
||||
InterceptorMulti() = default;
|
||||
InterceptorMulti(const InterceptorMulti& other) = default;
|
||||
InterceptorMulti(InterceptorMulti&& old) = default;
|
||||
virtual ~InterceptorMulti() = default;
|
||||
|
||||
InterceptorMulti& operator=(const InterceptorMulti& other) = default;
|
||||
InterceptorMulti& operator=(InterceptorMulti&& old) = default;
|
||||
|
||||
virtual std::vector<Response> intercept(MultiPerform& multi) = 0;
|
||||
|
||||
protected:
|
||||
static std::vector<Response> proceed(MultiPerform& multi);
|
||||
|
||||
static void PrepareDownloadSession(MultiPerform& multi, size_t sessions_index, const WriteCallback& write);
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
|
||||
#endif
|
6
vendor/CPR/include/cpr/interface.h
vendored
6
vendor/CPR/include/cpr/interface.h
vendored
@ -10,11 +10,11 @@ namespace cpr {
|
||||
|
||||
class Interface : public StringHolder<Interface> {
|
||||
public:
|
||||
Interface() : StringHolder<Interface>() {}
|
||||
Interface() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Interface(const std::string& iface) : StringHolder<Interface>(iface) {}
|
||||
Interface(std::string iface) : StringHolder<Interface>(std::move(iface)) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Interface(std::string&& iface) : StringHolder<Interface>(std::move(iface)) {}
|
||||
Interface(std::string_view iface) : StringHolder<Interface>(iface) {}
|
||||
// NOLINTNEXTLINE(google-explicit-constructor, hicpp-explicit-conversions)
|
||||
Interface(const char* iface) : StringHolder<Interface>(iface) {}
|
||||
Interface(const char* str, size_t len) : StringHolder<Interface>(str, len) {}
|
||||
|
3
vendor/CPR/include/cpr/limit_rate.h
vendored
3
vendor/CPR/include/cpr/limit_rate.h
vendored
@ -7,8 +7,7 @@ namespace cpr {
|
||||
|
||||
class LimitRate {
|
||||
public:
|
||||
LimitRate(const std::int64_t p_downrate, const std::int64_t p_uprate)
|
||||
: downrate(p_downrate), uprate(p_uprate) {}
|
||||
LimitRate(const std::int64_t p_downrate, const std::int64_t p_uprate) : downrate(p_downrate), uprate(p_uprate) {}
|
||||
|
||||
std::int64_t downrate = 0;
|
||||
std::int64_t uprate = 0;
|
||||
|
23
vendor/CPR/include/cpr/local_port.h
vendored
Normal file
23
vendor/CPR/include/cpr/local_port.h
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef CPR_LOCAL_PORT_H
|
||||
#define CPR_LOCAL_PORT_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
class LocalPort {
|
||||
public:
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
LocalPort(const std::uint16_t p_localport) : localport_(p_localport) {}
|
||||
|
||||
operator std::uint16_t() const {
|
||||
return localport_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::uint16_t localport_ = 0;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
23
vendor/CPR/include/cpr/local_port_range.h
vendored
Normal file
23
vendor/CPR/include/cpr/local_port_range.h
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef CPR_LOCAL_PORT_RANGE_H
|
||||
#define CPR_LOCAL_PORT_RANGE_H
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace cpr {
|
||||
|
||||
class LocalPortRange {
|
||||
public:
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
LocalPortRange(const std::uint16_t p_localportrange) : localportrange_(p_localportrange) {}
|
||||
|
||||
operator std::uint16_t() const {
|
||||
return localportrange_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::uint16_t localportrange_ = 0;
|
||||
};
|
||||
|
||||
} // namespace cpr
|
||||
|
||||
#endif
|
62
vendor/CPR/include/cpr/multipart.h
vendored
62
vendor/CPR/include/cpr/multipart.h
vendored
@ -7,69 +7,35 @@
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "buffer.h"
|
||||
#include "file.h"
|
||||
|
||||
namespace cpr {
|
||||
|
||||
struct File {
|
||||
explicit File(std::string&& p_filepath) : filepath(std::move(p_filepath)) {}
|
||||
explicit File(const std::string& p_filepath) : filepath(p_filepath) {}
|
||||
const std::string filepath;
|
||||
};
|
||||
|
||||
struct Buffer {
|
||||
using data_t = const unsigned char*;
|
||||
|
||||
template <typename Iterator>
|
||||
Buffer(Iterator begin, Iterator end, std::string&& p_filename)
|
||||
// Ignored here since libcurl reqires a long.
|
||||
// There is also no way around the reinterpret_cast.
|
||||
// NOLINTNEXTLINE(google-runtime-int, cppcoreguidelines-pro-type-reinterpret-cast)
|
||||
: data{reinterpret_cast<data_t>(&(*begin))}, datalen{static_cast<long>(
|
||||
std::distance(begin, end))},
|
||||
filename(std::move(p_filename)) {
|
||||
is_random_access_iterator(begin, end);
|
||||
static_assert(sizeof(*begin) == 1, "only byte buffers can be used");
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
typename std::enable_if<std::is_same<typename std::iterator_traits<Iterator>::iterator_category,
|
||||
std::random_access_iterator_tag>::value>::type
|
||||
is_random_access_iterator(Iterator /* begin */, Iterator /* end */) {}
|
||||
|
||||
data_t data;
|
||||
// Ignored here since libcurl reqires a long:
|
||||
// NOLINTNEXTLINE(google-runtime-int)
|
||||
long datalen;
|
||||
const std::string filename;
|
||||
};
|
||||
|
||||
struct Part {
|
||||
Part(const std::string& p_name, const std::string& p_value, const std::string& p_content_type = {})
|
||||
: name{p_name}, value{p_value},
|
||||
content_type{p_content_type}, is_file{false}, is_buffer{false} {}
|
||||
Part(const std::string& p_name, const std::int32_t& p_value, const std::string& p_content_type = {})
|
||||
: name{p_name}, value{std::to_string(p_value)},
|
||||
content_type{p_content_type}, is_file{false}, is_buffer{false} {}
|
||||
Part(const std::string& p_name, const File& file, const std::string& p_content_type = {})
|
||||
: name{p_name}, value{file.filepath},
|
||||
content_type{p_content_type}, is_file{true}, is_buffer{false} {}
|
||||
Part(const std::string& p_name, const Buffer& buffer, const std::string& p_content_type = {})
|
||||
: name{p_name}, value{buffer.filename}, content_type{p_content_type}, data{buffer.data},
|
||||
datalen{buffer.datalen}, is_file{false}, is_buffer{true} {}
|
||||
Part(const std::string& p_name, const std::string& p_value, const std::string& p_content_type = {}) : name{p_name}, value{p_value}, content_type{p_content_type}, is_file{false}, is_buffer{false} {}
|
||||
Part(const std::string& p_name, const std::int32_t& p_value, const std::string& p_content_type = {}) : name{p_name}, value{std::to_string(p_value)}, content_type{p_content_type}, is_file{false}, is_buffer{false} {}
|
||||
Part(const std::string& p_name, const Files& p_files, const std::string& p_content_type = {}) : name{p_name}, content_type{p_content_type}, is_file{true}, is_buffer{false}, files{p_files} {}
|
||||
Part(const std::string& p_name, Files&& p_files, const std::string& p_content_type = {}) : name{p_name}, content_type{p_content_type}, is_file{true}, is_buffer{false}, files{p_files} {}
|
||||
Part(const std::string& p_name, const Buffer& buffer, const std::string& p_content_type = {}) : name{p_name}, value{buffer.filename.string()}, content_type{p_content_type}, data{buffer.data}, datalen{buffer.datalen}, is_file{false}, is_buffer{true} {}
|
||||
|
||||
std::string name;
|
||||
// We don't use fs::path here, as this leads to problems using windows
|
||||
std::string value;
|
||||
std::string content_type;
|
||||
Buffer::data_t data{nullptr};
|
||||
// Ignored here since libcurl reqires a long:
|
||||
// NOLINTNEXTLINE(google-runtime-int)
|
||||
long datalen{0};
|
||||
size_t datalen{0};
|
||||
bool is_file;
|
||||
bool is_buffer;
|
||||
|
||||
Files files;
|
||||
};
|
||||
|
||||
class Multipart {
|
||||
public:
|
||||
Multipart(const std::initializer_list<Part>& parts);
|
||||
Multipart(const std::vector<Part>& parts);
|
||||
Multipart(const std::vector<Part>&& parts);
|
||||
|
||||
std::vector<Part> parts;
|
||||
};
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user