mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-07-01 14:37:10 +02:00
Compare commits
48 Commits
discord
...
ebe60ebf4b
Author | SHA1 | Date | |
---|---|---|---|
ebe60ebf4b | |||
fa9c3a5821 | |||
f238588abe | |||
39524098f1 | |||
ea63899c9a | |||
8f11e08150 | |||
b8b5e89216 | |||
87387999f3 | |||
d6a56feb87 | |||
9c94fb7afc | |||
2f3684e251 | |||
7afc05e52b | |||
eca11b73ba | |||
5c54dc6a95 | |||
9330cd4eb3 | |||
7576409ceb | |||
f278d151d6 | |||
b3b57d5b2b | |||
c4130c589f | |||
2d24860905 | |||
eb90d9bc99 | |||
b87e68b9fc | |||
a1a71ee031 | |||
c4b9b4c0a5 | |||
b3f9f9e47a | |||
a2421afca1 | |||
e2cbd7d5cf | |||
2725387112 | |||
7248351469 | |||
e253dc2038 | |||
38f0a53cd8 | |||
1c7fee69ea | |||
2b85b3a035 | |||
11fb1fa25c | |||
8dc0ca18f5 | |||
7e39fab21a | |||
da139c6a81 | |||
27521f209d | |||
e6cbdfaf30 | |||
fd62cafe33 | |||
d749250e1b | |||
c205261ee9 | |||
4af93aff14 | |||
d246ee8430 | |||
6419fc0f4d | |||
0213ffe632 | |||
5f364605ab | |||
3e9f25502b |
@ -12,8 +12,6 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/vendor/POCO/cmake)
|
||||
|
||||
# Several plugin options
|
||||
option(ENABLE_API21 "Build for 2.1 API." OFF)
|
||||
option(ENABLE_DISCORD "Enable built-in Discord support" OFF)
|
||||
option(ENABLE_DISCORD_VOICE "Enable voice support in Discord library" OFF)
|
||||
option(ENABLE_OFFICIAL "Enable compatibility with official legacy plug-in" ON)
|
||||
# As a fall-back for certain situations (mainly some docker ubuntu containers)
|
||||
option(ENABLE_BUILTIN_MYSQL_C "Enable built-in MySQL connector library" OFF)
|
||||
|
@ -80,6 +80,7 @@ add_library(SqModule MODULE SqBase.hpp Main.cpp
|
||||
Library/Numeric.cpp Library/Numeric.hpp
|
||||
Library/Numeric/Math.cpp Library/Numeric/Math.hpp
|
||||
Library/Numeric/Random.cpp Library/Numeric/Random.hpp
|
||||
Library/RegEx.cpp Library/RegEx.hpp
|
||||
Library/String.cpp Library/String.hpp
|
||||
Library/System.cpp Library/System.hpp
|
||||
Library/System/Dir.cpp Library/System/Dir.hpp
|
||||
@ -106,7 +107,6 @@ add_library(SqModule MODULE SqBase.hpp Main.cpp
|
||||
PocoLib/Crypto.cpp PocoLib/Crypto.hpp
|
||||
PocoLib/Data.cpp PocoLib/Data.hpp
|
||||
PocoLib/Net.cpp PocoLib/Net.hpp
|
||||
PocoLib/RegEx.cpp PocoLib/RegEx.hpp
|
||||
PocoLib/Register.cpp PocoLib/Register.hpp
|
||||
PocoLib/Time.cpp PocoLib/Time.hpp
|
||||
PocoLib/Util.cpp PocoLib/Util.hpp
|
||||
@ -132,28 +132,7 @@ if(WIN32 OR MINGW)
|
||||
target_link_libraries(SqModule wsock32 ws2_32 shlwapi)
|
||||
endif()
|
||||
# Link to base libraries
|
||||
target_link_libraries(SqModule Squirrel fmt::fmt SimpleINI TinyDir xxHash ConcurrentQueue SAJSON CPR UTF8Lib PUGIXML CivetWeb maxminddb libzmq-static)
|
||||
# Enable built-in Discord support
|
||||
if(ENABLE_DISCORD)
|
||||
target_link_libraries(SqModule DPP)
|
||||
target_compile_definitions(SqModule PRIVATE VCMP_ENABLE_DISCORD=1)
|
||||
target_sources(SqModule PRIVATE
|
||||
Library/DPP.cpp Library/DPP.hpp
|
||||
Library/DPP/Channel.cpp Library/DPP/Channel.hpp
|
||||
Library/DPP/Client.cpp Library/DPP/Client.hpp
|
||||
Library/DPP/Cluster.cpp Library/DPP/Cluster.hpp
|
||||
Library/DPP/Command.cpp Library/DPP/Command.hpp
|
||||
Library/DPP/Constants.cpp Library/DPP/Constants.hpp
|
||||
Library/DPP/Events.cpp Library/DPP/Events.hpp
|
||||
Library/DPP/Guild.cpp Library/DPP/Guild.hpp
|
||||
Library/DPP/Integration.cpp Library/DPP/Integration.hpp
|
||||
Library/DPP/Message.cpp Library/DPP/Message.hpp
|
||||
Library/DPP/Other.cpp Library/DPP/Other.hpp
|
||||
Library/DPP/Role.cpp Library/DPP/Role.hpp
|
||||
Library/DPP/User.cpp Library/DPP/User.hpp
|
||||
Library/DPP/Utilities.cpp Library/DPP/Utilities.hpp
|
||||
)
|
||||
endif()
|
||||
target_link_libraries(SqModule RPMalloc Squirrel fmt::fmt SimpleINI TinyDir xxHash ConcurrentQueue SAJSON CPR UTF8Lib PUGIXML CivetWeb maxminddb libzmq-static)
|
||||
# Link to POCO libraries
|
||||
target_link_libraries(SqModule Poco::Foundation Poco::Crypto Poco::Data Poco::Net)
|
||||
# Does POCO have SQLite support?
|
||||
@ -224,6 +203,15 @@ endif(WIN32)
|
||||
target_include_directories(SqModule PRIVATE ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_include_directories(SqModule PRIVATE ${CMAKE_CURRENT_LIST_DIR}/VCMP)
|
||||
target_include_directories(SqModule PRIVATE ${CMAKE_CURRENT_LIST_DIR}/Sqrat)
|
||||
# Include PCRE directory in the header search path
|
||||
if (POCO_UNBUNDLED)
|
||||
find_package(PCRE REQUIRED)
|
||||
target_link_libraries(SqModule PRIVATE Pcre::Pcre)
|
||||
else()
|
||||
# Get the foundation source folder path
|
||||
get_target_property(POCO_FOUNDATION_SOURCE_DIR Foundation SOURCE_DIR)
|
||||
target_include_directories(SqModule PRIVATE "${POCO_FOUNDATION_SOURCE_DIR}/src")
|
||||
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)
|
||||
|
@ -49,9 +49,6 @@ extern void TerminateRoutines();
|
||||
extern void TerminateCommands();
|
||||
extern void TerminateSignals();
|
||||
extern void TerminateNet();
|
||||
#ifdef VCMP_ENABLE_DISCORD
|
||||
extern void TerminateDPP();
|
||||
#endif
|
||||
extern void TerminatePocoNet();
|
||||
extern void TerminatePocoData();
|
||||
|
||||
@ -552,11 +549,6 @@ void Core::Terminate(bool shutdown)
|
||||
// Release announcers
|
||||
AnnounceTerminate();
|
||||
cLogDbg(m_Verbosity >= 1, "Announcer terminated");
|
||||
// Release DPP
|
||||
#ifdef VCMP_ENABLE_DISCORD
|
||||
TerminateDPP();
|
||||
cLogDbg(m_Verbosity >= 1, "Discord terminated");
|
||||
#endif
|
||||
// Release network
|
||||
TerminateNet();
|
||||
cLogDbg(m_Verbosity >= 1, "Network terminated");
|
||||
|
@ -993,27 +993,59 @@ template < class F > inline void ForeachActivePickup(F f) { ForeachActiveEntity(
|
||||
template < class F > inline void ForeachActivePlayer(F f) { ForeachActiveEntity(Core::Get().GetPlayers(), std::forward< F >(f)); }
|
||||
template < class F > inline void ForeachActiveVehicle(F f) { ForeachActiveEntity(Core::Get().GetVehicles(), std::forward< F >(f)); }
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Process the identifier of each player slot.
|
||||
*/
|
||||
template < class F > inline void ForeachPlayerSlot(F f) {
|
||||
for (int32_t i = 0, n = static_cast< int32_t >(_Func->GetMaxPlayers()); i < n; ++i) {
|
||||
f(i);
|
||||
}
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Process the identifier of each player slot and count processed players.
|
||||
*/
|
||||
template < class F > SQMOD_NODISCARD inline int32_t ForeachPlayerSlotCount(F f) {
|
||||
int32_t c = 0;
|
||||
for (int32_t i = 0, n = static_cast< int32_t >(_Func->GetMaxPlayers()); i < n; ++i) {
|
||||
if (f(i)) ++c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Process the identifier of each player slot until a certain criteria is met.
|
||||
*/
|
||||
template < class F > SQMOD_NODISCARD inline int32_t ForeachPlayerSlotUntil(F f) {
|
||||
for (int32_t i = 0, n = static_cast< int32_t >(_Func->GetMaxPlayers()); i < n; ++i) {
|
||||
if (f(i)) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Process the identifier of each connected player.
|
||||
*/
|
||||
template < class F > inline void ForeachConnectedPlayer(F f) {
|
||||
for (int32_t i = 0, n = _Func->GetMaxPlayers(); i < n; ++i) f(i);
|
||||
for (int32_t i = 0, n = static_cast< int32_t >(_Func->GetMaxPlayers()); i < n; ++i) {
|
||||
if (_Func->IsPlayerConnected(i) != 0) f(i);
|
||||
}
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Process the identifier of each connected player and count processed players.
|
||||
*/
|
||||
template < class F > SQMOD_NODISCARD inline int32_t ForeachConnectedPlayerCount(F f) {
|
||||
int32_t c = 0;
|
||||
for (int32_t i = 0, n = _Func->GetMaxPlayers(); i < n; ++i)
|
||||
if (f(i)) ++c;
|
||||
for (int32_t i = 0, n = static_cast< int32_t >(_Func->GetMaxPlayers()); i < n; ++i) {
|
||||
if (_Func->IsPlayerConnected(i) != 0 && f(i)) ++c;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Process the identifier of each connected player until a certain criteria is met.
|
||||
*/
|
||||
template < class F > SQMOD_NODISCARD inline int32_t ForeachConnectedPlayerUntil(F f) {
|
||||
for (int32_t i = 0, n = _Func->GetMaxPlayers(); i < n; ++i)
|
||||
if (f(i)) return i;
|
||||
for (int32_t i = 0, n = static_cast< int32_t >(_Func->GetMaxPlayers()); i < n; ++i) {
|
||||
if (_Func->IsPlayerConnected(i) != 0 && f(i)) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -161,7 +161,7 @@ bool Area::IsInside(float x, float y) const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
AreaManager::AreaManager(size_t sz) noexcept
|
||||
: m_Queue(), m_ProcList(), m_Grid{}
|
||||
: m_Queue(), m_ProcList(), m_Grid{}, m_Cells{}
|
||||
{
|
||||
// Negative half grid size (left)
|
||||
int l = (-GRIDH * CELLD);
|
||||
@ -171,21 +171,30 @@ AreaManager::AreaManager(size_t sz) noexcept
|
||||
int r = (l + CELLD);
|
||||
// Positive half grid size (top)
|
||||
int t = abs(l);
|
||||
// Row/Column of the grid
|
||||
int row = 0, col = 0;
|
||||
// Initialize the grid cells
|
||||
for (auto & a : m_Grid)
|
||||
{
|
||||
// Reset the column
|
||||
col = 0;
|
||||
// Process row
|
||||
for (auto & c : a)
|
||||
{
|
||||
auto & cx = m_Cells[row][col];
|
||||
// Grab a reference to the cell
|
||||
// Configure the range of the cell
|
||||
c.mL = static_cast< float >(l);
|
||||
c.mB = static_cast< float >(b);
|
||||
c.mR = static_cast< float >(r);
|
||||
c.mT = static_cast< float >(t);
|
||||
c.mL = cx.mL = static_cast< float >(l);
|
||||
c.mB = cx.mB = static_cast< float >(b);
|
||||
c.mR = cx.mR = static_cast< float >(r);
|
||||
c.mT = cx.mT = static_cast< float >(t);
|
||||
// Reserve area memory if requested
|
||||
c.mAreas.reserve(sz);
|
||||
// Reset the locks on this area
|
||||
c.mLocks = 0;
|
||||
// Set the row and column
|
||||
c.mRow = row;
|
||||
c.mCol = col++;
|
||||
// Advance the left side
|
||||
l = r;
|
||||
// Advance the right side
|
||||
@ -203,6 +212,8 @@ AreaManager::AreaManager(size_t sz) noexcept
|
||||
t -= CELLD;
|
||||
}
|
||||
}
|
||||
// Advance row
|
||||
++row;
|
||||
}
|
||||
// Reserve some space in the queue
|
||||
m_Queue.reserve(128);
|
||||
@ -340,6 +351,21 @@ void AreaManager::RemoveArea(Area & a)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Vector2i AreaManager::LocateCell(float x, float y)
|
||||
{
|
||||
for (int r = 0; r < GRIDN; ++r)
|
||||
{
|
||||
for (int c = 0; c < GRIDN; ++c)
|
||||
{
|
||||
auto & bb = m_Cells[r][c];
|
||||
// Check whether point is inside cell
|
||||
if (bb.mL <= x && bb.mR >= x && bb.mB <= y && bb.mT >= y)
|
||||
{
|
||||
return {r, c}; // Is inside
|
||||
}
|
||||
}
|
||||
}
|
||||
// Point is out of bounds
|
||||
return {NOCELL, NOCELL};
|
||||
/*
|
||||
// Transform the world coordinates into a cell coordinates
|
||||
// and cast to integral after rounding the value
|
||||
int xc = static_cast< int >(std::round(x / CELLD));
|
||||
@ -364,6 +390,7 @@ Vector2i AreaManager::LocateCell(float x, float y)
|
||||
}
|
||||
// Return the identified cell row and column
|
||||
return {GRIDH+xc, GRIDH-yc};
|
||||
*/
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -469,6 +496,7 @@ void Register_Areas(HSQUIRRELVM vm)
|
||||
.Func(_SC("TestEx"), &Area::TestEx)
|
||||
.Func(_SC("Manage"), &Area::Manage)
|
||||
.Func(_SC("Unmanage"), &Area::Unmanage)
|
||||
.CbFunc(_SC("EachCell"), &Area::EachCell)
|
||||
// Static Functions
|
||||
.StaticFunc(_SC("GlobalTest"), &Areas_TestPoint)
|
||||
.StaticFunc(_SC("GlobalTestEx"), &Areas_TestPointEx)
|
||||
|
@ -29,15 +29,25 @@ struct AreaCell
|
||||
Areas mAreas; // Areas that intersect with the cell.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
int mLocks; // The amount of locks on the cell.
|
||||
int mRow; // Row location in the grid.
|
||||
int mCol; // Column location in the grid.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
AreaCell()
|
||||
: mL(0), mB(0), mR(0), mT(0), mAreas(0), mLocks(0)
|
||||
: mL(0), mB(0), mR(0), mT(0), mAreas(0), mLocks(0), mRow(0), mCol(0)
|
||||
{
|
||||
//...
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Show information (mainly for debug purposes).
|
||||
*/
|
||||
String Dump()
|
||||
{
|
||||
return fmt::format("({} : {} | {} : {}) {} : {}", mL, mB, mR, mT, mRow, mCol);
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -454,6 +464,17 @@ struct Area
|
||||
*/
|
||||
bool Unmanage();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate all managed cells through a functor.
|
||||
*/
|
||||
void EachCell(Function & fn) const
|
||||
{
|
||||
for (const auto & e : mCells)
|
||||
{
|
||||
fn.Execute(static_cast< SQInteger >(e->mRow), static_cast< SQInteger >(e->mCol));
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -610,7 +631,10 @@ private:
|
||||
ProcList m_ProcList; // Actions ready to be completed.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
AreaCell m_Grid[GRIDN][GRIDN]; // A grid of area lists.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
struct {
|
||||
float mL, mB, mR, mT;
|
||||
} m_Cells[GRIDN][GRIDN];
|
||||
public:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -664,7 +688,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Clear all cell lists and release any script references.
|
||||
*/
|
||||
static Vector2i LocateCell(float x, float y);
|
||||
Vector2i LocateCell(float x, float y);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Test a point to see whether it intersects with any areas
|
||||
@ -679,7 +703,7 @@ public:
|
||||
return; // Not our problem
|
||||
}
|
||||
// Retrieve a reference to the identified cell
|
||||
AreaCell & c = m_Grid[cc.y][cc.x];
|
||||
AreaCell & c = m_Grid[cc.x][cc.y];
|
||||
// Is this cell empty?
|
||||
if (c.mAreas.empty())
|
||||
{
|
||||
|
@ -40,6 +40,7 @@
|
||||
#include <sqratTable.h>
|
||||
#include <sqratUtil.h>
|
||||
#include <fmt/core.h>
|
||||
#include <rpmalloc.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
@ -173,7 +174,7 @@ void OutputError(const char * msg, ...);
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Generate a formatted string and throw it as a Sqrat exception.
|
||||
*/
|
||||
template < class... Args > void SqThrowF(Args &&... args)
|
||||
template < class... Args > inline void SqThrowF(Args &&... args)
|
||||
{
|
||||
throw Sqrat::Exception(fmt::format(std::forward< Args >(args)...));
|
||||
}
|
||||
@ -181,7 +182,7 @@ template < class... Args > void SqThrowF(Args &&... args)
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Generate a formatted string and throw it as a squirrel exception.
|
||||
*/
|
||||
template < class... Args > SQRESULT SqThrowErrorF(HSQUIRRELVM vm, Args &&... args)
|
||||
template < class... Args > inline SQRESULT SqThrowErrorF(HSQUIRRELVM vm, Args &&... args)
|
||||
{
|
||||
String msg;
|
||||
try
|
||||
@ -266,4 +267,93 @@ SQMOD_NODISCARD SQFloat PopStackFloat(HSQUIRRELVM vm, SQInteger idx);
|
||||
*/
|
||||
SQMOD_NODISCARD bool SToB(const SQChar * str);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* RAII allocator initializer.
|
||||
*/
|
||||
struct RPMallocInit
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
RPMallocInit()
|
||||
{
|
||||
if (rpmalloc_initialize() != 0)
|
||||
{
|
||||
OutputError("Failed to initialize memory allocator");
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
RPMallocInit(const RPMallocInit &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor (disabled).
|
||||
*/
|
||||
RPMallocInit(RPMallocInit &&) noexcept = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~RPMallocInit()
|
||||
{
|
||||
if (rpmalloc_is_thread_initialized()) rpmalloc_finalize();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
RPMallocInit & operator = (const RPMallocInit &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
RPMallocInit & operator = (RPMallocInit &&) noexcept = delete;
|
||||
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* RAII allocator thread initializer.
|
||||
*/
|
||||
struct RPMallocThreadInit
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
RPMallocThreadInit()
|
||||
{
|
||||
rpmalloc_thread_initialize();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
RPMallocThreadInit(const RPMallocThreadInit &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor (disabled).
|
||||
*/
|
||||
RPMallocThreadInit(RPMallocThreadInit &&) noexcept = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~RPMallocThreadInit()
|
||||
{
|
||||
if (rpmalloc_is_thread_initialized()) rpmalloc_thread_finalize(1);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
RPMallocThreadInit & operator = (const RPMallocThreadInit &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
RPMallocThreadInit & operator = (RPMallocThreadInit &&) noexcept = delete;
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -392,7 +392,8 @@ void Core::EmitPlayerRequestSpawn(int32_t player_id)
|
||||
#ifdef VCMP_ENABLE_OFFICIAL
|
||||
if (IsOfficial())
|
||||
{
|
||||
ExecuteLegacyEvent(m_VM, _SC("onPlayerRequestSpawn"), _player.mLgObj);
|
||||
LightObj r = EvaluateLegacyEvent(m_VM, _SC("onPlayerRequestSpawn"), _player.mLgObj);
|
||||
SetState(r.IsNull() ? 1 : r.Cast< int32_t >());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -549,6 +549,8 @@ void Register_Routine(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Inactive"), &Routine::GetInactive)
|
||||
.Prop(_SC("Persistent"), &Routine::GetPersistent, &Routine::SetPersistent)
|
||||
.Prop(_SC("Yields"), &Routine::GetYields, &Routine::SetYields)
|
||||
.Prop(_SC("Elapsed"), &Routine::GetElapsed)
|
||||
.Prop(_SC("Remaining"), &Routine::GetRemaining)
|
||||
.Prop(_SC("Terminated"), &Routine::GetTerminated)
|
||||
.Prop(_SC("Arguments"), &Routine::GetArguments)
|
||||
// Member Methods
|
||||
|
@ -408,7 +408,6 @@ public:
|
||||
}
|
||||
// Unable to find such routine
|
||||
STHROWF("Unable to fetch a routine with tag ({}). No such routine", tag.mPtr);
|
||||
SQ_UNREACHABLE
|
||||
// Should not reach this point but if it did, we have to return something
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic push
|
||||
@ -418,6 +417,7 @@ public:
|
||||
#ifdef __clang__
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
SQ_UNREACHABLE
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -804,6 +804,32 @@ public:
|
||||
return (m_Slot == SQMOD_MAX_ROUTINES);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the time elapsed since the routine was created or invoked.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetElapsed() const
|
||||
{
|
||||
if (m_Slot >= SQMOD_MAX_ROUTINES)
|
||||
{
|
||||
STHROWF("This instance does not reference a valid routine");
|
||||
}
|
||||
// We know it's valid so let's return it
|
||||
return s_Instances[m_Slot].mInterval - s_Intervals[m_Slot];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the time remaining until the routine is invoked.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetRemaining() const
|
||||
{
|
||||
if (m_Slot >= SQMOD_MAX_ROUTINES)
|
||||
{
|
||||
STHROWF("This instance does not reference a valid routine");
|
||||
}
|
||||
// We know it's valid so let's return it
|
||||
return s_Intervals[m_Slot];
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of arguments to be forwarded.
|
||||
*/
|
||||
|
@ -1723,6 +1723,7 @@ void Register_Signal(HSQUIRRELVM vm)
|
||||
.SquirrelFunc(_SC("Eliminate"), &Signal::SqEliminate)
|
||||
.SquirrelFunc(_SC("EliminateThis"), &Signal::SqEliminateThis)
|
||||
.SquirrelFunc(_SC("EliminateFunc"), &Signal::SqEliminateFunc)
|
||||
.SquirrelFunc(_SC("Broadcast"), &Signal::SqEmit)
|
||||
.SquirrelFunc(_SC("Emit"), &Signal::SqEmit)
|
||||
.SquirrelFunc(_SC("Query"), &Signal::SqQuery)
|
||||
.SquirrelFunc(_SC("Consume"), &Signal::SqConsume)
|
||||
|
@ -328,17 +328,40 @@ SQInteger Tasks::Find(int32_t id, int32_t type, SQInteger & pos, HSQUIRRELVM vm)
|
||||
{
|
||||
// Grab the top of the stack
|
||||
const SQInteger top = sq_gettop(vm);
|
||||
// Was there a callback specified?
|
||||
// Was there a callback or tag specified?
|
||||
if (top <= 1)
|
||||
{
|
||||
return sq_throwerror(vm, "Missing task callback");
|
||||
return sq_throwerror(vm, "Missing task callback or tag");
|
||||
}
|
||||
|
||||
SQRESULT res = SQ_OK;
|
||||
// Grab the hash of the callback object
|
||||
const SQHash chash = sq_gethash(vm, 2);
|
||||
// Fetch the task identifier type
|
||||
const SQObjectType ot = sq_gettype(vm, 2);
|
||||
// Are we looking for a task with a specific tag?
|
||||
if (ot == OT_STRING)
|
||||
{
|
||||
// Attempt to retrieve the value from the stack as a string
|
||||
StackStrF tag(vm, 2);
|
||||
// Have we failed to retrieve the string?
|
||||
if (SQ_FAILED(tag.Proc(true)))
|
||||
{
|
||||
return tag.mRes; // Propagate the error!
|
||||
}
|
||||
// Attempt to find the requested task
|
||||
for (const auto & t : s_Tasks)
|
||||
{
|
||||
if (t.mEntity == id && t.mType == type && t.mTag.compare(0, String::npos, tag.mPtr) == 0)
|
||||
{
|
||||
pos = static_cast< SQInteger >(&t - s_Tasks); // Store the index of this element
|
||||
}
|
||||
}
|
||||
}
|
||||
// Validate the callback type
|
||||
else if (ot != OT_CLOSURE && ot != OT_NATIVECLOSURE)
|
||||
{
|
||||
return sq_throwerror(vm, "Invalid callback type");
|
||||
}
|
||||
// Should we include the iterations in the criteria?
|
||||
if (top > 3)
|
||||
else if (top > 3)
|
||||
{
|
||||
SQInteger intrv = 0;
|
||||
// Grab the interval from the stack
|
||||
@ -348,6 +371,8 @@ SQInteger Tasks::Find(int32_t id, int32_t type, SQInteger & pos, HSQUIRRELVM vm)
|
||||
{
|
||||
return res; // Propagate the error
|
||||
}
|
||||
// Grab the hash of the callback object
|
||||
const SQHash chash = sq_gethash(vm, 2);
|
||||
// Attempt to find the requested task
|
||||
for (const auto & t : s_Tasks)
|
||||
{
|
||||
@ -375,6 +400,8 @@ SQInteger Tasks::Find(int32_t id, int32_t type, SQInteger & pos, HSQUIRRELVM vm)
|
||||
{
|
||||
return res; // Propagate the error
|
||||
}
|
||||
// Grab the hash of the callback object
|
||||
const SQHash chash = sq_gethash(vm, 2);
|
||||
// Cast iterations to the right type
|
||||
const Iterator itr = ConvTo< Iterator >::From(sqitr);
|
||||
// Attempt to find the requested task
|
||||
@ -388,6 +415,8 @@ SQInteger Tasks::Find(int32_t id, int32_t type, SQInteger & pos, HSQUIRRELVM vm)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Grab the hash of the callback object
|
||||
const SQHash chash = sq_gethash(vm, 2);
|
||||
// Attempt to find the requested task
|
||||
for (const auto & t : s_Tasks)
|
||||
{
|
||||
@ -416,7 +445,7 @@ SQInteger Tasks::Remove(int32_t id, int32_t type, HSQUIRRELVM vm)
|
||||
// Did we find anything?
|
||||
else if (pos < 0)
|
||||
{
|
||||
return sq_throwerror(vm, "Unable to locate such task");
|
||||
sq_pushbool(vm, SQFalse); // Unable to locate such task
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -424,9 +453,11 @@ SQInteger Tasks::Remove(int32_t id, int32_t type, HSQUIRRELVM vm)
|
||||
s_Tasks[pos].Terminate();
|
||||
// Reset the timer
|
||||
s_Intervals[pos] = 0;
|
||||
// A task was successfully removed
|
||||
sq_pushbool(vm, SQTrue);
|
||||
}
|
||||
// Specify that we don't return anything
|
||||
return 0;
|
||||
// Specify that we return a value
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
@ -37,9 +37,9 @@ private:
|
||||
LightObj mData; // A reference to the arbitrary data associated with this instance.
|
||||
Iterator mIterations; // Number of iterations before self destruct.
|
||||
Interval mInterval; // Interval between task invocations.
|
||||
int16_t mEntity; // The identifier of the entity to which is belongs.
|
||||
uint8_t mType; // The type of the entity to which is belongs.
|
||||
uint8_t mArgc; // The number of arguments that the task must forward.
|
||||
int16_t mEntity; // The identifier of the entity to which is belongs.
|
||||
uint8_t mType; // The type of the entity to which is belongs.
|
||||
uint8_t mArgc; // The number of arguments that the task must forward.
|
||||
Argument mArgv[8]; // The arguments that the task must forward.
|
||||
|
||||
/* ----------------------------------------------------------------------------------------
|
||||
|
@ -125,7 +125,11 @@ void ThreadPool::Process()
|
||||
// Is the item valid?
|
||||
if (item)
|
||||
{
|
||||
item->OnCompleted(); // Allow the item to finish itself
|
||||
try {
|
||||
item->OnCompleted(); // Allow the item to finish itself
|
||||
} catch (const std::exception & e) {
|
||||
LogErr("Exception occured in %s completion stage [%s] for [%s]", item->TypeName(), e.what(), item->IdentifiableInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -138,6 +142,8 @@ void ThreadPool::WorkerProc()
|
||||
bool retry = false;
|
||||
// Pointer to the dequeued item
|
||||
Item item;
|
||||
// Initialize third-party allocator for this thread
|
||||
auto rpmallocinit = std::make_unique< RPMallocThreadInit >();
|
||||
// Constantly process items from the queue
|
||||
while (true)
|
||||
{
|
||||
@ -147,7 +153,11 @@ void ThreadPool::WorkerProc()
|
||||
// Is there an item that requested to try again?
|
||||
if (item)
|
||||
{
|
||||
item->OnAborted(true); // NOLINT(bugprone-use-after-move) There's an `if` condition above idiot!
|
||||
try {
|
||||
item->OnAborted(true); // NOLINT(bugprone-use-after-move) There's an `if` condition above idiot!
|
||||
} catch (const std::exception & e) {
|
||||
LogErr("Exception occured in %s cancelation stage [%s] for [%s]", item->TypeName(), e.what(), item->IdentifiableInfo());
|
||||
}
|
||||
}
|
||||
// Exit the loop
|
||||
break;
|
||||
@ -173,15 +183,30 @@ void ThreadPool::WorkerProc()
|
||||
// Is there an item to be processed?
|
||||
if (item)
|
||||
{
|
||||
item->OnAborted(false); // It should mark itself as aborted somehow!
|
||||
try {
|
||||
item->OnAborted(false); // It should mark itself as aborted somehow!
|
||||
} catch (const std::exception & e) {
|
||||
LogErr("Exception occured in %s forced cancelation stage [%s] for [%s]", item->TypeName(), e.what(), item->IdentifiableInfo());
|
||||
}
|
||||
}
|
||||
// Exit the loop
|
||||
break;
|
||||
}
|
||||
bool r;
|
||||
// Attempt preparation
|
||||
try {
|
||||
r = item->OnPrepare();
|
||||
} catch (const std::exception & e) {
|
||||
LogErr("Exception occured in %s preparation stage [%s] for [%s]", item->TypeName(), e.what(), item->IdentifiableInfo());
|
||||
}
|
||||
// Perform the task
|
||||
if (item->OnPrepare())
|
||||
if (r)
|
||||
{
|
||||
retry = item->OnProcess();
|
||||
try {
|
||||
retry = item->OnProcess();
|
||||
} catch (const std::exception & e) {
|
||||
LogErr("Exception occured in %s processing stage [%s] for [%s]", item->TypeName(), e.what(), item->IdentifiableInfo());
|
||||
}
|
||||
}
|
||||
// The task was performed
|
||||
if (!retry)
|
||||
|
@ -55,6 +55,16 @@ struct ThreadPoolItem
|
||||
*/
|
||||
ThreadPoolItem & operator = (ThreadPoolItem && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Provide a name to what type of task this is. Mainly for debugging purposes.
|
||||
*/
|
||||
SQMOD_NODISCARD virtual const char * TypeName() noexcept { return "worker item"; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Provide unique information that may help identify the task. Mainly for debugging purposes.
|
||||
*/
|
||||
SQMOD_NODISCARD virtual const char * IdentifiableInfo() noexcept { return ""; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Invoked in worker thread by the thread pool after obtaining the task from the queue.
|
||||
* Must return true to indicate that the task can be performed. False indicates failure.
|
||||
@ -171,9 +181,17 @@ public:
|
||||
void Process();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Queue an item to be processed.
|
||||
* Queue an item to be processed. Will take ownership of the given pointer!
|
||||
*/
|
||||
void Enqueue(ThreadPoolItem * item)
|
||||
{
|
||||
Enqueue(Item{item});
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Queue an item to be processed. Will take ownership of the given pointer!
|
||||
*/
|
||||
void Enqueue(Item && item)
|
||||
{
|
||||
// Only queue valid items
|
||||
if (!item || !m_Running) return;
|
||||
@ -183,7 +201,7 @@ public:
|
||||
// Acquire a lock on the mutex
|
||||
std::unique_lock< std::mutex > lock(m_Mutex);
|
||||
// Push the item in the queue
|
||||
m_Queue.push(Item(item));
|
||||
m_Queue.push(std::forward< Item >(item));
|
||||
// Release the mutex before notifying
|
||||
lock.unlock();
|
||||
// Notify one thread that there's work
|
||||
@ -191,16 +209,32 @@ public:
|
||||
}
|
||||
else
|
||||
{
|
||||
bool r;
|
||||
// Attempt preparation
|
||||
try {
|
||||
r = item->OnPrepare();
|
||||
} catch (const std::exception & e) {
|
||||
LogErr("Exception occured in %s preparation stage [%s] for [%s]", item->TypeName(), e.what(), item->IdentifiableInfo());
|
||||
}
|
||||
// Perform the task in-place
|
||||
if (item->OnPrepare())
|
||||
if (r)
|
||||
{
|
||||
if (item->OnProcess())
|
||||
try {
|
||||
r = item->OnProcess();
|
||||
} catch (const std::exception & e) {
|
||||
LogErr("Exception occured in %s processing stage [%s] for [%s]", item->TypeName(), e.what(), item->IdentifiableInfo());
|
||||
}
|
||||
if (r)
|
||||
{
|
||||
item->OnAborted(true); // Not accepted in single thread
|
||||
try {
|
||||
item->OnAborted(true); // Not accepted in single thread
|
||||
} catch (const std::exception & e) {
|
||||
LogErr("Exception occured in %s cancelation stage [%s] for [%s]", item->TypeName(), e.what(), item->IdentifiableInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Item was finished in main thread
|
||||
item->OnCompleted();
|
||||
// Task is completed in processing stage
|
||||
m_Finished.enqueue(std::forward< Item >(item));
|
||||
}
|
||||
}
|
||||
|
||||
@ -211,7 +245,6 @@ public:
|
||||
{
|
||||
return m_Threads.size();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -251,6 +251,20 @@ template < class Key, class T, class Pred = std::equal_to< Key > > struct VecMap
|
||||
return m_Storage.back().second;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieves a reference to the front of the container.
|
||||
* Available for internal use only.
|
||||
*/
|
||||
reference front() { return m_Storage.front(); }
|
||||
const_reference front() const { return m_Storage.front(); }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieves a reference to the back of the container.
|
||||
* Available for internal use only.
|
||||
*/
|
||||
reference back() { return m_Storage.back(); }
|
||||
const_reference back() const { return m_Storage.back(); }
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
@ -1,72 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP.hpp"
|
||||
#include "Library/DPP/Cluster.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqratConst.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void TerminateDPP()
|
||||
{
|
||||
// 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 ProcessDPP()
|
||||
{
|
||||
// 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_DPP_Channel(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Client(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Cluster(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Command(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Constants(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Events(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Guild(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Integration(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Message(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Other(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_Role(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_DPP_User(HSQUIRRELVM vm, Table & ns);
|
||||
|
||||
// ================================================================================================
|
||||
void Register_DPP(HSQUIRRELVM vm)
|
||||
{
|
||||
Table ns(vm);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Register_DPP_Constants(vm, ns);
|
||||
Register_DPP_Client(vm, ns);
|
||||
Register_DPP_Integration(vm, ns);
|
||||
Register_DPP_Command(vm, ns);
|
||||
Register_DPP_Message(vm, ns);
|
||||
Register_DPP_Channel(vm, ns);
|
||||
Register_DPP_Other(vm, ns);
|
||||
Register_DPP_Role(vm, ns);
|
||||
Register_DPP_User(vm, ns);
|
||||
Register_DPP_Guild(vm, ns);
|
||||
{
|
||||
Table ens(vm);
|
||||
Register_DPP_Events(vm, ens);
|
||||
ns.Bind(_SC("Events"), ens);
|
||||
}
|
||||
Register_DPP_Cluster(vm, ns);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Func(_SC("HasVoice"), dpp::utility::has_voice);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
RootTable(vm).Bind(_SC("SqDiscord"), ns);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,16 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Channel.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Channel(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,16 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Client.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Client(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,757 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Cluster.hpp"
|
||||
#include "Library/DPP/Events.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDppCluster, _SC("SqDppCluster"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Cluster(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Cluster"),
|
||||
Class< DpCluster, NoCopy< DpCluster > >(vm, SqDppCluster::Str)
|
||||
// Constructors
|
||||
.Ctor< StackStrF & >()
|
||||
.Ctor< StackStrF &, SQInteger >()
|
||||
.Ctor< StackStrF &, SQInteger, SQInteger >()
|
||||
.Ctor< StackStrF &, SQInteger, SQInteger, SQInteger >()
|
||||
.Ctor< StackStrF &, SQInteger, SQInteger, SQInteger, SQInteger >()
|
||||
.Ctor< StackStrF &, SQInteger, SQInteger, SQInteger, SQInteger, bool >()
|
||||
.Ctor< StackStrF &, SQInteger, SQInteger, SQInteger, SQInteger, bool, const DpCachePolicy & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppCluster::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("On"), &DpCluster::GetEvents)
|
||||
.Prop(_SC("UpTime"), &DpCluster::UpTime)
|
||||
// Member Methods
|
||||
.Func(_SC("Start"), &DpCluster::Start)
|
||||
.Func(_SC("Log"), &DpCluster::Log)
|
||||
.Func(_SC("GetDmChannel"), &DpCluster::GetDmChannel)
|
||||
.Func(_SC("SetDmChannel"), &DpCluster::SetDmChannel)
|
||||
.Func(_SC("SetPresence"), &DpCluster::SetPresence)
|
||||
.Func(_SC("EnableEvent"), &DpCluster::EnableEvent)
|
||||
.Func(_SC("DisableEvent"), &DpCluster::DisableEvent)
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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
|
||||
}
|
||||
DpInternalEvent 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 type = event.GetType();
|
||||
// Fetch the event itself
|
||||
const auto data = event.GetData();
|
||||
// Is this a valid event and is anyone listening to it?
|
||||
if (event.mData == 0 || mEvents[type].first == nullptr || mEvents[type].first->IsEmpty())
|
||||
{
|
||||
continue; // Move on
|
||||
}
|
||||
// Transform the event instance into a script object
|
||||
LightObj obj = EventToScriptObject(type, data);
|
||||
// Allow the script to take ownership of the event instance now
|
||||
event.Reset();
|
||||
// Forward the call to the associated signal
|
||||
(*mEvents[type].first)(obj);
|
||||
// Allow the event instance to clean itself
|
||||
EventInvokeCleanup(type, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================================================
|
||||
* Event handlers.
|
||||
*/
|
||||
void DpCluster::OnVoiceStateUpdate(const dpp::voice_state_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::VoiceStateUpdate, new DpVoiceStateUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnLog(const dpp::log_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::Log, new DpLogEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildJoinRequestDelete(const dpp::guild_join_request_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildJoinRequestDelete, new DpGuildJoinRequestDeleteEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnInteractionCreate(const dpp::interaction_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::InteractionCreate, new DpInteractionCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnButtonClick(const dpp::button_click_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ButtonClick, new DpButtonClickEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnSelectClick(const dpp::select_click_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::SelectClick, new DpSelectClickEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildDelete(const dpp::guild_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildDelete, new DpGuildDeleteEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnChannelDelete(const dpp::channel_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ChannelDelete, new DpChannelDeleteEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnChannelUpdate(const dpp::channel_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ChannelUpdate, new DpChannelUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnReady(const dpp::ready_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::Ready, new DpReadyEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnMessageDelete(const dpp::message_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::MessageDelete, new DpMessageDeleteEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnApplicationCommandDelete(const dpp::application_command_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ApplicationCommandDelete, new DpApplicationCommandDeleteEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildMemberRemove(const dpp::guild_member_remove_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildMemberRemove, new DpGuildMemberRemoveEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnApplicationCommandCreate(const dpp::application_command_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ApplicationCommandCreate, new DpApplicationCommandCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnResumed(const dpp::resumed_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::Resumed, new DpResumedEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildRoleCreate(const dpp::guild_role_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildRoleCreate, new DpGuildRoleCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnTypingStart(const dpp::typing_start_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::TypingStart, new DpTypingStartEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnMessageReactionAdd(const dpp::message_reaction_add_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::MessageReactionAdd, new DpMessageReactionAddEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildMembersChunk(const dpp::guild_members_chunk_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildMembersChunk, new DpGuildMembersChunkEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnMessageReactionRemove(const dpp::message_reaction_remove_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::MessageReactionRemove, new DpMessageReactionRemoveEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildCreate(const dpp::guild_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildCreate, new DpGuildCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnChannelCreate(const dpp::channel_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ChannelCreate, new DpChannelCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnMessageReactionRemoveEmoji(const dpp::message_reaction_remove_emoji_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::MessageReactionRemoveEmoji, new DpMessageReactionRemoveEmojiEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnMessageDeleteBulk(const dpp::message_delete_bulk_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::MessageDeleteBulk, new DpMessageDeleteBulkEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildRoleUpdate(const dpp::guild_role_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildRoleUpdate, new DpGuildRoleUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildRoleDelete(const dpp::guild_role_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildRoleDelete, new DpGuildRoleDeleteEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnChannelPinsUpdate(const dpp::channel_pins_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ChannelPinsUpdate, new DpChannelPinsUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnMessageReactionRemoveAll(const dpp::message_reaction_remove_all_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::MessageReactionRemoveAll, new DpMessageReactionRemoveAllEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnVoiceServerUpdate(const dpp::voice_server_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::VoiceServerUpdate, new DpVoiceServerUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildEmojisUpdate(const dpp::guild_emojis_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildEmojisUpdate, new DpGuildEmojisUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildStickersUpdate(const dpp::guild_stickers_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildStickersUpdate, new DpGuildStickersUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnPresenceUpdate(const dpp::presence_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::PresenceUpdate, new DpPresenceUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnWebhooksUpdate(const dpp::webhooks_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::WebhooksUpdate, new DpWebhooksUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildMemberAdd(const dpp::guild_member_add_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildMemberAdd, new DpGuildMemberAddEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnInviteDelete(const dpp::invite_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::InviteDelete, new DpInviteDeleteEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildUpdate(const dpp::guild_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildUpdate, new DpGuildUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildIntegrationsUpdate(const dpp::guild_integrations_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildIntegrationsUpdate, new DpGuildIntegrationsUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildMemberUpdate(const dpp::guild_member_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildMemberUpdate, new DpGuildMemberUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnApplicationCommandUpdate(const dpp::application_command_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ApplicationCommandUpdate, new DpApplicationCommandUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnInviteCreate(const dpp::invite_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::InviteCreate, new DpInviteCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnMessageUpdate(const dpp::message_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::MessageUpdate, new DpMessageUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnUserUpdate(const dpp::user_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::UserUpdate, new DpUserUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnMessageCreate(const dpp::message_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::MessageCreate, new DpMessageCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildBanAdd(const dpp::guild_ban_add_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildBanAdd, new DpGuildBanAddEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnGuildBanRemove(const dpp::guild_ban_remove_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::GuildBanRemove, new DpGuildBanRemoveEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnIntegrationCreate(const dpp::integration_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::IntegrationCreate, new DpIntegrationCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnIntegrationUpdate(const dpp::integration_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::IntegrationUpdate, new DpIntegrationUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnIntegrationDelete(const dpp::integration_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::IntegrationDelete, new DpIntegrationDeleteEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnThreadCreate(const dpp::thread_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ThreadCreate, new DpThreadCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnThreadUpdate(const dpp::thread_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ThreadUpdate, new DpThreadUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnThreadDelete(const dpp::thread_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ThreadDelete, new DpThreadDeleteEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnThreadListSync(const dpp::thread_list_sync_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ThreadListSync, new DpThreadListSyncEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnThreadMemberUpdate(const dpp::thread_member_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ThreadMemberUpdate, new DpThreadMemberUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnThreadMembersUpdate(const dpp::thread_members_update_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::ThreadMembersUpdate, new DpThreadMembersUpdateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnVoiceBufferSend(const dpp::voice_buffer_send_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::VoiceBufferSend, new DpVoiceBufferSendEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnVoiceUserTalking(const dpp::voice_user_talking_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::VoiceUserTalking, new DpVoiceUserTalkingEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnVoiceReady(const dpp::voice_ready_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::VoiceReady, new DpVoiceReadyEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnVoiceReceive(const dpp::voice_receive_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::VoiceReceive, new DpVoiceReceiveEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnVoiceTrackMarker(const dpp::voice_track_marker_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::VoiceTrackMarker, new DpVoiceTrackMarkerEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnStageInstanceCreate(const dpp::stage_instance_create_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::StageInstanceCreate, new DpStageInstanceCreateEvent(ev)));
|
||||
}
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpCluster::OnStageInstanceDelete(const dpp::stage_instance_delete_t & ev)
|
||||
{
|
||||
mQueue.enqueue(DpInternalEvent(DpEventID::StageInstanceDelete, new DpStageInstanceDeleteEvent(ev)));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
DpCluster & DpCluster::EnableEvent(SQInteger id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case DpEventID::VoiceStateUpdate: mC->on_voice_state_update([this](auto && e) { OnVoiceStateUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::Log: mC->on_log([this](auto && e) { OnLog(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildJoinRequestDelete: mC->on_guild_join_request_delete([this](auto && e) { OnGuildJoinRequestDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::InteractionCreate: mC->on_interaction_create([this](auto && e) { OnInteractionCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ButtonClick: mC->on_button_click([this](auto && e) { OnButtonClick(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::SelectClick: mC->on_select_click([this](auto && e) { OnSelectClick(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildDelete: mC->on_guild_delete([this](auto && e) { OnGuildDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ChannelDelete: mC->on_channel_delete([this](auto && e) { OnChannelDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ChannelUpdate: mC->on_channel_update([this](auto && e) { OnChannelUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::Ready: mC->on_ready([this](auto && e) { OnReady(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::MessageDelete: mC->on_message_delete([this](auto && e) { OnMessageDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ApplicationCommandDelete: mC->on_application_command_delete([this](auto && e) { OnApplicationCommandDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildMemberRemove: mC->on_guild_member_remove([this](auto && e) { OnGuildMemberRemove(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ApplicationCommandCreate: mC->on_application_command_create([this](auto && e) { OnApplicationCommandCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::Resumed: mC->on_resumed([this](auto && e) { OnResumed(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildRoleCreate: mC->on_guild_role_create([this](auto && e) { OnGuildRoleCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::TypingStart: mC->on_typing_start([this](auto && e) { OnTypingStart(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::MessageReactionAdd: mC->on_message_reaction_add([this](auto && e) { OnMessageReactionAdd(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildMembersChunk: mC->on_guild_members_chunk([this](auto && e) { OnGuildMembersChunk(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::MessageReactionRemove: mC->on_message_reaction_remove([this](auto && e) { OnMessageReactionRemove(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildCreate: mC->on_guild_create([this](auto && e) { OnGuildCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ChannelCreate: mC->on_channel_create([this](auto && e) { OnChannelCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::MessageReactionRemoveEmoji: mC->on_message_reaction_remove_emoji([this](auto && e) { OnMessageReactionRemoveEmoji(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::MessageDeleteBulk: mC->on_message_delete_bulk([this](auto && e) { OnMessageDeleteBulk(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildRoleUpdate: mC->on_guild_role_update([this](auto && e) { OnGuildRoleUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildRoleDelete: mC->on_guild_role_delete([this](auto && e) { OnGuildRoleDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ChannelPinsUpdate: mC->on_channel_pins_update([this](auto && e) { OnChannelPinsUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::MessageReactionRemoveAll: mC->on_message_reaction_remove_all([this](auto && e) { OnMessageReactionRemoveAll(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::VoiceServerUpdate: mC->on_voice_server_update([this](auto && e) { OnVoiceServerUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildEmojisUpdate: mC->on_guild_emojis_update([this](auto && e) { OnGuildEmojisUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildStickersUpdate: mC->on_guild_stickers_update([this](auto && e) { OnGuildStickersUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::PresenceUpdate: mC->on_presence_update([this](auto && e) { OnPresenceUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::WebhooksUpdate: mC->on_webhooks_update([this](auto && e) { OnWebhooksUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildMemberAdd: mC->on_guild_member_add([this](auto && e) { OnGuildMemberAdd(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::InviteDelete: mC->on_invite_delete([this](auto && e) { OnInviteDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildUpdate: mC->on_guild_update([this](auto && e) { OnGuildUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildIntegrationsUpdate: mC->on_guild_integrations_update([this](auto && e) { OnGuildIntegrationsUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildMemberUpdate: mC->on_guild_member_update([this](auto && e) { OnGuildMemberUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ApplicationCommandUpdate: mC->on_application_command_update([this](auto && e) { OnApplicationCommandUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::InviteCreate: mC->on_invite_create([this](auto && e) { OnInviteCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::MessageUpdate: mC->on_message_update([this](auto && e) { OnMessageUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::UserUpdate: mC->on_user_update([this](auto && e) { OnUserUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::MessageCreate: mC->on_message_create([this](auto && e) { OnMessageCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildBanAdd: mC->on_guild_ban_add([this](auto && e) { OnGuildBanAdd(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::GuildBanRemove: mC->on_guild_ban_remove([this](auto && e) { OnGuildBanRemove(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::IntegrationCreate: mC->on_integration_create([this](auto && e) { OnIntegrationCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::IntegrationUpdate: mC->on_integration_update([this](auto && e) { OnIntegrationUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::IntegrationDelete: mC->on_integration_delete([this](auto && e) { OnIntegrationDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ThreadCreate: mC->on_thread_create([this](auto && e) { OnThreadCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ThreadUpdate: mC->on_thread_update([this](auto && e) { OnThreadUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ThreadDelete: mC->on_thread_delete([this](auto && e) { OnThreadDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ThreadListSync: mC->on_thread_list_sync([this](auto && e) { OnThreadListSync(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ThreadMemberUpdate: mC->on_thread_member_update([this](auto && e) { OnThreadMemberUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::ThreadMembersUpdate: mC->on_thread_members_update([this](auto && e) { OnThreadMembersUpdate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::VoiceBufferSend: mC->on_voice_buffer_send([this](auto && e) { OnVoiceBufferSend(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::VoiceUserTalking: mC->on_voice_user_talking([this](auto && e) { OnVoiceUserTalking(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::VoiceReady: mC->on_voice_ready([this](auto && e) { OnVoiceReady(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::VoiceReceive: mC->on_voice_receive([this](auto && e) { OnVoiceReceive(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::VoiceTrackMarker: mC->on_voice_track_marker([this](auto && e) { OnVoiceTrackMarker(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::StageInstanceCreate: mC->on_stage_instance_create([this](auto && e) { OnStageInstanceCreate(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::StageInstanceDelete: mC->on_stage_instance_delete([this](auto && e) { OnStageInstanceDelete(std::forward< decltype(e) >(e)); }); break;
|
||||
case DpEventID::Max: // Fall through
|
||||
default: STHROWF("Invalid discord event identifier {}", id);
|
||||
}
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
DpCluster & DpCluster::DisableEvent(SQInteger id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case DpEventID::VoiceStateUpdate: mC->on_voice_state_update(std::function<void(const dpp::voice_state_update_t&)>{}); break;
|
||||
case DpEventID::Log: mC->on_log(std::function<void(const dpp::log_t&)>{}); break;
|
||||
case DpEventID::GuildJoinRequestDelete: mC->on_guild_join_request_delete(std::function<void(const dpp::guild_join_request_delete_t&)>{}); break;
|
||||
case DpEventID::InteractionCreate: mC->on_interaction_create(std::function<void(const dpp::interaction_create_t&)>{}); break;
|
||||
case DpEventID::ButtonClick: mC->on_button_click(std::function<void(const dpp::button_click_t&)>{}); break;
|
||||
case DpEventID::SelectClick: mC->on_select_click(std::function<void(const dpp::select_click_t&)>{}); break;
|
||||
case DpEventID::GuildDelete: mC->on_guild_delete(std::function<void(const dpp::guild_delete_t&)>{}); break;
|
||||
case DpEventID::ChannelDelete: mC->on_channel_delete(std::function<void(const dpp::channel_delete_t&)>{}); break;
|
||||
case DpEventID::ChannelUpdate: mC->on_channel_update(std::function<void(const dpp::channel_update_t&)>{}); break;
|
||||
case DpEventID::Ready: mC->on_ready(std::function<void(const dpp::ready_t&)>{}); break;
|
||||
case DpEventID::MessageDelete: mC->on_message_delete(std::function<void(const dpp::message_delete_t&)>{}); break;
|
||||
case DpEventID::ApplicationCommandDelete: mC->on_application_command_delete(std::function<void(const dpp::application_command_delete_t&)>{}); break;
|
||||
case DpEventID::GuildMemberRemove: mC->on_guild_member_remove(std::function<void(const dpp::guild_member_remove_t&)>{}); break;
|
||||
case DpEventID::ApplicationCommandCreate: mC->on_application_command_create(std::function<void(const dpp::application_command_create_t&)>{}); break;
|
||||
case DpEventID::Resumed: mC->on_resumed(std::function<void(const dpp::resumed_t&)>{}); break;
|
||||
case DpEventID::GuildRoleCreate: mC->on_guild_role_create(std::function<void(const dpp::guild_role_create_t&)>{}); break;
|
||||
case DpEventID::TypingStart: mC->on_typing_start(std::function<void(const dpp::typing_start_t&)>{}); break;
|
||||
case DpEventID::MessageReactionAdd: mC->on_message_reaction_add(std::function<void(const dpp::message_reaction_add_t&)>{}); break;
|
||||
case DpEventID::GuildMembersChunk: mC->on_guild_members_chunk(std::function<void(const dpp::guild_members_chunk_t&)>{}); break;
|
||||
case DpEventID::MessageReactionRemove: mC->on_message_reaction_remove(std::function<void(const dpp::message_reaction_remove_t&)>{}); break;
|
||||
case DpEventID::GuildCreate: mC->on_guild_create(std::function<void(const dpp::guild_create_t&)>{}); break;
|
||||
case DpEventID::ChannelCreate: mC->on_channel_create(std::function<void(const dpp::channel_create_t&)>{}); break;
|
||||
case DpEventID::MessageReactionRemoveEmoji: mC->on_message_reaction_remove_emoji(std::function<void(const dpp::message_reaction_remove_emoji_t&)>{}); break;
|
||||
case DpEventID::MessageDeleteBulk: mC->on_message_delete_bulk(std::function<void(const dpp::message_delete_bulk_t&)>{}); break;
|
||||
case DpEventID::GuildRoleUpdate: mC->on_guild_role_update(std::function<void(const dpp::guild_role_update_t&)>{}); break;
|
||||
case DpEventID::GuildRoleDelete: mC->on_guild_role_delete(std::function<void(const dpp::guild_role_delete_t&)>{}); break;
|
||||
case DpEventID::ChannelPinsUpdate: mC->on_channel_pins_update(std::function<void(const dpp::channel_pins_update_t&)>{}); break;
|
||||
case DpEventID::MessageReactionRemoveAll: mC->on_message_reaction_remove_all(std::function<void(const dpp::message_reaction_remove_all_t&)>{}); break;
|
||||
case DpEventID::VoiceServerUpdate: mC->on_voice_server_update(std::function<void(const dpp::voice_server_update_t&)>{}); break;
|
||||
case DpEventID::GuildEmojisUpdate: mC->on_guild_emojis_update(std::function<void(const dpp::guild_emojis_update_t&)>{}); break;
|
||||
case DpEventID::GuildStickersUpdate: mC->on_guild_stickers_update(std::function<void(const dpp::guild_stickers_update_t&)>{}); break;
|
||||
case DpEventID::PresenceUpdate: mC->on_presence_update(std::function<void(const dpp::presence_update_t&)>{}); break;
|
||||
case DpEventID::WebhooksUpdate: mC->on_webhooks_update(std::function<void(const dpp::webhooks_update_t&)>{}); break;
|
||||
case DpEventID::GuildMemberAdd: mC->on_guild_member_add(std::function<void(const dpp::guild_member_add_t&)>{}); break;
|
||||
case DpEventID::InviteDelete: mC->on_invite_delete(std::function<void(const dpp::invite_delete_t&)>{}); break;
|
||||
case DpEventID::GuildUpdate: mC->on_guild_update(std::function<void(const dpp::guild_update_t&)>{}); break;
|
||||
case DpEventID::GuildIntegrationsUpdate: mC->on_guild_integrations_update(std::function<void(const dpp::guild_integrations_update_t&)>{}); break;
|
||||
case DpEventID::GuildMemberUpdate: mC->on_guild_member_update(std::function<void(const dpp::guild_member_update_t&)>{}); break;
|
||||
case DpEventID::ApplicationCommandUpdate: mC->on_application_command_update(std::function<void(const dpp::application_command_update_t&)>{}); break;
|
||||
case DpEventID::InviteCreate: mC->on_invite_create(std::function<void(const dpp::invite_create_t&)>{}); break;
|
||||
case DpEventID::MessageUpdate: mC->on_message_update(std::function<void(const dpp::message_update_t&)>{}); break;
|
||||
case DpEventID::UserUpdate: mC->on_user_update(std::function<void(const dpp::user_update_t&)>{}); break;
|
||||
case DpEventID::MessageCreate: mC->on_message_create(std::function<void(const dpp::message_create_t&)>{}); break;
|
||||
case DpEventID::GuildBanAdd: mC->on_guild_ban_add(std::function<void(const dpp::guild_ban_add_t&)>{}); break;
|
||||
case DpEventID::GuildBanRemove: mC->on_guild_ban_remove(std::function<void(const dpp::guild_ban_remove_t&)>{}); break;
|
||||
case DpEventID::IntegrationCreate: mC->on_integration_create(std::function<void(const dpp::integration_create_t&)>{}); break;
|
||||
case DpEventID::IntegrationUpdate: mC->on_integration_update(std::function<void(const dpp::integration_update_t&)>{}); break;
|
||||
case DpEventID::IntegrationDelete: mC->on_integration_delete(std::function<void(const dpp::integration_delete_t&)>{}); break;
|
||||
case DpEventID::ThreadCreate: mC->on_thread_create(std::function<void(const dpp::thread_create_t&)>{}); break;
|
||||
case DpEventID::ThreadUpdate: mC->on_thread_update(std::function<void(const dpp::thread_update_t&)>{}); break;
|
||||
case DpEventID::ThreadDelete: mC->on_thread_delete(std::function<void(const dpp::thread_delete_t&)>{}); break;
|
||||
case DpEventID::ThreadListSync: mC->on_thread_list_sync(std::function<void(const dpp::thread_list_sync_t&)>{}); break;
|
||||
case DpEventID::ThreadMemberUpdate: mC->on_thread_member_update(std::function<void(const dpp::thread_member_update_t&)>{}); break;
|
||||
case DpEventID::ThreadMembersUpdate: mC->on_thread_members_update(std::function<void(const dpp::thread_members_update_t&)>{}); break;
|
||||
case DpEventID::VoiceBufferSend: mC->on_voice_buffer_send(std::function<void(const dpp::voice_buffer_send_t&)>{}); break;
|
||||
case DpEventID::VoiceUserTalking: mC->on_voice_user_talking(std::function<void(const dpp::voice_user_talking_t&)>{}); break;
|
||||
case DpEventID::VoiceReady: mC->on_voice_ready(std::function<void(const dpp::voice_ready_t&)>{}); break;
|
||||
case DpEventID::VoiceReceive: mC->on_voice_receive(std::function<void(const dpp::voice_receive_t&)>{}); break;
|
||||
case DpEventID::VoiceTrackMarker: mC->on_voice_track_marker(std::function<void(const dpp::voice_track_marker_t&)>{}); break;
|
||||
case DpEventID::StageInstanceCreate: mC->on_stage_instance_create(std::function<void(const dpp::stage_instance_create_t&)>{}); break;
|
||||
case DpEventID::StageInstanceDelete: mC->on_stage_instance_delete(std::function<void(const dpp::stage_instance_delete_t&)>{}); break;
|
||||
case DpEventID::Max: // Fall through
|
||||
default: STHROWF("Invalid discord event identifier {}", id);
|
||||
}
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void DpInternalEvent::Release()
|
||||
{
|
||||
// Make sure we actually manage something
|
||||
if (mData == 0) return;
|
||||
// Fetch the type of data
|
||||
const auto type = GetType();
|
||||
// Fetch the data itself
|
||||
const auto data = GetData();
|
||||
// Identify data type
|
||||
switch (type)
|
||||
{
|
||||
case DpEventID::VoiceStateUpdate: delete reinterpret_cast< DpVoiceStateUpdateEvent * >(data); break;
|
||||
case DpEventID::Log: delete reinterpret_cast< DpLogEvent * >(data); break;
|
||||
case DpEventID::GuildJoinRequestDelete: delete reinterpret_cast< DpGuildJoinRequestDeleteEvent * >(data); break;
|
||||
case DpEventID::InteractionCreate: delete reinterpret_cast< DpInteractionCreateEvent * >(data); break;
|
||||
case DpEventID::ButtonClick: delete reinterpret_cast< DpButtonClickEvent * >(data); break;
|
||||
case DpEventID::SelectClick: delete reinterpret_cast< DpSelectClickEvent * >(data); break;
|
||||
case DpEventID::GuildDelete: delete reinterpret_cast< DpGuildDeleteEvent * >(data); break;
|
||||
case DpEventID::ChannelDelete: delete reinterpret_cast< DpChannelDeleteEvent * >(data); break;
|
||||
case DpEventID::ChannelUpdate: delete reinterpret_cast< DpChannelUpdateEvent * >(data); break;
|
||||
case DpEventID::Ready: delete reinterpret_cast< DpReadyEvent * >(data); break;
|
||||
case DpEventID::MessageDelete: delete reinterpret_cast< DpMessageDeleteEvent * >(data); break;
|
||||
case DpEventID::ApplicationCommandDelete: delete reinterpret_cast< DpApplicationCommandDeleteEvent * >(data); break;
|
||||
case DpEventID::GuildMemberRemove: delete reinterpret_cast< DpGuildMemberRemoveEvent * >(data); break;
|
||||
case DpEventID::ApplicationCommandCreate: delete reinterpret_cast< DpApplicationCommandCreateEvent * >(data); break;
|
||||
case DpEventID::Resumed: delete reinterpret_cast< DpResumedEvent * >(data); break;
|
||||
case DpEventID::GuildRoleCreate: delete reinterpret_cast< DpGuildRoleCreateEvent * >(data); break;
|
||||
case DpEventID::TypingStart: delete reinterpret_cast< DpTypingStartEvent * >(data); break;
|
||||
case DpEventID::MessageReactionAdd: delete reinterpret_cast< DpMessageReactionAddEvent * >(data); break;
|
||||
case DpEventID::GuildMembersChunk: delete reinterpret_cast< DpGuildMembersChunkEvent * >(data); break;
|
||||
case DpEventID::MessageReactionRemove: delete reinterpret_cast< DpMessageReactionRemoveEvent * >(data); break;
|
||||
case DpEventID::GuildCreate: delete reinterpret_cast< DpGuildCreateEvent * >(data); break;
|
||||
case DpEventID::ChannelCreate: delete reinterpret_cast< DpChannelCreateEvent * >(data); break;
|
||||
case DpEventID::MessageReactionRemoveEmoji: delete reinterpret_cast< DpMessageReactionRemoveEmojiEvent * >(data); break;
|
||||
case DpEventID::MessageDeleteBulk: delete reinterpret_cast< DpMessageDeleteBulkEvent * >(data); break;
|
||||
case DpEventID::GuildRoleUpdate: delete reinterpret_cast< DpGuildRoleUpdateEvent * >(data); break;
|
||||
case DpEventID::GuildRoleDelete: delete reinterpret_cast< DpGuildRoleDeleteEvent * >(data); break;
|
||||
case DpEventID::ChannelPinsUpdate: delete reinterpret_cast< DpChannelPinsUpdateEvent * >(data); break;
|
||||
case DpEventID::MessageReactionRemoveAll: delete reinterpret_cast< DpMessageReactionRemoveAllEvent * >(data); break;
|
||||
case DpEventID::VoiceServerUpdate: delete reinterpret_cast< DpVoiceServerUpdateEvent * >(data); break;
|
||||
case DpEventID::GuildEmojisUpdate: delete reinterpret_cast< DpGuildEmojisUpdateEvent * >(data); break;
|
||||
case DpEventID::GuildStickersUpdate: delete reinterpret_cast< DpGuildStickersUpdateEvent * >(data); break;
|
||||
case DpEventID::PresenceUpdate: delete reinterpret_cast< DpPresenceUpdateEvent * >(data); break;
|
||||
case DpEventID::WebhooksUpdate: delete reinterpret_cast< DpWebhooksUpdateEvent * >(data); break;
|
||||
case DpEventID::GuildMemberAdd: delete reinterpret_cast< DpGuildMemberAddEvent * >(data); break;
|
||||
case DpEventID::InviteDelete: delete reinterpret_cast< DpInviteDeleteEvent * >(data); break;
|
||||
case DpEventID::GuildUpdate: delete reinterpret_cast< DpGuildUpdateEvent * >(data); break;
|
||||
case DpEventID::GuildIntegrationsUpdate: delete reinterpret_cast< DpGuildIntegrationsUpdateEvent * >(data); break;
|
||||
case DpEventID::GuildMemberUpdate: delete reinterpret_cast< DpGuildMemberUpdateEvent * >(data); break;
|
||||
case DpEventID::ApplicationCommandUpdate: delete reinterpret_cast< DpApplicationCommandUpdateEvent * >(data); break;
|
||||
case DpEventID::InviteCreate: delete reinterpret_cast< DpInviteCreateEvent * >(data); break;
|
||||
case DpEventID::MessageUpdate: delete reinterpret_cast< DpMessageUpdateEvent * >(data); break;
|
||||
case DpEventID::UserUpdate: delete reinterpret_cast< DpUserUpdateEvent * >(data); break;
|
||||
case DpEventID::MessageCreate: delete reinterpret_cast< DpMessageCreateEvent * >(data); break;
|
||||
case DpEventID::GuildBanAdd: delete reinterpret_cast< DpGuildBanAddEvent * >(data); break;
|
||||
case DpEventID::GuildBanRemove: delete reinterpret_cast< DpGuildBanRemoveEvent * >(data); break;
|
||||
case DpEventID::IntegrationCreate: delete reinterpret_cast< DpIntegrationCreateEvent * >(data); break;
|
||||
case DpEventID::IntegrationUpdate: delete reinterpret_cast< DpIntegrationUpdateEvent * >(data); break;
|
||||
case DpEventID::IntegrationDelete: delete reinterpret_cast< DpIntegrationDeleteEvent * >(data); break;
|
||||
case DpEventID::ThreadCreate: delete reinterpret_cast< DpThreadCreateEvent * >(data); break;
|
||||
case DpEventID::ThreadUpdate: delete reinterpret_cast< DpThreadUpdateEvent * >(data); break;
|
||||
case DpEventID::ThreadDelete: delete reinterpret_cast< DpThreadDeleteEvent * >(data); break;
|
||||
case DpEventID::ThreadListSync: delete reinterpret_cast< DpThreadListSyncEvent * >(data); break;
|
||||
case DpEventID::ThreadMemberUpdate: delete reinterpret_cast< DpThreadMemberUpdateEvent * >(data); break;
|
||||
case DpEventID::ThreadMembersUpdate: delete reinterpret_cast< DpThreadMembersUpdateEvent * >(data); break;
|
||||
case DpEventID::VoiceBufferSend: delete reinterpret_cast< DpVoiceBufferSendEvent * >(data); break;
|
||||
case DpEventID::VoiceUserTalking: delete reinterpret_cast< DpVoiceUserTalkingEvent * >(data); break;
|
||||
case DpEventID::VoiceReady: delete reinterpret_cast< DpVoiceReadyEvent * >(data); break;
|
||||
case DpEventID::VoiceReceive: delete reinterpret_cast< DpVoiceReceiveEvent * >(data); break;
|
||||
case DpEventID::VoiceTrackMarker: delete reinterpret_cast< DpVoiceTrackMarkerEvent * >(data); break;
|
||||
case DpEventID::StageInstanceCreate: delete reinterpret_cast< DpStageInstanceCreateEvent * >(data); break;
|
||||
case DpEventID::StageInstanceDelete: delete reinterpret_cast< DpStageInstanceDeleteEvent * >(data); break;
|
||||
case DpEventID::Max: // Fall through
|
||||
default: LogFtl("Unrecognized discord event instance type"); assert(0); break;
|
||||
}
|
||||
// Forget about it
|
||||
Reset();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD LightObj EventToScriptObject(uint8_t type, uintptr_t data)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DpEventID::VoiceStateUpdate: return LightObj(reinterpret_cast< DpVoiceStateUpdateEvent * >(data));
|
||||
case DpEventID::Log: return LightObj(reinterpret_cast< DpLogEvent * >(data));
|
||||
case DpEventID::GuildJoinRequestDelete: return LightObj(reinterpret_cast< DpGuildJoinRequestDeleteEvent * >(data));
|
||||
case DpEventID::InteractionCreate: return LightObj(reinterpret_cast< DpInteractionCreateEvent * >(data));
|
||||
case DpEventID::ButtonClick: return LightObj(reinterpret_cast< DpButtonClickEvent * >(data));
|
||||
case DpEventID::SelectClick: return LightObj(reinterpret_cast< DpSelectClickEvent * >(data));
|
||||
case DpEventID::GuildDelete: return LightObj(reinterpret_cast< DpGuildDeleteEvent * >(data));
|
||||
case DpEventID::ChannelDelete: return LightObj(reinterpret_cast< DpChannelDeleteEvent * >(data));
|
||||
case DpEventID::ChannelUpdate: return LightObj(reinterpret_cast< DpChannelUpdateEvent * >(data));
|
||||
case DpEventID::Ready: return LightObj(reinterpret_cast< DpReadyEvent * >(data));
|
||||
case DpEventID::MessageDelete: return LightObj(reinterpret_cast< DpMessageDeleteEvent * >(data));
|
||||
case DpEventID::ApplicationCommandDelete: return LightObj(reinterpret_cast< DpApplicationCommandDeleteEvent * >(data));
|
||||
case DpEventID::GuildMemberRemove: return LightObj(reinterpret_cast< DpGuildMemberRemoveEvent * >(data));
|
||||
case DpEventID::ApplicationCommandCreate: return LightObj(reinterpret_cast< DpApplicationCommandCreateEvent * >(data));
|
||||
case DpEventID::Resumed: return LightObj(reinterpret_cast< DpResumedEvent * >(data));
|
||||
case DpEventID::GuildRoleCreate: return LightObj(reinterpret_cast< DpGuildRoleCreateEvent * >(data));
|
||||
case DpEventID::TypingStart: return LightObj(reinterpret_cast< DpTypingStartEvent * >(data));
|
||||
case DpEventID::MessageReactionAdd: return LightObj(reinterpret_cast< DpMessageReactionAddEvent * >(data));
|
||||
case DpEventID::GuildMembersChunk: return LightObj(reinterpret_cast< DpGuildMembersChunkEvent * >(data));
|
||||
case DpEventID::MessageReactionRemove: return LightObj(reinterpret_cast< DpMessageReactionRemoveEvent * >(data));
|
||||
case DpEventID::GuildCreate: return LightObj(reinterpret_cast< DpGuildCreateEvent * >(data));
|
||||
case DpEventID::ChannelCreate: return LightObj(reinterpret_cast< DpChannelCreateEvent * >(data));
|
||||
case DpEventID::MessageReactionRemoveEmoji: return LightObj(reinterpret_cast< DpMessageReactionRemoveEmojiEvent * >(data));
|
||||
case DpEventID::MessageDeleteBulk: return LightObj(reinterpret_cast< DpMessageDeleteBulkEvent * >(data));
|
||||
case DpEventID::GuildRoleUpdate: return LightObj(reinterpret_cast< DpGuildRoleUpdateEvent * >(data));
|
||||
case DpEventID::GuildRoleDelete: return LightObj(reinterpret_cast< DpGuildRoleDeleteEvent * >(data));
|
||||
case DpEventID::ChannelPinsUpdate: return LightObj(reinterpret_cast< DpChannelPinsUpdateEvent * >(data));
|
||||
case DpEventID::MessageReactionRemoveAll: return LightObj(reinterpret_cast< DpMessageReactionRemoveAllEvent * >(data));
|
||||
case DpEventID::VoiceServerUpdate: return LightObj(reinterpret_cast< DpVoiceServerUpdateEvent * >(data));
|
||||
case DpEventID::GuildEmojisUpdate: return LightObj(reinterpret_cast< DpGuildEmojisUpdateEvent * >(data));
|
||||
case DpEventID::GuildStickersUpdate: return LightObj(reinterpret_cast< DpGuildStickersUpdateEvent * >(data));
|
||||
case DpEventID::PresenceUpdate: return LightObj(reinterpret_cast< DpPresenceUpdateEvent * >(data));
|
||||
case DpEventID::WebhooksUpdate: return LightObj(reinterpret_cast< DpWebhooksUpdateEvent * >(data));
|
||||
case DpEventID::GuildMemberAdd: return LightObj(reinterpret_cast< DpGuildMemberAddEvent * >(data));
|
||||
case DpEventID::InviteDelete: return LightObj(reinterpret_cast< DpInviteDeleteEvent * >(data));
|
||||
case DpEventID::GuildUpdate: return LightObj(reinterpret_cast< DpGuildUpdateEvent * >(data));
|
||||
case DpEventID::GuildIntegrationsUpdate: return LightObj(reinterpret_cast< DpGuildIntegrationsUpdateEvent * >(data));
|
||||
case DpEventID::GuildMemberUpdate: return LightObj(reinterpret_cast< DpGuildMemberUpdateEvent * >(data));
|
||||
case DpEventID::ApplicationCommandUpdate: return LightObj(reinterpret_cast< DpApplicationCommandUpdateEvent * >(data));
|
||||
case DpEventID::InviteCreate: return LightObj(reinterpret_cast< DpInviteCreateEvent * >(data));
|
||||
case DpEventID::MessageUpdate: return LightObj(reinterpret_cast< DpMessageUpdateEvent * >(data));
|
||||
case DpEventID::UserUpdate: return LightObj(reinterpret_cast< DpUserUpdateEvent * >(data));
|
||||
case DpEventID::MessageCreate: return LightObj(reinterpret_cast< DpMessageCreateEvent * >(data));
|
||||
case DpEventID::GuildBanAdd: return LightObj(reinterpret_cast< DpGuildBanAddEvent * >(data));
|
||||
case DpEventID::GuildBanRemove: return LightObj(reinterpret_cast< DpGuildBanRemoveEvent * >(data));
|
||||
case DpEventID::IntegrationCreate: return LightObj(reinterpret_cast< DpIntegrationCreateEvent * >(data));
|
||||
case DpEventID::IntegrationUpdate: return LightObj(reinterpret_cast< DpIntegrationUpdateEvent * >(data));
|
||||
case DpEventID::IntegrationDelete: return LightObj(reinterpret_cast< DpIntegrationDeleteEvent * >(data));
|
||||
case DpEventID::ThreadCreate: return LightObj(reinterpret_cast< DpThreadCreateEvent * >(data));
|
||||
case DpEventID::ThreadUpdate: return LightObj(reinterpret_cast< DpThreadUpdateEvent * >(data));
|
||||
case DpEventID::ThreadDelete: return LightObj(reinterpret_cast< DpThreadDeleteEvent * >(data));
|
||||
case DpEventID::ThreadListSync: return LightObj(reinterpret_cast< DpThreadListSyncEvent * >(data));
|
||||
case DpEventID::ThreadMemberUpdate: return LightObj(reinterpret_cast< DpThreadMemberUpdateEvent * >(data));
|
||||
case DpEventID::ThreadMembersUpdate: return LightObj(reinterpret_cast< DpThreadMembersUpdateEvent * >(data));
|
||||
case DpEventID::VoiceBufferSend: return LightObj(reinterpret_cast< DpVoiceBufferSendEvent * >(data));
|
||||
case DpEventID::VoiceUserTalking: return LightObj(reinterpret_cast< DpVoiceUserTalkingEvent * >(data));
|
||||
case DpEventID::VoiceReady: return LightObj(reinterpret_cast< DpVoiceReadyEvent * >(data));
|
||||
case DpEventID::VoiceReceive: return LightObj(reinterpret_cast< DpVoiceReceiveEvent * >(data));
|
||||
case DpEventID::VoiceTrackMarker: return LightObj(reinterpret_cast< DpVoiceTrackMarkerEvent * >(data));
|
||||
case DpEventID::StageInstanceCreate: return LightObj(reinterpret_cast< DpStageInstanceCreateEvent * >(data));
|
||||
case DpEventID::StageInstanceDelete: return LightObj(reinterpret_cast< DpStageInstanceDeleteEvent * >(data));
|
||||
case DpEventID::Max: // Fall through
|
||||
default: assert(0); return LightObj{};
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void EventInvokeCleanup(uint8_t type, uintptr_t data)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case DpEventID::VoiceStateUpdate: reinterpret_cast< DpVoiceStateUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::Log: reinterpret_cast< DpLogEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildJoinRequestDelete: reinterpret_cast< DpGuildJoinRequestDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::InteractionCreate: reinterpret_cast< DpInteractionCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ButtonClick: reinterpret_cast< DpButtonClickEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::SelectClick: reinterpret_cast< DpSelectClickEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildDelete: reinterpret_cast< DpGuildDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ChannelDelete: reinterpret_cast< DpChannelDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ChannelUpdate: reinterpret_cast< DpChannelUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::Ready: reinterpret_cast< DpReadyEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::MessageDelete: reinterpret_cast< DpMessageDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ApplicationCommandDelete: reinterpret_cast< DpApplicationCommandDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildMemberRemove: reinterpret_cast< DpGuildMemberRemoveEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ApplicationCommandCreate: reinterpret_cast< DpApplicationCommandCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::Resumed: reinterpret_cast< DpResumedEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildRoleCreate: reinterpret_cast< DpGuildRoleCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::TypingStart: reinterpret_cast< DpTypingStartEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::MessageReactionAdd: reinterpret_cast< DpMessageReactionAddEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildMembersChunk: reinterpret_cast< DpGuildMembersChunkEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::MessageReactionRemove: reinterpret_cast< DpMessageReactionRemoveEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildCreate: reinterpret_cast< DpGuildCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ChannelCreate: reinterpret_cast< DpChannelCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::MessageReactionRemoveEmoji: reinterpret_cast< DpMessageReactionRemoveEmojiEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::MessageDeleteBulk: reinterpret_cast< DpMessageDeleteBulkEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildRoleUpdate: reinterpret_cast< DpGuildRoleUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildRoleDelete: reinterpret_cast< DpGuildRoleDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ChannelPinsUpdate: reinterpret_cast< DpChannelPinsUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::MessageReactionRemoveAll: reinterpret_cast< DpMessageReactionRemoveAllEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::VoiceServerUpdate: reinterpret_cast< DpVoiceServerUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildEmojisUpdate: reinterpret_cast< DpGuildEmojisUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildStickersUpdate: reinterpret_cast< DpGuildStickersUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::PresenceUpdate: reinterpret_cast< DpPresenceUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::WebhooksUpdate: reinterpret_cast< DpWebhooksUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildMemberAdd: reinterpret_cast< DpGuildMemberAddEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::InviteDelete: reinterpret_cast< DpInviteDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildUpdate: reinterpret_cast< DpGuildUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildIntegrationsUpdate: reinterpret_cast< DpGuildIntegrationsUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildMemberUpdate: reinterpret_cast< DpGuildMemberUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ApplicationCommandUpdate: reinterpret_cast< DpApplicationCommandUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::InviteCreate: reinterpret_cast< DpInviteCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::MessageUpdate: reinterpret_cast< DpMessageUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::UserUpdate: reinterpret_cast< DpUserUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::MessageCreate: reinterpret_cast< DpMessageCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildBanAdd: reinterpret_cast< DpGuildBanAddEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::GuildBanRemove: reinterpret_cast< DpGuildBanRemoveEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::IntegrationCreate: reinterpret_cast< DpIntegrationCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::IntegrationUpdate: reinterpret_cast< DpIntegrationUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::IntegrationDelete: reinterpret_cast< DpIntegrationDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ThreadCreate: reinterpret_cast< DpThreadCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ThreadUpdate: reinterpret_cast< DpThreadUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ThreadDelete: reinterpret_cast< DpThreadDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ThreadListSync: reinterpret_cast< DpThreadListSyncEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ThreadMemberUpdate: reinterpret_cast< DpThreadMemberUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::ThreadMembersUpdate: reinterpret_cast< DpThreadMembersUpdateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::VoiceBufferSend: reinterpret_cast< DpVoiceBufferSendEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::VoiceUserTalking: reinterpret_cast< DpVoiceUserTalkingEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::VoiceReady: reinterpret_cast< DpVoiceReadyEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::VoiceReceive: reinterpret_cast< DpVoiceReceiveEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::VoiceTrackMarker: reinterpret_cast< DpVoiceTrackMarkerEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::StageInstanceCreate: reinterpret_cast< DpStageInstanceCreateEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::StageInstanceDelete: reinterpret_cast< DpStageInstanceDeleteEvent * >(data)->Cleanup(); break;
|
||||
case DpEventID::Max: // Fall through
|
||||
default: assert(0); return;
|
||||
}
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,431 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
#include "Core/Signal.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Other.hpp"
|
||||
#include "Library/DPP/Constants.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <functional>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <concurrentqueue.h>
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Internal event proxy.
|
||||
*/
|
||||
struct DpInternalEvent
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Event data.
|
||||
*/
|
||||
uint64_t mData{0llu};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpInternalEvent() noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpInternalEvent(uint64_t type, void * data) noexcept
|
||||
: mData((type << 56u) | reinterpret_cast< uint64_t >(data))
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpInternalEvent(const DpInternalEvent & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpInternalEvent(DpInternalEvent && o) noexcept
|
||||
: mData(o.mData)
|
||||
{
|
||||
o.mData = 0llu; // Take ownership
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpInternalEvent()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpInternalEvent & operator = (const DpInternalEvent & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpInternalEvent & operator = (DpInternalEvent && o) noexcept
|
||||
{
|
||||
if (mData != o.mData)
|
||||
{
|
||||
// Release current information
|
||||
Release();
|
||||
// Replicate members
|
||||
mData = o.mData;
|
||||
// Take ownership
|
||||
o.mData = 0llu;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Forget about the managed event data.
|
||||
*/
|
||||
void Reset() noexcept
|
||||
{
|
||||
mData = 0llu;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the event type.
|
||||
*/
|
||||
SQMOD_NODISCARD uint8_t GetType() const noexcept
|
||||
{
|
||||
return static_cast< uint8_t >((mData >> 56u) & 0xFFllu);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the event data.
|
||||
*/
|
||||
SQMOD_NODISCARD uintptr_t GetData() const noexcept
|
||||
{
|
||||
return static_cast< uintptr_t >((~(0xFFllu << 56u)) & mData);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release associated event data, if any.
|
||||
*/
|
||||
void Release();
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* The cluster class represents a group of shards and a command queue for sending and receiving
|
||||
* commands from discord via HTTP.
|
||||
*/
|
||||
struct DpCluster : public SqChainedInstances< DpCluster >
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Queue of events generated from other threads.
|
||||
*/
|
||||
using EventQueue = moodycamel::ConcurrentQueue< DpInternalEvent >;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Managed cluster instance.
|
||||
*/
|
||||
std::unique_ptr< dpp::cluster > mC{nullptr};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Event queue.
|
||||
*/
|
||||
EventQueue mQueue{4096};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpCluster(StackStrF & token)
|
||||
: mC(std::make_unique< dpp::cluster >(token.ToStr()))
|
||||
, mQueue(4096)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpCluster(StackStrF & token, SQInteger intents)
|
||||
: mC(std::make_unique< dpp::cluster >(token.ToStr(), static_cast< uint32_t >(intents)))
|
||||
, mQueue(4096)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpCluster(StackStrF & token, SQInteger intents, SQInteger shards)
|
||||
: mC(std::make_unique< dpp::cluster >(token.ToStr(), static_cast< uint32_t >(intents), static_cast< uint32_t >(shards)))
|
||||
, mQueue(4096)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpCluster(StackStrF & token, SQInteger intents, SQInteger shards, SQInteger cluster_id)
|
||||
: mC(std::make_unique< dpp::cluster >(token.ToStr(), static_cast< uint32_t >(intents), static_cast< uint32_t >(shards), static_cast< uint32_t >(cluster_id)))
|
||||
, mQueue(4096)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpCluster(StackStrF & token, SQInteger intents, SQInteger shards, SQInteger cluster_id, SQInteger max_clusters)
|
||||
: mC(std::make_unique< dpp::cluster >(token.ToStr(), static_cast< uint32_t >(intents), static_cast< uint32_t >(shards), static_cast< uint32_t >(cluster_id), static_cast< uint32_t >(max_clusters)))
|
||||
, mQueue(4096)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpCluster(StackStrF & token, SQInteger intents, SQInteger shards, SQInteger cluster_id, SQInteger max_clusters, bool compressed)
|
||||
: mC(std::make_unique< dpp::cluster >(token.ToStr(), static_cast< uint32_t >(intents), static_cast< uint32_t >(shards), static_cast< uint32_t >(cluster_id), static_cast< uint32_t >(max_clusters), compressed))
|
||||
, mQueue(4096)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
DpCluster(StackStrF & token, SQInteger intents, SQInteger shards, SQInteger cluster_id, SQInteger max_clusters, bool compressed, const DpCachePolicy & cp)
|
||||
: mC(std::make_unique< dpp::cluster >(token.ToStr(), static_cast< uint32_t >(intents), static_cast< uint32_t >(shards), static_cast< uint32_t >(cluster_id), static_cast< uint32_t >(max_clusters), compressed, cp.ToNative()))
|
||||
, mQueue(4096)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpCluster()
|
||||
{
|
||||
DropEvents();
|
||||
// Forget about this instance
|
||||
UnchainInstance();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Start the cluster, connecting all its shards. Returns once all shards are connected.
|
||||
*/
|
||||
DpCluster & Start()
|
||||
{
|
||||
LogInf("Before start...");
|
||||
mC->start(true);
|
||||
LogInf("After start...");
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Log a message to whatever log the user is using.
|
||||
*/
|
||||
DpCluster & Log(SQInteger severity, StackStrF & message)
|
||||
{
|
||||
mC->log(static_cast< dpp::loglevel >(severity), message.ToStr());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Get the dm channel for a user id.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetDmChannel(dpp::snowflake user_id) const
|
||||
{
|
||||
return mC->get_dm_channel(static_cast< dpp::snowflake >(user_id));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the dm channel id for a user id.
|
||||
*/
|
||||
DpCluster & SetDmChannel(dpp::snowflake user_id, dpp::snowflake channel_id)
|
||||
{
|
||||
mC->set_dm_channel(user_id, channel_id);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the uptime of the cluster.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::utility::uptime UpTime() const
|
||||
{
|
||||
return mC->uptime();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns the uptime of the cluster.
|
||||
*/
|
||||
DpCluster & SetPresence(const DpPresence & p)
|
||||
{
|
||||
mC->set_presence(p.Valid());
|
||||
return *this;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
LightObj mSqEvents{}; // Table containing the emitted cluster events.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the events table of this cluster.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetEvents()
|
||||
{
|
||||
return mSqEvents;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Cluster signals.
|
||||
*/
|
||||
std::array< SignalPair, static_cast< size_t >(DpEventID::Max) > mEvents{};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Process the cluster.
|
||||
*/
|
||||
void Process(bool force = false);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Terminate the cluster.
|
||||
*/
|
||||
void Terminate()
|
||||
{
|
||||
// Delete the cluster instance
|
||||
mC.reset();
|
||||
// Release associated script objects
|
||||
mSqEvents.Release();
|
||||
// Release event signal objects
|
||||
DropEvents();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Enable a certain event for the cluster.
|
||||
*/
|
||||
DpCluster & EnableEvent(SQInteger id);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Disable a certain event for the cluster.
|
||||
*/
|
||||
DpCluster & DisableEvent(SQInteger id);
|
||||
|
||||
private:
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Initialize the cluster.
|
||||
*/
|
||||
void Initialize()
|
||||
{
|
||||
InitEvents();
|
||||
// Remember this instance
|
||||
ChainInstance();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Signal initialization.
|
||||
*/
|
||||
void InitEvents()
|
||||
{
|
||||
// Ignore the call if already initialized
|
||||
if (!mSqEvents.IsNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Create a new table on the stack
|
||||
sq_newtableex(SqVM(), 64);
|
||||
// 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 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 OnButtonClick(const dpp::button_click_t & ev);
|
||||
void OnSelectClick(const dpp::select_click_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 OnApplicationCommandDelete(const dpp::application_command_delete_t & ev);
|
||||
void OnGuildMemberRemove(const dpp::guild_member_remove_t & ev);
|
||||
void OnApplicationCommandCreate(const dpp::application_command_create_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 OnMessageDeleteBulk(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 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 OnApplicationCommandUpdate(const dpp::application_command_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 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 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 OnVoiceTrackMarker(const dpp::voice_track_marker_t & ev);
|
||||
void OnStageInstanceCreate(const dpp::stage_instance_create_t & ev);
|
||||
void OnStageInstanceDelete(const dpp::stage_instance_delete_t & ev);
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,16 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Command.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Command(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,427 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Constants.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqratConst.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const std::array< const char *, static_cast< size_t >(DpEventID::Max) > DpEventID::NAME{
|
||||
"VoiceStateUpdate",
|
||||
"Log",
|
||||
"GuildJoinRequestDelete",
|
||||
"InteractionCreate",
|
||||
"ButtonClick",
|
||||
"SelectClick",
|
||||
"GuildDelete",
|
||||
"ChannelDelete",
|
||||
"ChannelUpdate",
|
||||
"Ready",
|
||||
"MessageDelete",
|
||||
"ApplicationCommandDelete",
|
||||
"GuildMemberRemove",
|
||||
"ApplicationCommandCreate",
|
||||
"Resumed",
|
||||
"GuildRoleCreate",
|
||||
"TypingStart",
|
||||
"MessageReactionAdd",
|
||||
"GuildMembersChunk",
|
||||
"MessageReactionRemove",
|
||||
"GuildCreate",
|
||||
"ChannelCreate",
|
||||
"MessageReactionRemoveEmoji",
|
||||
"MessageDeleteBulk",
|
||||
"GuildRoleUpdate",
|
||||
"GuildRoleDelete",
|
||||
"ChannelPinsUpdate",
|
||||
"MessageReactionRemoveAll",
|
||||
"VoiceServerUpdate",
|
||||
"GuildEmojisUpdate",
|
||||
"GuildStickersUpdate",
|
||||
"PresenceUpdate",
|
||||
"WebhooksUpdate",
|
||||
"GuildMemberAdd",
|
||||
"InviteDelete",
|
||||
"GuildUpdate",
|
||||
"GuildIntegrationsUpdate",
|
||||
"GuildMemberUpdate",
|
||||
"ApplicationCommandUpdate",
|
||||
"InviteCreate",
|
||||
"MessageUpdate",
|
||||
"UserUpdate",
|
||||
"MessageCreate",
|
||||
"GuildBanAdd",
|
||||
"GuildBanRemove",
|
||||
"IntegrationCreate",
|
||||
"IntegrationUpdate",
|
||||
"IntegrationDelete",
|
||||
"ThreadCreate",
|
||||
"ThreadUpdate",
|
||||
"ThreadDelete",
|
||||
"ThreadListSync",
|
||||
"ThreadMemberUpdate",
|
||||
"ThreadMembersUpdate",
|
||||
"VoiceBufferSend",
|
||||
"VoiceUserTalking",
|
||||
"VoiceReady",
|
||||
"VoiceReceive",
|
||||
"VoiceTrackMarker",
|
||||
"StageInstanceCreate",
|
||||
"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_DpImageTypeEnum[] = {
|
||||
{_SC("PNG"), static_cast< SQInteger >(dpp::i_png)},
|
||||
{_SC("JPG"), static_cast< SQInteger >(dpp::i_jpg)},
|
||||
{_SC("GIF"), static_cast< SQInteger >(dpp::i_gif)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpCachePolicyEnum[] = {
|
||||
{_SC("Aggressive"), static_cast< SQInteger >(dpp::cp_aggressive)},
|
||||
{_SC("Lazy"), static_cast< SQInteger >(dpp::cp_lazy)},
|
||||
{_SC("None"), static_cast< SQInteger >(dpp::cp_none)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpClusterIntentsEnum[] = {
|
||||
{_SC("Guilds"), static_cast< SQInteger >(dpp::i_guilds)},
|
||||
{_SC("GuildMembers"), static_cast< SQInteger >(dpp::i_guild_members)},
|
||||
{_SC("GuildBans"), static_cast< SQInteger >(dpp::i_guild_bans)},
|
||||
{_SC("GuildEmojis"), static_cast< SQInteger >(dpp::i_guild_emojis)},
|
||||
{_SC("GuildIntegrations"), static_cast< SQInteger >(dpp::i_guild_integrations)},
|
||||
{_SC("GuildWebhooks"), static_cast< SQInteger >(dpp::i_guild_webhooks)},
|
||||
{_SC("GuildInvites"), static_cast< SQInteger >(dpp::i_guild_invites)},
|
||||
{_SC("GuildVoiceStates"), static_cast< SQInteger >(dpp::i_guild_voice_states)},
|
||||
{_SC("GuildPresences"), static_cast< SQInteger >(dpp::i_guild_presences)},
|
||||
{_SC("GuildMessages"), static_cast< SQInteger >(dpp::i_guild_messages)},
|
||||
{_SC("GuildMessageReactions"), static_cast< SQInteger >(dpp::i_guild_message_reactions)},
|
||||
{_SC("GuildMessageTyping"), static_cast< SQInteger >(dpp::i_guild_message_typing)},
|
||||
{_SC("DirectMessages"), static_cast< SQInteger >(dpp::i_direct_messages)},
|
||||
{_SC("DirectMessageReactions"), static_cast< SQInteger >(dpp::i_direct_message_reactions)},
|
||||
{_SC("DirectMessageTyping"), static_cast< SQInteger >(dpp::i_direct_message_typing)},
|
||||
{_SC("Default"), static_cast< SQInteger >(dpp::i_default_intents)},
|
||||
{_SC("Privileged"), static_cast< SQInteger >(dpp::i_privileged_intents)},
|
||||
{_SC("All"), static_cast< SQInteger >(dpp::i_all_intents)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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("WebWnline"), 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)},
|
||||
// Helper bit-shift flags
|
||||
{_SC("BitShiftDesktop"), static_cast< SQInteger >(PF_SHIFT_DESKTOP)},
|
||||
{_SC("BitShiftWeb"), static_cast< SQInteger >(PF_SHIFT_WEB)},
|
||||
{_SC("BitShiftMobile"), static_cast< SQInteger >(PF_SHIFT_MOBILE)},
|
||||
{_SC("BitShiftMain"), static_cast< SQInteger >(PF_SHIFT_MAIN)},
|
||||
{_SC("BitStatusMask"), static_cast< SQInteger >(PF_STATUS_MASK)},
|
||||
{_SC("BitClearDesktop"), static_cast< SQInteger >(PF_CLEAR_DESKTOP)},
|
||||
{_SC("BitClearWeb"), static_cast< SQInteger >(PF_CLEAR_WEB)},
|
||||
{_SC("BitClearMobile"), static_cast< SQInteger >(PF_CLEAR_MOBILE)},
|
||||
{_SC("BitClearStatus"), static_cast< SQInteger >(PF_CLEAR_STATUS)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpDesktopStatusBitsEnum[] = {
|
||||
{_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("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)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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_DpRoleFlagsEnum[] = {
|
||||
{_SC("Hoist"), static_cast< SQInteger >(dpp::r_hoist)},
|
||||
{_SC("Managed"), static_cast< SQInteger >(dpp::r_managed)},
|
||||
{_SC("Mentionable"), static_cast< SQInteger >(dpp::r_mentionable)},
|
||||
{_SC("PremiumSubscriber"), static_cast< SQInteger >(dpp::r_premium_subscriber)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpRolePermissionsEnum[] = {
|
||||
{_SC("CreateInstantInvite"), static_cast< SQInteger >(dpp::p_create_instant_invite)},
|
||||
{_SC("KickMembers"), static_cast< SQInteger >(dpp::p_kick_members)},
|
||||
{_SC("BanMembers"), static_cast< SQInteger >(dpp::p_ban_members)},
|
||||
{_SC("Administrator"), static_cast< SQInteger >(dpp::p_administrator)},
|
||||
{_SC("ManageChannels"), static_cast< SQInteger >(dpp::p_manage_channels)},
|
||||
{_SC("ManageGuild"), static_cast< SQInteger >(dpp::p_manage_guild)},
|
||||
{_SC("AddReactions"), static_cast< SQInteger >(dpp::p_add_reactions)},
|
||||
{_SC("ViewAuditLog"), static_cast< SQInteger >(dpp::p_view_audit_log)},
|
||||
{_SC("PrioritySpeaker"), static_cast< SQInteger >(dpp::p_priority_speaker)},
|
||||
{_SC("Stream"), static_cast< SQInteger >(dpp::p_stream)},
|
||||
{_SC("ViewChannel"), static_cast< SQInteger >(dpp::p_view_channel)},
|
||||
{_SC("SendMessages"), static_cast< SQInteger >(dpp::p_send_messages)},
|
||||
{_SC("SendTtsMessages"), static_cast< SQInteger >(dpp::p_send_tts_messages)},
|
||||
{_SC("ManageMessages"), static_cast< SQInteger >(dpp::p_manage_messages)},
|
||||
{_SC("EmbedLinks"), static_cast< SQInteger >(dpp::p_embed_links)},
|
||||
{_SC("AttachFiles"), static_cast< SQInteger >(dpp::p_attach_files)},
|
||||
{_SC("ReadMessageHistory"), static_cast< SQInteger >(dpp::p_read_message_history)},
|
||||
{_SC("MentionEveryone"), static_cast< SQInteger >(dpp::p_mention_everyone)},
|
||||
{_SC("UseExternalEmojis"), static_cast< SQInteger >(dpp::p_use_external_emojis)},
|
||||
{_SC("ViewGuildInsights"), static_cast< SQInteger >(dpp::p_view_guild_insights)},
|
||||
{_SC("Connect"), static_cast< SQInteger >(dpp::p_connect)},
|
||||
{_SC("Speak"), static_cast< SQInteger >(dpp::p_speak)},
|
||||
{_SC("MuteMembers"), static_cast< SQInteger >(dpp::p_mute_members)},
|
||||
{_SC("DeafenMembers"), static_cast< SQInteger >(dpp::p_deafen_members)},
|
||||
{_SC("MoveMembers"), static_cast< SQInteger >(dpp::p_move_members)},
|
||||
{_SC("UseVAD"), static_cast< SQInteger >(dpp::p_use_vad)},
|
||||
{_SC("ChangeNickname"), static_cast< SQInteger >(dpp::p_change_nickname)},
|
||||
{_SC("ManageNicknames"), static_cast< SQInteger >(dpp::p_manage_nicknames)},
|
||||
{_SC("ManageRoles"), static_cast< SQInteger >(dpp::p_manage_roles)},
|
||||
{_SC("ManageWebHooks"), static_cast< SQInteger >(dpp::p_manage_webhooks)},
|
||||
{_SC("ManageEmojis"), static_cast< SQInteger >(dpp::p_manage_emojis)},
|
||||
{_SC("UseSlashCommands"), static_cast< SQInteger >(dpp::p_use_slash_commands)},
|
||||
{_SC("RequestToSpeak"), static_cast< SQInteger >(dpp::p_request_to_speak)},
|
||||
{_SC("ManageThreads"), static_cast< SQInteger >(dpp::p_manage_threads)},
|
||||
{_SC("UsePublicThreads"), static_cast< SQInteger >(dpp::p_use_public_threads)},
|
||||
{_SC("UsePrivateThreads"), static_cast< SQInteger >(dpp::p_use_private_threads)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpUserFlagsEnum[] = {
|
||||
{_SC("Bot"), static_cast< SQInteger >(dpp::u_bot)},
|
||||
{_SC("System"), static_cast< SQInteger >(dpp::u_system)},
|
||||
{_SC("MfaEnabled"), static_cast< SQInteger >(dpp::u_mfa_enabled)},
|
||||
{_SC("Verified"), static_cast< SQInteger >(dpp::u_verified)},
|
||||
{_SC("NitroFull"), static_cast< SQInteger >(dpp::u_nitro_full)},
|
||||
{_SC("NitroClassic"), static_cast< SQInteger >(dpp::u_nitro_classic)},
|
||||
{_SC("DiscordEmployee"), static_cast< SQInteger >(dpp::u_discord_employee)},
|
||||
{_SC("PartneredOwner"), static_cast< SQInteger >(dpp::u_partnered_owner)},
|
||||
{_SC("HypesquadEvents"), static_cast< SQInteger >(dpp::u_hypesquad_events)},
|
||||
{_SC("Bughunter1"), static_cast< SQInteger >(dpp::u_bughunter_1)},
|
||||
{_SC("HouseBravery"), static_cast< SQInteger >(dpp::u_house_bravery)},
|
||||
{_SC("HouseBrilliance"), static_cast< SQInteger >(dpp::u_house_brilliance)},
|
||||
{_SC("HouseBalanace"), static_cast< SQInteger >(dpp::u_house_balanace)},
|
||||
{_SC("EarlySupporter"), static_cast< SQInteger >(dpp::u_early_supporter)},
|
||||
{_SC("TeamUser"), static_cast< SQInteger >(dpp::u_team_user)},
|
||||
{_SC("Bughunter2"), static_cast< SQInteger >(dpp::u_bughunter_2)},
|
||||
{_SC("VerifiedBot"), static_cast< SQInteger >(dpp::u_verified_bot)},
|
||||
{_SC("VerifiedBotDev"), static_cast< SQInteger >(dpp::u_verified_bot_dev)},
|
||||
{_SC("AnimatedIcon"), static_cast< SQInteger >(dpp::u_animated_icon)},
|
||||
{_SC("CertifiedModerator"), static_cast< SQInteger >(dpp::u_certified_moderator)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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("Commerce"), static_cast< SQInteger >(dpp::g_commerce)},
|
||||
{_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)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpComponentTypeEnum[] = {
|
||||
{_SC("ActionRow"), static_cast< SQInteger >(dpp::cot_action_row)},
|
||||
{_SC("Button"), static_cast< SQInteger >(dpp::cot_button)},
|
||||
{_SC("SelectMenu"), static_cast< SQInteger >(dpp::cot_selectmenu)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpComponentStyleEnum[] = {
|
||||
{_SC("Primary"), static_cast< SQInteger >(dpp::cos_primary)},
|
||||
{_SC("Secondary"), static_cast< SQInteger >(dpp::cos_secondary)},
|
||||
{_SC("Success"), static_cast< SQInteger >(dpp::cos_success)},
|
||||
{_SC("Danger"), static_cast< SQInteger >(dpp::cos_danger)},
|
||||
{_SC("Link"), static_cast< SQInteger >(dpp::cos_link)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpStickerTypeEnum[] = {
|
||||
{_SC("Standard"), static_cast< SQInteger >(dpp::st_standard)},
|
||||
{_SC("Guild"), static_cast< SQInteger >(dpp::st_guild)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpStickerFormatEnum[] = {
|
||||
{_SC("PNG"), static_cast< SQInteger >(dpp::sf_png)},
|
||||
{_SC("APNG"), static_cast< SQInteger >(dpp::sf_apng)},
|
||||
{_SC("Lottie"), static_cast< SQInteger >(dpp::sf_lottie)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpMessageFlagsEnum[] = {
|
||||
{_SC("Crossposted"), static_cast< SQInteger >(dpp::m_crossposted)},
|
||||
{_SC("IsCrosspost"), static_cast< SQInteger >(dpp::m_is_crosspost)},
|
||||
{_SC("SuppressEmbeds"), static_cast< SQInteger >(dpp::m_suppress_embeds)},
|
||||
{_SC("SourceMessageDeleted"), static_cast< SQInteger >(dpp::m_source_message_deleted)},
|
||||
{_SC("Urgent"), static_cast< SQInteger >(dpp::m_urgent)},
|
||||
{_SC("Ephemeral"), static_cast< SQInteger >(dpp::m_ephemeral)},
|
||||
{_SC("Loading"), static_cast< SQInteger >(dpp::m_loading)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElement g_DpMessageTypeEnum[] = {
|
||||
{_SC("Default"), static_cast< SQInteger >(dpp::mt_default)},
|
||||
{_SC("RecipientAdd"), static_cast< SQInteger >(dpp::mt_recipient_add)},
|
||||
{_SC("RecipientRemove"), static_cast< SQInteger >(dpp::mt_recipient_remove)},
|
||||
{_SC("Call"), static_cast< SQInteger >(dpp::mt_call)},
|
||||
{_SC("ChannelNameChange"), static_cast< SQInteger >(dpp::mt_channel_name_change)},
|
||||
{_SC("ChannelIconChange"), static_cast< SQInteger >(dpp::mt_channel_icon_change)},
|
||||
{_SC("ChannelPinnedMessage"), static_cast< SQInteger >(dpp::mt_channel_pinned_message)},
|
||||
{_SC("GuildMemberJoin"), static_cast< SQInteger >(dpp::mt_guild_member_join)},
|
||||
{_SC("UserPremiumGuildSubscription"), static_cast< SQInteger >(dpp::mt_user_premium_guild_subscription)},
|
||||
{_SC("UserPremiumGuildSubscriptionTier1"), static_cast< SQInteger >(dpp::mt_user_premium_guild_subscription_tier_1)},
|
||||
{_SC("UserPremiumGuildSubscriptionTier2"), static_cast< SQInteger >(dpp::mt_user_premium_guild_subscription_tier_2)},
|
||||
{_SC("UserPremiumGuildSubscriptionTier3"), static_cast< SQInteger >(dpp::mt_user_premium_guild_subscription_tier_3)},
|
||||
{_SC("ChannelFollowAdd"), static_cast< SQInteger >(dpp::mt_channel_follow_add)},
|
||||
{_SC("GuildDiscoveryDisqualified"), static_cast< SQInteger >(dpp::mt_guild_discovery_disqualified)},
|
||||
{_SC("GuildDiscoveryRequalified"), static_cast< SQInteger >(dpp::mt_guild_discovery_requalified)},
|
||||
{_SC("GuildDiscoveryGracePeriodInitialWarning"), static_cast< SQInteger >(dpp::mt_guild_discovery_grace_period_initial_warning)},
|
||||
{_SC("GuildDiscoveryGracePeriodFinalWarning"), static_cast< SQInteger >(dpp::mt_guild_discovery_grace_period_final_warning)},
|
||||
{_SC("ThreadCreated"), static_cast< SQInteger >(dpp::mt_thread_created)},
|
||||
{_SC("Reply"), static_cast< SQInteger >(dpp::mt_reply)},
|
||||
{_SC("ApplicationCommand"), static_cast< SQInteger >(dpp::mt_application_command)},
|
||||
{_SC("ThreadStarterMessage"), static_cast< SQInteger >(dpp::mt_thread_starter_message)},
|
||||
{_SC("GuildInviteReminder"), static_cast< SQInteger >(dpp::mt_guild_invite_reminder)}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static const EnumElements g_EnumList[] = {
|
||||
{_SC("SqDiscordLogLevel"), g_DpLogLevelEnum},
|
||||
{_SC("SqDiscordImageType"), g_DpImageTypeEnum},
|
||||
{_SC("SqDiscordCachePolicy"), g_DpCachePolicyEnum},
|
||||
{_SC("SqDiscordClusterIntents"), g_DpClusterIntentsEnum},
|
||||
{_SC("SqDiscordPresenceFlags"), g_DpPresenceFlagsEnum},
|
||||
{_SC("SqDiscordPresenceStatus"), g_DpPresenceStatusEnum},
|
||||
{_SC("SqDiscordDesktopStatusBits"), g_DpDesktopStatusBitsEnum},
|
||||
{_SC("SqDiscordActivityType"), g_DpActivityTypeEnum},
|
||||
{_SC("SqDiscordActivityFlags"), g_DpActivityFlagsEnum},
|
||||
{_SC("SqDiscordVoiceStateFlags"), g_DpVoiceStateFlagsEnum},
|
||||
{_SC("SqDiscordRoleFlags"), g_DpRoleFlagsEnum},
|
||||
{_SC("SqDiscordRolePermissions"), g_DpRolePermissionsEnum},
|
||||
{_SC("SqDiscordUserFlags"), g_DpUserFlagsEnum},
|
||||
{_SC("SqDiscordRegion"), g_DpRegionEnum},
|
||||
{_SC("SqDiscordGuildFlags"), g_DpGuildFlagsEnum},
|
||||
{_SC("SqDiscordGuildMemberFlags"), g_DpGuildMemberFlagsEnum},
|
||||
{_SC("SqDiscordComponentType"), g_DpComponentTypeEnum},
|
||||
{_SC("SqDiscordComponentStyle"), g_DpComponentStyleEnum},
|
||||
{_SC("SqDiscordStickerType"), g_DpStickerTypeEnum},
|
||||
{_SC("SqDiscordStickerFormat"), g_DpStickerFormatEnum},
|
||||
{_SC("SqDiscordMessageFlags"), g_DpMessageFlagsEnum},
|
||||
{_SC("SqDiscordMessageType"), g_DpMessageTypeEnum}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_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
|
@ -1,91 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Unique ID for each event.
|
||||
*/
|
||||
struct DpEventID
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* ID enumeration.
|
||||
*/
|
||||
enum Type
|
||||
{
|
||||
VoiceStateUpdate=0,
|
||||
Log,
|
||||
GuildJoinRequestDelete,
|
||||
InteractionCreate,
|
||||
ButtonClick,
|
||||
SelectClick,
|
||||
GuildDelete,
|
||||
ChannelDelete,
|
||||
ChannelUpdate,
|
||||
Ready,
|
||||
MessageDelete,
|
||||
ApplicationCommandDelete,
|
||||
GuildMemberRemove,
|
||||
ApplicationCommandCreate,
|
||||
Resumed,
|
||||
GuildRoleCreate,
|
||||
TypingStart,
|
||||
MessageReactionAdd,
|
||||
GuildMembersChunk,
|
||||
MessageReactionRemove,
|
||||
GuildCreate,
|
||||
ChannelCreate,
|
||||
MessageReactionRemoveEmoji,
|
||||
MessageDeleteBulk,
|
||||
GuildRoleUpdate,
|
||||
GuildRoleDelete,
|
||||
ChannelPinsUpdate,
|
||||
MessageReactionRemoveAll,
|
||||
VoiceServerUpdate,
|
||||
GuildEmojisUpdate,
|
||||
GuildStickersUpdate,
|
||||
PresenceUpdate,
|
||||
WebhooksUpdate,
|
||||
GuildMemberAdd,
|
||||
InviteDelete,
|
||||
GuildUpdate,
|
||||
GuildIntegrationsUpdate,
|
||||
GuildMemberUpdate,
|
||||
ApplicationCommandUpdate,
|
||||
InviteCreate,
|
||||
MessageUpdate,
|
||||
UserUpdate,
|
||||
MessageCreate,
|
||||
GuildBanAdd,
|
||||
GuildBanRemove,
|
||||
IntegrationCreate,
|
||||
IntegrationUpdate,
|
||||
IntegrationDelete,
|
||||
ThreadCreate,
|
||||
ThreadUpdate,
|
||||
ThreadDelete,
|
||||
ThreadListSync,
|
||||
ThreadMemberUpdate,
|
||||
ThreadMembersUpdate,
|
||||
VoiceBufferSend,
|
||||
VoiceUserTalking,
|
||||
VoiceReady,
|
||||
VoiceReceive,
|
||||
VoiceTrackMarker,
|
||||
StageInstanceCreate,
|
||||
StageInstanceDelete,
|
||||
Max
|
||||
};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* String identification for each event ID.
|
||||
*/
|
||||
static const std::array< const char *, static_cast< size_t >(Max) > NAME;
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,630 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Events.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDppVoiceStateUpdateEvent, _SC("SqDppVoiceStateUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppLogEvent, _SC("SqDppLogEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildJoinRequestDeleteEvent, _SC("SqDppGuildJoinRequestDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppInteractionCreateEvent, _SC("SqDppInteractionCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppButtonClickEvent, _SC("SqDppButtonClickEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppSelectClickEvent, _SC("SqDppSelectClickEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildDeleteEvent, _SC("SqDppGuildDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppChannelDeleteEvent, _SC("SqDppChannelDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppChannelUpdateEvent, _SC("SqDppChannelUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppReadyEvent, _SC("SqDppReadyEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppMessageDeleteEvent, _SC("SqDppMessageDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppApplicationCommandDeleteEvent, _SC("SqDppApplicationCommandDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildMemberRemoveEvent, _SC("SqDppGuildMemberRemoveEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppApplicationCommandCreateEvent, _SC("SqDppApplicationCommandCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppResumedEvent, _SC("SqDppResumedEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildRoleCreateEvent, _SC("SqDppGuildRoleCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppTypingStartEvent, _SC("SqDppTypingStartEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppMessageReactionAddEvent, _SC("SqDppMessageReactionAddEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildMembersChunkEvent, _SC("SqDppGuildMembersChunkEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppMessageReactionRemoveEvent, _SC("SqDppMessageReactionRemoveEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildCreateEvent, _SC("SqDppGuildCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppChannelCreateEvent, _SC("SqDppChannelCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppMessageReactionRemoveEmojiEvent, _SC("SqDppMessageReactionRemoveEmojiEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppMessageDeleteBulkEvent, _SC("SqDppMessageDeleteBulkEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildRoleUpdateEvent, _SC("SqDppGuildRoleUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildRoleDeleteEvent, _SC("SqDppGuildRoleDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppChannelPinsUpdateEvent, _SC("SqDppChannelPinsUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppMessageReactionRemoveAllEvent, _SC("SqDppMessageReactionRemoveAllEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppVoiceServerUpdateEvent, _SC("SqDppVoiceServerUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildEmojisUpdateEvent, _SC("SqDppGuildEmojisUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildStickersUpdateEvent, _SC("SqDppGuildStickersUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppPresenceUpdateEvent, _SC("SqDppPresenceUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppWebhooksUpdateEvent, _SC("SqDppWebhooksUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildMemberAddEvent, _SC("SqDppGuildMemberAddEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppInviteDeleteEvent, _SC("SqDppInviteDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildUpdateEvent, _SC("SqDppGuildUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildIntegrationsUpdateEvent, _SC("SqDppGuildIntegrationsUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildMemberUpdateEvent, _SC("SqDppGuildMemberUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppApplicationCommandUpdateEvent, _SC("SqDppApplicationCommandUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppInviteCreateEvent, _SC("SqDppInviteCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppMessageUpdateEvent, _SC("SqDppMessageUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppUserUpdateEvent, _SC("SqDppUserUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppMessageCreateEvent, _SC("SqDppMessageCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildBanAddEvent, _SC("SqDppGuildBanAddEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildBanRemoveEvent, _SC("SqDppGuildBanRemoveEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppIntegrationCreateEvent, _SC("SqDppIntegrationCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppIntegrationUpdateEvent, _SC("SqDppIntegrationUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppIntegrationDeleteEvent, _SC("SqDppIntegrationDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppThreadCreateEvent, _SC("SqDppThreadCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppThreadUpdateEvent, _SC("SqDppThreadUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppThreadDeleteEvent, _SC("SqDppThreadDeleteEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppThreadListSyncEvent, _SC("SqDppThreadListSyncEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppThreadMemberUpdateEvent, _SC("SqDppThreadMemberUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppThreadMembersUpdateEvent, _SC("SqDppThreadMembersUpdateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppVoiceBufferSendEvent, _SC("SqDppVoiceBufferSendEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppVoiceUserTalkingEvent, _SC("SqDppVoiceUserTalkingEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppVoiceReadyEvent, _SC("SqDppVoiceReadyEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppVoiceReceiveEvent, _SC("SqDppVoiceReceiveEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppVoiceTrackMarkerEvent, _SC("SqDppVoiceTrackMarkerEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppStageInstanceCreateEvent, _SC("SqDppStageInstanceCreateEvent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppStageInstanceDeleteEvent, _SC("SqDppStageInstanceDeleteEvent"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Events(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceStateUpdate"),
|
||||
Class< DpVoiceStateUpdateEvent, NoConstructor< DpVoiceStateUpdateEvent > >(vm, SqDppVoiceStateUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppVoiceStateUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceStateUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("State"), &DpVoiceStateUpdateEvent::GetState)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Log"),
|
||||
Class< DpLogEvent, NoConstructor< DpLogEvent > >(vm, SqDppLogEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppLogEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpLogEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpLogEvent::GetRawEvent)
|
||||
.Prop(_SC("Severity"), &DpLogEvent::GetSeverity)
|
||||
.Prop(_SC("Message"), &DpLogEvent::GetMessage)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildJoinRequestDelete"),
|
||||
Class< DpGuildJoinRequestDeleteEvent, NoConstructor< DpGuildJoinRequestDeleteEvent > >(vm, SqDppGuildJoinRequestDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildJoinRequestDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildJoinRequestDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildJoinRequestDeleteEvent::GetRawEvent)
|
||||
.Prop(_SC("GuildID"), &DpGuildJoinRequestDeleteEvent::GetGuildID)
|
||||
.Prop(_SC("UserID"), &DpGuildJoinRequestDeleteEvent::GetUserID)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("InteractionCreate"),
|
||||
Class< DpInteractionCreateEvent, NoConstructor< DpInteractionCreateEvent > >(vm, SqDppInteractionCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppInteractionCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpInteractionCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpInteractionCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ButtonClick"),
|
||||
Class< DpButtonClickEvent, NoConstructor< DpButtonClickEvent > >(vm, SqDppButtonClickEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppButtonClickEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpButtonClickEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpButtonClickEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("SelectClick"),
|
||||
Class< DpSelectClickEvent, NoConstructor< DpSelectClickEvent > >(vm, SqDppSelectClickEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppSelectClickEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpSelectClickEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpSelectClickEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildDelete"),
|
||||
Class< DpGuildDeleteEvent, NoConstructor< DpGuildDeleteEvent > >(vm, SqDppGuildDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ChannelDelete"),
|
||||
Class< DpChannelDeleteEvent, NoConstructor< DpChannelDeleteEvent > >(vm, SqDppChannelDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppChannelDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpChannelDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpChannelDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ChannelUpdate"),
|
||||
Class< DpChannelUpdateEvent, NoConstructor< DpChannelUpdateEvent > >(vm, SqDppChannelUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppChannelUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpChannelUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpChannelUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Ready"),
|
||||
Class< DpReadyEvent, NoConstructor< DpReadyEvent > >(vm, SqDppReadyEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppReadyEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpReadyEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpReadyEvent::GetRawEvent)
|
||||
.Prop(_SC("SessionID"), &DpReadyEvent::GetSessionID)
|
||||
.Prop(_SC("ShardID"), &DpReadyEvent::GetShardID)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageDelete"),
|
||||
Class< DpMessageDeleteEvent, NoConstructor< DpMessageDeleteEvent > >(vm, SqDppMessageDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppMessageDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpMessageDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ApplicationCommandDelete"),
|
||||
Class< DpApplicationCommandDeleteEvent, NoConstructor< DpApplicationCommandDeleteEvent > >(vm, SqDppApplicationCommandDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppApplicationCommandDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpApplicationCommandDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpApplicationCommandDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildMemberRemove"),
|
||||
Class< DpGuildMemberRemoveEvent, NoConstructor< DpGuildMemberRemoveEvent > >(vm, SqDppGuildMemberRemoveEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildMemberRemoveEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildMemberRemoveEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildMemberRemoveEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ApplicationCommandCreate"),
|
||||
Class< DpApplicationCommandCreateEvent, NoConstructor< DpApplicationCommandCreateEvent > >(vm, SqDppApplicationCommandCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppApplicationCommandCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpApplicationCommandCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpApplicationCommandCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Resumed"),
|
||||
Class< DpResumedEvent, NoConstructor< DpResumedEvent > >(vm, SqDppResumedEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppResumedEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpResumedEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpResumedEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildRoleCreate"),
|
||||
Class< DpGuildRoleCreateEvent, NoConstructor< DpGuildRoleCreateEvent > >(vm, SqDppGuildRoleCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildRoleCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildRoleCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildRoleCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("TypingStart"),
|
||||
Class< DpTypingStartEvent, NoConstructor< DpTypingStartEvent > >(vm, SqDppTypingStartEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppTypingStartEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpTypingStartEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpTypingStartEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageReactionAdd"),
|
||||
Class< DpMessageReactionAddEvent, NoConstructor< DpMessageReactionAddEvent > >(vm, SqDppMessageReactionAddEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppMessageReactionAddEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageReactionAddEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpMessageReactionAddEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildMembersChunk"),
|
||||
Class< DpGuildMembersChunkEvent, NoConstructor< DpGuildMembersChunkEvent > >(vm, SqDppGuildMembersChunkEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildMembersChunkEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildMembersChunkEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildMembersChunkEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageReactionRemove"),
|
||||
Class< DpMessageReactionRemoveEvent, NoConstructor< DpMessageReactionRemoveEvent > >(vm, SqDppMessageReactionRemoveEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppMessageReactionRemoveEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageReactionRemoveEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpMessageReactionRemoveEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildCreate"),
|
||||
Class< DpGuildCreateEvent, NoConstructor< DpGuildCreateEvent > >(vm, SqDppGuildCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ChannelCreate"),
|
||||
Class< DpChannelCreateEvent, NoConstructor< DpChannelCreateEvent > >(vm, SqDppChannelCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppChannelCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpChannelCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpChannelCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageReactionRemoveEmoji"),
|
||||
Class< DpMessageReactionRemoveEmojiEvent, NoConstructor< DpMessageReactionRemoveEmojiEvent > >(vm, SqDppMessageReactionRemoveEmojiEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppMessageReactionRemoveEmojiEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageReactionRemoveEmojiEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpMessageReactionRemoveEmojiEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageDeleteBulk"),
|
||||
Class< DpMessageDeleteBulkEvent, NoConstructor< DpMessageDeleteBulkEvent > >(vm, SqDppMessageDeleteBulkEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppMessageDeleteBulkEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageDeleteBulkEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpMessageDeleteBulkEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildRoleUpdate"),
|
||||
Class< DpGuildRoleUpdateEvent, NoConstructor< DpGuildRoleUpdateEvent > >(vm, SqDppGuildRoleUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildRoleUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildRoleUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildRoleUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildRoleDelete"),
|
||||
Class< DpGuildRoleDeleteEvent, NoConstructor< DpGuildRoleDeleteEvent > >(vm, SqDppGuildRoleDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildRoleDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildRoleDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildRoleDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ChannelPinsUpdate"),
|
||||
Class< DpChannelPinsUpdateEvent, NoConstructor< DpChannelPinsUpdateEvent > >(vm, SqDppChannelPinsUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppChannelPinsUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpChannelPinsUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpChannelPinsUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageReactionRemoveAll"),
|
||||
Class< DpMessageReactionRemoveAllEvent, NoConstructor< DpMessageReactionRemoveAllEvent > >(vm, SqDppMessageReactionRemoveAllEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppMessageReactionRemoveAllEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageReactionRemoveAllEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpMessageReactionRemoveAllEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceServerUpdate"),
|
||||
Class< DpVoiceServerUpdateEvent, NoConstructor< DpVoiceServerUpdateEvent > >(vm, SqDppVoiceServerUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppVoiceServerUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceServerUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpVoiceServerUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildEmojisUpdate"),
|
||||
Class< DpGuildEmojisUpdateEvent, NoConstructor< DpGuildEmojisUpdateEvent > >(vm, SqDppGuildEmojisUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildEmojisUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildEmojisUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildEmojisUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildStickersUpdate"),
|
||||
Class< DpGuildStickersUpdateEvent, NoConstructor< DpGuildStickersUpdateEvent > >(vm, SqDppGuildStickersUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildStickersUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildStickersUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildStickersUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("PresenceUpdate"),
|
||||
Class< DpPresenceUpdateEvent, NoConstructor< DpPresenceUpdateEvent > >(vm, SqDppPresenceUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppPresenceUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpPresenceUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpPresenceUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("WebhooksUpdate"),
|
||||
Class< DpWebhooksUpdateEvent, NoConstructor< DpWebhooksUpdateEvent > >(vm, SqDppWebhooksUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppWebhooksUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpWebhooksUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpWebhooksUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildMemberAdd"),
|
||||
Class< DpGuildMemberAddEvent, NoConstructor< DpGuildMemberAddEvent > >(vm, SqDppGuildMemberAddEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildMemberAddEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildMemberAddEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildMemberAddEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("InviteDelete"),
|
||||
Class< DpInviteDeleteEvent, NoConstructor< DpInviteDeleteEvent > >(vm, SqDppInviteDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppInviteDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpInviteDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpInviteDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildUpdate"),
|
||||
Class< DpGuildUpdateEvent, NoConstructor< DpGuildUpdateEvent > >(vm, SqDppGuildUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildIntegrationsUpdate"),
|
||||
Class< DpGuildIntegrationsUpdateEvent, NoConstructor< DpGuildIntegrationsUpdateEvent > >(vm, SqDppGuildIntegrationsUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildIntegrationsUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildIntegrationsUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildIntegrationsUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildMemberUpdate"),
|
||||
Class< DpGuildMemberUpdateEvent, NoConstructor< DpGuildMemberUpdateEvent > >(vm, SqDppGuildMemberUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildMemberUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildMemberUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildMemberUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ApplicationCommandUpdate"),
|
||||
Class< DpApplicationCommandUpdateEvent, NoConstructor< DpApplicationCommandUpdateEvent > >(vm, SqDppApplicationCommandUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppApplicationCommandUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpApplicationCommandUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpApplicationCommandUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("InviteCreate"),
|
||||
Class< DpInviteCreateEvent, NoConstructor< DpInviteCreateEvent > >(vm, SqDppInviteCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppInviteCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpInviteCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpInviteCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageUpdate"),
|
||||
Class< DpMessageUpdateEvent, NoConstructor< DpMessageUpdateEvent > >(vm, SqDppMessageUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppMessageUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpMessageUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("UserUpdate"),
|
||||
Class< DpUserUpdateEvent, NoConstructor< DpUserUpdateEvent > >(vm, SqDppUserUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppUserUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpUserUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpUserUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("MessageCreate"),
|
||||
Class< DpMessageCreateEvent, NoConstructor< DpMessageCreateEvent > >(vm, SqDppMessageCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppMessageCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpMessageCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpMessageCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildBanAdd"),
|
||||
Class< DpGuildBanAddEvent, NoConstructor< DpGuildBanAddEvent > >(vm, SqDppGuildBanAddEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildBanAddEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildBanAddEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildBanAddEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("GuildBanRemove"),
|
||||
Class< DpGuildBanRemoveEvent, NoConstructor< DpGuildBanRemoveEvent > >(vm, SqDppGuildBanRemoveEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildBanRemoveEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpGuildBanRemoveEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpGuildBanRemoveEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("IntegrationCreate"),
|
||||
Class< DpIntegrationCreateEvent, NoConstructor< DpIntegrationCreateEvent > >(vm, SqDppIntegrationCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppIntegrationCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpIntegrationCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpIntegrationCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("IntegrationUpdate"),
|
||||
Class< DpIntegrationUpdateEvent, NoConstructor< DpIntegrationUpdateEvent > >(vm, SqDppIntegrationUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppIntegrationUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpIntegrationUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpIntegrationUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("IntegrationDelete"),
|
||||
Class< DpIntegrationDeleteEvent, NoConstructor< DpIntegrationDeleteEvent > >(vm, SqDppIntegrationDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppIntegrationDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpIntegrationDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpIntegrationDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadCreate"),
|
||||
Class< DpThreadCreateEvent, NoConstructor< DpThreadCreateEvent > >(vm, SqDppThreadCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppThreadCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpThreadCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadUpdate"),
|
||||
Class< DpThreadUpdateEvent, NoConstructor< DpThreadUpdateEvent > >(vm, SqDppThreadUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppThreadUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpThreadUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadDelete"),
|
||||
Class< DpThreadDeleteEvent, NoConstructor< DpThreadDeleteEvent > >(vm, SqDppThreadDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppThreadDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpThreadDeleteEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadListSync"),
|
||||
Class< DpThreadListSyncEvent, NoConstructor< DpThreadListSyncEvent > >(vm, SqDppThreadListSyncEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppThreadListSyncEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadListSyncEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpThreadListSyncEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadMemberUpdate"),
|
||||
Class< DpThreadMemberUpdateEvent, NoConstructor< DpThreadMemberUpdateEvent > >(vm, SqDppThreadMemberUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppThreadMemberUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadMemberUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpThreadMemberUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("ThreadMembersUpdate"),
|
||||
Class< DpThreadMembersUpdateEvent, NoConstructor< DpThreadMembersUpdateEvent > >(vm, SqDppThreadMembersUpdateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppThreadMembersUpdateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpThreadMembersUpdateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpThreadMembersUpdateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceBufferSend"),
|
||||
Class< DpVoiceBufferSendEvent, NoConstructor< DpVoiceBufferSendEvent > >(vm, SqDppVoiceBufferSendEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppVoiceBufferSendEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceBufferSendEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpVoiceBufferSendEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceUserTalking"),
|
||||
Class< DpVoiceUserTalkingEvent, NoConstructor< DpVoiceUserTalkingEvent > >(vm, SqDppVoiceUserTalkingEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppVoiceUserTalkingEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceUserTalkingEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpVoiceUserTalkingEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceReady"),
|
||||
Class< DpVoiceReadyEvent, NoConstructor< DpVoiceReadyEvent > >(vm, SqDppVoiceReadyEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppVoiceReadyEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceReadyEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpVoiceReadyEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceReceive"),
|
||||
Class< DpVoiceReceiveEvent, NoConstructor< DpVoiceReceiveEvent > >(vm, SqDppVoiceReceiveEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppVoiceReceiveEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceReceiveEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpVoiceReceiveEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceTrackMarker"),
|
||||
Class< DpVoiceTrackMarkerEvent, NoConstructor< DpVoiceTrackMarkerEvent > >(vm, SqDppVoiceTrackMarkerEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppVoiceTrackMarkerEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpVoiceTrackMarkerEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpVoiceTrackMarkerEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("StageInstanceCreate"),
|
||||
Class< DpStageInstanceCreateEvent, NoConstructor< DpStageInstanceCreateEvent > >(vm, SqDppStageInstanceCreateEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppStageInstanceCreateEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpStageInstanceCreateEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpStageInstanceCreateEvent::GetRawEvent)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("StageInstanceDelete"),
|
||||
Class< DpStageInstanceDeleteEvent, NoConstructor< DpStageInstanceDeleteEvent > >(vm, SqDppStageInstanceDeleteEvent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppStageInstanceDeleteEvent::Fn)
|
||||
.Func(_SC("_tostring"), &DpStageInstanceDeleteEvent::GetRawEvent)
|
||||
// Member Properties
|
||||
.Prop(_SC("RawEvent"), &DpStageInstanceDeleteEvent::GetRawEvent)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
File diff suppressed because it is too large
Load Diff
@ -1,146 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Guild.hpp"
|
||||
#include "Library/DPP/Other.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDppGuildMember, _SC("SqDppGuildMember"))
|
||||
SQMOD_DECL_TYPENAME(SqDppGuild, _SC("SqDppGuild"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Table DpGuild::GetMembers() const
|
||||
{
|
||||
Table t(SqVM(), static_cast< SQInteger >(Valid().members.size()));
|
||||
// Attempt to convert the [members] associative container into a script table
|
||||
const auto r = t.InsertFromMapWith(mPtr->members, [](HSQUIRRELVM vm, auto id, auto & m) -> SQRESULT {
|
||||
// The [id] is a dpp::snowflake which is basically a uint64_t so let's leave that as is
|
||||
sq_pushinteger(vm, static_cast< SQInteger >(id));
|
||||
// Wrap the dpp::guild_member type into a DpGuildMember instance
|
||||
ClassType< DpGuildMember >::PushInstance(vm, new DpGuildMember(m));
|
||||
// The elements are now on the stack and can be inserted in the table
|
||||
return SQ_OK;
|
||||
});
|
||||
// Did anything fail?
|
||||
if (SQ_FAILED(r))
|
||||
{
|
||||
STHROWF("Unable to convert [members] container");
|
||||
}
|
||||
// Return the resulted table
|
||||
return t;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Table DpGuild::GetVoiceMembers() const
|
||||
{
|
||||
Table t(SqVM(), static_cast< SQInteger >(Valid().voice_members.size()));
|
||||
// Attempt to convert the [voice_members] associative container into a script table
|
||||
const auto r = t.InsertFromMapWith(mPtr->voice_members, [](HSQUIRRELVM vm, auto id, auto & m) -> SQRESULT {
|
||||
// The [id] is a dpp::snowflake which is basically a uint64_t so let's leave that as is
|
||||
sq_pushinteger(vm, static_cast< SQInteger >(id));
|
||||
// Wrap the dpp::guild_member type into a DpGuildMember instance
|
||||
ClassType< DpVoiceState >::PushInstance(vm, new DpVoiceState(m));
|
||||
// The elements are now on the stack and can be inserted in the table
|
||||
return SQ_OK;
|
||||
});
|
||||
// Did anything fail?
|
||||
if (SQ_FAILED(r))
|
||||
{
|
||||
STHROWF("Unable to convert [voice_members] container");
|
||||
}
|
||||
// Return the resulted table
|
||||
return t;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Guild(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
ns.Bind(_SC("GuildMember"),
|
||||
Class< DpGuildMember, NoConstructor< DpGuildMember > >(vm, SqDppGuildMember::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuildMember::Fn)
|
||||
.Func(_SC("_tojson"), &DpGuildMember::BuildJSON)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpGuildMember::IsValid)
|
||||
.Prop(_SC("JSON"), &DpGuildMember::BuildJSON)
|
||||
.Prop(_SC("Nickname"), &DpGuildMember::GetNickname)
|
||||
.Prop(_SC("GuildID"), &DpGuildMember::GetGuildID)
|
||||
.Prop(_SC("UserID"), &DpGuildMember::GetUserID)
|
||||
.Prop(_SC("JoinedAt"), &DpGuildMember::GetJoinedAt)
|
||||
.Prop(_SC("PremiumSince"), &DpGuildMember::GetPremiumSince)
|
||||
.Prop(_SC("Flags"), &DpGuildMember::GetFlags)
|
||||
.Prop(_SC("IsDeaf"), &DpGuildMember::IsDeaf)
|
||||
.Prop(_SC("IsMuted"), &DpGuildMember::IsMuted)
|
||||
.Prop(_SC("IsPending"), &DpGuildMember::IsPending)
|
||||
// Member Methods
|
||||
.Func(_SC("GetRoles"), &DpGuildMember::GetRoles)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Guild"),
|
||||
Class< DpGuild, NoConstructor< DpGuild > >(vm, SqDppGuild::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppGuild::Fn)
|
||||
.Func(_SC("_tojson"), &DpGuild::BuildJSON)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpGuild::IsValid)
|
||||
.Prop(_SC("JSON"), &DpGuild::BuildJSON)
|
||||
.Prop(_SC("ShardID"), &DpGuild::GetShardID)
|
||||
.Prop(_SC("Flags"), &DpGuild::GetFlags)
|
||||
.Prop(_SC("Name"), &DpGuild::GetName)
|
||||
.Prop(_SC("Description"), &DpGuild::GetDescription)
|
||||
.Prop(_SC("VanityUrlCode"), &DpGuild::GetVanityUrlCode)
|
||||
.Prop(_SC("Icon"), &DpGuild::GetIcon)
|
||||
.Prop(_SC("Splash"), &DpGuild::GetSplash)
|
||||
.Prop(_SC("DiscoverySplash"), &DpGuild::GetDiscoverySplash)
|
||||
.Prop(_SC("OwnerID"), &DpGuild::GetOwnerID)
|
||||
.Prop(_SC("VoiceRegion"), &DpGuild::GetVoiceRegion)
|
||||
.Prop(_SC("AfkChannelID"), &DpGuild::GetAfkChannelID)
|
||||
.Prop(_SC("AfkTimeout"), &DpGuild::GetAfkTimeout)
|
||||
.Prop(_SC("WidgetChannelID"), &DpGuild::GetWidgetChannelID)
|
||||
.Prop(_SC("VerificationLevel"), &DpGuild::GetVerificationLevel)
|
||||
.Prop(_SC("DefaultMessageNotifications"), &DpGuild::GetDefaultMessageNotifications)
|
||||
.Prop(_SC("ExplicitContentFilter"), &DpGuild::GetExplicitContentFilter)
|
||||
.Prop(_SC("MfaLevel"), &DpGuild::GetMfaLevel)
|
||||
.Prop(_SC("ApplicationID"), &DpGuild::GetApplicationID)
|
||||
.Prop(_SC("SystemChannelID"), &DpGuild::GetSystemChannelID)
|
||||
.Prop(_SC("RulesChannelID"), &DpGuild::GetRulesChannelID)
|
||||
.Prop(_SC("MemberCount"), &DpGuild::GetMemberCount)
|
||||
.Prop(_SC("Banner"), &DpGuild::GetBanner)
|
||||
.Prop(_SC("PremiumTier"), &DpGuild::GetPremiumTier)
|
||||
.Prop(_SC("PremiumSubscriptionCount"), &DpGuild::GetPremiumSubscriptionCount)
|
||||
.Prop(_SC("PublicUpdatesChannelID"), &DpGuild::GetPublicUpdatesChannelID)
|
||||
.Prop(_SC("MaxVideoChannelUsers"), &DpGuild::GetMaxVideoChannelUsers)
|
||||
.Prop(_SC("IsLarge"), &DpGuild::IsLarge)
|
||||
.Prop(_SC("IsUnavailable"), &DpGuild::IsUnavailable)
|
||||
.Prop(_SC("WidgetEnabled"), &DpGuild::WidgetEnabled)
|
||||
.Prop(_SC("HasInviteSplash"), &DpGuild::HasInviteSplash)
|
||||
.Prop(_SC("HasVipRegions"), &DpGuild::HasVipRegions)
|
||||
.Prop(_SC("HasVanityURL"), &DpGuild::HasVanityURL)
|
||||
.Prop(_SC("IsVerified"), &DpGuild::IsVerified)
|
||||
.Prop(_SC("IsPartnered"), &DpGuild::IsPartnered)
|
||||
.Prop(_SC("IsCommunity"), &DpGuild::IsCommunity)
|
||||
.Prop(_SC("HasCommerce"), &DpGuild::HasCommerce)
|
||||
.Prop(_SC("HasNews"), &DpGuild::HasNews)
|
||||
.Prop(_SC("IsDiscoverable"), &DpGuild::IsDiscoverable)
|
||||
.Prop(_SC("IsFeatureable"), &DpGuild::IsFeatureable)
|
||||
.Prop(_SC("HasAnimatedIcon"), &DpGuild::HasAnimatedIcon)
|
||||
.Prop(_SC("BasBanner"), &DpGuild::BasBanner)
|
||||
.Prop(_SC("WelcomeScreenEnabled"), &DpGuild::WelcomeScreenEnabled)
|
||||
.Prop(_SC("HasMemberVerificationGate"), &DpGuild::HasMemberVerificationGate)
|
||||
.Prop(_SC("IsPreviewEnabled"), &DpGuild::IsPreviewEnabled)
|
||||
.Prop(_SC("HasAnimatedIconHash"), &DpGuild::HasAnimatedIconHash)
|
||||
// Member Methods
|
||||
.Func(_SC("BuildJSON"), &DpGuild::BuildJSON_)
|
||||
.Func(_SC("GetRoles"), &DpGuild::GetRoles)
|
||||
.Func(_SC("GetChannels"), &DpGuild::GetChannels)
|
||||
.Func(_SC("GetThreads"), &DpGuild::GetThreads)
|
||||
.Func(_SC("GetMembers"), &DpGuild::GetMembers)
|
||||
.Func(_SC("GetVoiceMembers"), &DpGuild::GetVoiceMembers)
|
||||
.Func(_SC("GetEmojis"), &DpGuild::GetEmojis)
|
||||
.Func(_SC("RehashMembers"), &DpGuild::RehashMembers)
|
||||
.Func(_SC("ConnectMemberVoice"), &DpGuild::ConnectMemberVoice)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,478 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the gickname, or empty string if they don't have a nickname on this guild.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetNickname() const { return Valid().nickname; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild id.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetGuildID() const { return Valid().guild_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the user id.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetUserID() const { return Valid().user_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* 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 date and time since 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 has boosted the guild guild.
|
||||
*/
|
||||
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 set of flags built from the bitmask defined by dpp::guild_member_flags.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return static_cast< SQInteger >(Valid().flags); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build JSON string for the member object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is deafened.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsDeaf() const { return Valid().is_deaf(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is muted.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsMuted() const { return Valid().is_muted(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is pending verification by membership screening.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsPending() const { return Valid().is_pending(); }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the shard ID of the guild.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetShardID() const { return static_cast< SQInteger >(Valid().shard_id); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the flags bitmask as defined by values within dpp::guild_flags.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return static_cast< SQInteger >(Valid().flags); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild name.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetName() const { return Valid().name; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the server description for communities.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetDescription() const { return Valid().description; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the vanity url code for verified or partnered servers and boost level 3.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetVanityUrlCode() const { return Valid().vanity_url_code; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild icon hash.
|
||||
*/
|
||||
SQMOD_NODISCARD const dpp::utility::iconhash & GetIcon() const { return Valid().icon; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild splash hash.
|
||||
*/
|
||||
SQMOD_NODISCARD const dpp::utility::iconhash & GetSplash() const { return Valid().splash; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild discovery splash hash.
|
||||
*/
|
||||
SQMOD_NODISCARD const dpp::utility::iconhash & GetDiscoverySplash() const { return Valid().discovery_splash; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the snowflake id of guild owner.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetOwnerID() const { return Valid().owner_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild voice region.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetVoiceRegion() const { return static_cast< SQInteger >(Valid().voice_region); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the snowflake ID of AFK voice channel or 0.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetAfkChannelID() const { return Valid().afk_channel_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the voice AFK timeout before moving users to AFK channel.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetAfkTimeout() const { return static_cast< SQInteger >(Valid().afk_timeout); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the snowflake ID of widget channel, or 0.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetWidgetChannelID() const { return Valid().widget_channel_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the verification level of server.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetVerificationLevel() const { return static_cast< SQInteger >(Valid().verification_level); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the setting for how notifications are to be delivered to users.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetDefaultMessageNotifications() const { return static_cast< SQInteger >(Valid().default_message_notifications); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether or not explicit content filtering is enable and what setting it is.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetExplicitContentFilter() const { return static_cast< SQInteger >(Valid().explicit_content_filter); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether multi factor authentication is required for moderators or not.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetMfaLevel() const { return static_cast< SQInteger >(Valid().mfa_level); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the ID of creating application, if any, or 0.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetApplicationID() const { return Valid().application_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the ID of system channel where discord update messages are sent.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetSystemChannelID() const { return Valid().system_channel_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the ID of rules channel for communities.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetRulesChannelID() const { return Valid().rules_channel_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the approximate member count. May be sent as zero.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetMemberCount() const { return static_cast< SQInteger >(Valid().member_count); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the server banner hash.
|
||||
*/
|
||||
SQMOD_NODISCARD const dpp::utility::iconhash & GetBanner() const { return Valid().banner; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the boost level.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetPremiumTier() const { return static_cast< SQInteger >(Valid().premium_tier); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of boosters.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetPremiumSubscriptionCount() const { return static_cast< SQInteger >(Valid().premium_subscription_count); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve public updates channel ID or 0.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetPublicUpdatesChannelID() const { return Valid().public_updates_channel_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the maximum users in a video channel, or 0.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetMaxVideoChannelUsers() const { return static_cast< SQInteger >(Valid().max_video_channel_users); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a roles defined on this server.
|
||||
*/
|
||||
SQMOD_NODISCARD Array GetRoles() const { return Array(SqVM()).Reserve(static_cast< SQInteger >(Valid().roles.size())).AppendFromVector(Valid().roles); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a list of channels on this server.
|
||||
*/
|
||||
SQMOD_NODISCARD Array GetChannels() const { return Array(SqVM()).Reserve(static_cast< SQInteger >(Valid().channels.size())).AppendFromVector(Valid().channels); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a list of threads on this server.
|
||||
*/
|
||||
SQMOD_NODISCARD Array GetThreads() const { return Array(SqVM()).Reserve(static_cast< SQInteger >(Valid().threads.size())).AppendFromVector(Valid().threads); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a list of guild members. Note that when you first receive the guild create event,
|
||||
* this may be empty or near empty. This depends upon your dpp::intents and the size of your bot.
|
||||
* It will be filled by guild member chunk requests.
|
||||
*/
|
||||
SQMOD_NODISCARD Table GetMembers() const;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a list of members in voice channels in the guild.
|
||||
*/
|
||||
SQMOD_NODISCARD Table GetVoiceMembers() const;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a list of emojis.
|
||||
*/
|
||||
SQMOD_NODISCARD Array GetEmojis() const { return Array(SqVM()).Reserve(static_cast< SQInteger >(Valid().emojis.size())).AppendFromVector(Valid().emojis); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build a JSON string from this object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build a JSON string from this object. If [with_id] is True then ID is to be included in the JSON.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON_(bool with_id) const { return Valid().build_json(with_id); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Rehash members map.
|
||||
*/
|
||||
SQMOD_NODISCARD DpGuild & RehashMembers() { Valid().rehash_members(); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Connect to a voice channel another guild member is in.
|
||||
* Returns true if the user specified is in a voice channel, false if they aren't.
|
||||
*/
|
||||
SQMOD_NODISCARD bool ConnectMemberVoice(SQInteger user_id) const { return Valid().connect_member_voice(user_id); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Is a large server (>250 users).
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsLarge() const { return Valid().is_large(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Is unavailable due to outage (most other fields will be blank or outdated).
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsUnavailable() const { return Valid().is_unavailable(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Widget is enabled for this server.
|
||||
*/
|
||||
SQMOD_NODISCARD bool WidgetEnabled() const { return Valid().widget_enabled(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild has an invite splash.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasInviteSplash() const { return Valid().has_invite_splash(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild has VIP regions.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasVipRegions() const { return Valid().has_vip_regions(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild can have a vanity URL.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasVanityURL() const { return Valid().has_vanity_url(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild is a verified server.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsVerified() const { return Valid().is_verified(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild is a discord partner server.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsPartnered() const { return Valid().is_partnered(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild has enabled community.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsCommunity() const { return Valid().is_community(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild has enabled commerce channels.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasCommerce() const { return Valid().has_commerce(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild has news channel.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasNews() const { return Valid().has_news(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild is discoverable.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsDiscoverable() const { return Valid().is_discoverable(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild is featureable.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsFeatureable() const { return Valid().is_featureable(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild is allowed an animated icon.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasAnimatedIcon() const { return Valid().has_animated_icon(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild has a banner image.
|
||||
*/
|
||||
SQMOD_NODISCARD bool BasBanner() const { return Valid().has_banner(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild has enabled welcome screen.
|
||||
*/
|
||||
SQMOD_NODISCARD bool WelcomeScreenEnabled() const { return Valid().is_welcome_screen_enabled(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild has enabled membership screening.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasMemberVerificationGate() const { return Valid().has_member_verification_gate(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Guild has preview enabled.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsPreviewEnabled() const { return Valid().is_preview_enabled(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Server icon is actually an animated gif.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasAnimatedIconHash() const { return Valid().has_animated_icon_hash(); }
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,16 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Integration.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Integration(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,19 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,242 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Message.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDppSelectOption, _SC("SqDppSelectOption"))
|
||||
SQMOD_DECL_TYPENAME(SqDppSelectOptions, _SC("SqDppSelectOptions"))
|
||||
SQMOD_DECL_TYPENAME(SqDppComponent, _SC("SqDppComponent"))
|
||||
SQMOD_DECL_TYPENAME(SqDppComponents, _SC("SqDppComponents"))
|
||||
SQMOD_DECL_TYPENAME(SqDppEmbedFooter, _SC("SqDppEmbedFooter"))
|
||||
SQMOD_DECL_TYPENAME(SqDppEmbedImage, _SC("SqDppEmbedImage"))
|
||||
SQMOD_DECL_TYPENAME(SqDppEmbedProvider, _SC("SqDppEmbedProvider"))
|
||||
SQMOD_DECL_TYPENAME(SqDppEmbedAuthor, _SC("SqDppEmbedAuthor"))
|
||||
SQMOD_DECL_TYPENAME(SqDppEmbedField, _SC("SqDppEmbedField"))
|
||||
SQMOD_DECL_TYPENAME(SqDppEmbed, _SC("SqDppEmbed"))
|
||||
SQMOD_DECL_TYPENAME(SqDppReaction, _SC("SqDppReaction"))
|
||||
SQMOD_DECL_TYPENAME(SqDppAttachment, _SC("SqDppAttachment"))
|
||||
SQMOD_DECL_TYPENAME(SqDppSticker, _SC("SqDppSticker"))
|
||||
SQMOD_DECL_TYPENAME(SqDppStickerPack, _SC("SqDppStickerPack"))
|
||||
SQMOD_DECL_TYPENAME(SqDppMessage, _SC("SqDppMessage"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Message(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("SelectOption"),
|
||||
Class< DpSelectOption, NoCopy< DpSelectOption > >(vm, SqDppSelectOption::Str)
|
||||
.Ctor()
|
||||
.Ctor< StackStrF &, StackStrF &, StackStrF & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppSelectOption::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpSelectOption::IsValid)
|
||||
.Prop(_SC("Label"), &DpSelectOption::GetLabel, &DpSelectOption::SetLabel)
|
||||
.Prop(_SC("Value"), &DpSelectOption::GetValue, &DpSelectOption::SetValue)
|
||||
.Prop(_SC("Description"), &DpSelectOption::GetDescription, &DpSelectOption::SetDescription)
|
||||
.Prop(_SC("IsDefault"), &DpSelectOption::IsDefault, &DpSelectOption::SetDefault)
|
||||
.Prop(_SC("IsAnimated"), &DpSelectOption::IsAnimated, &DpSelectOption::SetAnimated)
|
||||
.Prop(_SC("EmojiName"), &DpSelectOption::GetEmojiName, &DpSelectOption::SetEmojiName)
|
||||
.Prop(_SC("EmojiID"), &DpSelectOption::GetEmojiID, &DpSelectOption::SetEmojiID)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetLabel"), &DpSelectOption::ApplyLabel)
|
||||
.FmtFunc(_SC("SetValue"), &DpSelectOption::ApplyValue)
|
||||
.FmtFunc(_SC("SetDescription"), &DpSelectOption::ApplyDescription)
|
||||
.FmtFunc(_SC("SetEmoji"), &DpSelectOption::SetEmoji)
|
||||
.FmtFunc(_SC("SetDefault"), &DpSelectOption::SetDefault)
|
||||
.FmtFunc(_SC("SetAnimated"), &DpSelectOption::SetAnimated)
|
||||
.FmtFunc(_SC("SetEmojiName"), &DpSelectOption::ApplyEmojiName)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Register_DPP_VectorProxy< dpp::select_option, DpSelectOption, SqDppSelectOptions >(vm, ns, _SC("SelectOptions"));
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Component"),
|
||||
Class< DpComponent, NoConstructor< DpComponent > >(vm, SqDppComponent::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppComponent::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpComponent::IsValid)
|
||||
.Prop(_SC("JSON"), &DpComponent::BuildJSON)
|
||||
.Prop(_SC("Type"), &DpComponent::GetType, &DpComponent::SetType)
|
||||
.Prop(_SC("Label"), &DpComponent::GetLabel, &DpComponent::SetLabel)
|
||||
.Prop(_SC("Style"), &DpComponent::GetStyle, &DpComponent::SetStyle)
|
||||
.Prop(_SC("CustomID"), &DpComponent::GetCustomID, &DpComponent::SetCustomID)
|
||||
.Prop(_SC("URL"), &DpComponent::GetURL, &DpComponent::SetURL)
|
||||
.Prop(_SC("Placeholder"), &DpComponent::GetPlaceholder, &DpComponent::SetPlaceholder)
|
||||
.Prop(_SC("MinValues"), &DpComponent::GetMinValues, &DpComponent::SetMinValues)
|
||||
.Prop(_SC("MaxValues"), &DpComponent::GetMaxValues, &DpComponent::SetMaxValues)
|
||||
.Prop(_SC("Disabled"), &DpComponent::IsDisabled, &DpComponent::SetDisabled)
|
||||
.Prop(_SC("IsAnimated"), &DpComponent::IsAnimated, &DpComponent::SetAnimated)
|
||||
.Prop(_SC("EmojiName"), &DpComponent::GetEmojiName, &DpComponent::SetEmojiName)
|
||||
.Prop(_SC("EmojiID"), &DpComponent::GetEmojiID, &DpComponent::SetEmojiID)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetLabel"), &DpComponent::ApplyLabel)
|
||||
.FmtFunc(_SC("SetCustomID"), &DpComponent::ApplyCustomID)
|
||||
.FmtFunc(_SC("SetURL"), &DpComponent::ApplyURL)
|
||||
.FmtFunc(_SC("SetPlaceholder"), &DpComponent::ApplyPlaceholder)
|
||||
.FmtFunc(_SC("SetDisabled"), &DpComponent::SetDisabled)
|
||||
.FmtFunc(_SC("SetAnimated"), &DpComponent::SetAnimated)
|
||||
.FmtFunc(_SC("SetEmojiName"), &DpComponent::ApplyEmojiName)
|
||||
.FmtFunc(_SC("GetComponents"), &DpComponent::GetComponents)
|
||||
.FmtFunc(_SC("GetOptions"), &DpComponent::GetOptions)
|
||||
.FmtFunc(_SC("AddComponent"), &DpComponent::AddComponent)
|
||||
.FmtFunc(_SC("AddOption"), &DpComponent::AddSelectOption)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Register_DPP_VectorProxy< dpp::component, DpComponent, SqDppComponent >(vm, ns, _SC("Components"));
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedFooter"),
|
||||
Class< DpEmbedFooter, NoConstructor< DpEmbedFooter > >(vm, SqDppEmbedFooter::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedFooter::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedFooter::IsValid)
|
||||
.Prop(_SC("Text"), &DpEmbedFooter::GetText, &DpEmbedFooter::SetText)
|
||||
.Prop(_SC("Icon"), &DpEmbedFooter::GetIconURL, &DpEmbedFooter::SetIconURL)
|
||||
.Prop(_SC("Proxy"), &DpEmbedFooter::GetProxyURL, &DpEmbedFooter::SetProxyURL)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetText"), &DpEmbedFooter::ApplyText)
|
||||
.FmtFunc(_SC("SetIcon"), &DpEmbedFooter::ApplyIconURL)
|
||||
.FmtFunc(_SC("SetProxy"), &DpEmbedFooter::ApplyProxyURL)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedImage"),
|
||||
Class< DpEmbedImage, NoConstructor< DpEmbedImage > >(vm, SqDppEmbedImage::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedImage::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedImage::IsValid)
|
||||
.Prop(_SC("URL"), &DpEmbedImage::GetURL, &DpEmbedImage::SetURL)
|
||||
.Prop(_SC("Proxy"), &DpEmbedImage::GetProxyURL, &DpEmbedImage::SetProxyURL)
|
||||
.Prop(_SC("Height"), &DpEmbedImage::GetHeight, &DpEmbedImage::SetHeight)
|
||||
.Prop(_SC("Width"), &DpEmbedImage::GetWidth, &DpEmbedImage::SetWidth)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetURL"), &DpEmbedImage::ApplyURL)
|
||||
.FmtFunc(_SC("SetProxy"), &DpEmbedImage::ApplyProxyURL)
|
||||
.FmtFunc(_SC("SetHeight"), &DpEmbedImage::ApplyHeight)
|
||||
.FmtFunc(_SC("SetWidth"), &DpEmbedImage::ApplyWidth)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedProvider"),
|
||||
Class< DpEmbedProvider, NoConstructor< DpEmbedProvider > >(vm, SqDppEmbedProvider::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedProvider::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedProvider::IsValid)
|
||||
.Prop(_SC("Name"), &DpEmbedProvider::GetName, &DpEmbedProvider::SetName)
|
||||
.Prop(_SC("URL"), &DpEmbedProvider::GetURL, &DpEmbedProvider::SetURL)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetName"), &DpEmbedProvider::ApplyName)
|
||||
.FmtFunc(_SC("SetURL"), &DpEmbedProvider::ApplyURL)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedAuthor"),
|
||||
Class< DpEmbedAuthor, NoConstructor< DpEmbedAuthor > >(vm, SqDppEmbedAuthor::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedAuthor::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedAuthor::IsValid)
|
||||
.Prop(_SC("Name"), &DpEmbedAuthor::GetName, &DpEmbedAuthor::SetName)
|
||||
.Prop(_SC("URL"), &DpEmbedAuthor::GetURL, &DpEmbedAuthor::SetURL)
|
||||
.Prop(_SC("Icon"), &DpEmbedAuthor::GetIconURL, &DpEmbedAuthor::SetIconURL)
|
||||
.Prop(_SC("ProxyIcon"), &DpEmbedAuthor::GetProxyIconURL, &DpEmbedAuthor::SetProxyIconURL)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetName"), &DpEmbedAuthor::ApplyName)
|
||||
.FmtFunc(_SC("SetURL"), &DpEmbedAuthor::ApplyURL)
|
||||
.FmtFunc(_SC("SetIcon"), &DpEmbedAuthor::ApplyIconURL)
|
||||
.FmtFunc(_SC("SetProxyIcon"), &DpEmbedAuthor::ApplyProxyIconURL)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedField"),
|
||||
Class< DpEmbedField, NoConstructor< DpEmbedField > >(vm, SqDppEmbedField::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbedField::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbedField::IsValid)
|
||||
.Prop(_SC("Name"), &DpEmbedField::GetName, &DpEmbedField::SetName)
|
||||
.Prop(_SC("Value"), &DpEmbedField::GetValue, &DpEmbedField::SetValue)
|
||||
.Prop(_SC("Inline"), &DpEmbedField::IsInline, &DpEmbedField::SetInline)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetName"), &DpEmbedField::ApplyName)
|
||||
.FmtFunc(_SC("SetValue"), &DpEmbedField::ApplyValue)
|
||||
.FmtFunc(_SC("SetInline"), &DpEmbedField::SetInline)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Embed"),
|
||||
Class< DpEmbed, NoConstructor< DpEmbed > >(vm, SqDppEmbed::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppEmbed::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpEmbed::IsValid)
|
||||
.Prop(_SC("Title"), &DpEmbed::GetTitle, &DpEmbed::SetTitle)
|
||||
.Prop(_SC("Type"), &DpEmbed::GetType, &DpEmbed::SetType)
|
||||
.Prop(_SC("Description"), &DpEmbed::GetDescription, &DpEmbed::SetDescription)
|
||||
.Prop(_SC("URL"), &DpEmbed::GetURL, &DpEmbed::SetURL)
|
||||
.Prop(_SC("TimeStamp"), &DpEmbed::GetTimeStamp, &DpEmbed::SetTimeStamp)
|
||||
.Prop(_SC("Color"), &DpEmbed::GetColor, &DpEmbed::SetColor)
|
||||
.Prop(_SC("Footer"), &DpEmbed::GetFooter, &DpEmbed::SetFooter)
|
||||
.Prop(_SC("Image"), &DpEmbed::GetImage, &DpEmbed::SetImage)
|
||||
.Prop(_SC("Thumbnail"), &DpEmbed::GetThumbnail, &DpEmbed::SetThumbnail)
|
||||
.Prop(_SC("Video"), &DpEmbed::GetVideo, &DpEmbed::SetVideo)
|
||||
.Prop(_SC("Provider"), &DpEmbed::GetProvider, &DpEmbed::SetProvider)
|
||||
.Prop(_SC("Author"), &DpEmbed::GetAuthor, &DpEmbed::SetAuthor)
|
||||
.Prop(_SC("Fields"), &DpEmbed::GetFields)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("SetTitle"), &DpEmbed::ApplyTitle)
|
||||
.FmtFunc(_SC("SetType"), &DpEmbed::ApplyType)
|
||||
.FmtFunc(_SC("SetDescription"), &DpEmbed::ApplyDescription)
|
||||
.FmtFunc(_SC("SetURL"), &DpEmbed::ApplyURL)
|
||||
.FmtFunc(_SC("SetTimeStamp"), &DpEmbed::ApplyTimeStamp)
|
||||
.FmtFunc(_SC("SetFooter"), &DpEmbed::ApplyFooter)
|
||||
.FmtFunc(_SC("SetImage"), &DpEmbed::ApplyImage)
|
||||
.FmtFunc(_SC("SetThumbnail"), &DpEmbed::ApplyThumbnail)
|
||||
.FmtFunc(_SC("SetVideo"), &DpEmbed::ApplyVideo)
|
||||
.FmtFunc(_SC("SetProvider"), &DpEmbed::ApplyProvider)
|
||||
.FmtFunc(_SC("SetAuthor"), &DpEmbed::ApplyAuthor)
|
||||
.FmtFunc(_SC("AddField"), &DpEmbed::AddField)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Reaction"),
|
||||
Class< DpReaction, NoConstructor< DpReaction > >(vm, SqDppReaction::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppReaction::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpReaction::IsValid)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Attachment"),
|
||||
Class< DpAttachment, NoConstructor< DpAttachment > >(vm, SqDppAttachment::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppAttachment::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpAttachment::IsValid)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Sticker"),
|
||||
Class< DpSticker, NoConstructor< DpSticker > >(vm, SqDppSticker::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppSticker::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpSticker::IsValid)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("StickerPack"),
|
||||
Class< DpStickerPack, NoConstructor< DpStickerPack > >(vm, SqDppStickerPack::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppStickerPack::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpStickerPack::IsValid)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Message"),
|
||||
Class< DpMessage, NoConstructor< DpMessage > >(vm, SqDppMessage::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppMessage::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpMessage::IsValid)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
File diff suppressed because it is too large
Load Diff
@ -1,141 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Other.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDppCachePolicy, _SC("SqDppCachePolicy"))
|
||||
SQMOD_DECL_TYPENAME(SqDppIconHash, _SC("SqDppIconHash"))
|
||||
SQMOD_DECL_TYPENAME(SqDppUptime, _SC("SqDppUptime"))
|
||||
SQMOD_DECL_TYPENAME(SqDppActivity, _SC("SqDppActivity"))
|
||||
SQMOD_DECL_TYPENAME(SqDppPresence, _SC("SqDppPresence"))
|
||||
SQMOD_DECL_TYPENAME(SqDppVoiceState, _SC("SqDppVoiceState"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Other(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Uptime"),
|
||||
Class< dpp::utility::uptime >(vm, SqDppUptime::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppUptime::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, SqDppIconHash::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< const std::string & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppIconHash::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, SqDppCachePolicy::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< SQInteger >()
|
||||
.Ctor< SQInteger, SQInteger >()
|
||||
.Ctor< SQInteger, SQInteger, SQInteger >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppCachePolicy::Fn)
|
||||
// Member Variables
|
||||
.Var(_SC("UserPolicy"), &DpCachePolicy::mUserPolicy)
|
||||
.Var(_SC("EmojiPolicy"), &DpCachePolicy::mEmojiPolicy)
|
||||
.Var(_SC("RolePolicy"), &DpCachePolicy::mRolePolicy)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Activity"),
|
||||
Class< DpActivity, NoCopy< DpActivity > >(vm, SqDppActivity::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< SQInteger, StackStrF &, StackStrF &, StackStrF & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppActivity::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Name"), &DpActivity::GetName, &DpActivity::SetName)
|
||||
.Prop(_SC("State"), &DpActivity::GetState, &DpActivity::SetState)
|
||||
.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)
|
||||
// Member Methods
|
||||
.Func(_SC("SetName"), &DpActivity::ApplyName)
|
||||
.Func(_SC("SetState"), &DpActivity::ApplyState)
|
||||
.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)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("Presence"),
|
||||
Class< DpPresence, NoCopy< DpPresence > >(vm, SqDppPresence::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppPresence::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpPresence::IsValid)
|
||||
.Prop(_SC("UserID"), &DpPresence::GetUserID, &DpPresence::SetUserID)
|
||||
.Prop(_SC("GuildID"), &DpPresence::GetGuildID, &DpPresence::SetGuildID)
|
||||
.Prop(_SC("Flags"), &DpPresence::GetFlags, &DpPresence::SetFlags)
|
||||
.Prop(_SC("ActivityCount"), &DpPresence::ActivityCount)
|
||||
.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("AddActivity"), &DpPresence::AddActivity)
|
||||
.Func(_SC("EachActivity"), &DpPresence::EachActivity)
|
||||
.Func(_SC("ClearActivities"), &DpPresence::ClearActivities)
|
||||
.Func(_SC("FilterActivities"), &DpPresence::FilterActivities)
|
||||
.Func(_SC("BuildJSON"), &DpPresence::BuildJSON)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("VoiceState"),
|
||||
Class< DpVoiceState, NoConstructor< DpVoiceState > >(vm, SqDppVoiceState::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppVoiceState::Fn)
|
||||
.Func(_SC("_tojson"), &DpVoiceState::BuildJSON)
|
||||
// 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("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)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,607 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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)
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* 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()
|
||||
{
|
||||
// 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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
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 url of the activity.
|
||||
*/
|
||||
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 type of the activity.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetType() const { return static_cast< SQInteger >(Valid().type); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the type of the activity.
|
||||
*/
|
||||
void SetType(SQInteger s) const { Valid().type = static_cast< dpp::activity_type >(s); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the type of the activity.
|
||||
*/
|
||||
DpActivity & ApplyType(SQInteger s) { SetType(s); 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; }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* 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)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* 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()
|
||||
{
|
||||
// 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 number of activities.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger ActivityCount() const { return static_cast< SQInteger >(Valid().activities.size()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Add a new activity.
|
||||
*/
|
||||
DpPresence & AddActivity(const DpActivity & a) { Valid().activities.push_back(a.Valid()); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate all activities.
|
||||
*/
|
||||
DpPresence & EachActivity(Function & fn)
|
||||
{
|
||||
for (const auto & a : Valid().activities)
|
||||
{
|
||||
fn.Execute(a);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of activities.
|
||||
*/
|
||||
DpPresence & ClearActivities(const DpActivity & a) { Valid().activities.clear(); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Filter activities.
|
||||
*/
|
||||
DpPresence & FilterActivities(Function & fn)
|
||||
{
|
||||
std::vector< dpp::activity > list;
|
||||
// Reserve memory in advance
|
||||
list.reserve(Valid().activities.size());
|
||||
// Process each activity individually
|
||||
for (const auto & a : Valid().activities)
|
||||
{
|
||||
auto ret = fn.Eval(a);
|
||||
// (null || true) == keep & false == skip
|
||||
if (!ret.IsNull() || !ret.template Cast< bool >())
|
||||
{
|
||||
list.push_back(a); // Keep this activity
|
||||
}
|
||||
}
|
||||
// Use filtered activities
|
||||
Valid().activities.swap(list);
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build JSON string from this object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* 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()); }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* 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 guild id this voice state is for (optional).
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetChannelID() const { return Valid().channel_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild id this voice state is for (optional).
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetUserID() const { return Valid().user_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild id this voice state is for (optional).
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetSessionID() const { return Valid().session_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild id this voice state is for (optional).
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return Valid().flags; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild id this voice state is for (optional).
|
||||
*/
|
||||
void SetFlags(SQInteger flags) const { Valid().flags = flags; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the guild id this voice state is for (optional).
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if user is deafened.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsDeaf() const { return Valid().is_deaf(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if user is muted.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsMute() const { return Valid().is_mute(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if user muted themselves.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsSelfMute() const { return Valid().is_self_mute(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if user deafened themselves.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsSelfDeaf() const { return Valid().is_self_deaf(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if user is streamig.
|
||||
*/
|
||||
SQMOD_NODISCARD bool SelfStream() const { return Valid().self_stream(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if user is in video.
|
||||
*/
|
||||
SQMOD_NODISCARD bool SelfVideo() const { return Valid().self_video(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if user is surpressed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsSuppressed() const { return Valid().is_suppressed(); }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,74 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Role.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDppRole, _SC("SqDppRole"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_Role(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
ns.Bind(_SC("Role"),
|
||||
Class< DpRole, NoConstructor< DpRole > >(vm, SqDppRole::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppRole::Fn)
|
||||
.Func(_SC("_tojson"), &DpRole::BuildJSON)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpRole::IsValid)
|
||||
.Prop(_SC("JSON"), &DpRole::BuildJSON)
|
||||
.Prop(_SC("Name"), &DpRole::GetName)
|
||||
.Prop(_SC("GuildID"), &DpRole::GetGuildID)
|
||||
.Prop(_SC("Color"), &DpRole::GetColour)
|
||||
.Prop(_SC("Colour"), &DpRole::GetColour)
|
||||
.Prop(_SC("Position"), &DpRole::GetPosition)
|
||||
.Prop(_SC("Permissions"), &DpRole::GetPermissions)
|
||||
.Prop(_SC("Flags"), &DpRole::GetFlags)
|
||||
.Prop(_SC("IntegrationID"), &DpRole::GetIntegrationID)
|
||||
.Prop(_SC("BotID"), &DpRole::GetBotID)
|
||||
.Prop(_SC("IsHoisted"), &DpRole::IsHoisted)
|
||||
.Prop(_SC("IsMentionable"), &DpRole::IsMentionable)
|
||||
.Prop(_SC("IsManaged"), &DpRole::IsManaged)
|
||||
.Prop(_SC("CanCreateInstantInvite"), &DpRole::CanCreateInstantInvite)
|
||||
.Prop(_SC("CanKickMembers"), &DpRole::CanKickMembers)
|
||||
.Prop(_SC("CanBanMembers"), &DpRole::CanBanMembers)
|
||||
.Prop(_SC("IsAdministrator"), &DpRole::IsAdministrator)
|
||||
.Prop(_SC("CanManageChannels"), &DpRole::CanManageChannels)
|
||||
.Prop(_SC("CanManageGuild"), &DpRole::CanManageGuild)
|
||||
.Prop(_SC("CanAddReactions"), &DpRole::CanAddReactions)
|
||||
.Prop(_SC("CanViewAuditLog"), &DpRole::CanViewAuditLog)
|
||||
.Prop(_SC("IsPrioritySpeaker"), &DpRole::IsPrioritySpeaker)
|
||||
.Prop(_SC("CanStream"), &DpRole::CanStream)
|
||||
.Prop(_SC("CanViewChannel"), &DpRole::CanViewChannel)
|
||||
.Prop(_SC("CanSendMessages"), &DpRole::CanSendMessages)
|
||||
.Prop(_SC("CanSendTtsMessages"), &DpRole::CanSendTtsMessages)
|
||||
.Prop(_SC("CanManageMessages"), &DpRole::CanManageMessages)
|
||||
.Prop(_SC("CanEmbedLinks"), &DpRole::CanEmbedLinks)
|
||||
.Prop(_SC("CanAttachFiles"), &DpRole::CanAttachFiles)
|
||||
.Prop(_SC("CanReadMessageHistory"), &DpRole::CanReadMessageHistory)
|
||||
.Prop(_SC("CanMentionEveryone"), &DpRole::CanMentionEveryone)
|
||||
.Prop(_SC("CanUseExternalEmojis"), &DpRole::CanUseExternalEmojis)
|
||||
.Prop(_SC("CanViewGuildInsights"), &DpRole::CanViewGuildInsights)
|
||||
.Prop(_SC("CanConnect"), &DpRole::CanConnect)
|
||||
.Prop(_SC("CanSpeak"), &DpRole::CanSpeak)
|
||||
.Prop(_SC("CanMuteMembers"), &DpRole::CanMuteMembers)
|
||||
.Prop(_SC("CanDeafenMembers"), &DpRole::CanDeafenMembers)
|
||||
.Prop(_SC("CanMoveMembers"), &DpRole::CanMoveMembers)
|
||||
.Prop(_SC("CanUseVAT"), &DpRole::CanUseVAT)
|
||||
.Prop(_SC("CanChangeNickname"), &DpRole::CanChangeNickname)
|
||||
.Prop(_SC("CanManageNicknames"), &DpRole::CanManageNicknames)
|
||||
.Prop(_SC("CanManageRoles"), &DpRole::CanManageRoles)
|
||||
.Prop(_SC("CanManageWebhooks"), &DpRole::CanManageWebhooks)
|
||||
.Prop(_SC("CanManageEmojis"), &DpRole::CanManageEmojis)
|
||||
.Prop(_SC("CanUseSlashCommands"), &DpRole::CanUseSlashCommands)
|
||||
.Prop(_SC("HasRequestToSpeak"), &DpRole::HasRequestToSpeak)
|
||||
.Prop(_SC("CanManageThreads"), &DpRole::CanManageThreads)
|
||||
.Prop(_SC("HasUsePublicThreads"), &DpRole::HasUsePublicThreads)
|
||||
.Prop(_SC("HasUsePrivateThreads"), &DpRole::HasUsePrivateThreads)
|
||||
// Member Methods
|
||||
.Func(_SC("BuildJSON"), &DpRole::BuildJSON_)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,301 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Represents a role within a DpGuild.
|
||||
*/
|
||||
struct DpRole
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::role >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced role instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpRole() noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpRole(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpRole(const Ptr::element_type & o) noexcept
|
||||
: DpRole(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpRole(Ptr::element_type && o) noexcept
|
||||
: DpRole(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpRole(const DpRole & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpRole(DpRole && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpRole() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpRole & operator = (const DpRole & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpRole & operator = (DpRole && 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 role 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 role name.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetName() const { return Valid().name; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the role guild id.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetGuildID() const { return Valid().guild_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the role colour.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetColour() const { return static_cast< SQInteger >(Valid().colour); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the role position.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetPosition() const { return static_cast< SQInteger >(Valid().position); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the role permissions bitmask values from SqDiscordRolePermissions.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetPermissions() const { return static_cast< SQInteger >(Valid().permissions); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the role flags from SqDiscordRoleFlags.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return static_cast< SQInteger >(Valid().flags); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the role integration id if any (e.g. role is a bot's role created when it was invited).
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetIntegrationID() const { return Valid().integration_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the role bot id if any (e.g. role is a bot's role created when it was invited).
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetBotID() const { return Valid().bot_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build a JSON string from this object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build a JSON string from this object. If [with_id] is True then ID is to be included in the JSON.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON_(bool with_id) const { return Valid().build_json(with_id); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role is hoisted.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsHoisted() const { return Valid().is_hoisted(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role is mentionable.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsMentionable() const { return Valid().is_mentionable(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role is managed (belongs to a bot or application).
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsManaged() const { return Valid().is_managed(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has create instant invite permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanCreateInstantInvite() const { return Valid().has_create_instant_invite(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the kick members permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanKickMembers() const { return Valid().has_kick_members(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the ban members permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanBanMembers() const { return Valid().has_ban_members(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the administrator permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsAdministrator() const { return Valid().has_administrator(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the manage channels permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanManageChannels() const { return Valid().has_manage_channels(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the manage guild permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanManageGuild() const { return Valid().has_manage_guild(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the add reactions permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanAddReactions() const { return Valid().has_add_reactions(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the view audit log permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanViewAuditLog() const { return Valid().has_view_audit_log(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the priority speaker permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsPrioritySpeaker() const { return Valid().has_priority_speaker(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the stream permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanStream() const { return Valid().has_stream(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the view channel permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanViewChannel() const { return Valid().has_view_channel(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the send messages permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanSendMessages() const { return Valid().has_send_messages(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the send TTS messages permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanSendTtsMessages() const { return Valid().has_send_tts_messages(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the manage messages permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanManageMessages() const { return Valid().has_manage_messages(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the embed links permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanEmbedLinks() const { return Valid().has_embed_links(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the attach files permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanAttachFiles() const { return Valid().has_attach_files(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the read message history permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanReadMessageHistory() const { return Valid().has_read_message_history(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the mention \@everyone and \@here permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanMentionEveryone() const { return Valid().has_mention_everyone(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the use external emojis permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanUseExternalEmojis() const { return Valid().has_use_external_emojis(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the view guild insights permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanViewGuildInsights() const { return Valid().has_view_guild_insights(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the connect voice permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanConnect() const { return Valid().has_connect(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the speak permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanSpeak() const { return Valid().has_speak(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the mute members permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanMuteMembers() const { return Valid().has_mute_members(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the deafen members permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanDeafenMembers() const { return Valid().has_deafen_members(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the move members permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanMoveMembers() const { return Valid().has_move_members(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has use voice activity detection permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanUseVAT() const { return Valid().has_use_vad(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the change nickname permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanChangeNickname() const { return Valid().has_change_nickname(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the manage nicknames permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanManageNicknames() const { return Valid().has_manage_nicknames(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the manage roles permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanManageRoles() const { return Valid().has_manage_roles(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the manage webhooks permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanManageWebhooks() const { return Valid().has_manage_webhooks(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the manage emojis permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanManageEmojis() const { return Valid().has_manage_emojis(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the use slash commands permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanUseSlashCommands() const { return Valid().has_use_slash_commands(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the request to speak permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasRequestToSpeak() const { return Valid().has_request_to_speak(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the manage threads permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool CanManageThreads() const { return Valid().has_manage_threads(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the use public threads permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasUsePublicThreads() const { return Valid().has_use_public_threads(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the role has the use private threads permission.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasUsePrivateThreads() const { return Valid().has_use_private_threads(); }
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,48 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/User.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqDppUser, _SC("SqDppUser"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Register_DPP_User(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
ns.Bind(_SC("User"),
|
||||
Class< DpUser, NoConstructor< DpUser > >(vm, SqDppUser::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqDppUser::Fn)
|
||||
// Member Properties
|
||||
.Prop(_SC("Valid"), &DpUser::IsValid)
|
||||
.Prop(_SC("Username"), &DpUser::GetUsername)
|
||||
.Prop(_SC("Discriminator"), &DpUser::GetDiscriminator)
|
||||
.Prop(_SC("Avatar"), &DpUser::GetAvatar)
|
||||
.Prop(_SC("Flags"), &DpUser::GetFlags)
|
||||
.Prop(_SC("RefCount"), &DpUser::GetRefCount)
|
||||
.Prop(_SC("AvatarURL"), &DpUser::GetAvatarURL)
|
||||
.Prop(_SC("IsBot"), &DpUser::IsBot)
|
||||
.Prop(_SC("IsSystem"), &DpUser::IsSystem)
|
||||
.Prop(_SC("IsMfaEnabled"), &DpUser::IsMfaEnabled)
|
||||
.Prop(_SC("IsVerified"), &DpUser::IsVerified)
|
||||
.Prop(_SC("HasNitroFull"), &DpUser::HasNitroFull)
|
||||
.Prop(_SC("HasNitroClassic"), &DpUser::HasNitroClassic)
|
||||
.Prop(_SC("IsDiscordEmployee"), &DpUser::IsDiscordEmployee)
|
||||
.Prop(_SC("IsPartneredOwner"), &DpUser::IsPartneredOwner)
|
||||
.Prop(_SC("HasHypesquadEvents"), &DpUser::HasHypesquadEvents)
|
||||
.Prop(_SC("IsBughunter1"), &DpUser::IsBughunter1)
|
||||
.Prop(_SC("IsHouseBravery"), &DpUser::IsHouseBravery)
|
||||
.Prop(_SC("IsHouseBrilliance"), &DpUser::IsHouseBrilliance)
|
||||
.Prop(_SC("IsHouseBalanace"), &DpUser::IsHouseBalanace)
|
||||
.Prop(_SC("IsEarlySupporter"), &DpUser::IsEarlySupporter)
|
||||
.Prop(_SC("IsTeamUser"), &DpUser::IsTeamUser)
|
||||
.Prop(_SC("IsBughunter2"), &DpUser::IsBughunter2)
|
||||
.Prop(_SC("IsVerifiedBot"), &DpUser::IsVerifiedBot)
|
||||
.Prop(_SC("IsVerifiedBotDev"), &DpUser::IsVerifiedBotDev)
|
||||
.Prop(_SC("IsCertifiedDoderator"), &DpUser::IsCertifiedDoderator)
|
||||
.Prop(_SC("HasAnimatedIcon"), &DpUser::HasAnimatedIcon)
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,206 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Represents a user on discord. May or may not be a member of a DpGuild.
|
||||
*/
|
||||
struct DpUser
|
||||
{
|
||||
using Ptr = std::unique_ptr< dpp::user >;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Referenced user instance.
|
||||
*/
|
||||
Ptr mPtr{nullptr};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
DpUser() noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit DpUser(Ptr::pointer ptr, bool owned = false) noexcept
|
||||
: mPtr(ptr), mOwned(owned)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
explicit DpUser(const Ptr::element_type & o) noexcept
|
||||
: DpUser(new Ptr::element_type(o), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
explicit DpUser(Ptr::element_type && o) noexcept
|
||||
: DpUser(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
|
||||
{ }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
DpUser(const DpUser & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
DpUser(DpUser && o) noexcept = default;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpUser() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
DpUser & operator = (const DpUser & o) = delete;
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
DpUser & operator = (DpUser && 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 user 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 user discord username.
|
||||
*/
|
||||
SQMOD_NODISCARD const std::string & GetUsername() const { return Valid().username; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve user discriminator (aka tag), 4 digits usually displayed with leading zeroes.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetDiscriminator() const { return static_cast< SQInteger >(Valid().discriminator); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve user avatar hash.
|
||||
*/
|
||||
SQMOD_NODISCARD const dpp::utility::iconhash & GetAvatar() const { return Valid().avatar; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve user flags built from a bitmask of values in dpp::user_flags.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetFlags() const { return static_cast< SQInteger >(Valid().flags); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve user feference count of how many guilds this user is in.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetRefCount() const { return static_cast< SQInteger >(Valid().refcount); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the avatar url of the user object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string GetAvatarURL() const { return Valid().get_avatar_url(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is a bot.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsBot() const { return Valid().is_bot(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is a system user (Clyde).
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsSystem() const { return Valid().is_system(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user has multi-factor authentication enabled.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsMfaEnabled() const { return Valid().is_mfa_enabled(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user has verified account.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsVerified() const { return Valid().is_verified(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user has full nitro.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasNitroFull() const { return Valid().has_nitro_full(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user has nitro classic.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasNitroClassic() const { return Valid().has_nitro_classic(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is a discord employee.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsDiscordEmployee() const { return Valid().is_discord_employee(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user owns a partnered server.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsPartneredOwner() const { return Valid().is_partnered_owner(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user has hype-squad events.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasHypesquadEvents() const { return Valid().has_hypesquad_events(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user has the bug-hunter level 1 badge.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsBughunter1() const { return Valid().is_bughunter_1(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is in house bravery.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsHouseBravery() const { return Valid().is_house_bravery(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is in house brilliance.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsHouseBrilliance() const { return Valid().is_house_brilliance(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is in house balance.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsHouseBalanace() const { return Valid().is_house_balanace(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is an early supporter.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsEarlySupporter() const { return Valid().is_early_supporter(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is a team user.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsTeamUser() const { return Valid().is_team_user(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user has the bug-hunter level 2 badge.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsBughunter2() const { return Valid().is_bughunter_2(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user has the verified bot badge.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsVerifiedBot() const { return Valid().is_verified_bot(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is an early verified bot developer.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsVerifiedBotDev() const { return Valid().is_verified_bot_dev(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user is a certified moderator.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsCertifiedDoderator() const { return Valid().is_certified_moderator(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the user has an animated icon.
|
||||
*/
|
||||
SQMOD_NODISCARD bool HasAnimatedIcon() const { return Valid().has_animated_icon(); }
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,12 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Utilities.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,429 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <dpp/dpp.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <memory>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
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_DPP_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
|
@ -381,7 +381,7 @@ void Register_INI(HSQUIRRELVM vm)
|
||||
.Func(_SC("Check"), &IniResult::Check)
|
||||
);
|
||||
|
||||
inins.Bind(_SC("IniEntries"),
|
||||
inins.Bind(_SC("Entries"),
|
||||
Class< IniEntries >(vm, EntriesTypename::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
@ -409,7 +409,7 @@ void Register_INI(HSQUIRRELVM vm)
|
||||
.Func(_SC("SortByLoadOrder"), &IniEntries::SortByLoadOrder)
|
||||
);
|
||||
|
||||
inins.Bind(_SC("IniDocument"),
|
||||
inins.Bind(_SC("Document"),
|
||||
Class< IniDocument, NoCopy< IniDocument > >(vm, DocumentTypename::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
@ -464,7 +464,7 @@ void Register_INI(HSQUIRRELVM vm)
|
||||
.Overload< bool (IniDocument::*)(const SQChar *, const SQChar *, const SQChar *, bool) >(_SC("DeleteValue"), &IniDocument::DeleteValue)
|
||||
);
|
||||
|
||||
RootTable(vm).Bind(_SC("SqIni"), inins);
|
||||
RootTable(vm).Bind(_SC("SqINI"), inins);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqIniError"), Enumeration(vm)
|
||||
.Const(_SC("Ok"), int32_t(SI_OK))
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -756,5 +756,4 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
191
module/Library/RegEx.cpp
Normal file
191
module/Library/RegEx.cpp
Normal file
@ -0,0 +1,191 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/RegEx.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqratConst.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqRxMatchTypename, _SC("SqRxMatch"))
|
||||
SQMOD_DECL_TYPENAME(SqRxMatchesTypename, _SC("SqRxMatches"))
|
||||
SQMOD_DECL_TYPENAME(SqRxInstanceTypename, _SC("SqRxInstance"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool RxInstance::STUDY = true;
|
||||
int RxInstance::OPTIONS = 0;
|
||||
int RxInstance::STUDY_OPTIONS = 0;
|
||||
|
||||
// ================================================================================================
|
||||
void Register_RegEx(HSQUIRRELVM vm)
|
||||
{
|
||||
RootTable(vm).Bind(SqRxMatchTypename::Str,
|
||||
Class< RxMatch >(vm, SqRxMatchTypename::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< SQInteger >()
|
||||
.Ctor< SQInteger, SQInteger >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqRxMatchTypename::Fn)
|
||||
// Properties
|
||||
.Prop(_SC("Offset"), &RxMatch::GetOffset, &RxMatch::SetOffset)
|
||||
.Prop(_SC("Length"), &RxMatch::GetLength, &RxMatch::SetLength)
|
||||
.Prop(_SC("End"), &RxMatch::GetEnd)
|
||||
// Member Methods
|
||||
.Func(_SC("SubStr"), &RxMatch::SubStr)
|
||||
);
|
||||
RootTable(vm).Bind(SqRxMatchesTypename::Str,
|
||||
Class< RxMatches >(vm, SqRxMatchesTypename::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqRxMatchesTypename::Fn)
|
||||
// Properties
|
||||
.Prop(_SC("Front"), &RxMatches::Front)
|
||||
.Prop(_SC("Back"), &RxMatches::Back)
|
||||
.Prop(_SC("Empty"), &RxMatches::Empty)
|
||||
.Prop(_SC("Size"), &RxMatches::Size)
|
||||
.Prop(_SC("Capacity"), &RxMatches::Capacity, &RxMatches::Reserve)
|
||||
// Member Methods
|
||||
.Func(_SC("Get"), &RxMatches::Get)
|
||||
.Func(_SC("Reserve"), &RxMatches::Reserve)
|
||||
.Func(_SC("Compact"), &RxMatches::Compact)
|
||||
.Func(_SC("Clear"), &RxMatches::Clear)
|
||||
.Func(_SC("Pop"), &RxMatches::Pop)
|
||||
.Func(_SC("EraseAt"), &RxMatches::EraseAt)
|
||||
.Func(_SC("EraseFrom"), &RxMatches::EraseFrom)
|
||||
.Func(_SC("Each"), &RxMatches::Each)
|
||||
.Func(_SC("EachRange"), &RxMatches::EachRange)
|
||||
.Func(_SC("While"), &RxMatches::While)
|
||||
.Func(_SC("WhileRange"), &RxMatches::WhileRange)
|
||||
.Func(_SC("SubStr"), &RxMatches::SubStr)
|
||||
);
|
||||
RootTable(vm).Bind(_SC("SqRx"),
|
||||
Class< RxInstance, NoCopy< RxInstance > >(vm, SqRxInstanceTypename::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< StackStrF & >()
|
||||
.Ctor< int, StackStrF & >()
|
||||
.Ctor< int, bool, StackStrF & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqRxInstanceTypename::Fn)
|
||||
//.Func(_SC("_tostring"), &CPlayer::ToString)
|
||||
// Static Values
|
||||
.SetStaticValue(_SC("STUDY"), RxInstance::STUDY)
|
||||
.SetStaticValue(_SC("OPTIONS"), RxInstance::OPTIONS)
|
||||
.SetStaticValue(_SC("STUDY_OPTIONS"), RxInstance::STUDY_OPTIONS)
|
||||
// Properties
|
||||
.Prop(_SC("Valid"), &RxInstance::IsValid)
|
||||
.Prop(_SC("Studied"), &RxInstance::IsStudied)
|
||||
// Member Methods
|
||||
.FmtFunc(_SC("CompileF"), &RxInstance::Compile1)
|
||||
.FmtFunc(_SC("CompileExF"), &RxInstance::Compile2)
|
||||
.FmtFunc(_SC("TryCompileF"), &RxInstance::TryCompile1)
|
||||
.FmtFunc(_SC("TryCompileExF"), &RxInstance::TryCompile2)
|
||||
.FmtFunc(_SC("MatchFirst"), &RxInstance::MatchFirst)
|
||||
.FmtFunc(_SC("MatchFirstEx"), &RxInstance::MatchFirst_)
|
||||
.FmtFunc(_SC("MatchFirstFrom"), &RxInstance::MatchFirstFrom)
|
||||
.FmtFunc(_SC("MatchFirstFromEx"), &RxInstance::MatchFirstFrom_)
|
||||
.FmtFunc(_SC("Match"), &RxInstance::Match)
|
||||
.FmtFunc(_SC("MatchEx"), &RxInstance::Match_)
|
||||
.FmtFunc(_SC("MatchFrom"), &RxInstance::MatchFrom)
|
||||
.FmtFunc(_SC("MatchFromEx"), &RxInstance::MatchFrom_)
|
||||
.FmtFunc(_SC("Matches"), &RxInstance::Matches)
|
||||
.FmtFunc(_SC("MatchesEx"), &RxInstance::Matches_)
|
||||
.FmtFunc(_SC("MatchesEx2"), &RxInstance::MatchesEx)
|
||||
// Member Overloads
|
||||
.Overload(_SC("Compile"), &RxInstance::Compile1)
|
||||
.Overload(_SC("Compile"), &RxInstance::Compile2)
|
||||
.Overload(_SC("TryCompile"), &RxInstance::TryCompile1)
|
||||
.Overload(_SC("TryCompile"), &RxInstance::TryCompile2)
|
||||
.Overload(_SC("Study"), &RxInstance::Study0)
|
||||
.Overload(_SC("Study"), &RxInstance::Study1)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ConstTable(vm).Enum(_SC("SqRxOption"), Enumeration(vm)
|
||||
.Const(_SC("Caseless"), static_cast< SQInteger >(PCRE_CASELESS))
|
||||
.Const(_SC("Multiline"), static_cast< SQInteger >(PCRE_MULTILINE))
|
||||
.Const(_SC("Dotall"), static_cast< SQInteger >(PCRE_DOTALL))
|
||||
.Const(_SC("Extended"), static_cast< SQInteger >(PCRE_EXTENDED))
|
||||
.Const(_SC("Anchored"), static_cast< SQInteger >(PCRE_ANCHORED))
|
||||
.Const(_SC("DollarEndOnly"), static_cast< SQInteger >(PCRE_DOLLAR_ENDONLY))
|
||||
.Const(_SC("Extra"), static_cast< SQInteger >(PCRE_EXTRA))
|
||||
.Const(_SC("NotBOL"), static_cast< SQInteger >(PCRE_NOTBOL))
|
||||
.Const(_SC("NotEOL"), static_cast< SQInteger >(PCRE_NOTEOL))
|
||||
.Const(_SC("UnGreedy"), static_cast< SQInteger >(PCRE_UNGREEDY))
|
||||
.Const(_SC("NotEmpty"), static_cast< SQInteger >(PCRE_NOTEMPTY))
|
||||
.Const(_SC("UTF8"), static_cast< SQInteger >(PCRE_UTF8))
|
||||
.Const(_SC("UTF16"), static_cast< SQInteger >(PCRE_UTF16))
|
||||
.Const(_SC("UTF32"), static_cast< SQInteger >(PCRE_UTF32))
|
||||
.Const(_SC("NoAutoCapture"), static_cast< SQInteger >(PCRE_NO_AUTO_CAPTURE))
|
||||
.Const(_SC("NoUTF8Check"), static_cast< SQInteger >(PCRE_NO_UTF8_CHECK))
|
||||
.Const(_SC("NoUTF16Check"), static_cast< SQInteger >(PCRE_NO_UTF16_CHECK))
|
||||
.Const(_SC("NoUTF32Check"), static_cast< SQInteger >(PCRE_NO_UTF32_CHECK))
|
||||
.Const(_SC("AutoCallout"), static_cast< SQInteger >(PCRE_AUTO_CALLOUT))
|
||||
.Const(_SC("PartialSoft"), static_cast< SQInteger >(PCRE_PARTIAL_SOFT))
|
||||
.Const(_SC("Partial"), static_cast< SQInteger >(PCRE_PARTIAL))
|
||||
.Const(_SC("NeverUTF"), static_cast< SQInteger >(PCRE_NEVER_UTF))
|
||||
.Const(_SC("DfaShortest"), static_cast< SQInteger >(PCRE_DFA_SHORTEST))
|
||||
.Const(_SC("NoAutoPossess"), static_cast< SQInteger >(PCRE_NO_AUTO_POSSESS))
|
||||
.Const(_SC("DfaRestart"), static_cast< SQInteger >(PCRE_DFA_RESTART))
|
||||
.Const(_SC("FirstLine"), static_cast< SQInteger >(PCRE_FIRSTLINE))
|
||||
.Const(_SC("DupNames"), static_cast< SQInteger >(PCRE_DUPNAMES))
|
||||
.Const(_SC("NewLineCR"), static_cast< SQInteger >(PCRE_NEWLINE_CR))
|
||||
.Const(_SC("NewLineLF"), static_cast< SQInteger >(PCRE_NEWLINE_LF))
|
||||
.Const(_SC("NewLineCRLF"), static_cast< SQInteger >(PCRE_NEWLINE_CRLF))
|
||||
.Const(_SC("NewLineAny"), static_cast< SQInteger >(PCRE_NEWLINE_ANY))
|
||||
.Const(_SC("NewLineAnyCRLF"), static_cast< SQInteger >(PCRE_NEWLINE_ANYCRLF))
|
||||
.Const(_SC("BsrAnyCRLF"), static_cast< SQInteger >(PCRE_BSR_ANYCRLF))
|
||||
.Const(_SC("BsrUnicode"), static_cast< SQInteger >(PCRE_BSR_UNICODE))
|
||||
.Const(_SC("JavaScriptCompat"), static_cast< SQInteger >(PCRE_JAVASCRIPT_COMPAT))
|
||||
.Const(_SC("NoStartOptimize"), static_cast< SQInteger >(PCRE_NO_START_OPTIMIZE))
|
||||
.Const(_SC("NoStartOptimise"), static_cast< SQInteger >(PCRE_NO_START_OPTIMISE))
|
||||
.Const(_SC("PartialHard"), static_cast< SQInteger >(PCRE_PARTIAL_HARD))
|
||||
.Const(_SC("NotEmptyAtStart"), static_cast< SQInteger >(PCRE_NOTEMPTY_ATSTART))
|
||||
.Const(_SC("UCP"), static_cast< SQInteger >(PCRE_UCP))
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ConstTable(vm).Enum(_SC("SqRxError"), Enumeration(vm)
|
||||
.Const(_SC("NoMatch"), static_cast< SQInteger >(PCRE_ERROR_NOMATCH))
|
||||
.Const(_SC("Null"), static_cast< SQInteger >(PCRE_ERROR_NULL))
|
||||
.Const(_SC("BadOption"), static_cast< SQInteger >(PCRE_ERROR_BADOPTION))
|
||||
.Const(_SC("BadMagic"), static_cast< SQInteger >(PCRE_ERROR_BADMAGIC))
|
||||
.Const(_SC("UnknownOpCode"), static_cast< SQInteger >(PCRE_ERROR_UNKNOWN_OPCODE))
|
||||
.Const(_SC("UnknownNode"), static_cast< SQInteger >(PCRE_ERROR_UNKNOWN_NODE))
|
||||
.Const(_SC("NoMemory"), static_cast< SQInteger >(PCRE_ERROR_NOMEMORY))
|
||||
.Const(_SC("NoSubstring"), static_cast< SQInteger >(PCRE_ERROR_NOSUBSTRING))
|
||||
.Const(_SC("MatchLimit"), static_cast< SQInteger >(PCRE_ERROR_MATCHLIMIT))
|
||||
.Const(_SC("Callout"), static_cast< SQInteger >(PCRE_ERROR_CALLOUT))
|
||||
.Const(_SC("BadUTF8"), static_cast< SQInteger >(PCRE_ERROR_BADUTF8))
|
||||
.Const(_SC("BadUTF16"), static_cast< SQInteger >(PCRE_ERROR_BADUTF16))
|
||||
.Const(_SC("BadUTF32"), static_cast< SQInteger >(PCRE_ERROR_BADUTF32))
|
||||
.Const(_SC("BadUTF8Offset"), static_cast< SQInteger >(PCRE_ERROR_BADUTF8_OFFSET))
|
||||
.Const(_SC("BadUTF16Offset"), static_cast< SQInteger >(PCRE_ERROR_BADUTF16_OFFSET))
|
||||
.Const(_SC("Partial"), static_cast< SQInteger >(PCRE_ERROR_PARTIAL))
|
||||
.Const(_SC("BadPartial"), static_cast< SQInteger >(PCRE_ERROR_BADPARTIAL))
|
||||
.Const(_SC("Internal"), static_cast< SQInteger >(PCRE_ERROR_INTERNAL))
|
||||
.Const(_SC("BadCount"), static_cast< SQInteger >(PCRE_ERROR_BADCOUNT))
|
||||
.Const(_SC("DfaUitem"), static_cast< SQInteger >(PCRE_ERROR_DFA_UITEM))
|
||||
.Const(_SC("DfaUcond"), static_cast< SQInteger >(PCRE_ERROR_DFA_UCOND))
|
||||
.Const(_SC("DfaUmLimit"), static_cast< SQInteger >(PCRE_ERROR_DFA_UMLIMIT))
|
||||
.Const(_SC("DfaWsSize"), static_cast< SQInteger >(PCRE_ERROR_DFA_WSSIZE))
|
||||
.Const(_SC("DfaRecurse"), static_cast< SQInteger >(PCRE_ERROR_DFA_RECURSE))
|
||||
.Const(_SC("RecursionLimit"), static_cast< SQInteger >(PCRE_ERROR_RECURSIONLIMIT))
|
||||
.Const(_SC("NullWsLimit"), static_cast< SQInteger >(PCRE_ERROR_NULLWSLIMIT))
|
||||
.Const(_SC("BadNewLine"), static_cast< SQInteger >(PCRE_ERROR_BADNEWLINE))
|
||||
.Const(_SC("BadOffset"), static_cast< SQInteger >(PCRE_ERROR_BADOFFSET))
|
||||
.Const(_SC("ShortUTF8"), static_cast< SQInteger >(PCRE_ERROR_SHORTUTF8))
|
||||
.Const(_SC("ShortUTF16"), static_cast< SQInteger >(PCRE_ERROR_SHORTUTF16))
|
||||
.Const(_SC("RecurseLoop"), static_cast< SQInteger >(PCRE_ERROR_RECURSELOOP))
|
||||
.Const(_SC("JitStackLimit"), static_cast< SQInteger >(PCRE_ERROR_JIT_STACKLIMIT))
|
||||
.Const(_SC("BadMode"), static_cast< SQInteger >(PCRE_ERROR_BADMODE))
|
||||
.Const(_SC("BadEndianness"), static_cast< SQInteger >(PCRE_ERROR_BADENDIANNESS))
|
||||
.Const(_SC("DfaBadRestart"), static_cast< SQInteger >(PCRE_ERROR_DFA_BADRESTART))
|
||||
.Const(_SC("JitBadOption"), static_cast< SQInteger >(PCRE_ERROR_JIT_BADOPTION))
|
||||
.Const(_SC("BadLength"), static_cast< SQInteger >(PCRE_ERROR_BADLENGTH))
|
||||
.Const(_SC("Unset"), static_cast< SQInteger >(PCRE_ERROR_UNSET))
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
885
module/Library/RegEx.hpp
Normal file
885
module/Library/RegEx.hpp
Normal file
@ -0,0 +1,885 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#ifdef POCO_UNBUNDLED
|
||||
#include <pcre.h>
|
||||
#else
|
||||
#include "pcre_config.h"
|
||||
#include "pcre.h"
|
||||
#endif
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <utility>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
struct RxMatch
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
SQInteger mOffset{0};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
SQInteger mLength{0};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
RxMatch() noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Offset constructor.
|
||||
*/
|
||||
explicit RxMatch(SQInteger offset) noexcept
|
||||
: mOffset{offset}
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
RxMatch(SQInteger offset, SQInteger length) noexcept
|
||||
: mOffset{offset}, mLength{length}
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
RxMatch(const RxMatch & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
RxMatch(RxMatch && o) noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
RxMatch & operator = (const RxMatch & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
RxMatch & operator = (RxMatch && o) noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve offset.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetOffset() const noexcept
|
||||
{
|
||||
return mOffset;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify offset.
|
||||
*/
|
||||
void SetOffset(SQInteger value) noexcept
|
||||
{
|
||||
mOffset = value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve length.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetLength() const noexcept
|
||||
{
|
||||
return mLength;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify length.
|
||||
*/
|
||||
void SetLength(SQInteger value) noexcept
|
||||
{
|
||||
mLength = value;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve match end.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetEnd() const noexcept
|
||||
{
|
||||
return mOffset + mLength;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract a sub-string.
|
||||
*/
|
||||
[[nodiscard]] LightObj SubStr(StackStrF & str) const
|
||||
{
|
||||
if ((mOffset + mLength) > str.mLen)
|
||||
{
|
||||
STHROWF("Rx: Match is outside the range of the specified string.");
|
||||
}
|
||||
// Return the sub-string
|
||||
return LightObj{str.mPtr + mOffset, mLength};
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
struct RxMatches
|
||||
{
|
||||
using List = std::vector< RxMatch >;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Internal RegularExpression instance.
|
||||
*/
|
||||
List mList;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
RxMatches() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy list constructor.
|
||||
*/
|
||||
explicit RxMatches(const List & l) // NOLINT(modernize-pass-by-value)
|
||||
: mList{l}
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move list constructor.
|
||||
*/
|
||||
explicit RxMatches(List && m) noexcept
|
||||
: mList{std::move(m)}
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
RxMatches(const RxMatches & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
RxMatches(RxMatches && o) noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
RxMatches & operator = (const RxMatches & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
RxMatches & operator = (RxMatches && o) noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure an index is within range and return the container. Container must exist.
|
||||
*/
|
||||
List & ValidIdx(SQInteger i)
|
||||
{
|
||||
if (static_cast< size_t >(i) >= mList.size())
|
||||
{
|
||||
STHROWF("Invalid Regular Expression match list index({})", i);
|
||||
}
|
||||
return mList;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure an index is within range and return the container. Container must exist.
|
||||
*/
|
||||
SQMOD_NODISCARD const List & ValidIdx(SQInteger i) const
|
||||
{
|
||||
if (static_cast< size_t >(i) >= mList.size())
|
||||
{
|
||||
STHROWF("Invalid Regular Expression match list index({})", i);
|
||||
}
|
||||
return mList;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure a container instance is populated, then return it.
|
||||
*/
|
||||
SQMOD_NODISCARD List & ValidPop()
|
||||
{
|
||||
if (mList.empty())
|
||||
{
|
||||
STHROWF("Regular Expression match list container is empty");
|
||||
}
|
||||
return mList;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a value from the container.
|
||||
*/
|
||||
SQMOD_NODISCARD List::reference Get(SQInteger i)
|
||||
{
|
||||
return ValidIdx(i).at(ClampL< SQInteger, size_t >(i));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the first element in the container.
|
||||
*/
|
||||
SQMOD_NODISCARD List::reference Front()
|
||||
{
|
||||
return ValidPop().front();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the last element in the container.
|
||||
*/
|
||||
SQMOD_NODISCARD List::reference Back()
|
||||
{
|
||||
return mList.back();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the container has no elements.
|
||||
*/
|
||||
SQMOD_NODISCARD bool Empty() const
|
||||
{
|
||||
return mList.empty();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of elements in the container.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger Size() const
|
||||
{
|
||||
return static_cast< SQInteger >(mList.size());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of elements that the container has currently allocated space for.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger Capacity() const
|
||||
{
|
||||
return static_cast< SQInteger >(mList.capacity());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Increase the capacity of the container to a value that's greater or equal to the one specified.
|
||||
*/
|
||||
RxMatches & Reserve(SQInteger n)
|
||||
{
|
||||
mList.reserve(ClampL< SQInteger, size_t >(n));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Request the removal of unused capacity.
|
||||
*/
|
||||
void Compact()
|
||||
{
|
||||
mList.shrink_to_fit();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Erase all elements from the container.
|
||||
*/
|
||||
void Clear()
|
||||
{
|
||||
mList.clear();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Pop the last element in the container.
|
||||
*/
|
||||
void Pop()
|
||||
{
|
||||
ValidPop().pop_back();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Erase the element at a certain position.
|
||||
*/
|
||||
void EraseAt(SQInteger i)
|
||||
{
|
||||
mList.erase(ValidIdx(i).begin() + static_cast< size_t >(i)); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Erase a certain amount of elements starting from a specific position.
|
||||
*/
|
||||
void EraseFrom(SQInteger i, SQInteger n)
|
||||
{
|
||||
mList.erase(ValidIdx(i).begin() + static_cast< size_t >(i), // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||
ValidIdx(i + n).begin() + static_cast< size_t >(i + n)); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate all values through a functor.
|
||||
*/
|
||||
void Each(Function & fn) const
|
||||
{
|
||||
for (const auto & e : mList)
|
||||
{
|
||||
fn.Execute(static_cast< SQInteger >(e.mOffset), static_cast< SQInteger >(e.mLength));
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate values in range through a functor.
|
||||
*/
|
||||
void EachRange(SQInteger p, SQInteger n, Function & fn) const
|
||||
{
|
||||
std::for_each(ValidIdx(p).begin() + static_cast< size_t >(p), // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||
ValidIdx(p + n).begin() + static_cast< size_t >(p + n), // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||
[&](List::const_reference & e) {
|
||||
fn.Execute(static_cast< SQInteger >(e.mOffset), static_cast< SQInteger >(e.mLength));
|
||||
});
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate all values through a functor until stopped (i.e. false is returned).
|
||||
*/
|
||||
void While(Function & fn) const
|
||||
{
|
||||
for (const auto & e : mList)
|
||||
{
|
||||
auto ret = fn.Eval(static_cast< SQInteger >(e.mOffset), static_cast< SQInteger >(e.mLength));
|
||||
// (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) const
|
||||
{
|
||||
auto itr = ValidIdx(p).begin() + static_cast< size_t >(p); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||
auto end = ValidIdx(p + n).begin() + static_cast< size_t >(p + n); // NOLINT(cppcoreguidelines-narrowing-conversions)
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
auto ret = fn.Eval(static_cast< SQInteger >(itr->mOffset), static_cast< SQInteger >(itr->mLength));
|
||||
// (null || true) == continue & false == break
|
||||
if (!ret.IsNull() || !ret.template Cast< bool >())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Extract a sub-string.
|
||||
*/
|
||||
[[nodiscard]] LightObj SubStr(SQInteger i, StackStrF & str) const
|
||||
{
|
||||
const RxMatch & m = ValidIdx(i)[i];
|
||||
// Check if match is within range
|
||||
if ((m.mOffset + m.mLength) > str.mLen)
|
||||
{
|
||||
STHROWF("Rx: Match is outside the range of the specified string.");
|
||||
}
|
||||
// Return the sub-string
|
||||
return LightObj{str.mPtr + m.mOffset, m.mLength};
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
struct RxInstance
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Whether to analyze and optimize the pattern by default for evey new instance (true).
|
||||
*/
|
||||
static bool STUDY;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default options for every new instance (0).
|
||||
*/
|
||||
static int OPTIONS;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default study options for every new instance (0).
|
||||
*/
|
||||
static int STUDY_OPTIONS;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default offset vector size (must be multiple of 3).
|
||||
*/
|
||||
static constexpr int OVEC_SIZE = 63;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Internal vector type used for offsets buffer.
|
||||
*/
|
||||
using OVEC_t = std::vector< int >;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Internal RegularExpression instance.
|
||||
*/
|
||||
pcre * mPCRE{nullptr};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Internal RegularExpression instance.
|
||||
*/
|
||||
pcre_extra * mExtra{nullptr};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Internal buffer used for offsets.
|
||||
*/
|
||||
OVEC_t mOVEC{};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
RxInstance() noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor (disabled).
|
||||
*/
|
||||
RxInstance(const RxInstance &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
RxInstance(RxInstance && o) noexcept
|
||||
: mPCRE(o.mPCRE), mExtra(o.mExtra), mOVEC(std::move(o.mOVEC)) // Replicate it
|
||||
{
|
||||
o.mPCRE = nullptr; // Take ownership
|
||||
o.mExtra = nullptr; // Take ownership
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Basic constructor.
|
||||
*/
|
||||
explicit RxInstance(StackStrF & pattern)
|
||||
: RxInstance(OPTIONS, STUDY, pattern)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Basic constructor. With specific options.
|
||||
*/
|
||||
explicit RxInstance(int options, StackStrF & pattern)
|
||||
: RxInstance(options, STUDY, pattern)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Basic constructor. With specific options.
|
||||
*/
|
||||
explicit RxInstance(int options, bool study, StackStrF & pattern)
|
||||
: mPCRE(Compile_(pattern.mPtr, options)), mExtra(nullptr)
|
||||
{
|
||||
if (study)
|
||||
{
|
||||
Study0();
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Internal constructor.
|
||||
*/
|
||||
RxInstance(const char * pattern, int options, bool study)
|
||||
: mPCRE(Compile_(pattern, options)), mExtra(nullptr)
|
||||
{
|
||||
if (study)
|
||||
{
|
||||
Study0();
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~RxInstance()
|
||||
{
|
||||
Destroy();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
RxInstance & operator = (const RxInstance &) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
RxInstance & operator = (RxInstance && o) noexcept
|
||||
{
|
||||
// Prevent self assignment
|
||||
if (this != &o)
|
||||
{
|
||||
// Release current instance, if any
|
||||
Destroy();
|
||||
// Replicate it
|
||||
mPCRE = o.mPCRE;
|
||||
mExtra = o.mExtra;
|
||||
mOVEC = std::move(o.mOVEC);
|
||||
// Take ownership
|
||||
o.mPCRE = nullptr;
|
||||
o.mExtra = nullptr;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Estimate the size necessary for the offsets vector buffer.
|
||||
*/
|
||||
void EstimateOVEC(bool force = false)
|
||||
{
|
||||
if (mOVEC.empty() || force)
|
||||
{
|
||||
int size = 0;
|
||||
// Attempt to estimate the size of the offsets vector buffer
|
||||
const int r = pcre_fullinfo(ValidPCRE(), mExtra, PCRE_INFO_CAPTURECOUNT, &size);
|
||||
// Check for errors
|
||||
if (r != 0)
|
||||
{
|
||||
STHROWF("Rx: Offsets vector buffer estimation failed ({})", r);
|
||||
}
|
||||
// Attempt to scale the vector (must be multiple of 3)
|
||||
mOVEC.resize((size + 1) * 3);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return a valid `pcre` instance pointer or throw an exception.
|
||||
*/
|
||||
SQMOD_NODISCARD pcre * ValidPCRE() const
|
||||
{
|
||||
// Do we manage a valid instance?
|
||||
if (mPCRE == nullptr)
|
||||
{
|
||||
STHROWF("Uninitialized Regular Expression instance.");
|
||||
}
|
||||
// Return it
|
||||
return mPCRE;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Return a valid `pcre_extra` instance pointer or throw an exception.
|
||||
*/
|
||||
SQMOD_NODISCARD pcre_extra * ValidExtra() const
|
||||
{
|
||||
// Do we manage a valid instance?
|
||||
if (mExtra == nullptr)
|
||||
{
|
||||
STHROWF("Regular Expression was not studied and optimized.");
|
||||
}
|
||||
// Return it
|
||||
return mExtra;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Compile the specified pattern.
|
||||
*/
|
||||
SQMOD_NODISCARD static pcre * Compile_(const char * pattern, int options = OPTIONS)
|
||||
{
|
||||
const char * error_msg = nullptr;
|
||||
int error_code, error_offset = 0;
|
||||
// Attempt to compile the specified pattern
|
||||
pcre * ptr = pcre_compile2(pattern, options, &error_code, &error_msg, &error_offset, nullptr);
|
||||
// Did the compilation failed?
|
||||
if (ptr == nullptr)
|
||||
{
|
||||
STHROWF("Rx: {s} (code {}) (at offset {})", error_msg, error_code, error_offset);
|
||||
}
|
||||
// Return the `pcre` instance
|
||||
return ptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to compile the specified pattern. Error information is returned instead of thrown.
|
||||
*/
|
||||
SQMOD_NODISCARD static std::pair< pcre *, Table > TryCompile_(const char * pattern, int options = OPTIONS)
|
||||
{
|
||||
const char * error_msg = nullptr;
|
||||
int error_code, error_offset = 0;
|
||||
// Attempt to compile the specified pattern
|
||||
pcre * ptr = pcre_compile2(pattern, options, &error_code, &error_msg, &error_offset, nullptr);
|
||||
// Did the compilation failed?
|
||||
if (ptr == nullptr)
|
||||
{
|
||||
Table t;
|
||||
t.SetValue("message", error_msg);
|
||||
t.SetValue("code", error_code);
|
||||
t.SetValue("offset", error_offset);
|
||||
// Return the table with error information
|
||||
return std::make_pair(ptr, std::move(t));
|
||||
}
|
||||
// Return the `pcre` instance with no error information
|
||||
return std::make_pair(ptr, Table{});
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Compile the specified pattern.
|
||||
*/
|
||||
RxInstance & Compile1(StackStrF & pattern)
|
||||
{
|
||||
return Compile2(OPTIONS, pattern);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Compile the specified pattern. With specific options.
|
||||
*/
|
||||
RxInstance & Compile2(int options, StackStrF & pattern)
|
||||
{
|
||||
// Release current instance, if any
|
||||
Destroy();
|
||||
// Attempt to compile
|
||||
mPCRE = Compile_(pattern.mPtr, options);
|
||||
// Allocate offsets vector buffer
|
||||
EstimateOVEC();
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Compile the specified pattern.
|
||||
*/
|
||||
Table TryCompile1(StackStrF & pattern)
|
||||
{
|
||||
return TryCompile2(OPTIONS, pattern);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Compile the specified pattern. With specific options.
|
||||
*/
|
||||
Table TryCompile2(int options, StackStrF & pattern)
|
||||
{
|
||||
// Release current instance, if any
|
||||
Destroy();
|
||||
// Attempt to compile
|
||||
auto p = TryCompile_(pattern.mPtr, options);
|
||||
// Were there any compilation errors?
|
||||
if (p.first != nullptr)
|
||||
{
|
||||
mPCRE = p.first;
|
||||
}
|
||||
// Return compilation info
|
||||
return p.second;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Analyze the managed pattern and optimized it.
|
||||
*/
|
||||
RxInstance & Study0()
|
||||
{
|
||||
return Study1(STUDY_OPTIONS);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Analyze the managed pattern and optimized it. With specific options.
|
||||
*/
|
||||
RxInstance & Study1(int options)
|
||||
{
|
||||
if (mExtra != nullptr)
|
||||
{
|
||||
STHROWF("Regular Expression was already analyzed and optimized");
|
||||
}
|
||||
const char * error = nullptr;
|
||||
// Study and optimize the expression
|
||||
mExtra = pcre_study(ValidPCRE(), options, &error);
|
||||
// If there was an error studying the expression then throw it
|
||||
if (mExtra == nullptr && error != nullptr)
|
||||
{
|
||||
STHROWF("Rx: {s}", error);
|
||||
}
|
||||
// Allow chaining
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release managed resources and revert to uninitialized instance.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const
|
||||
{
|
||||
return (mPCRE != nullptr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release managed resources and revert to uninitialized instance.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsStudied() const
|
||||
{
|
||||
return (mExtra != nullptr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release managed resources and revert to uninitialized instance.
|
||||
*/
|
||||
void Destroy()
|
||||
{
|
||||
// Do we manage any instance?
|
||||
if (mPCRE != nullptr)
|
||||
{
|
||||
pcre_free(mPCRE);
|
||||
mPCRE = nullptr;
|
||||
}
|
||||
// Is the expression optimized?
|
||||
if (mExtra != nullptr)
|
||||
{
|
||||
pcre_free(mExtra);
|
||||
mExtra = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Matches the given subject string against the pattern.
|
||||
* Returns the position of the first captured sub-string in m.
|
||||
* If no part of the subject matches the pattern, m.mOffset is -1 and m.mLength is 0.
|
||||
* Returns the number of matches. Throws a exception in case of an error.
|
||||
*/
|
||||
SQMOD_NODISCARD int MatchFirstFrom(SQInteger o, RxMatch & m, StackStrF & s)
|
||||
{
|
||||
return MatchFirstFrom_(OPTIONS, o, m, s);
|
||||
}
|
||||
SQMOD_NODISCARD int MatchFirstFrom_(int f, SQInteger o, RxMatch & m, StackStrF & s)
|
||||
{
|
||||
if (o > s.mLen)
|
||||
{
|
||||
STHROWF("Rx: Offset is out of range");
|
||||
}
|
||||
EstimateOVEC();
|
||||
// Attempt to execute the expression on the specified subject
|
||||
const int rc = pcre_exec(ValidPCRE(), mExtra, s.mPtr, static_cast< int >(s.mLen), static_cast< int >(o), f & 0xFFFF, mOVEC.data(), static_cast< int >(mOVEC.size()));
|
||||
// Was there a match?
|
||||
if (rc == PCRE_ERROR_NOMATCH)
|
||||
{
|
||||
m.mOffset = -1;
|
||||
m.mLength = 0;
|
||||
// No match found
|
||||
return 0;
|
||||
}
|
||||
// Bad options/flags?
|
||||
else if (rc == PCRE_ERROR_BADOPTION)
|
||||
{
|
||||
STHROWF("Rx: Bad option");
|
||||
}
|
||||
// Overflow?
|
||||
else if (rc == 0)
|
||||
{
|
||||
STHROWF("Rx: too many captured sub-strings");
|
||||
}
|
||||
// Some other error?
|
||||
else if (rc < 0)
|
||||
{
|
||||
STHROWF("Rx: error {}", rc);
|
||||
}
|
||||
// Store match
|
||||
m.mOffset = mOVEC[0];
|
||||
m.mLength = mOVEC[1] - mOVEC[0];
|
||||
// Yield result back to script
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Matches the given subject string against the pattern.
|
||||
* Returns the position of the first captured sub-string in m.
|
||||
* If no part of the subject matches the pattern, m.mOffset is -1 and m.mLength is 0.
|
||||
* Returns the number of matches. Throws a exception in case of an error.
|
||||
*/
|
||||
SQMOD_NODISCARD int MatchFirst(RxMatch & m, StackStrF & s)
|
||||
{
|
||||
return MatchFirstFrom_(OPTIONS, 0, m, s);
|
||||
}
|
||||
SQMOD_NODISCARD int MatchFirst_(int f, RxMatch & m, StackStrF & s)
|
||||
{
|
||||
return MatchFirstFrom_(f, 0, m, s);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Matches the given subject string against the pattern.
|
||||
* The first entry in m contains the position of the captured sub-string.
|
||||
* The following entries identify matching sub-patterns. See the PCRE documentation for a more detailed explanation.
|
||||
* If no part of the subject matches the pattern, m is empty.
|
||||
* Returns the number of matches. Throws an exception in case of an error.
|
||||
*/
|
||||
SQMOD_NODISCARD int MatchFrom(SQInteger o, RxMatches & m, StackStrF & s)
|
||||
{
|
||||
return MatchFrom_(OPTIONS, o, m, s);
|
||||
}
|
||||
SQMOD_NODISCARD int MatchFrom_(int f, SQInteger o, RxMatches & m, StackStrF & s)
|
||||
{
|
||||
if (o > s.mLen)
|
||||
{
|
||||
STHROWF("Rx: Offset is out of range");
|
||||
}
|
||||
EstimateOVEC();
|
||||
// Clear previous matches, if any
|
||||
m.mList.clear();
|
||||
// Attempt to execute the expression on the specified subject
|
||||
const int rc = pcre_exec(ValidPCRE(), mExtra, s.mPtr, static_cast< int >(s.mLen), static_cast< int >(o), f & 0xFFFF, mOVEC.data(), static_cast< int >(mOVEC.size()));
|
||||
// Was there a match?
|
||||
if (rc == PCRE_ERROR_NOMATCH)
|
||||
{
|
||||
return 0; // No match found
|
||||
}
|
||||
// Bad options/flags?
|
||||
else if (rc == PCRE_ERROR_BADOPTION)
|
||||
{
|
||||
STHROWF("Rx: Bad option");
|
||||
}
|
||||
// Overflow?
|
||||
else if (rc == 0)
|
||||
{
|
||||
STHROWF("Rx: too many captured sub-strings");
|
||||
}
|
||||
// Some other error?
|
||||
else if (rc < 0)
|
||||
{
|
||||
STHROWF("Rx: error {}", rc);
|
||||
}
|
||||
// Reserve space in advance
|
||||
m.mList.reserve(static_cast< size_t >(rc));
|
||||
// Transfer matches to match-list
|
||||
for (int i = 0; i < rc; ++i)
|
||||
{
|
||||
m.mList.emplace_back(mOVEC[i*2], mOVEC[i*2+1] - mOVEC[i*2]);
|
||||
}
|
||||
// Yield result back to script
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Matches the given subject string against the pattern.
|
||||
* The first entry in m contains the position of the captured sub-string.
|
||||
* The following entries identify matching sub-patterns. See the PCRE documentation for a more detailed explanation.
|
||||
* If no part of the subject matches the pattern, m is empty.
|
||||
* Returns the number of matches. Throws an exception in case of an error.
|
||||
*/
|
||||
SQMOD_NODISCARD int Match(RxMatches & m, StackStrF & s)
|
||||
{
|
||||
return MatchFrom_(OPTIONS, 0, m, s);
|
||||
}
|
||||
SQMOD_NODISCARD int Match_(int f, RxMatches & m, StackStrF & s)
|
||||
{
|
||||
return MatchFrom_(f, 0, m, s);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns true if and only if the subject matches the regular expression.
|
||||
* Internally, this method sets the RE_ANCHORED and RE_NOTEMPTY options for matching,
|
||||
* which means that the empty string will never match and the pattern is treated as if it starts with a ^.
|
||||
*/
|
||||
SQMOD_NODISCARD bool Matches(StackStrF & s)
|
||||
{
|
||||
return Matches_(PCRE_ANCHORED | PCRE_NOTEMPTY, s);
|
||||
}
|
||||
SQMOD_NODISCARD bool Matches_(SQInteger o, StackStrF & s)
|
||||
{
|
||||
return MatchesEx(PCRE_ANCHORED | PCRE_NOTEMPTY, 0, s);
|
||||
}
|
||||
SQMOD_NODISCARD bool MatchesEx(int f, SQInteger o, StackStrF & s)
|
||||
{
|
||||
RxMatch m;
|
||||
const int rc = MatchFirstFrom_(f, o, m, s);
|
||||
return (rc > 0) && (m.mOffset == o) && (m.mLength == (s.mLen - o));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
@ -362,6 +362,15 @@ static const EnumElement g_MainEnum[] = {
|
||||
{_SC("WARNING_AUTOINDEX"), SQLITE_WARNING_AUTOINDEX}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LightObj GetSQLiteFromSession(Poco::Data::SessionImpl * session)
|
||||
{
|
||||
// Create a reference counted connection handle instance
|
||||
SQLiteConnRef ref(new SQLiteConnHnd(session));
|
||||
// Transform it into a connection instance and yield it as a script object
|
||||
return LightObj(SqTypeIdentity< SQLiteConnection >{}, SqVM(), ref);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static inline bool IsDigitsOnly(const SQChar * str)
|
||||
{
|
||||
@ -374,13 +383,13 @@ static inline bool IsDigitsOnly(const SQChar * str)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object GetConnectionObj(const ConnRef & conn)
|
||||
Object GetConnectionObj(const SQLiteConnRef & conn)
|
||||
{
|
||||
return Object(new SQLiteConnection(conn));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object GetStatementObj(const StmtRef & stmt)
|
||||
Object GetStatementObj(const SQLiteStmtRef & stmt)
|
||||
{
|
||||
return Object(new SQLiteStatement(stmt));
|
||||
}
|
||||
@ -602,6 +611,7 @@ SQLiteConnHnd::SQLiteConnHnd()
|
||||
, mFlags(0)
|
||||
, mName()
|
||||
, mVFS()
|
||||
, mSession()
|
||||
, mMemory(false)
|
||||
, mTrace(false)
|
||||
, mProfile(false)
|
||||
@ -609,6 +619,24 @@ SQLiteConnHnd::SQLiteConnHnd()
|
||||
/* ... */
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQLiteConnHnd::SQLiteConnHnd(Poco::Data::SessionImpl * session)
|
||||
: SQLiteConnHnd()
|
||||
{
|
||||
mSession.assign(session, true);
|
||||
// Retrieve the internal handle property
|
||||
mPtr = Poco::AnyCast< sqlite3 * >(session->getProperty("handle"));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQLiteConnHnd::SQLiteConnHnd(Poco::AutoPtr< Poco::Data::SessionImpl > && session)
|
||||
: SQLiteConnHnd()
|
||||
{
|
||||
mSession == std::forward< Poco::AutoPtr< Poco::Data::SessionImpl > >(session);
|
||||
// Retrieve the internal handle property
|
||||
mPtr = Poco::AnyCast< sqlite3 * >(session->getProperty("handle"));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQLiteConnHnd::~SQLiteConnHnd()
|
||||
{
|
||||
@ -619,10 +647,17 @@ SQLiteConnHnd::~SQLiteConnHnd()
|
||||
Flush(static_cast<uint32_t>(mQueue.size()), NullObject(), NullFunction());
|
||||
// NOTE: Should we call sqlite3_interrupt(...) before closing?
|
||||
// Attempt to close the database
|
||||
if ((sqlite3_close(mPtr)) != SQLITE_OK)
|
||||
// If this connection is a pooled session then let it clean itself up
|
||||
if (mSession.isNull() && (sqlite3_close(mPtr)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to close SQLite connection [%s]", sqlite3_errmsg(mPtr));
|
||||
}
|
||||
else
|
||||
{
|
||||
mSession.reset();
|
||||
}
|
||||
// Prevent further use of this connection
|
||||
mPtr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -630,7 +665,7 @@ SQLiteConnHnd::~SQLiteConnHnd()
|
||||
void SQLiteConnHnd::Create(const SQChar * name, int32_t flags, const SQChar * vfs)
|
||||
{
|
||||
// Make sure a previous connection doesn't exist
|
||||
if (mPtr)
|
||||
if (Access())
|
||||
{
|
||||
STHROWF("Unable to connect to database. Database already connected");
|
||||
}
|
||||
@ -663,7 +698,7 @@ void SQLiteConnHnd::Create(const SQChar * name, int32_t flags, const SQChar * vf
|
||||
int32_t SQLiteConnHnd::Flush(uint32_t num, Object & env, Function & func)
|
||||
{
|
||||
// Do we even have a valid connection?
|
||||
if (!mPtr)
|
||||
if (!Access())
|
||||
{
|
||||
return -1; // No connection!
|
||||
}
|
||||
@ -751,10 +786,10 @@ int32_t SQLiteConnHnd::Flush(uint32_t num, Object & env, Function & func)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQLiteStmtHnd::SQLiteStmtHnd(ConnRef conn)
|
||||
SQLiteStmtHnd::SQLiteStmtHnd(SQLiteConnRef conn)
|
||||
: mPtr(nullptr)
|
||||
, mStatus(SQLITE_OK)
|
||||
, mConn(std::move(conn))
|
||||
, mConnection(std::move(conn))
|
||||
, mQuery()
|
||||
, mColumns(0)
|
||||
, mParameters(0)
|
||||
@ -774,7 +809,7 @@ SQLiteStmtHnd::~SQLiteStmtHnd()
|
||||
// Attempt to finalize the statement
|
||||
if ((sqlite3_finalize(mPtr)) != SQLITE_OK)
|
||||
{
|
||||
LogErr("Unable to finalize SQLite statement [%s]", mConn->ErrMsg());
|
||||
LogErr("Unable to finalize SQLite statement [%s]", mConnection->ErrMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -783,12 +818,12 @@ SQLiteStmtHnd::~SQLiteStmtHnd()
|
||||
void SQLiteStmtHnd::Create(const SQChar * query, SQInteger length)
|
||||
{
|
||||
// Make sure a previous statement doesn't exist
|
||||
if (mPtr)
|
||||
if (Access())
|
||||
{
|
||||
STHROWF("Unable to prepare statement. Statement already prepared");
|
||||
}
|
||||
// Is the specified database connection is valid?
|
||||
else if (!mConn)
|
||||
else if (!mConnection)
|
||||
{
|
||||
STHROWF("Unable to prepare statement. Invalid connection handle");
|
||||
}
|
||||
@ -800,7 +835,7 @@ void SQLiteStmtHnd::Create(const SQChar * query, SQInteger length)
|
||||
// Save the query string
|
||||
mQuery.assign(query, static_cast< size_t >(length));
|
||||
// Attempt to prepare a statement with the specified query string
|
||||
if ((mStatus = sqlite3_prepare_v2(mConn->mPtr, mQuery.c_str(), ConvTo< int32_t >::From(mQuery.size()),
|
||||
if ((mStatus = sqlite3_prepare_v2(mConnection->mPtr, mQuery.c_str(), ConvTo< int32_t >::From(mQuery.size()),
|
||||
&mPtr, nullptr)) != SQLITE_OK)
|
||||
{
|
||||
// Clear the query string since it failed
|
||||
@ -808,7 +843,7 @@ void SQLiteStmtHnd::Create(const SQChar * query, SQInteger length)
|
||||
// Explicitly make sure the handle is null
|
||||
mPtr = nullptr;
|
||||
// Now it's safe to throw the error
|
||||
STHROWF("Unable to prepare statement [{}]", mConn->ErrMsg());
|
||||
STHROWF("Unable to prepare statement [{}]", mConnection->ErrMsg());
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -823,7 +858,7 @@ void SQLiteStmtHnd::Create(const SQChar * query, SQInteger length)
|
||||
int32_t SQLiteStmtHnd::GetColumnIndex(const SQChar * name, SQInteger length)
|
||||
{
|
||||
// Validate the handle
|
||||
if (!mPtr)
|
||||
if (!Access())
|
||||
{
|
||||
STHROWF("Invalid SQLite statement");
|
||||
}
|
||||
@ -861,25 +896,25 @@ int32_t SQLiteStmtHnd::GetColumnIndex(const SQChar * name, SQInteger length)
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const char * SQLiteStmtHnd::ErrStr() const
|
||||
{
|
||||
return mConn ? sqlite3_errstr(sqlite3_errcode(mConn->mPtr)) : _SC("");
|
||||
return mConnection ? sqlite3_errstr(sqlite3_errcode(mConnection->Access())) : _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const char * SQLiteStmtHnd::ErrMsg() const
|
||||
{
|
||||
return mConn ? sqlite3_errmsg(mConn->mPtr) : _SC("");
|
||||
return mConnection ? sqlite3_errmsg(mConnection->Access()) : _SC("");
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int32_t SQLiteStmtHnd::ErrNo() const
|
||||
{
|
||||
return mConn ? sqlite3_errcode(mConn->mPtr) : SQLITE_NOMEM;
|
||||
return mConnection ? sqlite3_errcode(mConnection->Access()) : SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
int32_t SQLiteStmtHnd::ExErrNo() const
|
||||
{
|
||||
return mConn ? sqlite3_extended_errcode(mConn->mPtr) : SQLITE_NOMEM;
|
||||
return mConnection ? sqlite3_extended_errcode(mConnection->Access()) : SQLITE_NOMEM;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -921,7 +956,7 @@ void SQLiteConnection::ValidateCreated(const char * file, int32_t line) const
|
||||
{
|
||||
SqThrowF(SQMOD_RTFMT("Invalid SQLite connection reference =>[{}:{}]"), file, line);
|
||||
}
|
||||
else if (m_Handle->mPtr == nullptr)
|
||||
else if (m_Handle->Access() == nullptr)
|
||||
{
|
||||
SqThrowF(SQMOD_RTFMT("Invalid SQLite connection =>[{}:{}]"), file, line);
|
||||
}
|
||||
@ -933,7 +968,7 @@ void SQLiteConnection::ValidateCreated() const
|
||||
{
|
||||
SqThrowF(fmt::runtime("Invalid SQLite connection reference"));
|
||||
}
|
||||
else if (m_Handle->mPtr == nullptr)
|
||||
else if (m_Handle->Access() == nullptr)
|
||||
{
|
||||
SqThrowF(fmt::runtime("Invalid SQLite connection"));
|
||||
}
|
||||
@ -942,13 +977,13 @@ void SQLiteConnection::ValidateCreated() const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
const ConnRef & SQLiteConnection::GetValid(const char * file, int32_t line) const
|
||||
const SQLiteConnRef & SQLiteConnection::GetValid(const char * file, int32_t line) const
|
||||
{
|
||||
Validate(file, line);
|
||||
return m_Handle;
|
||||
}
|
||||
#else
|
||||
const ConnRef & SQLiteConnection::GetValid() const
|
||||
const SQLiteConnRef & SQLiteConnection::GetValid() const
|
||||
{
|
||||
Validate();
|
||||
return m_Handle;
|
||||
@ -957,13 +992,13 @@ const ConnRef & SQLiteConnection::GetValid() const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
const ConnRef & SQLiteConnection::GetCreated(const char * file, int32_t line) const
|
||||
const SQLiteConnRef & SQLiteConnection::GetCreated(const char * file, int32_t line) const
|
||||
{
|
||||
ValidateCreated(file, line);
|
||||
return m_Handle;
|
||||
}
|
||||
#else
|
||||
const ConnRef & SQLiteConnection::GetCreated() const
|
||||
const SQLiteConnRef & SQLiteConnection::GetCreated() const
|
||||
{
|
||||
ValidateCreated();
|
||||
return m_Handle;
|
||||
@ -976,7 +1011,7 @@ void SQLiteConnection::Open(StackStrF & name)
|
||||
// Should we create a connection handle?
|
||||
if (!m_Handle)
|
||||
{
|
||||
m_Handle = ConnRef(new SQLiteConnHnd());
|
||||
m_Handle = SQLiteConnRef(new SQLiteConnHnd());
|
||||
}
|
||||
// Make sure another database isn't opened
|
||||
if (SQMOD_GET_VALID(*this)->mPtr != nullptr)
|
||||
@ -996,7 +1031,7 @@ void SQLiteConnection::Open(StackStrF & name, int32_t flags)
|
||||
// Should we create a connection handle?
|
||||
if (!m_Handle)
|
||||
{
|
||||
m_Handle = ConnRef(new SQLiteConnHnd());
|
||||
m_Handle = SQLiteConnRef(new SQLiteConnHnd());
|
||||
}
|
||||
// Make sure another database isn't opened
|
||||
if (SQMOD_GET_VALID(*this)->mPtr != nullptr)
|
||||
@ -1013,7 +1048,7 @@ void SQLiteConnection::Open(StackStrF & name, int32_t flags, StackStrF & vfs)
|
||||
// Should we create a connection handle?
|
||||
if (!m_Handle)
|
||||
{
|
||||
m_Handle = ConnRef(new SQLiteConnHnd());
|
||||
m_Handle = SQLiteConnRef(new SQLiteConnHnd());
|
||||
}
|
||||
// Make sure another database isn't opened
|
||||
if (SQMOD_GET_VALID(*this)->mPtr != nullptr)
|
||||
@ -1029,14 +1064,14 @@ int32_t SQLiteConnection::Exec(StackStrF & str)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to execute the specified query
|
||||
m_Handle->mStatus = sqlite3_exec(m_Handle->mPtr, str.mPtr, nullptr, nullptr, nullptr);
|
||||
m_Handle->mStatus = sqlite3_exec(m_Handle->Access(), str.mPtr, nullptr, nullptr, nullptr);
|
||||
// Validate the execution result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
STHROWF("Unable to execute query [{}]", m_Handle->ErrMsg());
|
||||
}
|
||||
// Return rows affected by this query
|
||||
return sqlite3_changes(m_Handle->mPtr);
|
||||
return sqlite3_changes(m_Handle->Access());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -1109,12 +1144,12 @@ void SQLiteConnection::SetTracing(bool SQ_UNUSED_ARG(toggle)) // NOLINT(readabil
|
||||
// Do we have to disable it?
|
||||
else if (m_Handle->mTrace)
|
||||
{
|
||||
sqlite3_trace(m_Handle->mPtr, nullptr, nullptr);
|
||||
sqlite3_trace(m_Handle->Access(), nullptr, nullptr);
|
||||
}
|
||||
// Go ahead and enable tracing
|
||||
else
|
||||
{
|
||||
sqlite3_trace(m_Handle->mPtr, &SQLiteConnection::TraceOutput, nullptr);
|
||||
sqlite3_trace(m_Handle->Access(), &SQLiteConnection::TraceOutput, nullptr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1133,12 +1168,12 @@ void SQLiteConnection::SetProfiling(bool SQ_UNUSED_ARG(toggle)) // NOLINT(readab
|
||||
// Do we have to disable it?
|
||||
else if (m_Handle->mProfile)
|
||||
{
|
||||
sqlite3_profile(m_Handle->mPtr, nullptr, nullptr);
|
||||
sqlite3_profile(m_Handle->Access(), nullptr, nullptr);
|
||||
}
|
||||
// Go ahead and enable profiling
|
||||
else
|
||||
{
|
||||
sqlite3_profile(m_Handle->mPtr, &SQLiteConnection::ProfileOutput, nullptr);
|
||||
sqlite3_profile(m_Handle->Access(), &SQLiteConnection::ProfileOutput, nullptr);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@ -1148,7 +1183,7 @@ void SQLiteConnection::SetBusyTimeout(int32_t millis)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Apply the requested timeout
|
||||
if ((m_Handle->mStatus = sqlite3_busy_timeout(m_Handle->mPtr, millis)) != SQLITE_OK)
|
||||
if ((m_Handle->mStatus = sqlite3_busy_timeout(m_Handle->Access(), millis)) != SQLITE_OK)
|
||||
{
|
||||
STHROWF("Unable to set busy timeout [{}]", m_Handle->ErrMsg());
|
||||
}
|
||||
@ -1269,7 +1304,7 @@ void SQLiteParameter::ValidateCreated(const char * file, int32_t line) const
|
||||
{
|
||||
SqThrowF(SQMOD_RTFMT("Invalid SQLite statement reference =>[{}:{}]"), file, line);
|
||||
}
|
||||
else if (m_Handle->mPtr == nullptr)
|
||||
else if (m_Handle->Access() == nullptr)
|
||||
{
|
||||
SqThrowF(SQMOD_RTFMT("Invalid SQLite statement =>[{}:{}]"), file, line);
|
||||
}
|
||||
@ -1286,7 +1321,7 @@ void SQLiteParameter::ValidateCreated() const
|
||||
{
|
||||
SqThrowF(fmt::runtime("Invalid SQLite statement reference"));
|
||||
}
|
||||
else if (m_Handle->mPtr == nullptr)
|
||||
else if (m_Handle->Access() == nullptr)
|
||||
{
|
||||
SqThrowF(fmt::runtime("Invalid SQLite statement"));
|
||||
}
|
||||
@ -1295,13 +1330,13 @@ void SQLiteParameter::ValidateCreated() const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
const StmtRef & SQLiteParameter::GetValid(const char * file, int32_t line) const
|
||||
const SQLiteStmtRef & SQLiteParameter::GetValid(const char * file, int32_t line) const
|
||||
{
|
||||
Validate(file, line);
|
||||
return m_Handle;
|
||||
}
|
||||
#else
|
||||
const StmtRef & SQLiteParameter::GetValid() const
|
||||
const SQLiteStmtRef & SQLiteParameter::GetValid() const
|
||||
{
|
||||
Validate();
|
||||
return m_Handle;
|
||||
@ -1310,13 +1345,13 @@ const StmtRef & SQLiteParameter::GetValid() const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
const StmtRef & SQLiteParameter::GetCreated(const char * file, int32_t line) const
|
||||
const SQLiteStmtRef & SQLiteParameter::GetCreated(const char * file, int32_t line) const
|
||||
{
|
||||
ValidateCreated(file, line);
|
||||
return m_Handle;
|
||||
}
|
||||
#else
|
||||
const StmtRef & SQLiteParameter::GetCreated() const
|
||||
const SQLiteStmtRef & SQLiteParameter::GetCreated() const
|
||||
{
|
||||
ValidateCreated();
|
||||
return m_Handle;
|
||||
@ -1377,7 +1412,7 @@ void SQLiteParameter::SetIndex(const Object & param)
|
||||
STHROWF("Cannot use an empty parameter name");
|
||||
}
|
||||
// Attempt to find a parameter with the specified name
|
||||
idx = sqlite3_bind_parameter_index(SQMOD_GET_CREATED(*this)->mPtr, val.mPtr);
|
||||
idx = sqlite3_bind_parameter_index(SQMOD_GET_CREATED(*this)->Access(), val.mPtr);
|
||||
} break;
|
||||
// Is this an integer value? (or at least can be easily converted to one)
|
||||
case OT_INTEGER:
|
||||
@ -1409,7 +1444,7 @@ void SQLiteParameter::SetIndex(const Object & param)
|
||||
// Attempt to find a parameter with the specified name
|
||||
else
|
||||
{
|
||||
idx = sqlite3_bind_parameter_index(SQMOD_GET_CREATED(*this)->mPtr, val.mPtr);
|
||||
idx = sqlite3_bind_parameter_index(SQMOD_GET_CREATED(*this)->Access(), val.mPtr);
|
||||
}
|
||||
} break;
|
||||
// We don't recognize this kind of value!
|
||||
@ -1432,7 +1467,7 @@ Object SQLiteParameter::GetStatement() const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object SQLiteParameter::GetConnection() const
|
||||
{
|
||||
return GetConnectionObj(SQMOD_GET_VALID(*this)->mConn);
|
||||
return GetConnectionObj(SQMOD_GET_VALID(*this)->mConnection);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -1477,7 +1512,7 @@ void SQLiteParameter::SetBool(bool value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, value);
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, value);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1490,7 +1525,7 @@ void SQLiteParameter::SetChar(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< SQChar >::From(value));
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, ConvTo< SQChar >::From(value));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1503,7 +1538,7 @@ void SQLiteParameter::SetInteger(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_integer(m_Handle->mPtr, m_Index, value);
|
||||
m_Handle->mStatus = sqlite3_bind_integer(m_Handle->Access(), m_Index, value);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1516,7 +1551,7 @@ void SQLiteParameter::SetInt8(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< int8_t >::From(value));
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, ConvTo< int8_t >::From(value));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1529,7 +1564,7 @@ void SQLiteParameter::SetUint8(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< uint8_t >::From(value));
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, ConvTo< uint8_t >::From(value));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1542,7 +1577,7 @@ void SQLiteParameter::SetInt16(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< int16_t >::From(value));
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, ConvTo< int16_t >::From(value));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1555,7 +1590,7 @@ void SQLiteParameter::SetUint16(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< uint16_t >::From(value));
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, ConvTo< uint16_t >::From(value));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1568,7 +1603,7 @@ void SQLiteParameter::SetInt32(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, ConvTo< int32_t >::From(value));
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, ConvTo< int32_t >::From(value));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1581,7 +1616,7 @@ void SQLiteParameter::SetUint32(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, static_cast< int32_t >(ConvTo< uint32_t >::From(value)));
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, static_cast< int32_t >(ConvTo< uint32_t >::From(value)));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1594,7 +1629,7 @@ void SQLiteParameter::SetInt64(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int64(m_Handle->mPtr, m_Index, value);
|
||||
m_Handle->mStatus = sqlite3_bind_int64(m_Handle->Access(), m_Index, value);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1607,7 +1642,7 @@ void SQLiteParameter::SetUint64(SQInteger value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int64(m_Handle->mPtr, m_Index, value);
|
||||
m_Handle->mStatus = sqlite3_bind_int64(m_Handle->Access(), m_Index, value);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1620,7 +1655,7 @@ void SQLiteParameter::SetFloat(SQFloat value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_double(m_Handle->mPtr, m_Index, value);
|
||||
m_Handle->mStatus = sqlite3_bind_double(m_Handle->Access(), m_Index, value);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1633,7 +1668,7 @@ void SQLiteParameter::SetFloat32(SQFloat value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_double(m_Handle->mPtr, m_Index, ConvTo< float >::From(value));
|
||||
m_Handle->mStatus = sqlite3_bind_double(m_Handle->Access(), m_Index, ConvTo< float >::From(value));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1646,7 +1681,7 @@ void SQLiteParameter::SetFloat64(SQFloat value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_double(m_Handle->mPtr, m_Index, value);
|
||||
m_Handle->mStatus = sqlite3_bind_double(m_Handle->Access(), m_Index, value);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1659,7 +1694,7 @@ void SQLiteParameter::SetString(StackStrF & value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, value.mPtr, static_cast<int>(value.mLen), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->Access(), m_Index, value.mPtr, static_cast<int>(value.mLen), SQLITE_TRANSIENT);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1672,7 +1707,7 @@ void SQLiteParameter::SetStringRaw(const SQChar * value, SQInteger length)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, value, static_cast<int>(length), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->Access(), m_Index, value, static_cast<int>(length), SQLITE_TRANSIENT);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1685,7 +1720,7 @@ void SQLiteParameter::SetZeroBlob(SQInteger size)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_zeroblob(m_Handle->mPtr, m_Index, ConvTo< int32_t >::From(size));
|
||||
m_Handle->mStatus = sqlite3_bind_zeroblob(m_Handle->Access(), m_Index, ConvTo< int32_t >::From(size));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1717,7 +1752,7 @@ void SQLiteParameter::SetBlob(const Object & value)
|
||||
len = sqstd_getblobsize(vm, -1);
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_blob(m_Handle->mPtr, m_Index, ptr, static_cast<int>(len), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_blob(m_Handle->Access(), m_Index, ptr, static_cast<int>(len), SQLITE_TRANSIENT);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1731,9 +1766,9 @@ void SQLiteParameter::SetData(const SqBuffer & value)
|
||||
Buffer & buff = *value.GetRef();
|
||||
// Attempt to bind the specified value
|
||||
#ifdef _SQ64
|
||||
m_Handle->mStatus = sqlite3_bind_blob64(m_Handle->mPtr, m_Index, buff.Data(), buff.Position(), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_blob64(m_Handle->Access(), m_Index, buff.Data(), buff.Position(), SQLITE_TRANSIENT);
|
||||
#else
|
||||
m_Handle->mStatus = sqlite3_bind_blob(m_Handle->mPtr, m_Index, buff.Data(), buff.Position(), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_blob(m_Handle->Access(), m_Index, buff.Data(), buff.Position(), SQLITE_TRANSIENT);
|
||||
#endif
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
@ -1762,9 +1797,9 @@ void SQLiteParameter::SetDataEx(const SqBuffer & value, SQInteger offset, SQInte
|
||||
}
|
||||
// Attempt to bind the specified value
|
||||
#ifdef _SQ64
|
||||
m_Handle->mStatus = sqlite3_bind_blob64(m_Handle->mPtr, m_Index, (buff.Data() + offset), static_cast< sqlite3_uint64 >(offset + length), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_blob64(m_Handle->Access(), m_Index, (buff.Data() + offset), static_cast< sqlite3_uint64 >(offset + length), SQLITE_TRANSIENT);
|
||||
#else
|
||||
m_Handle->mStatus = sqlite3_bind_blob(m_Handle->mPtr, m_Index, (buff.Data() + offset), static_cast< int >(offset + length), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_blob(m_Handle->Access(), m_Index, (buff.Data() + offset), static_cast< int >(offset + length), SQLITE_TRANSIENT);
|
||||
#endif
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
@ -1780,7 +1815,7 @@ void SQLiteParameter::SetDate(const Date & value)
|
||||
// Attempt to generate the specified date string
|
||||
auto str = fmt::format("{} 00:00:00", value.ToString());
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, str.data(), static_cast< int >(str.size()), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->Access(), m_Index, str.data(), static_cast< int >(str.size()), SQLITE_TRANSIENT);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1803,7 +1838,7 @@ void SQLiteParameter::SetDateEx(SQInteger year, SQInteger month, SQInteger day)
|
||||
// Attempt to generate the specified date string
|
||||
auto str = fmt::format("{}-{}-{} 00:00:00", y, m, d);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, str.data(), static_cast< int >(str.size()), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->Access(), m_Index, str.data(), static_cast< int >(str.size()), SQLITE_TRANSIENT);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1816,7 +1851,7 @@ void SQLiteParameter::SetTime(const Time & value)
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, static_cast<int>(value.GetTimestamp().GetSecondsI()));
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, static_cast<int>(value.GetTimestamp().GetSecondsI()));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1848,7 +1883,7 @@ void SQLiteParameter::SetTimeEx(SQInteger hour, SQInteger minute, SQInteger seco
|
||||
STHROWF("Second value is out of range: {} >= 60", s);
|
||||
}
|
||||
// Calculate the number of seconds in the specified time and bind the resulted value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index, (h * (60 * 60)) + (m * 60) + s);
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index, (h * (60 * 60)) + (m * 60) + s);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1896,7 +1931,7 @@ void SQLiteParameter::SetDatetimeEx(SQInteger year, SQInteger month, SQInteger d
|
||||
// Attempt to generate the specified date string
|
||||
auto str = fmt::format(_SC("{:04}-{:02}-{:02} {:02}:{:02}:{:02}"), y, mo, d, h, mi, s);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->mPtr, m_Index, str.data(), static_cast< int >(str.size()), SQLITE_TRANSIENT);
|
||||
m_Handle->mStatus = sqlite3_bind_text(m_Handle->Access(), m_Index, str.data(), static_cast< int >(str.size()), SQLITE_TRANSIENT);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1909,7 +1944,7 @@ void SQLiteParameter::SetNow()
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->mPtr, m_Index,
|
||||
m_Handle->mStatus = sqlite3_bind_int(m_Handle->Access(), m_Index,
|
||||
static_cast< int32_t >(std::time(nullptr)));
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
@ -1923,7 +1958,7 @@ void SQLiteParameter::SetNull()
|
||||
{
|
||||
SQMOD_VALIDATE_CREATED(*this);
|
||||
// Attempt to bind the specified value
|
||||
m_Handle->mStatus = sqlite3_bind_null(m_Handle->mPtr, m_Index);
|
||||
m_Handle->mStatus = sqlite3_bind_null(m_Handle->Access(), m_Index);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -1975,7 +2010,7 @@ void SQLiteColumn::ValidateCreated(const char * file, int32_t line) const
|
||||
{
|
||||
SqThrowF(SQMOD_RTFMT("Invalid SQLite statement reference =>[{}:{}]"), file, line);
|
||||
}
|
||||
else if (m_Handle->mPtr == nullptr)
|
||||
else if (m_Handle->Access() == nullptr)
|
||||
{
|
||||
SqThrowF(SQMOD_RTFMT("Invalid SQLite statement =>[{}:{}]"), file, line);
|
||||
}
|
||||
@ -1992,7 +2027,7 @@ void SQLiteColumn::ValidateCreated() const
|
||||
{
|
||||
SqThrowF(fmt::runtime("Invalid SQLite statement reference"));
|
||||
}
|
||||
else if (m_Handle->mPtr == nullptr)
|
||||
else if (m_Handle->Access() == nullptr)
|
||||
{
|
||||
SqThrowF(fmt::runtime("Invalid SQLite statement"));
|
||||
}
|
||||
@ -2001,13 +2036,13 @@ void SQLiteColumn::ValidateCreated() const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
const StmtRef & SQLiteColumn::GetValid(const char * file, int32_t line) const
|
||||
const SQLiteStmtRef & SQLiteColumn::GetValid(const char * file, int32_t line) const
|
||||
{
|
||||
Validate(file, line);
|
||||
return m_Handle;
|
||||
}
|
||||
#else
|
||||
const StmtRef & SQLiteColumn::GetValid() const
|
||||
const SQLiteStmtRef & SQLiteColumn::GetValid() const
|
||||
{
|
||||
Validate();
|
||||
return m_Handle;
|
||||
@ -2016,13 +2051,13 @@ const StmtRef & SQLiteColumn::GetValid() const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
const StmtRef & SQLiteColumn::GetCreated(const char * file, int32_t line) const
|
||||
const SQLiteStmtRef & SQLiteColumn::GetCreated(const char * file, int32_t line) const
|
||||
{
|
||||
ValidateCreated(file, line);
|
||||
return m_Handle;
|
||||
}
|
||||
#else
|
||||
const StmtRef & SQLiteColumn::GetCreated() const
|
||||
const SQLiteStmtRef & SQLiteColumn::GetCreated() const
|
||||
{
|
||||
ValidateCreated();
|
||||
return m_Handle;
|
||||
@ -2161,7 +2196,7 @@ Object SQLiteColumn::GetStatement() const
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object SQLiteColumn::GetConnection() const
|
||||
{
|
||||
return GetConnectionObj(SQMOD_GET_VALID(*this)->mConn);
|
||||
return GetConnectionObj(SQMOD_GET_VALID(*this)->mConnection);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -2207,7 +2242,7 @@ Object SQLiteColumn::GetValue() const
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg;
|
||||
// Identify which type of value must be pushed on the stack
|
||||
switch (sqlite3_column_type(m_Handle->mPtr, m_Index))
|
||||
switch (sqlite3_column_type(m_Handle->Access(), m_Index))
|
||||
{
|
||||
// Is this a null value?
|
||||
case SQLITE_NULL:
|
||||
@ -2217,28 +2252,28 @@ Object SQLiteColumn::GetValue() const
|
||||
// Is this an integer?
|
||||
case SQLITE_INTEGER:
|
||||
{
|
||||
sq_pushinteger(SqVM(), sqlite3_column_integer(m_Handle->mPtr, m_Index));
|
||||
sq_pushinteger(SqVM(), sqlite3_column_integer(m_Handle->Access(), m_Index));
|
||||
} break;
|
||||
// Is this a floating point?
|
||||
case SQLITE_FLOAT:
|
||||
{
|
||||
sq_pushfloat(SqVM(),
|
||||
ConvTo< SQFloat >::From(sqlite3_column_double(m_Handle->mPtr, m_Index)));
|
||||
ConvTo< SQFloat >::From(sqlite3_column_double(m_Handle->Access(), m_Index)));
|
||||
} break;
|
||||
// Is this a string?
|
||||
case SQLITE_TEXT:
|
||||
{
|
||||
sq_pushstring(SqVM(),
|
||||
reinterpret_cast< const SQChar * >(sqlite3_column_text(m_Handle->mPtr, m_Index)),
|
||||
sqlite3_column_bytes(m_Handle->mPtr, m_Index));
|
||||
reinterpret_cast< const SQChar * >(sqlite3_column_text(m_Handle->Access(), m_Index)),
|
||||
sqlite3_column_bytes(m_Handle->Access(), m_Index));
|
||||
} break;
|
||||
// Is this raw data?
|
||||
case SQLITE_BLOB:
|
||||
{
|
||||
// Retrieve the size of the blob that must be allocated
|
||||
const int32_t size = sqlite3_column_bytes(m_Handle->mPtr, m_Index);
|
||||
const int32_t size = sqlite3_column_bytes(m_Handle->Access(), m_Index);
|
||||
// Retrieve the the actual blob data that must be returned
|
||||
auto data = reinterpret_cast< const char * >(sqlite3_column_blob(m_Handle->mPtr, m_Index));
|
||||
auto data = reinterpret_cast< const char * >(sqlite3_column_blob(m_Handle->Access(), m_Index));
|
||||
// Attempt to create a buffer with the blob data on the stack
|
||||
Var< const SqBuffer & >::push(SqVM(), SqBuffer(data, size, 0));
|
||||
} break;
|
||||
@ -2256,7 +2291,7 @@ Object SQLiteColumn::GetNumber() const
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg;
|
||||
// Identify which type of value must be pushed on the stack
|
||||
switch (sqlite3_column_type(m_Handle->mPtr, m_Index))
|
||||
switch (sqlite3_column_type(m_Handle->Access(), m_Index))
|
||||
{
|
||||
// Is this a null value?
|
||||
case SQLITE_NULL:
|
||||
@ -2266,18 +2301,18 @@ Object SQLiteColumn::GetNumber() const
|
||||
// Is this an integer?
|
||||
case SQLITE_INTEGER:
|
||||
{
|
||||
sq_pushinteger(SqVM(), sqlite3_column_integer(m_Handle->mPtr, m_Index));
|
||||
sq_pushinteger(SqVM(), sqlite3_column_integer(m_Handle->Access(), m_Index));
|
||||
} break;
|
||||
// Is this a floating point?
|
||||
case SQLITE_FLOAT:
|
||||
{
|
||||
sq_pushfloat(SqVM(),
|
||||
ConvTo< SQFloat >::From(sqlite3_column_double(m_Handle->mPtr, m_Index)));
|
||||
ConvTo< SQFloat >::From(sqlite3_column_double(m_Handle->Access(), m_Index)));
|
||||
} break;
|
||||
// Is this a string?
|
||||
case SQLITE_TEXT:
|
||||
{
|
||||
auto str = reinterpret_cast< const SQChar * >(sqlite3_column_text(m_Handle->mPtr, m_Index));
|
||||
auto str = reinterpret_cast< const SQChar * >(sqlite3_column_text(m_Handle->Access(), m_Index));
|
||||
// Is there even a string to parse?
|
||||
if (!str || *str == '\0')
|
||||
{
|
||||
@ -2308,7 +2343,7 @@ SQInteger SQLiteColumn::GetInteger() const
|
||||
{
|
||||
SQMOD_VALIDATE_ROW(*this);
|
||||
// Return the requested information
|
||||
return sqlite3_column_integer(m_Handle->mPtr, m_Index);
|
||||
return sqlite3_column_integer(m_Handle->Access(), m_Index);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -2316,7 +2351,7 @@ SQFloat SQLiteColumn::GetFloat() const
|
||||
{
|
||||
SQMOD_VALIDATE_ROW(*this);
|
||||
// Return the requested information
|
||||
return ConvTo< SQFloat >::From(sqlite3_column_double(m_Handle->mPtr, m_Index));
|
||||
return ConvTo< SQFloat >::From(sqlite3_column_double(m_Handle->Access(), m_Index));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -2324,7 +2359,7 @@ SQInteger SQLiteColumn::GetLong() const
|
||||
{
|
||||
SQMOD_VALIDATE_ROW(*this);
|
||||
// Return the requested information
|
||||
return sqlite3_column_int64(m_Handle->mPtr, m_Index);
|
||||
return sqlite3_column_int64(m_Handle->Access(), m_Index);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -2334,8 +2369,8 @@ Object SQLiteColumn::GetString() const
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg;
|
||||
// Push the column text on the stack
|
||||
sq_pushstring(SqVM(), reinterpret_cast< const SQChar * >(sqlite3_column_text(m_Handle->mPtr, m_Index)),
|
||||
sqlite3_column_bytes(m_Handle->mPtr, m_Index));
|
||||
sq_pushstring(SqVM(), reinterpret_cast< const SQChar * >(sqlite3_column_text(m_Handle->Access(), m_Index)),
|
||||
sqlite3_column_bytes(m_Handle->Access(), m_Index));
|
||||
// Get the object from the stack and return it
|
||||
return Var< Object >(SqVM(), -1).value;
|
||||
}
|
||||
@ -2345,7 +2380,7 @@ bool SQLiteColumn::GetBoolean() const
|
||||
{
|
||||
SQMOD_VALIDATE_ROW(*this);
|
||||
// Return the requested information
|
||||
return sqlite3_column_int(m_Handle->mPtr, m_Index) > 0;
|
||||
return sqlite3_column_int(m_Handle->Access(), m_Index) > 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -2353,7 +2388,7 @@ SQChar SQLiteColumn::GetChar() const
|
||||
{
|
||||
SQMOD_VALIDATE_ROW(*this);
|
||||
// Return the requested information
|
||||
return (SQChar)sqlite3_column_int(m_Handle->mPtr, m_Index);
|
||||
return (SQChar)sqlite3_column_int(m_Handle->Access(), m_Index);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -2363,9 +2398,9 @@ Object SQLiteColumn::GetBuffer() const
|
||||
// Remember the current stack size
|
||||
const StackGuard sg;
|
||||
// Retrieve the size of the blob that must be allocated
|
||||
const int32_t size = sqlite3_column_bytes(m_Handle->mPtr, m_Index);
|
||||
const int32_t size = sqlite3_column_bytes(m_Handle->Access(), m_Index);
|
||||
// Retrieve the the actual blob data that must be returned
|
||||
auto data = reinterpret_cast< const char * >(sqlite3_column_blob(m_Handle->mPtr, m_Index));
|
||||
auto data = reinterpret_cast< const char * >(sqlite3_column_blob(m_Handle->Access(), m_Index));
|
||||
// Attempt to create a buffer with the blob data on the stack
|
||||
Var< const SqBuffer & >::push(SqVM(), SqBuffer(data, size, 0));
|
||||
// Get the object from the stack and return it
|
||||
@ -2379,11 +2414,11 @@ Object SQLiteColumn::GetBlob() const
|
||||
// Obtain the initial stack size
|
||||
const StackGuard sg;
|
||||
// Obtain the size of the data
|
||||
const int32_t sz = sqlite3_column_bytes(m_Handle->mPtr, m_Index);
|
||||
const int32_t sz = sqlite3_column_bytes(m_Handle->Access(), m_Index);
|
||||
// Allocate a blob of the same size
|
||||
SQUserPointer p = sqstd_createblob(SqVM(), sz);
|
||||
// Obtain a pointer to the data
|
||||
const void * b = sqlite3_column_blob(m_Handle->mPtr, m_Index);
|
||||
const void * b = sqlite3_column_blob(m_Handle->Access(), m_Index);
|
||||
// Could the memory blob be allocated?
|
||||
if (!p)
|
||||
{
|
||||
@ -2433,7 +2468,7 @@ void SQLiteStatement::ValidateCreated(const char * file, int32_t line) const
|
||||
{
|
||||
SqThrowF(SQMOD_RTFMT("Invalid SQLite statement reference =>[{}:{}]"), file, line);
|
||||
}
|
||||
else if (m_Handle->mPtr == nullptr)
|
||||
else if (m_Handle->Access() == nullptr)
|
||||
{
|
||||
SqThrowF(SQMOD_RTFMT("Invalid SQLite statement =>[{}:{}]"), file, line);
|
||||
}
|
||||
@ -2445,7 +2480,7 @@ void SQLiteStatement::ValidateCreated() const
|
||||
{
|
||||
SqThrowF(fmt::runtime("Invalid SQLite statement reference"));
|
||||
}
|
||||
else if (m_Handle->mPtr == nullptr)
|
||||
else if (m_Handle->Access() == nullptr)
|
||||
{
|
||||
SqThrowF(fmt::runtime("Invalid SQLite statement"));
|
||||
}
|
||||
@ -2454,13 +2489,13 @@ void SQLiteStatement::ValidateCreated() const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
const StmtRef & SQLiteStatement::GetValid(const char * file, int32_t line) const
|
||||
const SQLiteStmtRef & SQLiteStatement::GetValid(const char * file, int32_t line) const
|
||||
{
|
||||
Validate(file, line);
|
||||
return m_Handle;
|
||||
}
|
||||
#else
|
||||
const StmtRef & SQLiteStatement::GetValid() const
|
||||
const SQLiteStmtRef & SQLiteStatement::GetValid() const
|
||||
{
|
||||
Validate();
|
||||
return m_Handle;
|
||||
@ -2469,13 +2504,13 @@ const StmtRef & SQLiteStatement::GetValid() const
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
const StmtRef & SQLiteStatement::GetCreated(const char * file, int32_t line) const
|
||||
const SQLiteStmtRef & SQLiteStatement::GetCreated(const char * file, int32_t line) const
|
||||
{
|
||||
ValidateCreated(file, line);
|
||||
return m_Handle;
|
||||
}
|
||||
#else
|
||||
const StmtRef & SQLiteStatement::GetCreated() const
|
||||
const SQLiteStmtRef & SQLiteStatement::GetCreated() const
|
||||
{
|
||||
ValidateCreated();
|
||||
return m_Handle;
|
||||
@ -2561,7 +2596,7 @@ SQLiteStatement::SQLiteStatement(const SQLiteConnection & connection, StackStrF
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Object SQLiteStatement::GetConnection() const
|
||||
{
|
||||
return Object(new SQLiteConnection(SQMOD_GET_VALID(*this)->mConn));
|
||||
return Object(new SQLiteConnection(SQMOD_GET_VALID(*this)->mConnection));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -2572,7 +2607,7 @@ SQLiteStatement & SQLiteStatement::Reset()
|
||||
m_Handle->mGood = false;
|
||||
m_Handle->mDone = false;
|
||||
// Attempt to reset the statement to it's initial state
|
||||
m_Handle->mStatus = sqlite3_reset(m_Handle->mPtr);
|
||||
m_Handle->mStatus = sqlite3_reset(m_Handle->Access());
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -2590,7 +2625,7 @@ SQLiteStatement & SQLiteStatement::Clear()
|
||||
m_Handle->mGood = false;
|
||||
m_Handle->mDone = false;
|
||||
// Attempt to clear the statement
|
||||
m_Handle->mStatus = sqlite3_clear_bindings(m_Handle->mPtr);
|
||||
m_Handle->mStatus = sqlite3_clear_bindings(m_Handle->Access());
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -2610,7 +2645,7 @@ int32_t SQLiteStatement::Exec()
|
||||
STHROWF("Executed without resetting first");
|
||||
}
|
||||
// Attempt to step the statement
|
||||
m_Handle->mStatus = sqlite3_step(m_Handle->mPtr);
|
||||
m_Handle->mStatus = sqlite3_step(m_Handle->Access());
|
||||
// Have we finished stepping?
|
||||
if (m_Handle->mStatus == SQLITE_DONE)
|
||||
{
|
||||
@ -2618,7 +2653,7 @@ int32_t SQLiteStatement::Exec()
|
||||
m_Handle->mGood = false;
|
||||
m_Handle->mDone = true;
|
||||
// Return the changes made by this statement
|
||||
return sqlite3_changes(m_Handle->mConn->mPtr);
|
||||
return sqlite3_changes(m_Handle->mConnection->mPtr);
|
||||
}
|
||||
// Specify that we don't have any row and we haven't finished stepping
|
||||
m_Handle->mGood = false;
|
||||
@ -2651,7 +2686,7 @@ bool SQLiteStatement::Step()
|
||||
STHROWF("Stepped without resetting first");
|
||||
}
|
||||
// Attempt to step the statement
|
||||
m_Handle->mStatus = sqlite3_step(m_Handle->mPtr);
|
||||
m_Handle->mStatus = sqlite3_step(m_Handle->Access());
|
||||
// Do we have a row available?
|
||||
if (m_Handle->mStatus == SQLITE_ROW)
|
||||
{
|
||||
@ -2801,7 +2836,7 @@ Table SQLiteStatement::GetTable(int32_t min, int32_t max) const
|
||||
while (min <= max)
|
||||
{
|
||||
// Attempt to obtain the column name
|
||||
const SQChar * name = sqlite3_column_name(m_Handle->mPtr, min);
|
||||
const SQChar * name = sqlite3_column_name(m_Handle->Access(), min);
|
||||
// Validate the obtained name
|
||||
if (!name)
|
||||
{
|
||||
@ -2824,7 +2859,7 @@ SQLiteTransaction::SQLiteTransaction(const SQLiteConnection & db)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQLiteTransaction::SQLiteTransaction(ConnRef db)
|
||||
SQLiteTransaction::SQLiteTransaction(SQLiteConnRef db)
|
||||
: m_Handle(std::move(db)), m_Committed(false)
|
||||
{
|
||||
// Was the specified database connection valid?
|
||||
@ -2833,7 +2868,7 @@ SQLiteTransaction::SQLiteTransaction(ConnRef db)
|
||||
STHROWF("Invalid connection handle");
|
||||
}
|
||||
// Attempt to begin transaction
|
||||
m_Handle->mStatus = sqlite3_exec(m_Handle->mPtr, "BEGIN", nullptr, nullptr, nullptr);
|
||||
m_Handle->mStatus = sqlite3_exec(m_Handle->Access(), "BEGIN", nullptr, nullptr, nullptr);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -2850,7 +2885,7 @@ SQLiteTransaction::~SQLiteTransaction()
|
||||
return; // We're done here!
|
||||
}
|
||||
// Attempt to roll back changes because this failed to commit
|
||||
m_Handle->mStatus = sqlite3_exec(m_Handle->mPtr, "ROLLBACK", nullptr, nullptr, nullptr);
|
||||
m_Handle->mStatus = sqlite3_exec(m_Handle->Access(), "ROLLBACK", nullptr, nullptr, nullptr);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
@ -2873,7 +2908,7 @@ bool SQLiteTransaction::Commit()
|
||||
STHROWF("Transaction was already committed");
|
||||
}
|
||||
// Attempt to commit the change during this transaction
|
||||
m_Handle->mStatus = sqlite3_exec(m_Handle->mPtr, "COMMIT", nullptr, nullptr, nullptr);
|
||||
m_Handle->mStatus = sqlite3_exec(m_Handle->Access(), "COMMIT", nullptr, nullptr, nullptr);
|
||||
// Validate the result
|
||||
if (m_Handle->mStatus != SQLITE_OK)
|
||||
{
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
#include "Core/ThreadPool.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/IO/Buffer.hpp"
|
||||
@ -10,6 +11,10 @@
|
||||
#include "Library/Chrono/Time.hpp"
|
||||
#include "Library/Chrono/Timestamp.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Poco/AutoPtr.h"
|
||||
#include "Poco/Data/SessionImpl.h"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@ -78,18 +83,18 @@ struct SQLiteStmtHnd;
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Common typedefs.
|
||||
*/
|
||||
typedef SharedPtr< SQLiteConnHnd > ConnRef;
|
||||
typedef SharedPtr< SQLiteStmtHnd > StmtRef;
|
||||
typedef SharedPtr< SQLiteConnHnd > SQLiteConnRef;
|
||||
typedef SharedPtr< SQLiteStmtHnd > SQLiteStmtRef;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Obtain a script object from a connection handle. (meant to avoid having to include the header)
|
||||
*/
|
||||
Object GetConnectionObj(const ConnRef & conn);
|
||||
Object GetConnectionObj(const SQLiteConnRef & conn);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Obtain a script object from a statement handle. (meant to avoid having to include the header)
|
||||
*/
|
||||
Object GetStatementObj(const StmtRef & stmt);
|
||||
Object GetStatementObj(const SQLiteStmtRef & stmt);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Tests if a certain query string is empty.
|
||||
@ -178,6 +183,9 @@ public:
|
||||
String mName; // The specified name to be used as the database file.
|
||||
String mVFS; // The specified virtual file system.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Poco::AutoPtr< Poco::Data::SessionImpl > mSession; // POCO session when this connection comes from a pool.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
bool mMemory; // Whether the database exists in memory and not disk.
|
||||
bool mTrace; // Whether tracing was activated on the database.
|
||||
@ -188,6 +196,16 @@ public:
|
||||
*/
|
||||
SQLiteConnHnd();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit SQLiteConnHnd(Poco::Data::SessionImpl * session);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
explicit SQLiteConnHnd(Poco::AutoPtr< Poco::Data::SessionImpl > && session);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
@ -254,6 +272,20 @@ public:
|
||||
{
|
||||
return sqlite3_extended_errcode(mPtr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Access the connection pointer.
|
||||
*/
|
||||
SQMOD_NODISCARD Pointer Access() const
|
||||
{
|
||||
if (!mSession.isNull()) {
|
||||
// Only reason this is necessary is to dirty the connection handle access time-stamp
|
||||
// So it won't be closed/collected when it comes from a connection/session-pool
|
||||
[[maybe_unused]] auto _ = mSession->isConnected();
|
||||
}
|
||||
// We yield access to the pointer anyway
|
||||
return mPtr;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -286,7 +318,7 @@ public:
|
||||
int32_t mStatus; // The last status code of this connection handle.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ConnRef mConn; // The handle to the associated database connection.
|
||||
SQLiteConnRef mConnection; // The handle to the associated database connection.
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
String mQuery; // The query string used to create this statement.
|
||||
@ -303,7 +335,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
explicit SQLiteStmtHnd(ConnRef conn);
|
||||
explicit SQLiteStmtHnd(SQLiteConnRef conn);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
@ -375,6 +407,20 @@ public:
|
||||
* Return the extended numeric result code for the most recent failed API call (if any).
|
||||
*/
|
||||
SQMOD_NODISCARD int32_t ExErrNo() const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Access the statement pointer.
|
||||
*/
|
||||
SQMOD_NODISCARD Pointer Access() const
|
||||
{
|
||||
if (bool(mConnection) && !(mConnection->mSession.isNull())) {
|
||||
// Only reason this is necessary is to dirty the connection handle access time-stamp
|
||||
// So it won't be closed/collected when it comes from a connection/session-pool
|
||||
[[maybe_unused]] auto _ = mConnection->mSession->isConnected();
|
||||
}
|
||||
// We yield access to the pointer anyway
|
||||
return mPtr;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -385,7 +431,7 @@ class SQLiteConnection
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ConnRef m_Handle; // Reference to the managed connection.
|
||||
SQLiteConnRef m_Handle; // Reference to the managed connection.
|
||||
|
||||
protected:
|
||||
|
||||
@ -421,18 +467,18 @@ protected:
|
||||
* Validate the managed connection handle and throw an error if invalid.
|
||||
*/
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
SQMOD_NODISCARD const ConnRef & GetValid(const char * file, int32_t line) const;
|
||||
SQMOD_NODISCARD const SQLiteConnRef & GetValid(const char * file, int32_t line) const;
|
||||
#else
|
||||
SQMOD_NODISCARD const ConnRef & GetValid() const;
|
||||
SQMOD_NODISCARD const SQLiteConnRef & GetValid() const;
|
||||
#endif // _DEBUG
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed connection handle and throw an error if invalid.
|
||||
*/
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
SQMOD_NODISCARD const ConnRef & GetCreated(const char * file, int32_t line) const;
|
||||
SQMOD_NODISCARD const SQLiteConnRef & GetCreated(const char * file, int32_t line) const;
|
||||
#else
|
||||
SQMOD_NODISCARD const ConnRef & GetCreated() const;
|
||||
SQMOD_NODISCARD const SQLiteConnRef & GetCreated() const;
|
||||
#endif // _DEBUG
|
||||
|
||||
public:
|
||||
@ -479,7 +525,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Direct handle constructor.
|
||||
*/
|
||||
explicit SQLiteConnection(ConnRef c)
|
||||
explicit SQLiteConnection(SQLiteConnRef c)
|
||||
: m_Handle(std::move(c))
|
||||
{
|
||||
/* ... */
|
||||
@ -526,7 +572,7 @@ public:
|
||||
*/
|
||||
operator sqlite3 * () //NOLINT (intentionally implicit)
|
||||
{
|
||||
return m_Handle ? m_Handle->mPtr : nullptr;
|
||||
return m_Handle ? m_Handle->Access() : nullptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -534,7 +580,7 @@ public:
|
||||
*/
|
||||
operator sqlite3 * () const //NOLINT (intentionally implicit)
|
||||
{
|
||||
return m_Handle ? m_Handle->mPtr : nullptr;
|
||||
return m_Handle ? m_Handle->Access() : nullptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -548,7 +594,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated connection handle.
|
||||
*/
|
||||
SQMOD_NODISCARD const ConnRef & GetHandle() const
|
||||
SQMOD_NODISCARD const SQLiteConnRef & GetHandle() const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
@ -566,7 +612,7 @@ public:
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsConnected() const
|
||||
{
|
||||
return m_Handle && (m_Handle->mPtr != nullptr);
|
||||
return m_Handle && (m_Handle->Access() != nullptr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -679,6 +725,16 @@ public:
|
||||
*/
|
||||
Object Query(StackStrF & str) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to execute the specified query asynchronously.
|
||||
*/
|
||||
LightObj AsyncExec(StackStrF & str);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Attempt to create a statement from the specified query asynchronously.
|
||||
*/
|
||||
LightObj AsyncQuery(StackStrF & str) const;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* See if the database connection was opened in read-only mode.
|
||||
*/
|
||||
@ -857,8 +913,8 @@ class SQLiteParameter
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
int32_t m_Index{0}; // The index of the managed parameter.
|
||||
StmtRef m_Handle{}; // Reference to the managed statement.
|
||||
int32_t m_Index{0}; // The index of the managed parameter.
|
||||
SQLiteStmtRef m_Handle{}; // Reference to the managed statement.
|
||||
|
||||
protected:
|
||||
|
||||
@ -884,18 +940,18 @@ protected:
|
||||
* Validate the managed statement handle and throw an error if invalid.
|
||||
*/
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
SQMOD_NODISCARD const StmtRef & GetValid(const char * file, int32_t line) const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetValid(const char * file, int32_t line) const;
|
||||
#else
|
||||
SQMOD_NODISCARD const StmtRef & GetValid() const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetValid() const;
|
||||
#endif // _DEBUG
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed statement handle and throw an error if invalid.
|
||||
*/
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
SQMOD_NODISCARD const StmtRef & GetCreated(const char * file, int32_t line) const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetCreated(const char * file, int32_t line) const;
|
||||
#else
|
||||
SQMOD_NODISCARD const StmtRef & GetCreated() const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetCreated() const;
|
||||
#endif // _DEBUG
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -943,7 +999,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* No parameter constructor.
|
||||
*/
|
||||
explicit SQLiteParameter(StmtRef stmt)
|
||||
explicit SQLiteParameter(SQLiteStmtRef stmt)
|
||||
: m_Index(0), m_Handle(std::move(stmt))
|
||||
{
|
||||
/* ... */
|
||||
@ -952,7 +1008,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Index constructor.
|
||||
*/
|
||||
SQLiteParameter(StmtRef stmt, int32_t idx)
|
||||
SQLiteParameter(SQLiteStmtRef stmt, int32_t idx)
|
||||
: m_Index(idx), m_Handle(std::move(stmt))
|
||||
{
|
||||
SQMOD_VALIDATE_PARAM(*this, m_Index);
|
||||
@ -961,7 +1017,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Name constructor.
|
||||
*/
|
||||
SQLiteParameter(const StmtRef & stmt, const SQChar * name)
|
||||
SQLiteParameter(const SQLiteStmtRef & stmt, const SQChar * name)
|
||||
: m_Index(stmt ? sqlite3_bind_parameter_index(stmt->mPtr, name) : 0), m_Handle(stmt)
|
||||
{
|
||||
SQMOD_VALIDATE_PARAM(*this, m_Index);
|
||||
@ -970,7 +1026,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Dynamic constructor.
|
||||
*/
|
||||
SQLiteParameter(StmtRef stmt, const Object & param)
|
||||
SQLiteParameter(SQLiteStmtRef stmt, const Object & param)
|
||||
: m_Index(0), m_Handle(std::move(stmt))
|
||||
{
|
||||
if (!m_Handle)
|
||||
@ -1033,7 +1089,7 @@ public:
|
||||
// Can we attempt to return the parameter name?
|
||||
if (m_Handle && m_Index)
|
||||
{
|
||||
const SQChar * val = sqlite3_bind_parameter_name(m_Handle->mPtr, m_Index);
|
||||
const SQChar * val = sqlite3_bind_parameter_name(m_Handle->Access(), m_Index);
|
||||
// Return the value if valid
|
||||
return val ? val : String{};
|
||||
}
|
||||
@ -1252,7 +1308,7 @@ private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
int32_t m_Index{-1}; // The index of the managed column.
|
||||
StmtRef m_Handle{}; // The statement where the column exist.
|
||||
SQLiteStmtRef m_Handle{}; // The statement where the column exist.
|
||||
|
||||
protected:
|
||||
|
||||
@ -1278,18 +1334,18 @@ protected:
|
||||
* Validate the managed statement handle and throw an error if invalid.
|
||||
*/
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
SQMOD_NODISCARD const StmtRef & GetValid(const char * file, int32_t line) const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetValid(const char * file, int32_t line) const;
|
||||
#else
|
||||
SQMOD_NODISCARD const StmtRef & GetValid() const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetValid() const;
|
||||
#endif // _DEBUG
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed statement handle and throw an error if invalid.
|
||||
*/
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
SQMOD_NODISCARD const StmtRef & GetCreated(const char * file, int32_t line) const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetCreated(const char * file, int32_t line) const;
|
||||
#else
|
||||
SQMOD_NODISCARD const StmtRef & GetCreated() const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetCreated() const;
|
||||
#endif // _DEBUG
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1346,7 +1402,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* No column constructor.
|
||||
*/
|
||||
explicit SQLiteColumn(StmtRef stmt)
|
||||
explicit SQLiteColumn(SQLiteStmtRef stmt)
|
||||
: m_Index(-1), m_Handle(std::move(stmt))
|
||||
{
|
||||
/* ... */
|
||||
@ -1355,7 +1411,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Index constructor.
|
||||
*/
|
||||
SQLiteColumn(StmtRef stmt, int32_t idx)
|
||||
SQLiteColumn(SQLiteStmtRef stmt, int32_t idx)
|
||||
: m_Index(idx), m_Handle(std::move(stmt))
|
||||
{
|
||||
SQMOD_VALIDATE_COLUMN(*this, m_Index);
|
||||
@ -1364,7 +1420,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Name constructor.
|
||||
*/
|
||||
SQLiteColumn(const StmtRef & stmt, const SQChar * name)
|
||||
SQLiteColumn(const SQLiteStmtRef & stmt, const SQChar * name)
|
||||
: m_Index(stmt ? stmt->GetColumnIndex(name) : -1), m_Handle(stmt)
|
||||
{
|
||||
SQMOD_VALIDATE_COLUMN(*this, m_Index);
|
||||
@ -1373,7 +1429,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Dynamic constructor.
|
||||
*/
|
||||
SQLiteColumn(StmtRef stmt, const Object & column)
|
||||
SQLiteColumn(SQLiteStmtRef stmt, const Object & column)
|
||||
: m_Index(-1), m_Handle(std::move(stmt))
|
||||
{
|
||||
if (!m_Handle)
|
||||
@ -1436,7 +1492,7 @@ public:
|
||||
// Can we attempt to return the parameter name?
|
||||
if (m_Handle && m_Index)
|
||||
{
|
||||
const SQChar * val = sqlite3_column_name(m_Handle->mPtr, m_Index);
|
||||
const SQChar * val = sqlite3_column_name(m_Handle->Access(), m_Index);
|
||||
// Return the value if valid
|
||||
return val ? val : String{};
|
||||
}
|
||||
@ -1573,7 +1629,7 @@ class SQLiteStatement
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
StmtRef m_Handle; // Reference to the managed statement.
|
||||
SQLiteStmtRef m_Handle; // Reference to the managed statement.
|
||||
|
||||
protected:
|
||||
|
||||
@ -1599,18 +1655,18 @@ protected:
|
||||
* Validate the managed statement handle and throw an error if invalid.
|
||||
*/
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
SQMOD_NODISCARD const StmtRef & GetValid(const char * file, int32_t line) const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetValid(const char * file, int32_t line) const;
|
||||
#else
|
||||
SQMOD_NODISCARD const StmtRef & GetValid() const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetValid() const;
|
||||
#endif // _DEBUG
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed statement handle and throw an error if invalid.
|
||||
*/
|
||||
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
|
||||
SQMOD_NODISCARD const StmtRef & GetCreated(const char * file, int32_t line) const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetCreated(const char * file, int32_t line) const;
|
||||
#else
|
||||
SQMOD_NODISCARD const StmtRef & GetCreated() const;
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetCreated() const;
|
||||
#endif // _DEBUG
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1654,7 +1710,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct a statement under the specified connection using the specified string.
|
||||
*/
|
||||
SQLiteStatement(const ConnRef & connection, StackStrF & query)
|
||||
SQLiteStatement(const SQLiteConnRef & connection, StackStrF & query)
|
||||
: m_Handle(new SQLiteStmtHnd(connection))
|
||||
{
|
||||
SQMOD_GET_VALID(*this)->Create(query.mPtr, query.mLen);
|
||||
@ -1668,7 +1724,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Direct handle constructor.
|
||||
*/
|
||||
explicit SQLiteStatement(StmtRef s)
|
||||
explicit SQLiteStatement(SQLiteStmtRef s)
|
||||
: m_Handle(std::move(s))
|
||||
{
|
||||
/* ... */
|
||||
@ -1715,7 +1771,7 @@ public:
|
||||
*/
|
||||
operator sqlite3_stmt * () // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
|
||||
{
|
||||
return m_Handle ? m_Handle->mPtr : nullptr;
|
||||
return m_Handle ? m_Handle->Access() : nullptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1723,7 +1779,7 @@ public:
|
||||
*/
|
||||
operator sqlite3_stmt * () const // NOLINT(google-explicit-constructor,hicpp-explicit-conversions)
|
||||
{
|
||||
return m_Handle ? m_Handle->mPtr : nullptr;
|
||||
return m_Handle ? m_Handle->Access() : nullptr;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1737,7 +1793,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated statement handle.
|
||||
*/
|
||||
SQMOD_NODISCARD const StmtRef & GetHandle() const
|
||||
SQMOD_NODISCARD const SQLiteStmtRef & GetHandle() const
|
||||
{
|
||||
return m_Handle;
|
||||
}
|
||||
@ -1755,7 +1811,7 @@ public:
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsPrepared() const
|
||||
{
|
||||
return m_Handle && (m_Handle->mPtr != nullptr);
|
||||
return m_Handle && (m_Handle->Access() != nullptr);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -2436,7 +2492,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Construct using the direct connection handle.
|
||||
*/
|
||||
explicit SQLiteTransaction(ConnRef db);
|
||||
explicit SQLiteTransaction(SQLiteConnRef db);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
@ -2495,7 +2551,7 @@ public:
|
||||
private:
|
||||
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ConnRef m_Handle{}; // The database connection handle where the transaction began.
|
||||
SQLiteConnRef m_Handle{}; // The database connection handle where the transaction began.
|
||||
bool m_Committed{false}; // Whether changes were successfully committed to the database.
|
||||
};
|
||||
|
||||
|
@ -594,7 +594,7 @@ public:
|
||||
#if defined(UNICODE) || defined(_UNICODE)
|
||||
return String(mHandle->extension, mHandle->extension + std::wcslen(mHandle->extension));
|
||||
#else
|
||||
return String(mHandle->name);
|
||||
return String(mHandle->extension);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
@ -138,9 +138,10 @@ SQInteger XmlAttribute::GetLong() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void XmlAttribute::SetLong(SQInteger value)
|
||||
XmlAttribute & XmlAttribute::SetLong(SQInteger value)
|
||||
{
|
||||
m_Attr = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -150,9 +151,10 @@ SQInteger XmlAttribute::GetUlong() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void XmlAttribute::SetUlong(SQInteger value)
|
||||
XmlAttribute & XmlAttribute::SetUlong(SQInteger value)
|
||||
{
|
||||
m_Attr = static_cast< uint64_t >(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -186,9 +188,10 @@ SQInteger XmlText::GetLong() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void XmlText::SetLong(SQInteger value)
|
||||
XmlText & XmlText::SetLong(SQInteger value)
|
||||
{
|
||||
m_Text = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -198,9 +201,10 @@ SQInteger XmlText::GetUlong() const
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void XmlText::SetUlong(SQInteger value)
|
||||
XmlText & XmlText::SetUlong(SQInteger value)
|
||||
{
|
||||
m_Text = static_cast< uint64_t >(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -259,8 +263,8 @@ void Register_XML(HSQUIRRELVM vm)
|
||||
.Prop(_SC("Next"), &XmlAttribute::NextAttribute)
|
||||
.Prop(_SC("Prev"), &XmlAttribute::PrevAttribute)
|
||||
// Member Methods
|
||||
.Func(_SC("SetName"), &XmlAttribute::ApplyName)
|
||||
.Func(_SC("SetValue"), &XmlAttribute::ApplyValue)
|
||||
.FmtFunc(_SC("SetName"), &XmlAttribute::SetName)
|
||||
.FmtFunc(_SC("SetValue"), &XmlAttribute::ApplyValue)
|
||||
.Func(_SC("AsString"), &XmlAttribute::AsString)
|
||||
.Func(_SC("AsInt"), &XmlAttribute::AsInt)
|
||||
.Func(_SC("AsUint"), &XmlAttribute::AsUint)
|
||||
@ -350,8 +354,8 @@ void Register_XML(HSQUIRRELVM vm)
|
||||
.Overload(_SC("AppendBuffer"), &XmlNode::AppendBuffer1)
|
||||
.Overload(_SC("AppendBuffer"), &XmlNode::AppendBuffer2)
|
||||
.Overload(_SC("AppendBuffer"), &XmlNode::AppendBuffer3)
|
||||
.Func(_SC("SetName"), &XmlNode::ApplyName)
|
||||
.Func(_SC("SetValue"), &XmlNode::ApplyValue)
|
||||
.FmtFunc(_SC("SetName"), &XmlNode::SetName)
|
||||
.FmtFunc(_SC("SetValue"), &XmlNode::ApplyValue)
|
||||
.Func(_SC("GetChild"), &XmlNode::Child)
|
||||
.Func(_SC("GetAttr"), &XmlNode::GetAttribute)
|
||||
.Func(_SC("GetAttribute"), &XmlNode::GetAttribute)
|
||||
@ -368,8 +372,8 @@ void Register_XML(HSQUIRRELVM vm)
|
||||
.Func(_SC("PrependAttrCopy"), &XmlNode::PrependAttrCopy)
|
||||
.Func(_SC("InsertAttrCopyAfter"), &XmlNode::InsertAttrCopyAfter)
|
||||
.Func(_SC("InsertAttrCopyBefore"), &XmlNode::InsertAttrCopyBefore)
|
||||
.Func(_SC("AppendChild"), &XmlNode::AppendChild)
|
||||
.Func(_SC("PrependChild"), &XmlNode::PrependChild)
|
||||
.FmtFunc(_SC("AppendChild"), &XmlNode::AppendChild)
|
||||
.FmtFunc(_SC("PrependChild"), &XmlNode::PrependChild)
|
||||
.Func(_SC("AppendChildNode"), &XmlNode::AppendChildNode)
|
||||
.Func(_SC("PrependChildNode"), &XmlNode::PrependChildNode)
|
||||
.Func(_SC("AppendChildType"), &XmlNode::AppendChildType)
|
||||
@ -386,9 +390,9 @@ void Register_XML(HSQUIRRELVM vm)
|
||||
.Func(_SC("PrependMove"), &XmlNode::PrependMove)
|
||||
.Func(_SC("InsertMoveAfter"), &XmlNode::InsertMoveAfter)
|
||||
.Func(_SC("InsertMoveBefore"), &XmlNode::InsertMoveBefore)
|
||||
.Func(_SC("RemoveAttr"), &XmlNode::RemoveAttr)
|
||||
.FmtFunc(_SC("RemoveAttr"), &XmlNode::RemoveAttr)
|
||||
.Func(_SC("RemoveAttrInst"), &XmlNode::RemoveAttrInst)
|
||||
.Func(_SC("RemoveChild"), &XmlNode::RemoveChild)
|
||||
.FmtFunc(_SC("RemoveChild"), &XmlNode::RemoveChild)
|
||||
.Func(_SC("RemoveChildInst"), &XmlNode::RemoveChildInst)
|
||||
.Overload(_SC("FindChildByAttr"), &XmlNode::FindChildByAttr2)
|
||||
.Overload(_SC("FindChildByAttr"), &XmlNode::FindChildByAttr3)
|
||||
@ -421,7 +425,7 @@ void Register_XML(HSQUIRRELVM vm)
|
||||
.Overload(_SC("SaveFile"), &XmlDocument::SaveFile4)
|
||||
);
|
||||
|
||||
RootTable(vm).Bind(_SC("SqXml"), xmlns);
|
||||
RootTable(vm).Bind(_SC("SqXML"), xmlns);
|
||||
|
||||
ConstTable(vm).Enum(_SC("SqXmlNodeType"), Enumeration(vm)
|
||||
.Const(_SC("Null"), static_cast< int32_t >(node_null))
|
||||
|
@ -663,7 +663,7 @@ protected:
|
||||
* Explicit constructor.
|
||||
*/
|
||||
XmlNode(DocumentRef doc, const Type & node)
|
||||
: m_Doc(std::move(doc)), m_Node(node)
|
||||
: m_Node(node), m_Doc(std::move(doc))
|
||||
{
|
||||
/* ... */
|
||||
}
|
||||
@ -671,8 +671,8 @@ protected:
|
||||
private:
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
DocumentRef m_Doc{}; // The main xml document instance.
|
||||
Type m_Node{}; // The managed document node.
|
||||
DocumentRef m_Doc{}; // The main xml document instance.
|
||||
|
||||
public:
|
||||
|
||||
@ -777,20 +777,13 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify node name.
|
||||
*/
|
||||
void SetName(StackStrF & name)
|
||||
XmlNode & SetName(StackStrF & name)
|
||||
{
|
||||
if (!m_Node.set_name(name.mPtr))
|
||||
{
|
||||
STHROWF("Unable to set XML node name");
|
||||
STHROWF("Unable to set XML node name `{}`", name.ToStr());
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the node name.
|
||||
*/
|
||||
bool ApplyName(StackStrF & name)
|
||||
{
|
||||
return m_Node.set_name(name.mPtr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -804,12 +797,13 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify node value.
|
||||
*/
|
||||
void SetValue(StackStrF & name)
|
||||
XmlNode & SetValue(StackStrF & name)
|
||||
{
|
||||
if (!m_Node.set_value(name.mPtr))
|
||||
{
|
||||
STHROWF("Unable to set XML node value");
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1331,20 +1325,13 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve attribute name.
|
||||
*/
|
||||
void SetName(StackStrF & name)
|
||||
XmlAttribute & SetName(StackStrF & name)
|
||||
{
|
||||
if (!m_Attr.set_name(name.mPtr))
|
||||
{
|
||||
STHROWF("Unable to set XML attribute name");
|
||||
STHROWF("Unable to set XML attribute name `{}`", name.ToStr());
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the attribute name.
|
||||
*/
|
||||
bool ApplyName(StackStrF & name)
|
||||
{
|
||||
return m_Attr.set_name(name.mPtr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1358,12 +1345,13 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve attribute value.
|
||||
*/
|
||||
void SetValue(StackStrF & name)
|
||||
XmlAttribute SetValue(StackStrF & name)
|
||||
{
|
||||
if (!m_Attr.set_value(name.mPtr))
|
||||
{
|
||||
STHROWF("Unable to set XML attribute value");
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1501,9 +1489,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a string.
|
||||
*/
|
||||
void SetString(StackStrF & value)
|
||||
XmlAttribute & SetString(StackStrF & value)
|
||||
{
|
||||
m_Attr = value.mPtr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1517,9 +1506,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a integer.
|
||||
*/
|
||||
void SetInt(int32_t value)
|
||||
XmlAttribute & SetInt(int32_t value)
|
||||
{
|
||||
m_Attr = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1533,9 +1523,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a unsigned integer.
|
||||
*/
|
||||
void SetUint(uint32_t value)
|
||||
XmlAttribute & SetUint(uint32_t value)
|
||||
{
|
||||
m_Attr = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1549,9 +1540,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a floating point.
|
||||
*/
|
||||
void SetFloat(SQFloat value)
|
||||
XmlAttribute & SetFloat(SQFloat value)
|
||||
{
|
||||
m_Attr = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1565,9 +1557,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a double floating point.
|
||||
*/
|
||||
void SetDouble(SQFloat value)
|
||||
XmlAttribute & SetDouble(SQFloat value)
|
||||
{
|
||||
m_Attr = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1578,7 +1571,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a long integer.
|
||||
*/
|
||||
void SetLong(SQInteger value);
|
||||
XmlAttribute & SetLong(SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the value as a unsigned long integer.
|
||||
@ -1588,7 +1581,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a unsigned long integer.
|
||||
*/
|
||||
void SetUlong(SQInteger value);
|
||||
XmlAttribute & SetUlong(SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the value as a boolean.
|
||||
@ -1601,9 +1594,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a boolean.
|
||||
*/
|
||||
void SetBool(bool value)
|
||||
XmlAttribute & SetBool(bool value)
|
||||
{
|
||||
m_Attr = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1853,9 +1847,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a string.
|
||||
*/
|
||||
void SetString(StackStrF & value)
|
||||
XmlText & SetString(StackStrF & value)
|
||||
{
|
||||
m_Text = value.mPtr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1869,9 +1864,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a integer.
|
||||
*/
|
||||
void SetInt(int32_t value)
|
||||
XmlText & SetInt(int32_t value)
|
||||
{
|
||||
m_Text = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1885,9 +1881,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a unsigned integer.
|
||||
*/
|
||||
void SetUint(uint32_t value)
|
||||
XmlText & SetUint(uint32_t value)
|
||||
{
|
||||
m_Text = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1901,9 +1898,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a floating point.
|
||||
*/
|
||||
void SetFloat(SQFloat value)
|
||||
XmlText & SetFloat(SQFloat value)
|
||||
{
|
||||
m_Text = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1917,9 +1915,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a double floating point.
|
||||
*/
|
||||
void SetDouble(SQFloat value)
|
||||
XmlText & SetDouble(SQFloat value)
|
||||
{
|
||||
m_Text = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
@ -1930,7 +1929,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a long integer.
|
||||
*/
|
||||
void SetLong(SQInteger value);
|
||||
XmlText & SetLong(SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the value as a unsigned long integer.
|
||||
@ -1940,7 +1939,7 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a unsigned long integer.
|
||||
*/
|
||||
void SetUlong(SQInteger value);
|
||||
XmlText & SetUlong(SQInteger value);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the value as a boolean.
|
||||
@ -1953,9 +1952,10 @@ public:
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the value as a boolean.
|
||||
*/
|
||||
void SetBool(bool value)
|
||||
XmlText & SetBool(bool value)
|
||||
{
|
||||
m_Text = value;
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
|
@ -556,6 +556,21 @@ void Logger::ProcessMessage()
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Send(uint8_t level, bool sub, const char * msg)
|
||||
{
|
||||
// Is this level even allowed?
|
||||
if ((m_ConsoleLevels & level) || (m_LogFileLevels & level))
|
||||
{
|
||||
// Create a new message builder
|
||||
MsgPtr message(new Message(level, sub));
|
||||
// Generate the log message
|
||||
message->Append(msg);
|
||||
// Process the message in the buffer
|
||||
PushMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void Logger::Send(uint8_t level, bool sub, const char * msg, size_t len)
|
||||
{
|
||||
|
@ -409,6 +409,11 @@ public:
|
||||
*/
|
||||
void BindCb(uint8_t level, Function & func);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Send a log message.
|
||||
*/
|
||||
void Send(uint8_t level, bool sub, const char * msg);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Send a log message.
|
||||
*/
|
||||
|
@ -24,9 +24,6 @@ extern void ProcessRoutines();
|
||||
extern void ProcessTasks();
|
||||
extern void ProcessThreads();
|
||||
extern void ProcessNet();
|
||||
#ifdef VCMP_ENABLE_DISCORD
|
||||
extern void ProcessDPP();
|
||||
#endif
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Will the scripts be reloaded at the end of the current event?
|
||||
@ -175,10 +172,6 @@ static void OnServerFrame(float elapsed_time)
|
||||
ProcessThreads();
|
||||
// Process network
|
||||
ProcessNet();
|
||||
// Process DPP
|
||||
#ifdef VCMP_ENABLE_DISCORD
|
||||
ProcessDPP();
|
||||
#endif
|
||||
// Process log messages from other threads
|
||||
Logger::Get().ProcessQueue();
|
||||
// See if a reload was requested
|
||||
@ -972,6 +965,11 @@ static void OnServerPerformanceReport(size_t /*entry_count*/, const char * * /*d
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Automatically terminate the third-party allocator.
|
||||
*/
|
||||
static std::unique_ptr< SqMod::RPMallocInit > gsRPMallocInit;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Plug-in initialization procedure.
|
||||
*/
|
||||
@ -996,6 +994,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 third-party allocator
|
||||
gsRPMallocInit = std::make_unique< RPMallocInit >();
|
||||
// Attempt to initialize the logger before anything else
|
||||
Logger::Get().Initialize(nullptr);
|
||||
// Attempt to initialize the plug-in core
|
||||
|
@ -250,10 +250,10 @@ void LgEntityQuaternion::Set()
|
||||
case LgEntityType::Vehicle:
|
||||
switch (mFlag)
|
||||
{
|
||||
case LgVehicleVectorFlag::Angle:
|
||||
case LgVehicleQuaternionFlag::Angle:
|
||||
_Func->SetVehicleRotation(mID, x, y, z, w);
|
||||
break;
|
||||
case LgVehicleVectorFlag::SpawnAngle:
|
||||
case LgVehicleQuaternionFlag::SpawnAngle:
|
||||
_Func->SetVehicleSpawnRotation(mID, x, y, z, w);
|
||||
break;
|
||||
default: break;
|
||||
@ -523,7 +523,7 @@ struct LgObject
|
||||
void RotateToEuler(const Vector3 & rotation, int time) const { Get().RotateToEuler(rotation, static_cast< uint32_t >(time)); }
|
||||
void RotateByEuler(const Vector3 & rotOffset, int time) const { Get().RotateByEuler(rotOffset, static_cast< uint32_t >(time)); }
|
||||
void SetAlpha(int alpha, int fadeTime) const { Get().SetAlphaEx(alpha, static_cast< uint32_t >(fadeTime)); }
|
||||
SQMOD_NODISCARD bool StreamedToPlayer(LgPlayer & player) const;
|
||||
SQMOD_NODISCARD bool StreamedToPlayer(LgPlayer & player) const;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -943,8 +943,8 @@ struct LgVehicle
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
inline bool LgCheckpoint::StreamedToPlayer(LgPlayer & player) const { return Get().IsStreamedFor(player.Get()); }
|
||||
inline bool LgObject::StreamedToPlayer(LgPlayer & player) const { return Get().IsStreamedFor(player.Get()); }
|
||||
inline bool LgPickup::StreamedToPlayer(LgPlayer & player) const { return Get().IsStreamedFor(player.Get()); }
|
||||
inline bool LgObject::StreamedToPlayer(LgPlayer & player) const { return Get().IsStreamedFor(player.Get()); }
|
||||
inline bool LgPickup::StreamedToPlayer(LgPlayer & player) const { return Get().IsStreamedFor(player.Get()); }
|
||||
inline void LgPlayer::SetVehicle(LgVehicle & vehicle) const { Get().Embark(vehicle.Get()); }
|
||||
inline void LgPlayer::SetVehicleSlot(const LgVehicle & vehicle, int slot) const { Get().EmbarkEx(vehicle.Get(), slot, true, false); }
|
||||
|
||||
@ -1545,9 +1545,9 @@ SQMOD_NODISCARD SQInteger LgGetObjectCount() {
|
||||
}
|
||||
return count;
|
||||
}
|
||||
SQMOD_NODISCARD SQInteger LgGetPlayers() { return ForeachConnectedPlayerCount([](int32_t) { return true; }); }
|
||||
SQMOD_NODISCARD SQInteger LgGetPlayers() { return ForeachPlayerSlotCount([](int32_t idx) -> bool { return _Func->IsPlayerConnected(idx) != 0; }); }
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
static void LgSetVehiclesForcedRespawnHeight(SQFloat height) { _Func->SetVehiclesForcedRespawnHeight(height); }
|
||||
static void LgSetVehiclesForcedRespawnHeight(SQFloat height) { _Func->SetVehiclesForcedRespawnHeight(static_cast< float >(height)); }
|
||||
SQMOD_NODISCARD static SQFloat LgGetVehiclesForcedRespawnHeight() { return _Func->GetVehiclesForcedRespawnHeight(); }
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_NODISCARD static SQInteger LgFindPlayer(HSQUIRRELVM vm) {
|
||||
@ -1569,7 +1569,7 @@ SQMOD_NODISCARD static SQInteger LgFindPlayer(HSQUIRRELVM vm) {
|
||||
char name_buf[SQMOD_NAMELENGTH];
|
||||
const int32_t id = ForeachConnectedPlayerUntil([&](int32_t id) -> bool {
|
||||
_Func->GetPlayerName(id, name_buf, 64);
|
||||
std::transform(name_buf, name_buf + strlen(name_buf), name_buf, [](unsigned char c){ return std::tolower(c); });
|
||||
std::transform(name_buf, name_buf + strlen(name_buf), name_buf, [](unsigned char c) { return std::tolower(c); });
|
||||
return name.compare(name_buf) == 0; // NOLINT(readability-string-compare)
|
||||
});
|
||||
if (VALID_ENTITYEX(id, SQMOD_PLAYER_POOL)) Var< LightObj >::push(vm, Core::Get().GetPlayer(id).mLgObj);
|
||||
@ -1634,10 +1634,11 @@ SQMOD_NODISCARD static SQInteger LgInPolyProcStack(HSQUIRRELVM vm) {
|
||||
points.reserve(static_cast<unsigned long long int>((top - 1) / 2));
|
||||
for (SQInteger idx = 4; idx < top;) {
|
||||
points.emplace_back();
|
||||
points.back().x = PopStackFloat(vm, idx++);
|
||||
points.back().y = PopStackFloat(vm, idx++);
|
||||
points.back().x = SQMOD_DOUBLE_OR(static_cast< Vector2::Value >(PopStackFloat(vm, idx++)), PopStackFloat(vm, idx++));
|
||||
points.back().y = SQMOD_DOUBLE_OR(static_cast< Vector2::Value >(PopStackFloat(vm, idx++)), PopStackFloat(vm, idx++));
|
||||
}
|
||||
sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(x, y, points.size(), points.data())));
|
||||
sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(SQMOD_DOUBLE_OR(static_cast< float >(x), x),
|
||||
SQMOD_DOUBLE_OR(static_cast< float >(y), y), points.size(), points.data())));
|
||||
return 1;
|
||||
}
|
||||
SQMOD_NODISCARD static SQInteger LgInPolyProcString(HSQUIRRELVM vm) {
|
||||
@ -1654,7 +1655,8 @@ SQMOD_NODISCARD static SQInteger LgInPolyProcString(HSQUIRRELVM vm) {
|
||||
ss >> points.back().y >> c;
|
||||
else break;
|
||||
}
|
||||
sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(x, y, points.size(), points.data())));
|
||||
sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(SQMOD_DOUBLE_OR(static_cast< float >(x), x),
|
||||
SQMOD_DOUBLE_OR(static_cast< float >(y), y), points.size(), points.data())));
|
||||
return 1;
|
||||
}
|
||||
SQMOD_NODISCARD static SQInteger LgInPolyProcArray(HSQUIRRELVM vm) {
|
||||
@ -1665,13 +1667,14 @@ SQMOD_NODISCARD static SQInteger LgInPolyProcArray(HSQUIRRELVM vm) {
|
||||
arr.Foreach([&](HSQUIRRELVM vm, SQInteger i) -> SQRESULT {
|
||||
if ((i & 1) == 0) {
|
||||
points.emplace_back();
|
||||
points.back().x = PopStackFloat(vm, -1);
|
||||
points.back().x = SQMOD_DOUBLE_OR(static_cast< Vector2::Value >(PopStackFloat(vm, -1)), PopStackFloat(vm, -1));
|
||||
} else {
|
||||
points.back().y = PopStackFloat(vm, -1);
|
||||
points.back().y = SQMOD_DOUBLE_OR(static_cast< Vector2::Value >(PopStackFloat(vm, -1)), PopStackFloat(vm, -1));
|
||||
}
|
||||
return SQ_OK;
|
||||
});
|
||||
sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(x, y, points.size(), points.data())));
|
||||
sq_pushbool(vm, static_cast< SQBool >(LgInternal_InPoly(SQMOD_DOUBLE_OR(static_cast< float >(x), x),
|
||||
SQMOD_DOUBLE_OR(static_cast< float >(y), y), points.size(), points.data())));
|
||||
return 1;
|
||||
}
|
||||
SQMOD_NODISCARD static SQInteger LgInPoly(HSQUIRRELVM vm) {
|
||||
@ -1752,10 +1755,10 @@ void Register_Official_Functions(HSQUIRRELVM vm)
|
||||
.Func(_SC("SetMaxHeight"), LgSetMaxHeight)
|
||||
.Func(_SC("SetFallTimer"), LgSetFallTimer)
|
||||
|
||||
.Func(_SC("GetServerName"), LgGetServerName)
|
||||
.SquirrelFunc(_SC("GetServerName"), LgGetServerName)
|
||||
.Func(_SC("GetMaxPlayers"), LgGetMaxPlayers)
|
||||
.Func(_SC("GetPassword"), LgGetServerPassword)
|
||||
.Func(_SC("GetGameModeName"), LgGetGameModeText)
|
||||
.SquirrelFunc(_SC("GetPassword"), LgGetServerPassword)
|
||||
.SquirrelFunc(_SC("GetGameModeName"), LgGetGameModeText)
|
||||
.Func(_SC("GetTimeRate"), LgGetTimeRate)
|
||||
.Func(_SC("GetHour"), LgGetHour)
|
||||
.Func(_SC("GetMinute"), LgGetMinute)
|
||||
|
@ -113,8 +113,8 @@ int32_t GetSkinID(StackStrF & name)
|
||||
{
|
||||
// Clone the string into an editable version
|
||||
String str(name.mPtr, static_cast< size_t >(name.mLen));
|
||||
// Strip non alphanumeric characters from the name
|
||||
str.erase(std::remove_if(str.begin(), str.end(), std::not1(std::ptr_fun(::isalnum))), str.end());
|
||||
// Strip non-alphanumeric characters from the name
|
||||
str.erase(std::remove_if(str.begin(), str.end(), std::function<int(int)>(::isalnum)), str.end());
|
||||
// Convert the string to lowercase
|
||||
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
||||
// See if we still have a valid name after the cleanup
|
||||
|
@ -122,8 +122,8 @@ int32_t GetAutomobileID(StackStrF & name)
|
||||
{
|
||||
// Clone the string into an editable version
|
||||
String str(name.mPtr, static_cast< size_t >(name.mLen));
|
||||
// Strip non alphanumeric characters from the name
|
||||
str.erase(std::remove_if(str.begin(), str.end(), std::not1(std::ptr_fun(::isalnum))), str.end());
|
||||
// Strip non-alphanumeric characters from the name
|
||||
str.erase(std::remove_if(str.begin(), str.end(), std::function<int(int)>(::isalnum)), str.end());
|
||||
// Convert the string to lowercase
|
||||
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
||||
// See if we still have a valid name after the cleanup
|
||||
|
@ -162,8 +162,8 @@ int32_t GetWeaponID(StackStrF & name)
|
||||
{
|
||||
// Clone the string into an editable version
|
||||
String str(name.mPtr, static_cast< size_t >(name.mLen));
|
||||
// Strip non alphanumeric characters from the name
|
||||
str.erase(std::remove_if(str.begin(), str.end(), std::not1(std::ptr_fun(::isalnum))), str.end());
|
||||
// Strip non-alphanumeric characters from the name
|
||||
str.erase(std::remove_if(str.begin(), str.end(), std::function<int(int)>(::isalnum)), str.end());
|
||||
// Convert the string to lowercase
|
||||
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
|
||||
// See if we still have a valid name after the cleanup
|
||||
|
@ -1,5 +1,9 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "PocoLib/Data.hpp"
|
||||
#include "Core/ThreadPool.hpp"
|
||||
#include "Library/SQLite.hpp"
|
||||
#include "Library/MySQL.hpp"
|
||||
#include "Poco/Data/SessionImpl.h"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqratConst.h>
|
||||
@ -33,6 +37,7 @@ SQMOD_DECL_TYPENAME(SqPcDataStatement, _SC("SqDataStatement"))
|
||||
SQMOD_DECL_TYPENAME(SqPcDataRecordSet, _SC("SqDataRecordSet"))
|
||||
SQMOD_DECL_TYPENAME(SqPcDataTransaction, _SC("SqDataTransaction"))
|
||||
SQMOD_DECL_TYPENAME(SqPcDataSessionPool, _SC("SqDataSessionPool"))
|
||||
SQMOD_DECL_TYPENAME(SqPcSqDataAsyncBuilder, _SC("SqSqDataAsyncBuilder"))
|
||||
SQMOD_DECL_TYPENAME(SqPcDataStatementResult, _SC("SqDataStatementResult"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -470,6 +475,211 @@ SqDataStatement & SqDataStatement::Into_(LightObj & obj, LightObj & def)
|
||||
return *this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
extern LightObj GetSQLiteFromSession(Poco::Data::SessionImpl * session);
|
||||
extern LightObj GetMySQLFromSession(Poco::Data::SessionImpl * session);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LightObj SqDataSessionPool::GetSq()
|
||||
{
|
||||
auto session = get();
|
||||
auto * session_impl = session.impl();
|
||||
auto & connector = session_impl->connectorName();
|
||||
// Is this a SQLite session?
|
||||
if (connector == "sqlite")
|
||||
{
|
||||
return GetSQLiteFromSession(session_impl);
|
||||
}
|
||||
// Is this a MySQL session?
|
||||
else if (connector == "mysql")
|
||||
{
|
||||
return GetMySQLFromSession(session_impl);
|
||||
}
|
||||
STHROWF("Unknown connector type {}", connector);
|
||||
SQ_UNREACHABLE
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LightObj SqDataSessionPool::AsyncExec(StackStrF & sql)
|
||||
{
|
||||
return LightObj{SqTypeIdentity< SqDataAsyncBuilder >{}, SqVM(), get().impl(), sql, false};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LightObj SqDataSessionPool::AsyncQuery(StackStrF & sql)
|
||||
{
|
||||
return LightObj{SqTypeIdentity< SqDataAsyncBuilder >{}, SqVM(), get().impl(), sql, true};
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Common session action implementation.
|
||||
*/
|
||||
struct SQLiteAsyncExec : public ThreadPoolItem
|
||||
{
|
||||
using SessionRef = Poco::AutoPtr< Poco::Data::SessionImpl >;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
SessionRef mSession{}; // The connection that will be used by this task.
|
||||
sqlite3 * mConnection{nullptr}; // Raw connection handle.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Function mResolved{}; // Callback to invoke when the task was completed.
|
||||
Function mRejected{}; // Callback to invoke when the task was aborted.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
int32_t mResult{SQLITE_OK}; // Execution result code.
|
||||
int32_t mChanges{0}; // Rows affected by this query.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
const SQChar * mQueryStr{nullptr}; // The query string that will be executed.
|
||||
LightObj mQueryObj{}; // Strong reference to the query string object.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
String mError{}; // Error message, if any.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor. Members are supposed to be validated and filled by the builder/proxy.
|
||||
*/
|
||||
SQLiteAsyncExec() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~SQLiteAsyncExec() override = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Provide a name to what type of task this is. Mainly for debugging purposes.
|
||||
*/
|
||||
SQMOD_NODISCARD const char * TypeName() noexcept override { return "sqlite async execute"; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Provide unique information that may help identify the task. Mainly for debugging purposes.
|
||||
*/
|
||||
SQMOD_NODISCARD const char * IdentifiableInfo() noexcept override { return mQueryStr; }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Invoked in worker thread by the thread pool after obtaining the task from the queue.
|
||||
* Must return true to indicate that the task can be performed. False indicates failure.
|
||||
*/
|
||||
SQMOD_NODISCARD bool OnPrepare() override
|
||||
{
|
||||
// Coincidentally, this also dirties the handle time-stamp so it doesn't get collected
|
||||
return mSession->isConnected();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Called in worker by the thread pool to performed by the associated tasks.
|
||||
* Will be called continuously while the returned value is true. While false means it finished.
|
||||
*/
|
||||
SQMOD_NODISCARD bool OnProcess() override
|
||||
{
|
||||
char * err_msg = nullptr;
|
||||
// Attempt to execute the specified query
|
||||
mResult = sqlite3_exec(mConnection, mQueryStr, nullptr, nullptr, &err_msg);
|
||||
// Store changes count
|
||||
if (mResult == SQLITE_OK)
|
||||
{
|
||||
mChanges = sqlite3_changes(mConnection);
|
||||
}
|
||||
// Check for error message
|
||||
if (err_msg != nullptr)
|
||||
{
|
||||
mError.assign(err_msg);
|
||||
sqlite3_free(err_msg);
|
||||
}
|
||||
// Don't retry
|
||||
return false;
|
||||
};
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Invoked in main thread by the thread pool after the task was completed.
|
||||
*/
|
||||
void OnCompleted() override
|
||||
{
|
||||
if (mResult == SQLITE_OK)
|
||||
{
|
||||
if (!mResolved.IsNull())
|
||||
{
|
||||
SQLiteConnRef conn_ref{new SQLiteConnHnd(std::move(mSession))};
|
||||
LightObj connection{SqTypeIdentity< SQLiteConnection >{}, SqVM(), conn_ref};
|
||||
mResolved.Execute(connection, mChanges, mQueryObj);
|
||||
}
|
||||
}
|
||||
else if (!mRejected.IsNull())
|
||||
{
|
||||
SQLiteConnRef conn_ref{new SQLiteConnHnd(std::move(mSession))};
|
||||
LightObj connection{SqTypeIdentity< SQLiteConnection >{}, SqVM(), conn_ref};
|
||||
mRejected.Execute(connection, mResult, mError, mQueryObj);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Called in worker by the thread pool to let the task know that it will be aborted.
|
||||
* Most likely due to a shutdown of the thread pool.
|
||||
*/
|
||||
void OnAborted(bool SQ_UNUSED_ARG(retry)) override
|
||||
{
|
||||
// We don't really have to do anything for now
|
||||
}
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SqDataAsyncBuilder::SqDataAsyncBuilder(Poco::Data::SessionImpl * session, StackStrF & sql, bool stmt) noexcept
|
||||
: mSession(session, true)
|
||||
, mResolved(), mRejected()
|
||||
, mQueryStr(sql.mPtr), mQueryObj(sql.mObj)
|
||||
, mStmt(stmt)
|
||||
{
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void SqDataAsyncBuilder::Submit()
|
||||
{
|
||||
if (mSession.isNull())
|
||||
{
|
||||
STHROWF("Asynchronous query builder instance is invalid.");
|
||||
}
|
||||
auto & connector = mSession->connectorName();
|
||||
// Is this a SQLite session?
|
||||
if (connector == "sqlite")
|
||||
{
|
||||
// Retrieve the internal handle property
|
||||
auto * connection = Poco::AnyCast< sqlite3 * >(mSession->getProperty("handle"));
|
||||
// Is this a statement?
|
||||
if (mStmt)
|
||||
{
|
||||
//...
|
||||
}
|
||||
else
|
||||
{
|
||||
auto * item = new SQLiteAsyncExec();
|
||||
// Take ownership before any exception can be thrown
|
||||
std::unique_ptr< ThreadPoolItem > task{static_cast< ThreadPoolItem * >(item)};
|
||||
// Populate task information
|
||||
item->mConnection = connection;
|
||||
item->mResolved = std::move(mResolved);
|
||||
item->mRejected = std::move(mRejected);
|
||||
item->mQueryStr = mQueryStr;
|
||||
item->mQueryObj = std::move(mQueryObj);
|
||||
item->mSession = std::move(mSession);
|
||||
// Submit the task
|
||||
ThreadPool::Get().Enqueue(std::move(task));
|
||||
}
|
||||
}
|
||||
// Is this a MySQL session?
|
||||
else if (connector == "mysql")
|
||||
{
|
||||
if (mStmt)
|
||||
{
|
||||
//...
|
||||
}
|
||||
else
|
||||
{
|
||||
//...
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
STHROWF("Unknown connector type {}", connector);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
LightObj SqDataSessionPool::GetProperty(StackStrF & name)
|
||||
{
|
||||
@ -746,6 +956,16 @@ void Register_POCO_Data(HSQUIRRELVM vm, Table &)
|
||||
.Overload(_SC("Value"), &SqDataRecordSet::GetValueOr)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("AsyncBuilder"),
|
||||
Class< SqDataAsyncBuilder, NoConstructor< SqDataAsyncBuilder > >(vm, SqPcSqDataAsyncBuilder::Str)
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqPcSqDataAsyncBuilder::Fn)
|
||||
// Member Methods
|
||||
.Func(_SC("Submit"), &SqDataAsyncBuilder::Submit)
|
||||
.CbFunc(_SC("Resolved"), &SqDataAsyncBuilder::OnResolved)
|
||||
.CbFunc(_SC("Rejected"), &SqDataAsyncBuilder::OnRejected)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("SessionPool"),
|
||||
Class< SqDataSessionPool, NoCopy< SqDataSessionPool > >(vm, SqPcDataSessionPool::Str)
|
||||
// Constructors
|
||||
@ -764,6 +984,9 @@ void Register_POCO_Data(HSQUIRRELVM vm, Table &)
|
||||
.Prop(_SC("IsActive"), &SqDataSessionPool::IsActive)
|
||||
// Member Methods
|
||||
.Func(_SC("Get"), &SqDataSessionPool::Get)
|
||||
.Func(_SC("GetSq"), &SqDataSessionPool::GetSq)
|
||||
.Func(_SC("AsyncExec"), &SqDataSessionPool::AsyncExec)
|
||||
.Func(_SC("AsyncQuery"), &SqDataSessionPool::AsyncQuery)
|
||||
.FmtFunc(_SC("GetWithProperty"), &SqDataSessionPool::GetWithProperty)
|
||||
.FmtFunc(_SC("GetWithFeature"), &SqDataSessionPool::GetWithFeature)
|
||||
.FmtFunc(_SC("SetFeature"), &SqDataSessionPool::SetFeature)
|
||||
|
@ -1707,7 +1707,7 @@ protected:
|
||||
}
|
||||
SQ_UNREACHABLE
|
||||
// Unreachable
|
||||
return LightObj();
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
@ -1746,7 +1746,7 @@ struct SqDataSessionPool : public SessionPool
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destroys the SessionPool.
|
||||
*/
|
||||
~SqDataSessionPool() = default;
|
||||
~SqDataSessionPool() override = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Assignment operator (disabled).
|
||||
@ -1766,6 +1766,21 @@ struct SqDataSessionPool : public SessionPool
|
||||
return LightObj(SqTypeIdentity< SqDataSession >{}, SqVM(), get());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a Session wrapped in a native/legacy implementation.
|
||||
*/
|
||||
LightObj GetSq();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create an asynchronus query execution builder.
|
||||
*/
|
||||
LightObj AsyncExec(StackStrF & sql);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create an asynchronus query execution builder.
|
||||
*/
|
||||
LightObj AsyncQuery(StackStrF & sql);
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a Session with requested property set.
|
||||
*/
|
||||
@ -2070,4 +2085,75 @@ struct SqDataTransaction : public Transaction
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Common session action implementation.
|
||||
*/
|
||||
struct SqDataAsyncBuilder
|
||||
{
|
||||
using SessionRef = Poco::AutoPtr< Poco::Data::SessionImpl >;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
SessionRef mSession{}; // The connection that will be used by the task.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Function mResolved{}; // Callback to invoke when the task was completed.
|
||||
Function mRejected{}; // Callback to invoke when the task was aborted.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
const SQChar * mQueryStr{nullptr}; // The query string that will be executed.
|
||||
LightObj mQueryObj{}; // Strong reference to the query string object.
|
||||
// --------------------------------------------------------------------------------------------
|
||||
bool mStmt{false}; // Whether this is a query statement or a simple query execution.
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
SqDataAsyncBuilder(Poco::Data::SessionImpl * session, StackStrF & sql, bool stmt) noexcept;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
SqDataAsyncBuilder(const SqDataAsyncBuilder & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
SqDataAsyncBuilder(SqDataAsyncBuilder && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~SqDataAsyncBuilder() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
SqDataAsyncBuilder & operator = (const SqDataAsyncBuilder & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
SqDataAsyncBuilder & operator = (SqDataAsyncBuilder && o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Create the task with the suplied information and submit it to the worker pool.
|
||||
*/
|
||||
void Submit();
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the callback to be executed if the query was resolved.
|
||||
*/
|
||||
SqDataAsyncBuilder & OnResolved(Function & cb)
|
||||
{
|
||||
mResolved = std::move(cb);
|
||||
return *this; // Allow chaining
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Set the callback to be executed if the query was rejected/failed.
|
||||
*/
|
||||
SqDataAsyncBuilder & OnRejected(Function & cb)
|
||||
{
|
||||
mRejected = std::move(cb);
|
||||
return *this; // Allow chaining
|
||||
}
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
||||
|
@ -1,112 +0,0 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "PocoLib/RegEx.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqratConst.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
SQMOD_DECL_TYPENAME(SqRegEx, _SC("SqRegEx"))
|
||||
SQMOD_DECL_TYPENAME(SqRegExMatch, _SC("SqRegExMatch"))
|
||||
SQMOD_DECL_TYPENAME(SqRegExMatches, _SC("SqRegExMatches"))
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// ================================================================================================
|
||||
void Register_POCO_RegEx(HSQUIRRELVM vm, Table & ns)
|
||||
{
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("RegExMatch"),
|
||||
Class< PcRegExMatch >(vm, SqRegExMatch::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
.Ctor< SQInteger >()
|
||||
.Ctor< SQInteger, SQInteger >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqRegExMatch::Fn)
|
||||
// Properties
|
||||
.Prop(_SC("Offset"), &PcRegExMatch::GetOffset, &PcRegExMatch::SetOffset)
|
||||
.Prop(_SC("Length"), &PcRegExMatch::GetLength, &PcRegExMatch::SetLength)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("RegExMatches"),
|
||||
Class< PcRegExMatches >(vm, SqRegExMatches::Str)
|
||||
// Constructors
|
||||
.Ctor()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqRegExMatches::Fn)
|
||||
// Properties
|
||||
.Prop(_SC("Front"), &PcRegExMatches::Front)
|
||||
.Prop(_SC("Back"), &PcRegExMatches::Back)
|
||||
.Prop(_SC("Empty"), &PcRegExMatches::Empty)
|
||||
.Prop(_SC("Size"), &PcRegExMatches::Size)
|
||||
.Prop(_SC("Capacity"), &PcRegExMatches::Capacity, &PcRegExMatches::Reserve)
|
||||
// Member Methods
|
||||
.Func(_SC("Get"), &PcRegExMatches::Get)
|
||||
.Func(_SC("Reserve"), &PcRegExMatches::Reserve)
|
||||
.Func(_SC("Compact"), &PcRegExMatches::Compact)
|
||||
.Func(_SC("Clear"), &PcRegExMatches::Clear)
|
||||
.Func(_SC("Pop"), &PcRegExMatches::Pop)
|
||||
.Func(_SC("EraseAt"), &PcRegExMatches::EraseAt)
|
||||
.Func(_SC("EraseFrom"), &PcRegExMatches::EraseFrom)
|
||||
.Func(_SC("Each"), &PcRegExMatches::Each)
|
||||
.Func(_SC("EachRange"), &PcRegExMatches::EachRange)
|
||||
.Func(_SC("While"), &PcRegExMatches::While)
|
||||
.Func(_SC("WhileRange"), &PcRegExMatches::WhileRange)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("RegEx"),
|
||||
Class< PcRegEx, NoCopy< PcRegEx > >(vm, SqRegEx::Str)
|
||||
// Constructors
|
||||
.Ctor< StackStrF & >()
|
||||
.Ctor< int, StackStrF & >()
|
||||
.Ctor< int, bool, StackStrF & >()
|
||||
// Meta-methods
|
||||
.SquirrelFunc(_SC("_typename"), &SqRegEx::Fn)
|
||||
// Member Methods
|
||||
//.Func(_SC("Assign"), &PcRegEx::assign)
|
||||
// Overloaded Member Methods
|
||||
.Overload(_SC("MatchFirst"), &PcRegEx::MatchFirst)
|
||||
.Overload(_SC("MatchFirst"), &PcRegEx::MatchFirst_)
|
||||
.Overload(_SC("MatchFirstFrom"), &PcRegEx::MatchFirstFrom)
|
||||
.Overload(_SC("MatchFirstFrom"), &PcRegEx::MatchFirstFrom_)
|
||||
.Overload(_SC("Match"), &PcRegEx::Match)
|
||||
.Overload(_SC("Match"), &PcRegEx::Match_)
|
||||
.Overload(_SC("MatchFrom"), &PcRegEx::MatchFrom)
|
||||
.Overload(_SC("MatchFrom"), &PcRegEx::MatchFrom_)
|
||||
.Overload(_SC("Matches"), &PcRegEx::Matches)
|
||||
.Overload(_SC("Matches"), &PcRegEx::Matches_)
|
||||
.Overload(_SC("Matches"), &PcRegEx::MatchesEx)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ConstTable(vm).Enum(_SC("SqRegExOption"), Enumeration(vm)
|
||||
.Const(_SC("Caseless"), static_cast< SQInteger >(Poco::RegularExpression::RE_CASELESS))
|
||||
.Const(_SC("MultiLine"), static_cast< SQInteger >(Poco::RegularExpression::RE_MULTILINE))
|
||||
.Const(_SC("DotAll"), static_cast< SQInteger >(Poco::RegularExpression::RE_DOTALL))
|
||||
.Const(_SC("Extended"), static_cast< SQInteger >(Poco::RegularExpression::RE_EXTENDED))
|
||||
.Const(_SC("Anchored"), static_cast< SQInteger >(Poco::RegularExpression::RE_ANCHORED))
|
||||
.Const(_SC("DollarEndOnly"), static_cast< SQInteger >(Poco::RegularExpression::RE_DOLLAR_ENDONLY))
|
||||
.Const(_SC("Extra"), static_cast< SQInteger >(Poco::RegularExpression::RE_EXTRA))
|
||||
.Const(_SC("NotBOL"), static_cast< SQInteger >(Poco::RegularExpression::RE_NOTBOL))
|
||||
.Const(_SC("NotEOL"), static_cast< SQInteger >(Poco::RegularExpression::RE_NOTEOL))
|
||||
.Const(_SC("Ungreedy"), static_cast< SQInteger >(Poco::RegularExpression::RE_UNGREEDY))
|
||||
.Const(_SC("NotEmpty"), static_cast< SQInteger >(Poco::RegularExpression::RE_NOTEMPTY))
|
||||
.Const(_SC("UTF8"), static_cast< SQInteger >(Poco::RegularExpression::RE_UTF8))
|
||||
.Const(_SC("NoAutoCapture"), static_cast< SQInteger >(Poco::RegularExpression::RE_NO_AUTO_CAPTURE))
|
||||
.Const(_SC("NoUTF8Check"), static_cast< SQInteger >(Poco::RegularExpression::RE_NO_UTF8_CHECK))
|
||||
.Const(_SC("FirstLine"), static_cast< SQInteger >(Poco::RegularExpression::RE_FIRSTLINE))
|
||||
.Const(_SC("DupNames"), static_cast< SQInteger >(Poco::RegularExpression::RE_DUPNAMES))
|
||||
.Const(_SC("NewLineCR"), static_cast< SQInteger >(Poco::RegularExpression::RE_NEWLINE_CR))
|
||||
.Const(_SC("NewLineLF"), static_cast< SQInteger >(Poco::RegularExpression::RE_NEWLINE_LF))
|
||||
.Const(_SC("NewLineCRLF"), static_cast< SQInteger >(Poco::RegularExpression::RE_NEWLINE_CRLF))
|
||||
.Const(_SC("NewLineAny"), static_cast< SQInteger >(Poco::RegularExpression::RE_NEWLINE_ANY))
|
||||
.Const(_SC("NewLineAnyCRLF"), static_cast< SQInteger >(Poco::RegularExpression::RE_NEWLINE_ANYCRLF))
|
||||
.Const(_SC("Global"), static_cast< SQInteger >(Poco::RegularExpression::RE_GLOBAL))
|
||||
.Const(_SC("NoVars"), static_cast< SQInteger >(Poco::RegularExpression::RE_NO_VARS))
|
||||
);
|
||||
}
|
||||
|
||||
} // Namespace:: SqMod
|
@ -1,481 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <algorithm>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <Poco/RegularExpression.h>
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
struct PcRegExMatch : public Poco::RegularExpression::Match
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
PcRegExMatch() noexcept
|
||||
: Poco::RegularExpression::Match{}
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Offset constructor.
|
||||
*/
|
||||
explicit PcRegExMatch(SQInteger offset) noexcept
|
||||
: Poco::RegularExpression::Match{static_cast< std::string::size_type >(offset), 0}
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
PcRegExMatch(SQInteger offset, SQInteger length) noexcept
|
||||
: Poco::RegularExpression::Match{
|
||||
static_cast< std::string::size_type >(offset),
|
||||
static_cast< std::string::size_type >(length)
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
PcRegExMatch(const PcRegExMatch & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
PcRegExMatch(PcRegExMatch && o) noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
PcRegExMatch & operator = (const PcRegExMatch & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
PcRegExMatch & operator = (PcRegExMatch && o) noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve offset.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetOffset() const noexcept
|
||||
{
|
||||
return static_cast< SQInteger >(Poco::RegularExpression::Match::offset);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify offset.
|
||||
*/
|
||||
void SetOffset(SQInteger value) noexcept
|
||||
{
|
||||
Poco::RegularExpression::Match::offset = static_cast< std::string::size_type >(value);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve length.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetLength() const noexcept
|
||||
{
|
||||
return static_cast< SQInteger >(Poco::RegularExpression::Match::length);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify length.
|
||||
*/
|
||||
void SetLength(SQInteger value) noexcept
|
||||
{
|
||||
Poco::RegularExpression::Match::length = static_cast< std::string::size_type >(value);
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
*
|
||||
*/
|
||||
struct PcRegExMatches
|
||||
{
|
||||
using List = Poco::RegularExpression::MatchVec;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Internal RegularExpression instance.
|
||||
*/
|
||||
List m_List;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
PcRegExMatches() = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy list constructor.
|
||||
*/
|
||||
explicit PcRegExMatches(const List & l) // NOLINT(modernize-pass-by-value)
|
||||
: m_List{l}
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move list constructor.
|
||||
*/
|
||||
explicit PcRegExMatches(List && m) noexcept
|
||||
: m_List{std::move(m)}
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor.
|
||||
*/
|
||||
PcRegExMatches(const PcRegExMatches & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor.
|
||||
*/
|
||||
PcRegExMatches(PcRegExMatches && o) noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator.
|
||||
*/
|
||||
PcRegExMatches & operator = (const PcRegExMatches & o) = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator.
|
||||
*/
|
||||
PcRegExMatches & operator = (PcRegExMatches && o) noexcept = default;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure an index is within range and return the container. Container must exist.
|
||||
*/
|
||||
List & ValidIdx(SQInteger i)
|
||||
{
|
||||
if (static_cast< size_t >(i) >= m_List.size())
|
||||
{
|
||||
STHROWF("Invalid RegEx match list index({})", i);
|
||||
}
|
||||
return m_List;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure an index is within range and return the container. Container must exist.
|
||||
*/
|
||||
SQMOD_NODISCARD const List & ValidIdx(SQInteger i) const
|
||||
{
|
||||
if (static_cast< size_t >(i) >= m_List.size())
|
||||
{
|
||||
STHROWF("Invalid RegEx match list index({})", i);
|
||||
}
|
||||
return m_List;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Make sure a container instance is populated, then return it.
|
||||
*/
|
||||
SQMOD_NODISCARD List & ValidPop()
|
||||
{
|
||||
if (m_List.empty())
|
||||
{
|
||||
STHROWF("RegEx match list container is empty");
|
||||
}
|
||||
return m_List;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve a value from the container.
|
||||
*/
|
||||
SQMOD_NODISCARD List::reference Get(SQInteger i)
|
||||
{
|
||||
return ValidIdx(i).at(ClampL< SQInteger, size_t >(i));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the first element in the container.
|
||||
*/
|
||||
SQMOD_NODISCARD List::reference Front()
|
||||
{
|
||||
return ValidPop().front();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the last element in the container.
|
||||
*/
|
||||
SQMOD_NODISCARD List::reference Back()
|
||||
{
|
||||
return m_List.back();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if the container has no elements.
|
||||
*/
|
||||
SQMOD_NODISCARD bool Empty() const
|
||||
{
|
||||
return m_List.empty();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of elements in the container.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger Size() const
|
||||
{
|
||||
return static_cast< SQInteger >(m_List.size());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the number of elements that the container has currently allocated space for.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger Capacity() const
|
||||
{
|
||||
return static_cast< SQInteger >(m_List.capacity());
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Increase the capacity of the container to a value that's greater or equal to the one specified.
|
||||
*/
|
||||
PcRegExMatches & Reserve(SQInteger n)
|
||||
{
|
||||
m_List.reserve(ClampL< SQInteger, size_t >(n));
|
||||
return *this;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Request the removal of unused capacity.
|
||||
*/
|
||||
void Compact()
|
||||
{
|
||||
m_List.shrink_to_fit();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Erase all elements from the container.
|
||||
*/
|
||||
void Clear()
|
||||
{
|
||||
m_List.clear();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Pop the last element in the container.
|
||||
*/
|
||||
void Pop()
|
||||
{
|
||||
ValidPop().pop_back();
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Erase the element at a certain position.
|
||||
*/
|
||||
void EraseAt(SQInteger i)
|
||||
{
|
||||
m_List.erase(ValidIdx(i).begin() + static_cast< size_t >(i));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Erase a certain amount of elements starting from a specific position.
|
||||
*/
|
||||
void EraseFrom(SQInteger i, SQInteger n)
|
||||
{
|
||||
m_List.erase(ValidIdx(i).begin() + static_cast< size_t >(i),
|
||||
ValidIdx(i + n).begin() + static_cast< size_t >(i + n));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate all values through a functor.
|
||||
*/
|
||||
void Each(Function & fn) const
|
||||
{
|
||||
for (const auto & e : m_List)
|
||||
{
|
||||
fn.Execute(static_cast< SQInteger >(e.offset), static_cast< SQInteger >(e.length));
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate values in range through a functor.
|
||||
*/
|
||||
void EachRange(SQInteger p, SQInteger n, Function & fn) const
|
||||
{
|
||||
std::for_each(ValidIdx(p).begin() + static_cast< size_t >(p),
|
||||
ValidIdx(p + n).begin() + static_cast< size_t >(p + n),
|
||||
[&](List::const_reference & e) {
|
||||
fn.Execute(static_cast< SQInteger >(e.offset), static_cast< SQInteger >(e.length));
|
||||
});
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Iterate all values through a functor until stopped (i.e false is returned).
|
||||
*/
|
||||
void While(Function & fn) const
|
||||
{
|
||||
for (const auto & e : m_List)
|
||||
{
|
||||
auto ret = fn.Eval(static_cast< SQInteger >(e.offset), static_cast< SQInteger >(e.length));
|
||||
// (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) const
|
||||
{
|
||||
auto itr = ValidIdx(p).begin() + static_cast< size_t >(p);
|
||||
auto end = ValidIdx(p + n).begin() + static_cast< size_t >(p + n);
|
||||
for (; itr != end; ++itr)
|
||||
{
|
||||
auto ret = fn.Eval(static_cast< SQInteger >(itr->offset), static_cast< SQInteger >(itr->length));
|
||||
// (null || true) == continue & false == break
|
||||
if (!ret.IsNull() || !ret.template Cast< bool >())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* A class for working with regular expressions.
|
||||
* Implemented using PCRE, the Perl Compatible Regular Expressions library. (see http://www.pcre.org)
|
||||
*/
|
||||
struct PcRegEx
|
||||
{
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Internal RegularExpression instance.
|
||||
*/
|
||||
Poco::RegularExpression m_Rx;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Base constructor.
|
||||
*/
|
||||
explicit PcRegEx(StackStrF & str)
|
||||
: m_Rx(str.ToStr())
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
PcRegEx(int options, StackStrF & str)
|
||||
: m_Rx(str.ToStr(), options)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Explicit constructor.
|
||||
*/
|
||||
PcRegEx(int options, bool study, StackStrF & str)
|
||||
: m_Rx(str.ToStr(), options, study)
|
||||
{
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy constructor. (disabled)
|
||||
*/
|
||||
PcRegEx(const PcRegEx & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move constructor. (disabled)
|
||||
*/
|
||||
PcRegEx(PcRegEx && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator. (disabled)
|
||||
*/
|
||||
PcRegEx & operator = (const PcRegEx & o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Move assignment operator. (disabled)
|
||||
*/
|
||||
PcRegEx & operator = (PcRegEx && o) = delete;
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Matches the given subject string against the pattern.
|
||||
* Returns the position of the first captured sub-string in m.
|
||||
* If no part of the subject matches the pattern, m.offset is std::string::npos and m.length is 0.
|
||||
* Returns the number of matches. Throws a exception in case of an error.
|
||||
*/
|
||||
SQMOD_NODISCARD int MatchFirst(PcRegExMatch & m, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), m);
|
||||
}
|
||||
SQMOD_NODISCARD int MatchFirst_(int f, PcRegExMatch & m, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), m, f);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Matches the given subject string against the pattern.
|
||||
* Returns the position of the first captured sub-string in m.
|
||||
* If no part of the subject matches the pattern, m.offset is std::string::npos and m.length is 0.
|
||||
* Returns the number of matches. Throws a exception in case of an error.
|
||||
*/
|
||||
SQMOD_NODISCARD int MatchFirstFrom(SQInteger o, PcRegExMatch & m, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), static_cast< std::string::size_type >(o), m);
|
||||
}
|
||||
SQMOD_NODISCARD int MatchFirstFrom_(int f, SQInteger o, PcRegExMatch & m, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), static_cast< std::string::size_type >(o), m, f);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Matches the given subject string against the pattern.
|
||||
* The first entry in m contains the position of the captured sub-string.
|
||||
* The following entries identify matching subpatterns. See the PCRE documentation for a more detailed explanation.
|
||||
* If no part of the subject matches the pattern, m is empty.
|
||||
* Returns the number of matches. Throws a exception in case of an error.
|
||||
*/
|
||||
SQMOD_NODISCARD int Match(PcRegExMatches & m, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), 0, m.m_List);
|
||||
}
|
||||
SQMOD_NODISCARD int Match_(int f, PcRegExMatches & m, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), 0, m.m_List, f);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Matches the given subject string against the pattern.
|
||||
* The first entry in m contains the position of the captured sub-string.
|
||||
* The following entries identify matching subpatterns. See the PCRE documentation for a more detailed explanation.
|
||||
* If no part of the subject matches the pattern, m is empty.
|
||||
* Returns the number of matches. Throws a exception in case of an error.
|
||||
*/
|
||||
SQMOD_NODISCARD int MatchFrom(SQInteger o, PcRegExMatches & m, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), static_cast< std::string::size_type >(o), m.m_List);
|
||||
}
|
||||
SQMOD_NODISCARD int MatchFrom_(int f, SQInteger o, PcRegExMatches & m, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), static_cast< std::string::size_type >(o), m.m_List, f);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Returns true if and only if the subject matches the regular expression.
|
||||
* Internally, this method sets the RE_ANCHORED and RE_NOTEMPTY options for matching,
|
||||
* which means that the empty string will never match and the pattern is treated as if it starts with a ^.
|
||||
*/
|
||||
SQMOD_NODISCARD bool Matches(StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr());
|
||||
}
|
||||
SQMOD_NODISCARD bool Matches_(SQInteger o, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), static_cast< std::string::size_type >(o));
|
||||
}
|
||||
SQMOD_NODISCARD bool MatchesEx(int f, SQInteger o, StackStrF & s) const
|
||||
{
|
||||
return m_Rx.match(s.ToStr(), static_cast< std::string::size_type >(o), f);
|
||||
}
|
||||
};
|
||||
|
||||
} // Namespace:: SqMod
|
@ -8,7 +8,6 @@ namespace SqMod {
|
||||
extern void Register_POCO_Crypto(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_POCO_Data(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_POCO_Net(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_POCO_RegEx(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_POCO_Time(HSQUIRRELVM vm, Table & ns);
|
||||
extern void Register_POCO_Util(HSQUIRRELVM vm, Table & ns);
|
||||
|
||||
@ -20,7 +19,6 @@ void Register_POCO(HSQUIRRELVM vm)
|
||||
Register_POCO_Crypto(vm, ns);
|
||||
Register_POCO_Data(vm, ns);
|
||||
Register_POCO_Net(vm, ns);
|
||||
Register_POCO_RegEx(vm, ns);
|
||||
Register_POCO_Time(vm, ns);
|
||||
Register_POCO_Util(vm, ns);
|
||||
|
||||
|
@ -39,15 +39,13 @@ extern void Register_JSON(HSQUIRRELVM vm);
|
||||
extern void Register_MMDB(HSQUIRRELVM vm);
|
||||
extern void Register_Net(HSQUIRRELVM vm);
|
||||
extern void Register_Numeric(HSQUIRRELVM vm);
|
||||
extern void Register_RegEx(HSQUIRRELVM vm);
|
||||
extern void Register_String(HSQUIRRELVM vm);
|
||||
extern void Register_System(HSQUIRRELVM vm);
|
||||
extern void Register_UTF8(HSQUIRRELVM vm);
|
||||
extern void Register_Utils(HSQUIRRELVM vm);
|
||||
extern void Register_XML(HSQUIRRELVM vm);
|
||||
extern void Register_ZMQ(HSQUIRRELVM vm);
|
||||
#ifdef VCMP_ENABLE_DISCORD
|
||||
extern void Register_DPP(HSQUIRRELVM vm);
|
||||
#endif
|
||||
#ifdef SQMOD_POCO_HAS_SQLITE
|
||||
extern void Register_SQLite(HSQUIRRELVM vm);
|
||||
#endif
|
||||
@ -109,15 +107,13 @@ bool RegisterAPI(HSQUIRRELVM vm)
|
||||
Register_MMDB(vm);
|
||||
Register_Net(vm);
|
||||
Register_Numeric(vm);
|
||||
Register_RegEx(vm);
|
||||
Register_String(vm);
|
||||
Register_System(vm);
|
||||
Register_UTF8(vm);
|
||||
Register_Utils(vm);
|
||||
Register_XML(vm);
|
||||
Register_ZMQ(vm);
|
||||
#ifdef VCMP_ENABLE_DISCORD
|
||||
Register_DPP(vm);
|
||||
#endif
|
||||
#ifdef SQMOD_POCO_HAS_SQLITE
|
||||
Register_SQLite(vm);
|
||||
#endif
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include <squirrelex.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "sqratObject.h"
|
||||
@ -661,6 +662,80 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
// Used internally to proxy calls to wrapped squirrel methods.
|
||||
template < class T = C, SQInteger(T::*Mptr)(HSQUIRRELVM) > static SQInteger SquirrelMethodProxy(HSQUIRRELVM vm) noexcept
|
||||
{
|
||||
try {
|
||||
return ((::Sqrat::Var<T*>(vm, 1).value)->*Mptr)(vm);
|
||||
} catch (const Poco::Exception& e) {
|
||||
return sq_throwerror(vm, e.displayText().c_str());
|
||||
} catch (const std::exception& e) {
|
||||
return sq_throwerror(vm, e.what());
|
||||
} catch (...) {
|
||||
return sq_throwerror(vm, _SC("unknown exception occured"));
|
||||
}
|
||||
}
|
||||
|
||||
// Used internally to proxy calls to wrapped squirrel methods.
|
||||
template < class T = C, SQInteger(T::*Mptr)(HSQUIRRELVM) const > static SQInteger SquirrelMethodProxy(HSQUIRRELVM vm) noexcept
|
||||
{
|
||||
try {
|
||||
return ((::Sqrat::Var<T*>(vm, 1).value)->*Mptr)(vm);
|
||||
} catch (const Poco::Exception& e) {
|
||||
return sq_throwerror(vm, e.displayText().c_str());
|
||||
} catch (const std::exception& e) {
|
||||
return sq_throwerror(vm, e.what());
|
||||
} catch (...) {
|
||||
return sq_throwerror(vm, _SC("unknown exception occured"));
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Binds a class method that is treated as a squirrel function but invoked on the instance itself
|
||||
///
|
||||
/// \param name Name of the function as it will appear in Squirrel
|
||||
/// \param func Function to bind
|
||||
///
|
||||
/// \return The Class itself so the call can be chained
|
||||
///
|
||||
/// \remarks
|
||||
/// Inside of the function, the class instance the function was called with will be at index 1 on the
|
||||
/// stack and all arguments will be after that index in the order they were given to the function.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template < class T = C, SQInteger(T::*Mptr)(HSQUIRRELVM) > Class& SquirrelMethod(const SQChar* name) {
|
||||
return SquirrelFunc(name, &SquirrelMethodProxy< T, Mptr >);
|
||||
}
|
||||
template < class T = C, SQInteger(T::*Mptr)(HSQUIRRELVM) const > Class& SquirrelMethod(const SQChar* name) {
|
||||
return SquirrelFunc(name, &SquirrelMethodProxy< T, Mptr >);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Binds a class method that is treated as a squirrel function but invoked on the instance itself
|
||||
///
|
||||
/// \param name Name of the function as it will appear in Squirrel
|
||||
/// \param func Function to bind
|
||||
/// \param pnum Number of parameters the function expects.
|
||||
/// \param mask Types of parameters the function expects.
|
||||
///
|
||||
/// \return The Class itself so the call can be chained
|
||||
///
|
||||
/// \remarks
|
||||
/// Inside of the function, the class instance the function was called with will be at index 1 on the
|
||||
/// stack and all arguments will be after that index in the order they were given to the function.
|
||||
///
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
template < class T = C, SQInteger(T::*Mptr)(HSQUIRRELVM) > Class& SquirrelMethod(const SQChar* name, SQInteger pnum, const SQChar * mask) {
|
||||
return SquirrelFunc(name, &SquirrelMethodProxy< T, Mptr >, pnum, mask);
|
||||
}
|
||||
template < class T = C, SQInteger(T::*Mptr)(HSQUIRRELVM) const > Class& SquirrelMethod(const SQChar* name, SQInteger pnum, const SQChar * mask) {
|
||||
return SquirrelFunc(name, &SquirrelMethodProxy< T, Mptr >, pnum, mask);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// Gets a Function from a name in the Class
|
||||
///
|
||||
|
@ -157,7 +157,7 @@ template <class C,class R> struct SqMember {
|
||||
} catch (const std::exception& e) {
|
||||
return sq_throwerror(vm, e.what());
|
||||
} catch (...) {
|
||||
return sq_throwerror(vm, _SC("unknown exception occured"));
|
||||
return sq_throwerror(vm, _SC("unknown exception occurred"));
|
||||
}
|
||||
SQ_UNREACHABLE
|
||||
};
|
||||
@ -178,7 +178,7 @@ template <class C,class R> struct SqMember {
|
||||
} catch (const std::exception& e) {
|
||||
return sq_throwerror(vm, e.what());
|
||||
} catch (...) {
|
||||
return sq_throwerror(vm, _SC("unknown exception occured"));
|
||||
return sq_throwerror(vm, _SC("unknown exception occurred"));
|
||||
}
|
||||
SQ_UNREACHABLE
|
||||
};
|
||||
@ -206,7 +206,7 @@ template <class C, class R> struct SqMember<C,R&> {
|
||||
} catch (const std::exception& e) {
|
||||
return sq_throwerror(vm, e.what());
|
||||
} catch (...) {
|
||||
return sq_throwerror(vm, _SC("unknown exception occured"));
|
||||
return sq_throwerror(vm, _SC("unknown exception occurred"));
|
||||
}
|
||||
SQ_UNREACHABLE
|
||||
};
|
||||
@ -227,7 +227,7 @@ template <class C, class R> struct SqMember<C,R&> {
|
||||
} catch (const std::exception& e) {
|
||||
return sq_throwerror(vm, e.what());
|
||||
} catch (...) {
|
||||
return sq_throwerror(vm, _SC("unknown exception occured"));
|
||||
return sq_throwerror(vm, _SC("unknown exception occurred"));
|
||||
}
|
||||
SQ_UNREACHABLE
|
||||
};
|
||||
@ -256,7 +256,7 @@ template <class C> struct SqMember<C, void> {
|
||||
} catch (const std::exception& e) {
|
||||
return sq_throwerror(vm, e.what());
|
||||
} catch (...) {
|
||||
return sq_throwerror(vm, _SC("unknown exception occured"));
|
||||
return sq_throwerror(vm, _SC("unknown exception occurred"));
|
||||
}
|
||||
SQ_UNREACHABLE
|
||||
};
|
||||
@ -277,7 +277,7 @@ template <class C> struct SqMember<C, void> {
|
||||
} catch (const std::exception& e) {
|
||||
return sq_throwerror(vm, e.what());
|
||||
} catch (...) {
|
||||
return sq_throwerror(vm, _SC("unknown exception occured"));
|
||||
return sq_throwerror(vm, _SC("unknown exception occurred"));
|
||||
}
|
||||
SQ_UNREACHABLE
|
||||
};
|
||||
|
5
vendor/CMakeLists.txt
vendored
5
vendor/CMakeLists.txt
vendored
@ -1,6 +1,7 @@
|
||||
add_subdirectory(ConcurrentQueue)
|
||||
add_subdirectory(Fmt)
|
||||
add_subdirectory(xxHash)
|
||||
add_subdirectory(RPMalloc)
|
||||
add_subdirectory(Squirrel)
|
||||
add_subdirectory(SimpleIni)
|
||||
add_subdirectory(TinyDir)
|
||||
@ -70,7 +71,3 @@ if (WIN32 OR MINGW)
|
||||
set(ZMQ_HAVE_IPC OFF CACHE INTERNAL "" FORCE)
|
||||
endif()
|
||||
add_subdirectory(ZMQ)
|
||||
# Should we include DPP?
|
||||
if (ENABLE_DISCORD)
|
||||
add_subdirectory(DPP)
|
||||
endif()
|
||||
|
174
vendor/DPP/CMakeLists.txt
vendored
174
vendor/DPP/CMakeLists.txt
vendored
@ -1,174 +0,0 @@
|
||||
# Create the DPP library
|
||||
add_library(DPP STATIC
|
||||
include/dpp/nlohmann/json.hpp
|
||||
include/dpp/nlohmann/json_fwd.hpp
|
||||
include/dpp/auditlog.h
|
||||
include/dpp/ban.h
|
||||
include/dpp/cache.h
|
||||
include/dpp/channel.h
|
||||
include/dpp/cluster.h
|
||||
include/dpp/commandhandler.h
|
||||
include/dpp/discord.h
|
||||
include/dpp/discordclient.h
|
||||
include/dpp/discordevents.h
|
||||
include/dpp/discordvoiceclient.h
|
||||
include/dpp/dispatcher.h
|
||||
include/dpp/dpp.h
|
||||
include/dpp/dtemplate.h
|
||||
include/dpp/emoji.h
|
||||
include/dpp/event.h
|
||||
include/dpp/export.h
|
||||
include/dpp/guild.h
|
||||
include/dpp/httplib.h
|
||||
include/dpp/integration.h
|
||||
include/dpp/intents.h
|
||||
include/dpp/invite.h
|
||||
include/dpp/json_fwd.hpp
|
||||
include/dpp/message.h
|
||||
include/dpp/presence.h
|
||||
include/dpp/prune.h
|
||||
include/dpp/queues.h
|
||||
include/dpp/role.h
|
||||
include/dpp/slashcommand.h
|
||||
include/dpp/sslclient.h
|
||||
include/dpp/stringops.h
|
||||
include/dpp/user.h
|
||||
include/dpp/version.h
|
||||
include/dpp/voiceregion.h
|
||||
include/dpp/voicestate.h
|
||||
include/dpp/webhook.h
|
||||
include/dpp/wsclient.h
|
||||
src/dpp/ban.cpp
|
||||
src/dpp/cache.cpp
|
||||
src/dpp/channel.cpp
|
||||
src/dpp/cluster.cpp
|
||||
src/dpp/commandhandler.cpp
|
||||
src/dpp/discordclient.cpp
|
||||
src/dpp/discordevents.cpp
|
||||
src/dpp/discordvoiceclient.cpp
|
||||
src/dpp/dispatcher.cpp
|
||||
src/dpp/dtemplate.cpp
|
||||
src/dpp/emoji.cpp
|
||||
src/dpp/guild.cpp
|
||||
src/dpp/httplib.cpp
|
||||
src/dpp/integration.cpp
|
||||
src/dpp/invite.cpp
|
||||
src/dpp/managed.cpp
|
||||
src/dpp/message.cpp
|
||||
src/dpp/presence.cpp
|
||||
src/dpp/prune.cpp
|
||||
src/dpp/queues.cpp
|
||||
src/dpp/role.cpp
|
||||
src/dpp/slashcommand.cpp
|
||||
src/dpp/sslclient.cpp
|
||||
src/dpp/user.cpp
|
||||
src/dpp/utility.cpp
|
||||
src/dpp/voiceregion.cpp
|
||||
src/dpp/voicestate.cpp
|
||||
src/dpp/webhook.cpp
|
||||
src/dpp/wsclient.cpp
|
||||
src/dpp/auditlog.cpp
|
||||
src/dpp/events/application_command_update.cpp
|
||||
src/dpp/events/channel_create.cpp
|
||||
src/dpp/events/channel_delete.cpp
|
||||
src/dpp/events/channel_pins_update.cpp
|
||||
src/dpp/events/channel_update.cpp
|
||||
src/dpp/events/guild_ban_add.cpp
|
||||
src/dpp/events/guild_ban_remove.cpp
|
||||
src/dpp/events/guild_create.cpp
|
||||
src/dpp/events/guild_delete.cpp
|
||||
src/dpp/events/guild_emojis_update.cpp
|
||||
src/dpp/events/guild_integrations_update.cpp
|
||||
src/dpp/events/guild_join_request_delete.cpp
|
||||
src/dpp/events/guild_member_add.cpp
|
||||
src/dpp/events/guild_member_remove.cpp
|
||||
src/dpp/events/guild_member_update.cpp
|
||||
src/dpp/events/guild_members_chunk.cpp
|
||||
src/dpp/events/guild_role_create.cpp
|
||||
src/dpp/events/guild_role_delete.cpp
|
||||
src/dpp/events/guild_role_update.cpp
|
||||
src/dpp/events/guild_stickers_update.cpp
|
||||
src/dpp/events/guild_update.cpp
|
||||
src/dpp/events/integration_create.cpp
|
||||
src/dpp/events/integration_delete.cpp
|
||||
src/dpp/events/integration_update.cpp
|
||||
src/dpp/events/interaction_create.cpp
|
||||
src/dpp/events/invite_create.cpp
|
||||
src/dpp/events/invite_delete.cpp
|
||||
src/dpp/events/logger.cpp
|
||||
src/dpp/events/message_create.cpp
|
||||
src/dpp/events/message_delete.cpp
|
||||
src/dpp/events/message_delete_bulk.cpp
|
||||
src/dpp/events/message_reaction_add.cpp
|
||||
src/dpp/events/message_reaction_remove.cpp
|
||||
src/dpp/events/message_reaction_remove_all.cpp
|
||||
src/dpp/events/message_reaction_remove_emoji.cpp
|
||||
src/dpp/events/message_update.cpp
|
||||
src/dpp/events/presence_update.cpp
|
||||
src/dpp/events/ready.cpp
|
||||
src/dpp/events/resumed.cpp
|
||||
src/dpp/events/stage_instance_create.cpp
|
||||
src/dpp/events/stage_instance_delete.cpp
|
||||
src/dpp/events/thread_create.cpp
|
||||
src/dpp/events/thread_delete.cpp
|
||||
src/dpp/events/thread_list_sync.cpp
|
||||
src/dpp/events/thread_member_update.cpp
|
||||
src/dpp/events/thread_members_update.cpp
|
||||
src/dpp/events/thread_update.cpp
|
||||
src/dpp/events/typing_start.cpp
|
||||
src/dpp/events/user_update.cpp
|
||||
src/dpp/events/voice_server_update.cpp
|
||||
src/dpp/events/voice_state_update.cpp
|
||||
src/dpp/events/webhooks_update.cpp
|
||||
src/dpp/events/application_command_create.cpp
|
||||
src/dpp/events/application_command_delete.cpp
|
||||
)
|
||||
# Configure include folders
|
||||
target_include_directories(DPP PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src)
|
||||
target_include_directories(DPP PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/dpp)
|
||||
target_include_directories(DPP PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
|
||||
# Link to built-in third-party libraries
|
||||
target_link_libraries(DPP PUBLIC fmt::fmt)
|
||||
# Project defines
|
||||
target_compile_definitions(DPP PUBLIC DPP_BUILD=1)
|
||||
# Platform defines
|
||||
if(WIN32)
|
||||
target_compile_definitions(DPP PRIVATE _WIN32_WINNT=0x0601 OPENSSL_SYS_WIN32=1 _WINSOCK_DEPRECATED_NO_WARNINGS=1 WIN32_LEAN_AND_MEAN=1 _CRT_SECURE_NO_WARNINGS=1 _CRT_NONSTDC_NO_DEPRECATE=1)
|
||||
if (MINGW)
|
||||
target_compile_definitions(DPP PUBLIC WIN32=1)
|
||||
endif()
|
||||
target_link_libraries(DPP PRIVATE Crypt32)
|
||||
endif()
|
||||
# Third-party library preferences
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
# Find required third-party libraries
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
# Link to required third-party libraries
|
||||
target_link_libraries(DPP PUBLIC Threads::Threads ZLIB::ZLIB OpenSSL::Crypto OpenSSL::SSL)
|
||||
# Include the custom module folder
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/")
|
||||
# Enable voice support in discord library
|
||||
if (ENABLE_DISCORD_VOICE)
|
||||
# Look for sodium and opus libraries
|
||||
include("cmake/FindSodium.cmake")
|
||||
include("cmake/FindOpus.cmake")
|
||||
# Was the opus library found?
|
||||
if(DEFINED OPUS_FOUND)
|
||||
message(STATUS "Opus library was found")
|
||||
# Link to opus library
|
||||
target_include_directories(DPP PUBLIC ${OPUS_INCLUDE_DIRS})
|
||||
target_link_libraries(DPP PUBLIC ${OPUS_LIBRARIES})
|
||||
# Was the sodium library found?
|
||||
if(DEFINED sodium_VERSION_STRING)
|
||||
message(STATUS "Sodium library was found")
|
||||
message(STATUS "DPP voice support enabled")
|
||||
# Let the code know about this
|
||||
target_compile_definitions(DPP PRIVATE HAVE_VOICE=1)
|
||||
# Link to sodium library
|
||||
target_include_directories(DPP PUBLIC ${sodium_INCLUDE_DIR})
|
||||
target_link_libraries(DPP PUBLIC ${sodium_LIBRARY_RELEASE})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
201
vendor/DPP/LICENSE
vendored
201
vendor/DPP/LICENSE
vendored
@ -1,201 +0,0 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
36
vendor/DPP/cmake/FindOpus.cmake
vendored
36
vendor/DPP/cmake/FindOpus.cmake
vendored
@ -1,36 +0,0 @@
|
||||
# OPUS_FOUND - system has opus
|
||||
# OPUS_INCLUDE_DIRS - the opus include directory
|
||||
# OPUS_LIBRARIES - The libraries needed to use opus
|
||||
|
||||
find_path(OPUS_INCLUDE_DIRS
|
||||
NAMES opus/opus.h
|
||||
PATH_SUFFIXES include
|
||||
)
|
||||
if(OPUS_INCLUDE_DIRS)
|
||||
set(HAVE_OPUS_OPUS_H 1)
|
||||
endif()
|
||||
|
||||
if(OPUS_USE_STATIC_LIBS)
|
||||
find_library(OPUS_LIBRARIES NAMES "libopus.a")
|
||||
else()
|
||||
find_library(OPUS_LIBRARIES NAMES opus)
|
||||
endif()
|
||||
|
||||
if(OPUS_LIBRARIES)
|
||||
if(OPUS_USE_STATIC_LIBS)
|
||||
find_library(LIBM NAMES "libm.a" "libm.tbd")
|
||||
else()
|
||||
find_library(LIBM NAMES m)
|
||||
endif()
|
||||
if(LIBM)
|
||||
list(APPEND OPUS_LIBRARIES ${LIBM})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(Opus
|
||||
DEFAULT_MSG
|
||||
OPUS_INCLUDE_DIRS OPUS_LIBRARIES HAVE_OPUS_OPUS_H
|
||||
)
|
||||
|
||||
mark_as_advanced(OPUS_INCLUDE_DIRS OPUS_LIBRARIES HAVE_OPUS_OPUS_H)
|
293
vendor/DPP/cmake/FindSodium.cmake
vendored
293
vendor/DPP/cmake/FindSodium.cmake
vendored
@ -1,293 +0,0 @@
|
||||
# Written in 2016 by Henrik Steffen Gaßmann <henrik@gassmann.onl>
|
||||
#
|
||||
# To the extent possible under law, the author(s) have dedicated all copyright
|
||||
# and related and neighboring rights to this software to the public domain
|
||||
# worldwide. This software is distributed without any warranty.
|
||||
#
|
||||
# You should have received a copy of the CC0 Public Domain Dedication along with
|
||||
# this software. If not, see
|
||||
#
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
#
|
||||
# ##############################################################################
|
||||
# Tries to find the local libsodium installation.
|
||||
#
|
||||
# On Windows the sodium_DIR environment variable is used as a default hint which
|
||||
# can be overridden by setting the corresponding cmake variable.
|
||||
#
|
||||
# Once done the following variables will be defined:
|
||||
#
|
||||
# sodium_FOUND sodium_INCLUDE_DIR sodium_LIBRARY_DEBUG sodium_LIBRARY_RELEASE
|
||||
# sodium_VERSION_STRING
|
||||
#
|
||||
# Furthermore an imported "sodium" target is created.
|
||||
#
|
||||
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
set(_GCC_COMPATIBLE 1)
|
||||
endif()
|
||||
|
||||
# static library option
|
||||
if(NOT DEFINED sodium_USE_STATIC_LIBS)
|
||||
option(sodium_USE_STATIC_LIBS "enable to statically link against sodium" OFF)
|
||||
endif()
|
||||
if(NOT (sodium_USE_STATIC_LIBS EQUAL sodium_USE_STATIC_LIBS_LAST))
|
||||
unset(sodium_LIBRARY CACHE)
|
||||
unset(sodium_LIBRARY_DEBUG CACHE)
|
||||
unset(sodium_LIBRARY_RELEASE CACHE)
|
||||
unset(sodium_DLL_DEBUG CACHE)
|
||||
unset(sodium_DLL_RELEASE CACHE)
|
||||
set(sodium_USE_STATIC_LIBS_LAST
|
||||
${sodium_USE_STATIC_LIBS}
|
||||
CACHE INTERNAL "internal change tracking variable")
|
||||
endif()
|
||||
|
||||
# ##############################################################################
|
||||
# UNIX
|
||||
if(UNIX)
|
||||
# import pkg-config
|
||||
find_package(PkgConfig QUIET)
|
||||
if(PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(sodium_PKG QUIET libsodium)
|
||||
endif()
|
||||
|
||||
if(sodium_USE_STATIC_LIBS)
|
||||
if(sodium_PKG_STATIC_LIBRARIES)
|
||||
foreach(_libname ${sodium_PKG_STATIC_LIBRARIES})
|
||||
if(NOT _libname MATCHES "^lib.*\\.a$") # ignore strings already ending
|
||||
# with .a
|
||||
list(INSERT sodium_PKG_STATIC_LIBRARIES 0 "lib${_libname}.a")
|
||||
endif()
|
||||
endforeach()
|
||||
list(REMOVE_DUPLICATES sodium_PKG_STATIC_LIBRARIES)
|
||||
else()
|
||||
# if pkgconfig for libsodium doesn't provide static lib info, then
|
||||
# override PKG_STATIC here..
|
||||
set(sodium_PKG_STATIC_LIBRARIES libsodium.a)
|
||||
endif()
|
||||
|
||||
set(XPREFIX sodium_PKG_STATIC)
|
||||
else()
|
||||
if(sodium_PKG_LIBRARIES STREQUAL "")
|
||||
set(sodium_PKG_LIBRARIES sodium)
|
||||
endif()
|
||||
|
||||
set(XPREFIX sodium_PKG)
|
||||
endif()
|
||||
|
||||
find_path(sodium_INCLUDE_DIR sodium.h HINTS ${${XPREFIX}_INCLUDE_DIRS})
|
||||
find_library(sodium_LIBRARY_DEBUG
|
||||
NAMES ${${XPREFIX}_LIBRARIES}
|
||||
HINTS ${${XPREFIX}_LIBRARY_DIRS})
|
||||
find_library(sodium_LIBRARY_RELEASE
|
||||
NAMES ${${XPREFIX}_LIBRARIES}
|
||||
HINTS ${${XPREFIX}_LIBRARY_DIRS})
|
||||
|
||||
# ############################################################################
|
||||
# Windows
|
||||
elseif(WIN32)
|
||||
set(sodium_DIR "$ENV{sodium_DIR}" CACHE FILEPATH "sodium install directory")
|
||||
mark_as_advanced(sodium_DIR)
|
||||
|
||||
find_path(sodium_INCLUDE_DIR sodium.h
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES include)
|
||||
|
||||
if(MSVC)
|
||||
# detect target architecture
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/arch.cpp" [=[
|
||||
#if defined _M_IX86
|
||||
#error ARCH_VALUE x86_32
|
||||
#elif defined _M_X64
|
||||
#error ARCH_VALUE x86_64
|
||||
#endif
|
||||
#error ARCH_VALUE unknown
|
||||
]=])
|
||||
try_compile(_UNUSED_VAR "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/arch.cpp"
|
||||
OUTPUT_VARIABLE _COMPILATION_LOG)
|
||||
string(REGEX
|
||||
REPLACE ".*ARCH_VALUE ([a-zA-Z0-9_]+).*"
|
||||
"\\1"
|
||||
_TARGET_ARCH
|
||||
"${_COMPILATION_LOG}")
|
||||
|
||||
# construct library path
|
||||
if(_TARGET_ARCH STREQUAL "x86_32")
|
||||
string(APPEND _PLATFORM_PATH "Win32")
|
||||
elseif(_TARGET_ARCH STREQUAL "x86_64")
|
||||
string(APPEND _PLATFORM_PATH "x64")
|
||||
else()
|
||||
message(
|
||||
FATAL_ERROR
|
||||
"the ${_TARGET_ARCH} architecture is not supported by Findsodium.cmake."
|
||||
)
|
||||
endif()
|
||||
string(APPEND _PLATFORM_PATH "/$$CONFIG$$")
|
||||
|
||||
if(MSVC_VERSION LESS 1900)
|
||||
math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 60")
|
||||
else()
|
||||
math(EXPR _VS_VERSION "${MSVC_VERSION} / 10 - 50")
|
||||
endif()
|
||||
string(APPEND _PLATFORM_PATH "/v${_VS_VERSION}")
|
||||
|
||||
if(sodium_USE_STATIC_LIBS)
|
||||
string(APPEND _PLATFORM_PATH "/static")
|
||||
else()
|
||||
string(APPEND _PLATFORM_PATH "/dynamic")
|
||||
endif()
|
||||
|
||||
string(REPLACE "$$CONFIG$$"
|
||||
"Debug"
|
||||
_DEBUG_PATH_SUFFIX
|
||||
"${_PLATFORM_PATH}")
|
||||
string(REPLACE "$$CONFIG$$"
|
||||
"Release"
|
||||
_RELEASE_PATH_SUFFIX
|
||||
"${_PLATFORM_PATH}")
|
||||
|
||||
find_library(sodium_LIBRARY_DEBUG libsodium.lib
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX})
|
||||
find_library(sodium_LIBRARY_RELEASE libsodium.lib
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX})
|
||||
if(NOT sodium_USE_STATIC_LIBS)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES_BCK ${CMAKE_FIND_LIBRARY_SUFFIXES})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dll")
|
||||
find_library(sodium_DLL_DEBUG libsodium
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES ${_DEBUG_PATH_SUFFIX})
|
||||
find_library(sodium_DLL_RELEASE libsodium
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES ${_RELEASE_PATH_SUFFIX})
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_BCK})
|
||||
endif()
|
||||
|
||||
elseif(_GCC_COMPATIBLE)
|
||||
if(sodium_USE_STATIC_LIBS)
|
||||
find_library(sodium_LIBRARY_DEBUG libsodium.a
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES lib)
|
||||
find_library(sodium_LIBRARY_RELEASE libsodium.a
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES lib)
|
||||
else()
|
||||
find_library(sodium_LIBRARY_DEBUG libsodium.dll.a
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES lib)
|
||||
find_library(sodium_LIBRARY_RELEASE libsodium.dll.a
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES lib)
|
||||
|
||||
file(GLOB _DLL
|
||||
LIST_DIRECTORIES false
|
||||
RELATIVE "${sodium_DIR}/bin"
|
||||
"${sodium_DIR}/bin/libsodium*.dll")
|
||||
find_library(sodium_DLL_DEBUG ${_DLL} libsodium
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES bin)
|
||||
find_library(sodium_DLL_RELEASE ${_DLL} libsodium
|
||||
HINTS ${sodium_DIR}
|
||||
PATH_SUFFIXES bin)
|
||||
endif()
|
||||
else()
|
||||
message(FATAL_ERROR "this platform is not supported by FindSodium.cmake")
|
||||
endif()
|
||||
|
||||
# ############################################################################
|
||||
# unsupported
|
||||
else()
|
||||
message(FATAL_ERROR "this platform is not supported by FindSodium.cmake")
|
||||
endif()
|
||||
|
||||
# ##############################################################################
|
||||
# common stuff
|
||||
|
||||
# extract sodium version
|
||||
if(sodium_INCLUDE_DIR)
|
||||
set(_VERSION_HEADER "${sodium_INCLUDE_DIR}/sodium/version.h")
|
||||
if(EXISTS "${_VERSION_HEADER}")
|
||||
file(READ "${_VERSION_HEADER}" _VERSION_HEADER_CONTENT)
|
||||
string(
|
||||
REGEX
|
||||
REPLACE
|
||||
".*#define[ \t]*SODIUM_VERSION_STRING[ \t]*\"([^\n]*)\".*"
|
||||
"\\1"
|
||||
sodium_VERSION_STRING
|
||||
"${_VERSION_HEADER_CONTENT}")
|
||||
set(sodium_VERSION_STRING "${sodium_VERSION_STRING}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# communicate results
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(sodium
|
||||
REQUIRED_VARS
|
||||
sodium_LIBRARY_RELEASE
|
||||
sodium_LIBRARY_DEBUG
|
||||
sodium_INCLUDE_DIR
|
||||
VERSION_VAR
|
||||
sodium_VERSION_STRING)
|
||||
|
||||
# mark file paths as advanced
|
||||
mark_as_advanced(sodium_INCLUDE_DIR)
|
||||
mark_as_advanced(sodium_LIBRARY_DEBUG)
|
||||
mark_as_advanced(sodium_LIBRARY_RELEASE)
|
||||
if(WIN32)
|
||||
mark_as_advanced(sodium_DLL_DEBUG)
|
||||
mark_as_advanced(sodium_DLL_RELEASE)
|
||||
endif()
|
||||
|
||||
# create imported target
|
||||
if(sodium_USE_STATIC_LIBS)
|
||||
set(_LIB_TYPE STATIC)
|
||||
else()
|
||||
set(_LIB_TYPE SHARED)
|
||||
endif()
|
||||
add_library(sodium ${_LIB_TYPE} IMPORTED)
|
||||
|
||||
set_target_properties(sodium
|
||||
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
|
||||
"${sodium_INCLUDE_DIR}"
|
||||
IMPORTED_LINK_INTERFACE_LANGUAGES
|
||||
"C")
|
||||
|
||||
if(sodium_USE_STATIC_LIBS)
|
||||
set_target_properties(sodium
|
||||
PROPERTIES INTERFACE_COMPILE_DEFINITIONS
|
||||
"SODIUM_STATIC"
|
||||
IMPORTED_LOCATION
|
||||
"${sodium_LIBRARY_RELEASE}"
|
||||
IMPORTED_LOCATION_DEBUG
|
||||
"${sodium_LIBRARY_DEBUG}")
|
||||
else()
|
||||
if(UNIX)
|
||||
set_target_properties(sodium
|
||||
PROPERTIES IMPORTED_LOCATION
|
||||
"${sodium_LIBRARY_RELEASE}"
|
||||
IMPORTED_LOCATION_DEBUG
|
||||
"${sodium_LIBRARY_DEBUG}")
|
||||
elseif(WIN32)
|
||||
set_target_properties(sodium
|
||||
PROPERTIES IMPORTED_IMPLIB
|
||||
"${sodium_LIBRARY_RELEASE}"
|
||||
IMPORTED_IMPLIB_DEBUG
|
||||
"${sodium_LIBRARY_DEBUG}")
|
||||
if(NOT (sodium_DLL_DEBUG MATCHES ".*-NOTFOUND"))
|
||||
set_target_properties(sodium
|
||||
PROPERTIES IMPORTED_LOCATION_DEBUG
|
||||
"${sodium_DLL_DEBUG}")
|
||||
endif()
|
||||
if(NOT (sodium_DLL_RELEASE MATCHES ".*-NOTFOUND"))
|
||||
set_target_properties(sodium
|
||||
PROPERTIES IMPORTED_LOCATION_RELWITHDEBINFO
|
||||
"${sodium_DLL_RELEASE}"
|
||||
IMPORTED_LOCATION_MINSIZEREL
|
||||
"${sodium_DLL_RELEASE}"
|
||||
IMPORTED_LOCATION_RELEASE
|
||||
"${sodium_DLL_RELEASE}")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
165
vendor/DPP/include/dpp/auditlog.h
vendored
165
vendor/DPP/include/dpp/auditlog.h
vendored
@ -1,165 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
#include <optional>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Defines types of audit log entry
|
||||
*/
|
||||
enum audit_type {
|
||||
/// Guild update
|
||||
ae_guild_update = 1,
|
||||
/// Channel create
|
||||
ae_channel_create = 10,
|
||||
/// Channel update
|
||||
ae_channel_update = 11,
|
||||
/// Channel delete
|
||||
ae_channel_delete = 12,
|
||||
/// Channel overwrite create
|
||||
ae_channel_overwrite_create = 13,
|
||||
/// Channel overwrite update
|
||||
ae_channel_overwrite_update = 14,
|
||||
/// Channel overwrite delete
|
||||
ae_channel_overwrite_delete = 15,
|
||||
/// Channel member kick
|
||||
ae_member_kick = 20,
|
||||
/// Channel member prune
|
||||
ae_member_prune = 21,
|
||||
/// Channel member ban add
|
||||
ae_member_ban_add = 22,
|
||||
/// Channel member ban remove
|
||||
ae_member_ban_remove = 23,
|
||||
/// Guild member update
|
||||
ae_member_update = 24,
|
||||
/// Guild member role update
|
||||
ae_member_role_update = 25,
|
||||
/// Guild member move
|
||||
ae_member_move = 26,
|
||||
/// Guild member voice disconnect
|
||||
ae_member_disconnect = 27,
|
||||
/// Guild bot add
|
||||
ae_bot_add = 28,
|
||||
/// Guild role create
|
||||
ae_role_create = 30,
|
||||
/// Guild role update
|
||||
ae_role_update = 31,
|
||||
/// Guild role delete
|
||||
ae_role_delete = 32,
|
||||
/// Guild invite create
|
||||
ae_invite_create = 40,
|
||||
/// Guild invite update
|
||||
ae_invite_update = 41,
|
||||
/// Guild invite delete
|
||||
ae_invite_delete = 42,
|
||||
/// Guild webhook create
|
||||
ae_webhook_create = 50,
|
||||
/// Guild webhook update
|
||||
ae_webhook_update = 51,
|
||||
/// Guild webhook delete
|
||||
ae_webhook_delete = 52,
|
||||
/// Guild emoji create
|
||||
ae_emoji_create = 60,
|
||||
/// Guild emoji update
|
||||
ae_emoji_update = 61,
|
||||
/// Guild emoji delete
|
||||
ae_emoji_delete = 62,
|
||||
/// Guild message delete
|
||||
ae_message_delete = 72,
|
||||
/// Guild message bulk delete
|
||||
ae_message_bulk_delete = 73,
|
||||
/// Guild message pin
|
||||
ae_message_pin = 74,
|
||||
/// Guild message unpin
|
||||
ae_message_unpin = 75,
|
||||
/// Guild integration create
|
||||
ae_integration_create = 80,
|
||||
/// Guild integration update
|
||||
ae_integration_update = 81,
|
||||
/// Guild integration delete
|
||||
ae_integration_delete = 82
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines audit log changes
|
||||
*/
|
||||
struct CoreExport audit_change {
|
||||
/// Optional: Serialised new value of the key
|
||||
std::string new_value;
|
||||
/// Optional: Serialised old value of the key
|
||||
std::string old_value;
|
||||
/// name of audit log change key
|
||||
std::string key;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Extra information for an audit log entry
|
||||
*/
|
||||
struct CoreExport audit_extra {
|
||||
std::string delete_member_days; //!< number of days after which inactive members were kicked
|
||||
std::string members_removed; //!< number of members removed by the prune
|
||||
snowflake channel_id; //!< channel in which the entities were targeted
|
||||
snowflake message_id; //!< id of the message that was targeted
|
||||
std::string count; //!< number of entities that were targeted
|
||||
snowflake id; //!< id of the overwritten entity
|
||||
std::string type; //!< type of overwritten entity - "0" for "role" or "1" for "member"
|
||||
std::string role_name; //!< name of the role if type is "0" (not present if type is "1")
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief An individual audit log entry
|
||||
*/
|
||||
struct CoreExport audit_entry {
|
||||
snowflake id; //!< id of the entry
|
||||
snowflake target_id; //!< id of the affected entity (webhook, user, role, etc.) (may be empty)
|
||||
std::vector<audit_change> changes; //!< Optional: changes made to the target_id
|
||||
snowflake user_id; //!< the user who made the changes (may be empty)
|
||||
audit_type event; //!< type of action that occurred
|
||||
std::optional<audit_extra> options; //!< Optional: additional info for certain action types
|
||||
std::string reason; //!< Optional: the reason for the change (0-512 characters)
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The auditlog class represents the audit log entry of a guild.
|
||||
*/
|
||||
class CoreExport auditlog {
|
||||
public:
|
||||
std::vector<audit_entry> entries; //!< Audit log entries
|
||||
|
||||
/** Constructor */
|
||||
auditlog();
|
||||
|
||||
/** Destructor */
|
||||
~auditlog();
|
||||
|
||||
/** Read class values from json object
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
auditlog& fill_from_json(nlohmann::json* j);
|
||||
};
|
||||
|
||||
};
|
64
vendor/DPP/include/dpp/ban.h
vendored
64
vendor/DPP/include/dpp/ban.h
vendored
@ -1,64 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief The ban class represents a ban on a guild.
|
||||
*
|
||||
*/
|
||||
class CoreExport ban {
|
||||
public:
|
||||
/** The ban reason */
|
||||
std::string reason;
|
||||
/** User ID the ban applies to */
|
||||
snowflake user_id;
|
||||
|
||||
/** Constructor */
|
||||
ban();
|
||||
|
||||
/** Destructor */
|
||||
~ban();
|
||||
|
||||
/** Read class values from json object
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
ban& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build json representation of a ban
|
||||
*
|
||||
* @return std::string stringified json
|
||||
*/
|
||||
std::string build_json() const;
|
||||
};
|
||||
|
||||
/** A group of bans
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, ban> ban_map;
|
||||
|
||||
};
|
127
vendor/DPP/include/dpp/cache.h
vendored
127
vendor/DPP/include/dpp/cache.h
vendored
@ -1,127 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief A set of cached managed objects
|
||||
*/
|
||||
typedef std::unordered_map<uint64_t, managed*> cache_container;
|
||||
|
||||
/**
|
||||
* @brief A cache object maintains a cache of dpp::managed objects.
|
||||
* This is for example users, channels or guilds.
|
||||
*/
|
||||
class CoreExport cache {
|
||||
private:
|
||||
|
||||
/** Mutex to protect the cache */
|
||||
std::mutex cache_mutex;
|
||||
|
||||
/** Cached items */
|
||||
cache_container* cache_map;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a new cache object
|
||||
*/
|
||||
cache();
|
||||
|
||||
/**
|
||||
* @brief Destroy the cache object
|
||||
*/
|
||||
~cache();
|
||||
|
||||
/** Store an object in the cache.
|
||||
* @param object object to store
|
||||
*/
|
||||
void store(managed* object);
|
||||
|
||||
/** Remove an object from the cache.
|
||||
* @param object object to remove
|
||||
*/
|
||||
void remove(managed* object);
|
||||
|
||||
/** Find an object in the cache by id.
|
||||
* @param id Object id to find
|
||||
*/
|
||||
managed* find(snowflake id);
|
||||
|
||||
/** Return a count of the number of items in the cache.
|
||||
*/
|
||||
uint64_t count();
|
||||
|
||||
/**
|
||||
* @brief Return the cache's locking mutex. Use this whenever
|
||||
* you manipulate or iterate raw elements in the cache!
|
||||
*
|
||||
* @return The mutex used to protect the container
|
||||
*/
|
||||
std::mutex& get_mutex();
|
||||
|
||||
/**
|
||||
* @brief Get the container map
|
||||
* @warning Be sure to use cache::get_mutex() correctly if you
|
||||
* manipulate or iterate the map returned by this method! If you do
|
||||
* not, this is not thread safe and will cause crashes!
|
||||
* @see cache::get_mutex
|
||||
*
|
||||
* @return cache_container& A reference to the cache's container map
|
||||
*/
|
||||
cache_container& get_container();
|
||||
|
||||
/**
|
||||
* @brief "Rehash" a cache by cleaning out used RAM
|
||||
* @warning May be time consuming!
|
||||
*/
|
||||
void rehash();
|
||||
|
||||
/**
|
||||
* @brief Get "real" size in RAM of the cache
|
||||
*
|
||||
* @return size_t
|
||||
*/
|
||||
size_t bytes();
|
||||
|
||||
};
|
||||
|
||||
/** Run garbage collection across all caches removing deleted items
|
||||
* that have been deleted over 60 seconds ago.
|
||||
*/
|
||||
void CoreExport garbage_collection();
|
||||
|
||||
#define cache_decl(type, setter, getter, counter) CoreExport type * setter (snowflake id); CoreExport cache * getter (); CoreExport uint64_t counter ();
|
||||
|
||||
/* Declare major caches */
|
||||
cache_decl(user, find_user, get_user_cache, get_user_count);
|
||||
cache_decl(guild, find_guild, get_guild_cache, get_guild_count);
|
||||
cache_decl(role, find_role, get_role_cache, get_role_count);
|
||||
cache_decl(channel, find_channel, get_channel_cache, get_channel_count);
|
||||
cache_decl(emoji, find_emoji, get_emoji_cache, get_emoji_count);
|
||||
};
|
||||
|
302
vendor/DPP/include/dpp/channel.h
vendored
302
vendor/DPP/include/dpp/channel.h
vendored
@ -1,302 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/** @brief Flag integers as received from and sent to discord */
|
||||
enum channel_type {
|
||||
GUILD_TEXT = 0, //!< a text channel within a server
|
||||
DM = 1, //!< a direct message between users
|
||||
GUILD_VOICE = 2, //!< a voice channel within a server
|
||||
GROUP_DM = 3, //!< a direct message between multiple users
|
||||
GUILD_CATEGORY = 4, //!< an organizational category that contains up to 50 channels
|
||||
GUILD_NEWS = 5, //!< a channel that users can follow and crosspost into their own server
|
||||
GUILD_STORE = 6, //!< a channel in which game developers can sell their game on Discord
|
||||
GUILD_NEWS_THREAD = 10, //!< a temporary sub-channel within a GUILD_NEWS channel
|
||||
GUILD_PUBLIC_THREAD = 11, //!< a temporary sub-channel within a GUILD_TEXT channel
|
||||
GUILD_PRIVATE_THREAD = 12, //!< a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission
|
||||
GUILD_STAGE = 13 //!< a "stage" channel, like a voice channel with one authorised speaker
|
||||
};
|
||||
/** @brief Our flags as stored in the object */
|
||||
enum channel_flags {
|
||||
/// NSFW Gated Channel
|
||||
c_nsfw = 0b00000001,
|
||||
/// Text channel
|
||||
c_text = 0b00000010,
|
||||
/// Direct Message
|
||||
c_dm = 0b00000100,
|
||||
/// Voice channel
|
||||
c_voice = 0b00001000,
|
||||
/// Group
|
||||
c_group = 0b00010000,
|
||||
/// Category
|
||||
c_category = 0b00100000,
|
||||
/// News channel
|
||||
c_news = 0b01000000,
|
||||
/// Store page
|
||||
c_store = 0b10000000,
|
||||
/// Stage channel
|
||||
c_stage = 0b11000000,
|
||||
/// News thread
|
||||
c_news_thread = 0b11100000,
|
||||
/// Public thread
|
||||
c_public_thread = 0b11110000,
|
||||
/// Private thread
|
||||
c_private_thread = 0b11111000
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief channel permission overwrite types
|
||||
*/
|
||||
enum overwrite_type : uint8_t {
|
||||
/// Role
|
||||
ot_role = 0,
|
||||
/// Member
|
||||
ot_member = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief channel permission overwrites
|
||||
*/
|
||||
struct CoreExport permission_overwrite {
|
||||
/// Overwrite id
|
||||
snowflake id;
|
||||
/// Overwrite type
|
||||
uint8_t type;
|
||||
/// Allow mask
|
||||
uint64_t allow;
|
||||
/// Deny mask
|
||||
uint64_t deny;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief metadata for threads
|
||||
*/
|
||||
struct CoreExport thread_metadata {
|
||||
/// Whether a thread is archived
|
||||
bool archived;
|
||||
/// When the thread was archived
|
||||
time_t archive_timestamp;
|
||||
/// The duration after a thread will archive
|
||||
uint16_t auto_archive_duration;
|
||||
/// Whether a thread is locked
|
||||
bool locked;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief represents membership of a user with a thread
|
||||
*/
|
||||
struct CoreExport thread_member
|
||||
{
|
||||
/// ID of the thread member is part of
|
||||
snowflake thread_id;
|
||||
/// ID of the member
|
||||
snowflake user_id;
|
||||
/// When the user joined the thread
|
||||
time_t joined;
|
||||
/// Flags bitmap
|
||||
uint32_t flags;
|
||||
|
||||
/**
|
||||
* @brief Read struct values from a json object
|
||||
* @param j json to read values from
|
||||
* @return A reference to self
|
||||
*/
|
||||
thread_member& fill_from_json(nlohmann::json* j);
|
||||
};
|
||||
|
||||
/** @brief A group of thread member objects*/
|
||||
typedef std::unordered_map<snowflake, thread_member> thread_member_map;
|
||||
|
||||
/** @brief A definition of a discord channel */
|
||||
class CoreExport channel : public managed {
|
||||
public:
|
||||
/** Flags bitmap */
|
||||
uint8_t flags;
|
||||
|
||||
/** Guild id of the guild that owns the channel */
|
||||
snowflake guild_id;
|
||||
|
||||
/** Sorting position, lower number means higher up the list */
|
||||
uint16_t position;
|
||||
|
||||
/** Channel name */
|
||||
std::string name;
|
||||
|
||||
/** Channel topic */
|
||||
std::string topic;
|
||||
|
||||
/** ID of last message to be sent to the channel */
|
||||
snowflake last_message_id;
|
||||
|
||||
/** Maximum user limit for voice channels (0-99) */
|
||||
uint8_t user_limit;
|
||||
|
||||
/** Rate limit in kilobits per second for voice channels */
|
||||
uint16_t rate_limit_per_user;
|
||||
|
||||
/** User ID of owner for group DMs */
|
||||
snowflake owner_id;
|
||||
|
||||
/** Parent ID (category) */
|
||||
snowflake parent_id;
|
||||
|
||||
/** Timestamp of last pinned message */
|
||||
time_t last_pin_timestamp;
|
||||
|
||||
/** DM recipients */
|
||||
std::vector<snowflake> recipients;
|
||||
|
||||
/** Permission overwrites to apply to base permissions */
|
||||
std::vector<permission_overwrite> permission_overwrites;
|
||||
|
||||
/** Approximate count of messages in a thread (threads) */
|
||||
uint8_t message_count;
|
||||
|
||||
/** Approximate count of members in a thread (threads) */
|
||||
uint8_t member_count;
|
||||
|
||||
/** Thread metadata (threads) */
|
||||
thread_metadata metadata;
|
||||
|
||||
/** Constructor */
|
||||
channel();
|
||||
|
||||
/** Destructor */
|
||||
virtual ~channel();
|
||||
|
||||
/** Read class values from json object
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
channel& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build json for this channel object
|
||||
*
|
||||
* @param with_id include the ID in the json
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
std::string build_json(bool with_id = false) const;
|
||||
|
||||
/**
|
||||
* @brief Get the user permissions for a user on this channel
|
||||
*
|
||||
* @param member The user to return permissions for
|
||||
* @return uint64_t Permissions bitmask made of bits in role_permissions.
|
||||
* Note that if the user is not on the channel or the guild is
|
||||
* not in the cache, the function will always return 0.
|
||||
*/
|
||||
uint64_t get_user_permissions(const class user* member) const;
|
||||
|
||||
/**
|
||||
* @brief Return a map of members on the channel, built from the guild's
|
||||
* member list based on which members have the VIEW_CHANNEL permission.
|
||||
* Does not return reliable information for voice channels, use
|
||||
* dpp::channel::get_voice_members() instead for this.
|
||||
* @return A map of guild members keyed by user id.
|
||||
*/
|
||||
std::map<snowflake, class guild_member*> get_members();
|
||||
|
||||
/**
|
||||
* @brief Get a map of members in this channel, if it is a voice channel.
|
||||
* The map is keyed by snowflake id of the user.
|
||||
*
|
||||
* @return std::map<snowflake, voicestate> The voice members of the channel
|
||||
*/
|
||||
std::map<snowflake, voicestate> get_voice_members();
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is NSFW gated
|
||||
*
|
||||
* @return true if NSFW
|
||||
*/
|
||||
bool is_nsfw() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a text channel
|
||||
*
|
||||
* @return true if text channel
|
||||
*/
|
||||
bool is_text_channel() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a DM
|
||||
*
|
||||
* @return true if is a DM
|
||||
*/
|
||||
bool is_dm() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a voice channel
|
||||
*
|
||||
* @return true if voice channel
|
||||
*/
|
||||
bool is_voice_channel() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a group DM channel
|
||||
*
|
||||
* @return true if group DM
|
||||
*/
|
||||
bool is_group_dm() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a category
|
||||
*
|
||||
* @return true if a category
|
||||
*/
|
||||
bool is_category() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a news channel
|
||||
*
|
||||
* @return true if news channel
|
||||
*/
|
||||
bool is_news_channel() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a store channel
|
||||
*
|
||||
* @return true if store channel
|
||||
*/
|
||||
bool is_store_channel() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a stage channel
|
||||
*
|
||||
* @return true if stage channel
|
||||
*/
|
||||
bool is_stage_channel() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A group of channels
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, channel> channel_map;
|
||||
|
||||
};
|
||||
|
2138
vendor/DPP/include/dpp/cluster.h
vendored
2138
vendor/DPP/include/dpp/cluster.h
vendored
File diff suppressed because it is too large
Load Diff
319
vendor/DPP/include/dpp/commandhandler.h
vendored
319
vendor/DPP/include/dpp/commandhandler.h
vendored
@ -1,319 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <variant>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief dpp::resolved_user contains both a dpp::guild_member and a dpp::user.
|
||||
* The user can be used to obtain in-depth user details such as if they are nitro,
|
||||
* and the guild member information to check their roles on a guild etc.
|
||||
* The Discord API provides both if a parameter is a user ping,
|
||||
* so we offer both in a combined structure.
|
||||
*/
|
||||
struct CoreExport resolved_user {
|
||||
/**
|
||||
* @brief Holds user information
|
||||
*/
|
||||
dpp::user user;
|
||||
/**
|
||||
* @brief Holds member information
|
||||
*/
|
||||
dpp::guild_member member;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a received parameter.
|
||||
* We use variant so that multiple non-related types can be contained within.
|
||||
*/
|
||||
typedef std::variant<std::monostate, std::string, dpp::role, dpp::channel, dpp::resolved_user, int32_t, bool> command_parameter;
|
||||
|
||||
/**
|
||||
* @brief Parameter types when registering a command.
|
||||
* We don't pass these in when triggering the command in the handler, because it is
|
||||
* expected the developer added the command so they know what types to expect for each named
|
||||
* parameter.
|
||||
*/
|
||||
enum parameter_type {
|
||||
pt_string, //!< String value
|
||||
pt_role, //!< Role object
|
||||
pt_channel, //!< Channel object
|
||||
pt_user, //!< User object
|
||||
pt_integer, //!< 32 bit signed integer
|
||||
pt_boolean //!< boolean
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Details of a command parameter used in registration.
|
||||
* Note that for non-slash commands optional parameters can only be at the end of
|
||||
* the list of parameters.
|
||||
*/
|
||||
struct CoreExport param_info {
|
||||
|
||||
/**
|
||||
* @brief Type of parameter
|
||||
*/
|
||||
parameter_type type;
|
||||
|
||||
/**
|
||||
* @brief True if the parameter is optional.
|
||||
* For non-slash commands optional parameters may only be on the end of the list.
|
||||
*/
|
||||
bool optional;
|
||||
|
||||
/**
|
||||
* @brief Description of command. Displayed only for slash commands
|
||||
*/
|
||||
std::string description;
|
||||
|
||||
/**
|
||||
* @brief Allowed multiple choice options.
|
||||
* The key name is the string passed to the command handler
|
||||
* and the key value is its description displayed to the user.
|
||||
*/
|
||||
std::map<std::string, std::string> choices;
|
||||
|
||||
/**
|
||||
* @brief Construct a new param_info object
|
||||
*
|
||||
* @param t Type of parameter
|
||||
* @param o True if parameter is optional
|
||||
* @param description The parameter description
|
||||
* @param opts The options for a multiple choice parameter
|
||||
*/
|
||||
param_info(parameter_type t, bool o, const std::string &description, const std::map<std::string, std::string> &opts = {});
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Parameter list used during registration.
|
||||
* Note that use of vector/pair is important here to preserve parameter order,
|
||||
* as opposed to unordered_map (which doesnt guarantee any order at all) and
|
||||
* std::map, which reorders keys alphabetically.
|
||||
*/
|
||||
typedef std::vector<std::pair<std::string, param_info>> parameter_registration_t;
|
||||
|
||||
/**
|
||||
* @brief Parameter list for a called command.
|
||||
* See dpp::parameter_registration_t for an explanation as to why vector is used.
|
||||
*/
|
||||
typedef std::vector<std::pair<std::string, command_parameter>> parameter_list_t;
|
||||
|
||||
/**
|
||||
* @brief Represents the sending source of a command.
|
||||
* This is passed to any command handler and should be passed back to
|
||||
* commandhandler::reply(), allowing the reply method to route any replies back
|
||||
* to the origin, which may be a slash command or a message. Both require different
|
||||
* response facilities but we want this to be transparent if you use the command
|
||||
* handler class.
|
||||
*/
|
||||
struct CoreExport command_source {
|
||||
/**
|
||||
* @brief Sending guild id
|
||||
*/
|
||||
snowflake guild_id = 0;
|
||||
/**
|
||||
* @brief Source channel id
|
||||
*/
|
||||
snowflake channel_id = 0;
|
||||
/**
|
||||
* @brief Command ID of a slash command
|
||||
*/
|
||||
snowflake command_id = 0;
|
||||
/**
|
||||
* @brief Token for sending a slash command reply
|
||||
*/
|
||||
std::string command_token;
|
||||
/**
|
||||
* @brief The user who issued the command
|
||||
*/
|
||||
user* issuer;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The function definition for a command handler. Expects a command name string,
|
||||
* and a list of command parameters.
|
||||
*/
|
||||
typedef std::function<void(const std::string&, const parameter_list_t&, command_source)> command_handler;
|
||||
|
||||
/**
|
||||
* @brief Represents the details of a command added to the command handler class.
|
||||
*/
|
||||
struct CoreExport command_info_t {
|
||||
/**
|
||||
* @brief Function reference for the handler. This is std::function so it can represent
|
||||
* a class member, a lambda or a raw C function pointer.
|
||||
*/
|
||||
command_handler func;
|
||||
/**
|
||||
* @brief Parameters requested for the command, with their types
|
||||
*/
|
||||
parameter_registration_t parameters;
|
||||
/**
|
||||
* @brief Guild ID the command exists on, or 0 to be present on all guilds
|
||||
*/
|
||||
snowflake guild_id;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief The commandhandler class represents a group of commands, prefixed or slash commands with handling functions.
|
||||
*
|
||||
*/
|
||||
class CoreExport commandhandler {
|
||||
/**
|
||||
* @brief Commands in the handler
|
||||
*/
|
||||
std::unordered_map<std::string, command_info_t> commands;
|
||||
|
||||
/**
|
||||
* @brief Valid prefixes
|
||||
*/
|
||||
std::vector<std::string> prefixes;
|
||||
|
||||
/**
|
||||
* @brief Set to true automatically if one of the prefixes added is "/"
|
||||
*/
|
||||
bool slash_commands_enabled;
|
||||
|
||||
/**
|
||||
* @brief Cluster we are attached to for issuing REST calls
|
||||
*/
|
||||
class cluster* owner;
|
||||
|
||||
/**
|
||||
* @brief Application ID
|
||||
*/
|
||||
snowflake app_id;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the string has a known prefix on the start.
|
||||
* Modifies string to remove prefix if it returns true.
|
||||
*
|
||||
* @param str String to check and modify
|
||||
* @return true string contained a prefix, prefix removed from string
|
||||
* @return false string did not contain a prefix
|
||||
*/
|
||||
bool string_has_prefix(std::string &str);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a new commandhandler object
|
||||
*
|
||||
* @param o Owning cluster to attach to
|
||||
* @param auto_hook_events Set to true to automatically hook the on_interaction_create
|
||||
* and on_message events. Only do this if you have no other use for these events than
|
||||
* commands that are handled by the command handler (this is usually the case).
|
||||
* @param application_id The application id of the bot. If not specified, the class will
|
||||
* look within the cluster object and use cluster::me::id instead.
|
||||
*/
|
||||
commandhandler(class cluster* o, bool auto_hook_events = true, snowflake application_id = 0);
|
||||
|
||||
/**
|
||||
* @brief Destroy the commandhandler object
|
||||
*/
|
||||
~commandhandler();
|
||||
|
||||
/**
|
||||
* @brief Set the application id after construction
|
||||
*
|
||||
* @param o Owning cluster to attach to
|
||||
*/
|
||||
commandhandler& set_owner(class cluster* o);
|
||||
|
||||
/**
|
||||
* @brief Add a prefix to the command handler
|
||||
*
|
||||
* @param prefix Prefix to be handled by the command handler
|
||||
* @return commandhandler& reference to self
|
||||
*/
|
||||
commandhandler& add_prefix(const std::string &prefix);
|
||||
|
||||
/**
|
||||
* @brief Add a command to the command handler
|
||||
*
|
||||
* @param command Command to be handled.
|
||||
* Note that if any one of your prefixes is "/" this will attempt to register
|
||||
* a global command using the API and you will receive notification of this command
|
||||
* via an interaction event.
|
||||
*
|
||||
* @param handler Handler function
|
||||
* @param parameters Parameters to use for the command
|
||||
* @return commandhandler& reference to self
|
||||
*/
|
||||
commandhandler& add_command(const std::string &command, const parameter_registration_t ¶meters, command_handler handler, const std::string &description = "", snowflake guild_id = 0);
|
||||
|
||||
/**
|
||||
* @brief Route a command from the on_message_create function.
|
||||
* Call this method from within your on_message_create with the received
|
||||
* dpp::message object.
|
||||
*
|
||||
* @param msg message to parse
|
||||
*/
|
||||
void route(const class dpp::message& msg);
|
||||
|
||||
/**
|
||||
* @brief Route a command from the on_interaction_create function.
|
||||
* Call this method from your on_interaction_create with the received
|
||||
* dpp::interaction_create_t object.
|
||||
*
|
||||
* @param event command interaction event to parse
|
||||
*/
|
||||
void route(const class interaction_create_t & event);
|
||||
|
||||
/**
|
||||
* @brief Reply to a command.
|
||||
* You should use this method rather than cluster::message_create as
|
||||
* the way you reply varies between slash commands and message commands.
|
||||
* Note you should ALWAYS reply. Slash commands will emit an ugly error
|
||||
* to the user if you do not emit some form of reply within 3 seconds.
|
||||
*
|
||||
* @param m message to reply with.
|
||||
* @param source source of the command
|
||||
*/
|
||||
void reply(const dpp::message &m, command_source source);
|
||||
|
||||
/**
|
||||
* @brief Reply to a command without a message, causing the discord client
|
||||
* to display "Bot name is thinking...".
|
||||
* The "thinking" message will persist for a maximum of 15 minutes.
|
||||
* This counts as a reply for a slash command. Slash commands will emit an
|
||||
* ugly error to the user if you do not emit some form of reply within 3
|
||||
* seconds.
|
||||
*
|
||||
* @param source source of the command
|
||||
*/
|
||||
void thinking(command_source source);
|
||||
|
||||
/* Easter egg */
|
||||
void thonk(command_source source);
|
||||
|
||||
};
|
||||
|
||||
};
|
283
vendor/DPP/include/dpp/discord.h
vendored
283
vendor/DPP/include/dpp/discord.h
vendored
@ -1,283 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
/**
|
||||
* @brief The main namespace for D++ functions. classes and types
|
||||
*/
|
||||
namespace dpp {
|
||||
/** @brief A 64 bit unsigned value representing many things on discord.
|
||||
* Discord calls the value a 'snowflake' value.
|
||||
*/
|
||||
typedef uint64_t snowflake;
|
||||
|
||||
/** @brief The managed class is the base class for various types that can
|
||||
* be stored in a cache that are identified by a dpp::snowflake id
|
||||
*/
|
||||
class CoreExport managed {
|
||||
public:
|
||||
/** Unique ID of object */
|
||||
snowflake id;
|
||||
/** Constructor, initialises id to 0 */
|
||||
managed(const snowflake = 0);
|
||||
/** Default destructor */
|
||||
virtual ~managed() = default;
|
||||
};
|
||||
|
||||
/** @brief Supported image types for profile pictures */
|
||||
enum image_type {
|
||||
/// image/png
|
||||
i_png,
|
||||
/// image/jpeg
|
||||
i_jpg,
|
||||
/// image/gif
|
||||
i_gif
|
||||
};
|
||||
|
||||
/** @brief Log levels */
|
||||
enum loglevel {
|
||||
/// Trace
|
||||
ll_trace = 0,
|
||||
/// Debug
|
||||
ll_debug,
|
||||
/// Information
|
||||
ll_info,
|
||||
/// Warning
|
||||
ll_warning,
|
||||
/// Error
|
||||
ll_error,
|
||||
/// Critical
|
||||
ll_critical
|
||||
};
|
||||
|
||||
/** @brief Utility helper functions, generally for logging */
|
||||
namespace utility {
|
||||
|
||||
typedef std::function<void(const std::string& output)> cmd_result_t;
|
||||
|
||||
/**
|
||||
* @brief Run a commandline program asyncronously. The command line program
|
||||
* is spawned in a separate std::thread, and when complete, its output from
|
||||
* stdout is passed to the callback function in its string prameter. For eample
|
||||
* ```
|
||||
* dpp::utility::exec("ls", [](const std::string& output) {
|
||||
* std::cout << "Output of 'ls': " << output << "\n";
|
||||
* });
|
||||
* ```
|
||||
*
|
||||
* @param cmd The command to run.
|
||||
* @param parameters Command line parameters. Each will be escaped using std::quoted.
|
||||
* @param callback The callback to call on completion.
|
||||
*/
|
||||
void CoreExport exec(const std::string& cmd, std::vector<std::string> parameters = {}, cmd_result_t callback = {});
|
||||
|
||||
/**
|
||||
* @brief Returns urrent date and time
|
||||
*
|
||||
* @return std::string Current date and time
|
||||
*/
|
||||
std::string CoreExport current_date_time();
|
||||
/**
|
||||
* @brief Convert a dpp::loglevel enum value to a string
|
||||
*
|
||||
* @param in log level to convert
|
||||
* @return std::string string form of log level
|
||||
*/
|
||||
std::string CoreExport loglevel(dpp::loglevel in);
|
||||
|
||||
/**
|
||||
* @brief Store a 128 bit icon hash (profile picture, server icon etc)
|
||||
* as a 128 bit binary value made of two uint64_t.
|
||||
* Has a constructor to build one from a string, and a method to fetch
|
||||
* the value back in string form.
|
||||
*/
|
||||
struct CoreExport iconhash {
|
||||
|
||||
uint64_t first; //!< High 64 bits
|
||||
uint64_t second; //!< Low 64 bits
|
||||
|
||||
/**
|
||||
* @brief Construct a new iconcash object
|
||||
*/
|
||||
iconhash();
|
||||
|
||||
/**
|
||||
* @brief Construct a new iconhash object
|
||||
*
|
||||
* @param hash String hash to construct from.
|
||||
* Must contain a 32 character hex string.
|
||||
*
|
||||
* @throws std::length_error if the provided
|
||||
* string is not exactly 32 characters long.
|
||||
*/
|
||||
iconhash(const std::string &hash);
|
||||
|
||||
/**
|
||||
* @brief Assign from std::string
|
||||
*
|
||||
* @param assignment string to assign from.
|
||||
*
|
||||
* @throws std::length_error if the provided
|
||||
* string is not exactly 32 characters long.
|
||||
*/
|
||||
iconhash& operator=(const std::string &assignment);
|
||||
|
||||
/**
|
||||
* @brief Change value of iconhash object
|
||||
*
|
||||
* @param hash String hash to change to.
|
||||
* Must contain a 32 character hex string.
|
||||
*
|
||||
* @throws std::length_error if the provided
|
||||
* string is not exactly 32 characters long.
|
||||
*/
|
||||
void set(const std::string &hash);
|
||||
|
||||
/**
|
||||
* @brief Convert iconhash back to 32 character
|
||||
* string value.
|
||||
*
|
||||
* @return std::string Hash value
|
||||
*/
|
||||
std::string to_string() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Return the current time with fractions of seconds.
|
||||
* This is a unix epoch time with the fractional seconds part
|
||||
* after the decimal place.
|
||||
*
|
||||
* @return double time with fractional seconds
|
||||
*/
|
||||
double CoreExport time_f();
|
||||
|
||||
/**
|
||||
* @brief Returns true if D++ was built with voice support
|
||||
*
|
||||
* @return bool True if voice support is compiled in (libsodium/libopus)
|
||||
*/
|
||||
bool CoreExport has_voice();
|
||||
|
||||
/**
|
||||
* @brief Convert a byte count to display value
|
||||
*
|
||||
* @param c number of bytes
|
||||
* @return std::string display value suffixed with M, G, T where necessary
|
||||
*/
|
||||
std::string CoreExport bytes(uint64_t c);
|
||||
|
||||
/**
|
||||
* @brief A class used to represent an uptime in hours, minutes,
|
||||
* seconds and days, with helper functions to convert from time_t
|
||||
* and display as a string.
|
||||
*/
|
||||
struct CoreExport uptime {
|
||||
uint16_t days; //!< Number of days
|
||||
uint8_t hours; //!< Number of hours
|
||||
uint8_t mins; //!< Number of minutes
|
||||
uint8_t secs; //!< Number of seconds
|
||||
|
||||
/**
|
||||
* @brief Construct a new uptime object
|
||||
*/
|
||||
uptime();
|
||||
|
||||
/**
|
||||
* @brief Construct a new uptime object
|
||||
*
|
||||
* @param diff A time_t to initialise the object from
|
||||
*/
|
||||
uptime(time_t diff);
|
||||
|
||||
/**
|
||||
* @brief Get uptime as string
|
||||
*
|
||||
* @return std::string Uptime as string
|
||||
*/
|
||||
std::string to_string();
|
||||
|
||||
/**
|
||||
* @brief Get uptime as seconds
|
||||
*
|
||||
* @return uint64_t Uptime as seconds
|
||||
*/
|
||||
uint64_t to_secs();
|
||||
|
||||
/**
|
||||
* @brief Get uptime as milliseconds
|
||||
*
|
||||
* @return uint64_t Uptime as milliseconds
|
||||
*/
|
||||
uint64_t to_msecs();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Output hex values of a section of memory for debugging
|
||||
*
|
||||
* @param data The start of the data to display
|
||||
* @param length The length of data to display
|
||||
*/
|
||||
void CoreExport debug_dump(uint8_t* data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Returns the length of a UTF-8 string in codepoints
|
||||
*
|
||||
* @param str string to count length of
|
||||
* @return size_t length of string (0 for invalid utf8)
|
||||
*/
|
||||
size_t CoreExport utf8len(const std::string &str);
|
||||
|
||||
/**
|
||||
* @brief Return substring of a UTF-8 encoded string in codepoints
|
||||
*
|
||||
* @param str string to return substring from
|
||||
* @param start start codepoint offset
|
||||
* @param length length in codepoints
|
||||
* @return std::string Substring in UTF-8 or empty string if invalid UTF-8 passed in
|
||||
*/
|
||||
std::string CoreExport utf8substr(const std::string& str, std::string::size_type start, std::string::size_type length);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#include <dpp/voicestate.h>
|
||||
#include <dpp/role.h>
|
||||
#include <dpp/user.h>
|
||||
#include <dpp/channel.h>
|
||||
#include <dpp/guild.h>
|
||||
#include <dpp/invite.h>
|
||||
#include <dpp/dtemplate.h>
|
||||
#include <dpp/emoji.h>
|
||||
#include <dpp/ban.h>
|
||||
#include <dpp/prune.h>
|
||||
#include <dpp/voiceregion.h>
|
||||
#include <dpp/integration.h>
|
||||
#include <dpp/webhook.h>
|
||||
#include <dpp/presence.h>
|
||||
#include <dpp/intents.h>
|
||||
#include <dpp/slashcommand.h>
|
||||
#include <dpp/auditlog.h>
|
358
vendor/DPP/include/dpp/discordclient.h
vendored
358
vendor/DPP/include/dpp/discordclient.h
vendored
@ -1,358 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
#include <dpp/wsclient.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/discordvoiceclient.h>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#define DISCORD_API_VERSION "9"
|
||||
#define DEFAULT_GATEWAY "gateway.discord.gg"
|
||||
#define API_PATH "/api/v" DISCORD_API_VERSION
|
||||
namespace dpp {
|
||||
|
||||
// Forward declarations
|
||||
class cluster;
|
||||
|
||||
/** This is an opaque class containing zlib library specific structures.
|
||||
* We define it this way so that the public facing D++ library doesnt require
|
||||
* the zlib headers be available to build against it.
|
||||
*/
|
||||
class zlibcontext;
|
||||
|
||||
/**
|
||||
* @brief Represents a connection to a voice channel.
|
||||
* A client can only connect to one voice channel per guild at a time, so these are stored in a map
|
||||
* in the dpp::discord_client keyed by guild_id.
|
||||
*/
|
||||
class CoreExport voiceconn {
|
||||
/**
|
||||
* @brief Owning dpp::discord_client instance
|
||||
*/
|
||||
class discord_client* creator;
|
||||
public:
|
||||
/**
|
||||
* @brief Voice Channel ID
|
||||
*/
|
||||
snowflake channel_id;
|
||||
|
||||
/**
|
||||
* @brief Websocket hostname for status
|
||||
*/
|
||||
std::string websocket_hostname;
|
||||
|
||||
/**
|
||||
* @brief Voice Voice session ID
|
||||
*/
|
||||
std::string session_id;
|
||||
|
||||
/**
|
||||
* @brief Voice websocket token
|
||||
*/
|
||||
std::string token;
|
||||
|
||||
/**
|
||||
* @brief voice websocket client
|
||||
*/
|
||||
class discord_voice_client* voiceclient;
|
||||
|
||||
/**
|
||||
* @brief Construct a new voiceconn object
|
||||
*/
|
||||
voiceconn() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new voiceconn object
|
||||
*
|
||||
* @param o owner
|
||||
* @param _channel_id voice channel id
|
||||
*/
|
||||
voiceconn(class discord_client* o, snowflake _channel_id);
|
||||
|
||||
/**
|
||||
* @brief Destroy the voiceconn object
|
||||
*/
|
||||
~voiceconn();
|
||||
|
||||
/**
|
||||
* @brief return true if the connection is ready to connect
|
||||
* (has hostname, token and session id)
|
||||
*
|
||||
* @return true if ready to connect
|
||||
*/
|
||||
bool is_ready();
|
||||
|
||||
/**
|
||||
* @brief return true if the connection is active (websocket exists)
|
||||
*
|
||||
* @return true if has an active websocket
|
||||
*/
|
||||
bool is_active();
|
||||
|
||||
/**
|
||||
* @brief Create websocket object and connect it.
|
||||
* Needs hosname, token and session_id to be set or does nothing.
|
||||
*
|
||||
* @param guild_id Guild to connect to the voice channel on
|
||||
*/
|
||||
void connect(snowflake guild_id);
|
||||
|
||||
/**
|
||||
* @brief Disconnect from the currently connected voice channel
|
||||
*/
|
||||
void disconnect();
|
||||
};
|
||||
|
||||
/** @brief Implements a discord client. Each discord_client connects to one shard and derives from a websocket client. */
|
||||
class CoreExport discord_client : public websocket_client
|
||||
{
|
||||
/** Mutex for message queue */
|
||||
std::mutex queue_mutex;
|
||||
|
||||
/** Queue of outbound messages */
|
||||
std::deque<std::string> message_queue;
|
||||
|
||||
/** Thread this shard is executing on */
|
||||
std::thread* runner;
|
||||
|
||||
/** Run shard loop under a thread */
|
||||
void ThreadRun();
|
||||
|
||||
/** If true, stream compression is enabled */
|
||||
bool compressed;
|
||||
|
||||
/** ZLib decompression buffer */
|
||||
unsigned char* decomp_buffer;
|
||||
|
||||
/** Decompressed string */
|
||||
std::string decompressed;
|
||||
|
||||
/** Frame decompression stream */
|
||||
zlibcontext* zlib;
|
||||
|
||||
/** Total decompressed received bytes */
|
||||
uint64_t decompressed_total;
|
||||
|
||||
/** Last connect time of cluster */
|
||||
time_t connect_time;
|
||||
|
||||
/** Time last ping sent to websocket */
|
||||
double ping_start;
|
||||
|
||||
/**
|
||||
* @brief Initialise ZLib
|
||||
*/
|
||||
void SetupZLib();
|
||||
|
||||
/**
|
||||
* @brief Shut down ZLib
|
||||
*/
|
||||
void EndZLib();
|
||||
|
||||
public:
|
||||
/** Owning cluster */
|
||||
class dpp::cluster* creator;
|
||||
|
||||
/** Heartbeat interval for sending heartbeat keepalive */
|
||||
uint32_t heartbeat_interval;
|
||||
|
||||
/** Last heartbeat */
|
||||
time_t last_heartbeat;
|
||||
|
||||
/** Shard ID of this client */
|
||||
uint32_t shard_id;
|
||||
|
||||
/** Total number of shards */
|
||||
uint32_t max_shards;
|
||||
|
||||
/** Thread ID */
|
||||
std::thread::native_handle_type thread_id;
|
||||
|
||||
/** Last sequence number received, for resumes and pings */
|
||||
uint64_t last_seq;
|
||||
|
||||
/** Discord bot token */
|
||||
std::string token;
|
||||
|
||||
/** Privileged gateway intents */
|
||||
uint32_t intents;
|
||||
|
||||
/** Discord session id */
|
||||
std::string sessionid;
|
||||
|
||||
/** Mutex for voice connections map */
|
||||
std::mutex voice_mutex;
|
||||
|
||||
/** Resume count */
|
||||
uint32_t resumes;
|
||||
|
||||
/** Reconnection count */
|
||||
uint32_t reconnects;
|
||||
|
||||
/** Websocket latency in fractional seconds */
|
||||
double websocket_ping;
|
||||
|
||||
/** True if READY or RESUMED has been received */
|
||||
bool ready;
|
||||
|
||||
/** Last heartbeat ACK (opcode 11) */
|
||||
time_t last_heartbeat_ack;
|
||||
|
||||
/** List of voice channels we are connecting to keyed by guild id */
|
||||
std::unordered_map<snowflake, voiceconn*> connecting_voice_channels;
|
||||
|
||||
/** Log a message to whatever log the user is using.
|
||||
* The logged message is passed up the chain to the on_log event in user code which can then do whatever
|
||||
* it wants to do with it.
|
||||
* @param severity The log level from dpp::loglevel
|
||||
* @param msg The log message to output
|
||||
*/
|
||||
virtual void log(dpp::loglevel severity, const std::string &msg) const;
|
||||
|
||||
/** Handle an event (opcode 0)
|
||||
* @param event Event name, e.g. MESSAGE_CREATE
|
||||
* @param j JSON object for the event content
|
||||
* @param raw Raw JSON event string
|
||||
*/
|
||||
virtual void HandleEvent(const std::string &event, json &j, const std::string &raw);
|
||||
|
||||
/**
|
||||
* @brief Get the Guild Count for this shard
|
||||
*
|
||||
* @return uint64_t guild count
|
||||
*/
|
||||
uint64_t get_guild_count();
|
||||
|
||||
/**
|
||||
* @brief Get the Member Count for this shard
|
||||
*
|
||||
* @return uint64_t member count
|
||||
*/
|
||||
uint64_t get_member_count();
|
||||
|
||||
/**
|
||||
* @brief Get the Channel Count for this shard
|
||||
*
|
||||
* @return uint64_t channel count
|
||||
*/
|
||||
uint64_t get_channel_count();
|
||||
|
||||
/** Fires every second from the underlying socket I/O loop, used for sending heartbeats */
|
||||
virtual void one_second_timer();
|
||||
|
||||
/**
|
||||
* @brief Queue a message to be sent via the websocket
|
||||
*
|
||||
* @param j The JSON data of the message to be sent
|
||||
* @param to_front If set to true, will place the message at the front of the queue not the back
|
||||
* (this is for urgent messages such as heartbeat, presence, so they can take precedence over
|
||||
* chunk requests etc)
|
||||
*/
|
||||
void QueueMessage(const std::string &j, bool to_front = false);
|
||||
|
||||
/**
|
||||
* @brief Clear the outbound message queue
|
||||
*
|
||||
*/
|
||||
void ClearQueue();
|
||||
|
||||
/**
|
||||
* @brief Get the size of the outbound message queue
|
||||
*
|
||||
* @return The size of the queue
|
||||
*/
|
||||
size_t GetQueueSize();
|
||||
|
||||
/**
|
||||
* @brief Returns true if the shard is connected
|
||||
*
|
||||
* @return True if connected
|
||||
*/
|
||||
bool is_connected();
|
||||
|
||||
/**
|
||||
* @brief Returns the connection time of the shard
|
||||
*
|
||||
* @return dpp::utility::uptime Detail of how long the shard has been connected for
|
||||
*/
|
||||
dpp::utility::uptime get_uptime();
|
||||
|
||||
/** Constructor takes shard id, max shards and token.
|
||||
* @param _cluster The owning cluster for this shard
|
||||
* @param _shard_id The ID of the shard to start
|
||||
* @param _max_shards The total number of shards across all clusters
|
||||
* @param _token The bot token to use for identifying to the websocket
|
||||
* @param intents Privileged intents to use, a bitmask of values from dpp::intents
|
||||
* @param compressed True if the received data will be gzip compressed
|
||||
*/
|
||||
discord_client(dpp::cluster* _cluster, uint32_t _shard_id, uint32_t _max_shards, const std::string &_token, uint32_t intents = 0, bool compressed = true);
|
||||
|
||||
/** Destructor */
|
||||
virtual ~discord_client();
|
||||
|
||||
/** Get decompressed total bytes received */
|
||||
uint64_t get_decompressed_bytes_in();
|
||||
|
||||
/** Handle JSON from the websocket.
|
||||
* @param buffer The entire buffer content from the websocket client
|
||||
* @returns True if a frame has been handled
|
||||
*/
|
||||
virtual bool HandleFrame(const std::string &buffer);
|
||||
|
||||
/** Handle a websocket error.
|
||||
* @param errorcode The error returned from the websocket
|
||||
*/
|
||||
virtual void Error(uint32_t errorcode);
|
||||
|
||||
/** Start and monitor I/O loop */
|
||||
void Run();
|
||||
|
||||
/**
|
||||
* @brief Connect to a voice channel
|
||||
*
|
||||
* @param guild_id Guild where the voice channel is
|
||||
* @param channel_id Channel ID of the voice channel
|
||||
*/
|
||||
void connect_voice(snowflake guild_id, snowflake channel_id);
|
||||
|
||||
/**
|
||||
* @brief Disconnect from the connected voice channel on a guild
|
||||
*
|
||||
* @param guild_id The guild who's voice channel you wish to disconnect from
|
||||
*/
|
||||
void disconnect_voice(snowflake guild_id);
|
||||
|
||||
voiceconn* get_voice(snowflake guild_id);
|
||||
};
|
||||
|
||||
};
|
148
vendor/DPP/include/dpp/discordevents.h
vendored
148
vendor/DPP/include/dpp/discordevents.h
vendored
@ -1,148 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <dpp/json_fwd.hpp>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/** @brief Returns a snowflake id from a json field value, if defined, else returns 0
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @return found value
|
||||
*/
|
||||
uint64_t SnowflakeNotNull(const nlohmann::json* j, const char *keyname);
|
||||
|
||||
/** @brief Sets a snowflake id from a json field value, if defined, else does nothing
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @param v Value to change
|
||||
*/
|
||||
void SetSnowflakeNotNull(const nlohmann::json* j, const char *keyname, uint64_t &v);
|
||||
|
||||
/** @brief Returns a string from a json field value, if defined, else returns an empty string.
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @return found value
|
||||
*/
|
||||
std::string StringNotNull(const nlohmann::json* j, const char *keyname);
|
||||
|
||||
/** @brief Sets a string from a json field value, if defined, else does nothing
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @param v Value to change
|
||||
*/
|
||||
void SetStringNotNull(const nlohmann::json* j, const char *keyname, std::string &v);
|
||||
|
||||
/** @brief Returns a 64 bit unsigned integer from a json field value, if defined, else returns 0.
|
||||
* DO NOT use this for snowflakes, as usually snowflakes are wrapped in a string!
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @return found value
|
||||
*/
|
||||
uint64_t Int64NotNull(const nlohmann::json* j, const char *keyname);
|
||||
|
||||
/** @brief Sets an unsigned 64 bit integer from a json field value, if defined, else does nothing
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @param v Value to change
|
||||
*/
|
||||
void SetInt64NotNull(const nlohmann::json* j, const char *keyname, uint64_t &v);
|
||||
|
||||
/** @brief Returns a 32 bit unsigned integer from a json field value, if defined, else returns 0
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @return found value
|
||||
*/
|
||||
uint32_t Int32NotNull(const nlohmann::json* j, const char *keyname);
|
||||
|
||||
/** @brief Sets an unsigned 32 bit integer from a json field value, if defined, else does nothing
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @param v Value to change
|
||||
*/
|
||||
void SetInt32NotNull(const nlohmann::json* j, const char *keyname, uint32_t &v);
|
||||
|
||||
/** @brief Returns a 16 bit unsigned integer from a json field value, if defined, else returns 0
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @return found value
|
||||
*/
|
||||
uint16_t Int16NotNull(const nlohmann::json* j, const char *keyname);
|
||||
|
||||
/** @brief Sets an unsigned 16 bit integer from a json field value, if defined, else does nothing
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @param v Value to change
|
||||
*/
|
||||
void SetInt16NotNull(const nlohmann::json* j, const char *keyname, uint16_t &v);
|
||||
|
||||
/** @brief Returns an 8 bit unsigned integer from a json field value, if defined, else returns 0
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @return found value
|
||||
*/
|
||||
uint8_t Int8NotNull(const nlohmann::json* j, const char *keyname);
|
||||
|
||||
/** @brief Sets an unsigned 8 bit integer from a json field value, if defined, else does nothing
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @param v Value to change
|
||||
*/
|
||||
void SetInt8NotNull(const nlohmann::json* j, const char *keyname, uint8_t &v);
|
||||
|
||||
/** @brief Returns a boolean value from a json field value, if defined, else returns false
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @return found value
|
||||
*/
|
||||
bool BoolNotNull(const nlohmann::json* j, const char *keyname);
|
||||
|
||||
/** @brief Sets a boolean from a json field value, if defined, else does nothing
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @param v Value to change
|
||||
*/
|
||||
void SetBoolNotNull(const nlohmann::json* j, const char *keyname, bool &v);
|
||||
|
||||
/** @brief Returns a time_t from an ISO8601 timestamp field in a json value, if defined, else returns
|
||||
* epoch value of 0.
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @return found value
|
||||
*/
|
||||
time_t TimestampNotNull(const nlohmann::json* j, const char *keyname);
|
||||
|
||||
/** @brief Sets an timestamp from a json field value containing an ISO8601 string, if defined, else does nothing
|
||||
* @param j nlohmann::json instance to retrieve value from
|
||||
* @param keyname key name to check for a value
|
||||
* @param v Value to change
|
||||
*/
|
||||
void SetTimestampNotNull(const nlohmann::json* j, const char *keyname, time_t &v);
|
||||
|
||||
/** @brief Base64 encode data into a string.
|
||||
* @param buf Raw binary buffer
|
||||
* @param buffer_length Buffer length to encode
|
||||
* @return The base64 encoded string
|
||||
*/
|
||||
std::string base64_encode(unsigned char const* buf, unsigned int buffer_length);
|
||||
|
||||
};
|
513
vendor/DPP/include/dpp/discordvoiceclient.h
vendored
513
vendor/DPP/include/dpp/discordvoiceclient.h
vendored
@ -1,513 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <dpp/export.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <resolv.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
#include <dpp/wsclient.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
|
||||
#ifdef HAVE_VOICE
|
||||
#include <sodium.h>
|
||||
#include <opus/opus.h>
|
||||
#endif
|
||||
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp {
|
||||
|
||||
// Forward declaration
|
||||
class cluster;
|
||||
|
||||
#define AUDIO_TRACK_MARKER (uint16_t)0xFFFF
|
||||
|
||||
/** @brief Implements a discord voice connection.
|
||||
* Each discord_voice_client connects to one voice channel and derives from a websocket client.
|
||||
*/
|
||||
class CoreExport discord_voice_client : public websocket_client
|
||||
{
|
||||
/** Mutex for outbound packet stream */
|
||||
std::mutex stream_mutex;
|
||||
|
||||
/** Mutex for message queue */
|
||||
std::mutex queue_mutex;
|
||||
|
||||
/** Queue of outbound messages */
|
||||
std::deque<std::string> message_queue;
|
||||
|
||||
/** Thread this connection is executing on */
|
||||
std::thread* runner;
|
||||
|
||||
/** Run shard loop under a thread */
|
||||
void ThreadRun();
|
||||
|
||||
/** Last connect time of voice session */
|
||||
time_t connect_time;
|
||||
|
||||
/**
|
||||
* @brief IP of UDP/RTP endpoint
|
||||
*/
|
||||
std::string ip;
|
||||
|
||||
/**
|
||||
* @brief Port number of UDP/RTP endpoint
|
||||
*/
|
||||
uint16_t port;
|
||||
|
||||
/**
|
||||
* @brief SSRC value
|
||||
*/
|
||||
uint64_t ssrc;
|
||||
|
||||
/**
|
||||
* @brief List of supported audio encoding modes
|
||||
*/
|
||||
std::vector<std::string> modes;
|
||||
|
||||
/** Output buffer. Each string is a UDP packet.
|
||||
* Generally these will be RTP.
|
||||
*/
|
||||
std::vector<std::string> outbuf;
|
||||
|
||||
/** Input buffer. Each string is a received UDP
|
||||
* packet. These will usually be RTP.
|
||||
*/
|
||||
std::vector<std::string> inbuf;
|
||||
|
||||
/** If true, audio packet sending is paused
|
||||
*/
|
||||
bool paused;
|
||||
|
||||
#ifdef HAVE_VOICE
|
||||
/** libopus encoder
|
||||
*/
|
||||
OpusEncoder* encoder;
|
||||
|
||||
/** libopus decoder
|
||||
*/
|
||||
OpusDecoder* decoder;
|
||||
|
||||
/** libopus repacketizer
|
||||
* (merges frames into one packet)
|
||||
*/
|
||||
OpusRepacketizer* repacketizer;
|
||||
#endif
|
||||
|
||||
/** File descriptor for UDP connection
|
||||
*/
|
||||
SOCKET fd;
|
||||
|
||||
/** Socket address of voice server
|
||||
*/
|
||||
struct sockaddr_in servaddr;
|
||||
|
||||
/** Secret key for encrypting voice.
|
||||
* If it has been sent, this is non-null and points to a
|
||||
* sequence of exactly 32 bytes.
|
||||
*/
|
||||
uint8_t* secret_key;
|
||||
|
||||
/** Sequence number of outbound audio. This is incremented
|
||||
* once per frame sent.
|
||||
*/
|
||||
uint16_t sequence;
|
||||
|
||||
/** Timestamp value used in outbound audio. Each packet
|
||||
* has the timestamp value which is incremented to match
|
||||
* how many frames are sent.
|
||||
*/
|
||||
uint32_t timestamp;
|
||||
|
||||
/** This is set to true if we have started sending audio.
|
||||
* When this moves from false to true, this causes the
|
||||
* client to send the 'talking' notification to the websocket.
|
||||
*/
|
||||
bool sending;
|
||||
|
||||
/** Number of track markers in the buffer. For example if there
|
||||
* are two track markers in the buffer there are 3 tracks.
|
||||
* Special case:
|
||||
* If the buffer is empty, there are zero tracks in the
|
||||
* buffer.
|
||||
*/
|
||||
uint32_t tracks;
|
||||
|
||||
/** Meta data associated with each track.
|
||||
* Arbitrary string that the user can set via
|
||||
* dpp::discord_voice_client::AddMarker
|
||||
*/
|
||||
std::vector<std::string> track_meta;
|
||||
|
||||
/** Encoding buffer for opus repacketizer and encode
|
||||
*/
|
||||
uint8_t encode_buffer[65536];
|
||||
|
||||
/**
|
||||
* @brief Send data to UDP socket immediately.
|
||||
*
|
||||
* @param data data to send
|
||||
* @param length length of data to send
|
||||
* @return int bytes sent. Will return -1 if we cannot send
|
||||
*/
|
||||
int UDPSend(const char* data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Receive data from UDP socket immediately.
|
||||
*
|
||||
* @param data data to receive
|
||||
* @param max_length size of data receiving buffer
|
||||
* @return int bytes received. -1 if there is an error
|
||||
* (e.g. EAGAIN)
|
||||
*/
|
||||
int UDPRecv(char* data, size_t max_length);
|
||||
|
||||
/**
|
||||
* @brief This hooks the ssl_client, returning the file
|
||||
* descriptor if we want to send buffered data, or
|
||||
* -1 if there is nothing to send
|
||||
*
|
||||
* @return int file descriptor or -1
|
||||
*/
|
||||
int WantWrite();
|
||||
|
||||
/**
|
||||
* @brief This hooks the ssl_client, returning the file
|
||||
* descriptor if we want to receive buffered data, or
|
||||
* -1 if we are not wanting to receive
|
||||
*
|
||||
* @return int file descriptor or -1
|
||||
*/
|
||||
int WantRead();
|
||||
|
||||
/**
|
||||
* @brief Called by ssl_client when the socket is ready
|
||||
* for writing, at this point we pick the head item off
|
||||
* the buffer and send it. So long as it doesnt error
|
||||
* completely, we pop it off the head of the queue.
|
||||
*/
|
||||
void WriteReady();
|
||||
|
||||
/**
|
||||
* @brief Called by ssl_client when there is data to be
|
||||
* read. At this point we insert that data into the
|
||||
* input queue.
|
||||
*/
|
||||
void ReadReady();
|
||||
|
||||
/**
|
||||
* @brief Send data to the UDP socket, using the buffer.
|
||||
*
|
||||
* @param packet packet data
|
||||
* @param len length of packet
|
||||
*/
|
||||
void Send(const char* packet, size_t len);
|
||||
|
||||
/**
|
||||
* @brief Queue a message to be sent via the websocket
|
||||
*
|
||||
* @param j The JSON data of the message to be sent
|
||||
* @param to_front If set to true, will place the message at the front of the queue not the back
|
||||
* (this is for urgent messages such as heartbeat, presence, so they can take precedence over
|
||||
* chunk requests etc)
|
||||
*/
|
||||
void QueueMessage(const std::string &j, bool to_front = false);
|
||||
|
||||
/**
|
||||
* @brief Clear the outbound message queue
|
||||
*
|
||||
*/
|
||||
void ClearQueue();
|
||||
|
||||
/**
|
||||
* @brief Get the size of the outbound message queue
|
||||
*
|
||||
* @return The size of the queue
|
||||
*/
|
||||
size_t GetQueueSize();
|
||||
|
||||
/**
|
||||
* @brief Encode a byte buffer using opus codec.
|
||||
* Multiple opus frames (2880 bytes each) will be encoded into one packet for sending.
|
||||
*
|
||||
* @param input Input data as raw bytes of PCM data
|
||||
* @param inDataSize Input data length
|
||||
* @param output Output data as an opus encoded packet
|
||||
* @param outDataSize Output data length, should be at least equal to the input size.
|
||||
* Will be adjusted on return to the actual compressed data size.
|
||||
* @return size_t The compressed data size that was encoded.
|
||||
*/
|
||||
size_t encode(uint8_t *input, size_t inDataSize, uint8_t *output, size_t &outDataSize);
|
||||
|
||||
public:
|
||||
|
||||
/** Owning cluster */
|
||||
class dpp::cluster* creator;
|
||||
|
||||
/* This needs to be static, we only initialise libsodium once per program start,
|
||||
* so initialising it on first use in a voice connection is best.
|
||||
*/
|
||||
static bool sodium_initialised;
|
||||
|
||||
/** True when the thread is shutting down */
|
||||
bool terminating;
|
||||
|
||||
/** Heartbeat interval for sending heartbeat keepalive */
|
||||
uint32_t heartbeat_interval;
|
||||
|
||||
/** Last heartbeat */
|
||||
time_t last_heartbeat;
|
||||
|
||||
/** Thread ID */
|
||||
std::thread::native_handle_type thread_id;
|
||||
|
||||
/** Discord voice session token */
|
||||
std::string token;
|
||||
|
||||
/** Discord voice session id */
|
||||
std::string sessionid;
|
||||
|
||||
/** Server ID */
|
||||
snowflake server_id;
|
||||
|
||||
/** Channel ID */
|
||||
snowflake channel_id;
|
||||
|
||||
/** Log a message to whatever log the user is using.
|
||||
* The logged message is passed up the chain to the on_log event in user code which can then do whatever
|
||||
* it wants to do with it.
|
||||
* @param severity The log level from dpp::loglevel
|
||||
* @param msg The log message to output
|
||||
*/
|
||||
virtual void log(dpp::loglevel severity, const std::string &msg);
|
||||
|
||||
/** Fires every second from the underlying socket I/O loop, used for sending heartbeats */
|
||||
virtual void one_second_timer();
|
||||
|
||||
/**
|
||||
* @brief voice client is ready to stream audio.
|
||||
* The voice client is considered ready if it has a secret key.
|
||||
*
|
||||
* @return true if ready to stream audio
|
||||
*/
|
||||
bool is_ready();
|
||||
|
||||
/**
|
||||
* @brief Returns true if the voice client is connected to the websocket
|
||||
*
|
||||
* @return True if connected
|
||||
*/
|
||||
bool is_connected();
|
||||
|
||||
/**
|
||||
* @brief Returns the connection time of the voice client
|
||||
*
|
||||
* @return dpp::utility::uptime Detail of how long the voice client has been connected for
|
||||
*/
|
||||
dpp::utility::uptime get_uptime();
|
||||
|
||||
/** Constructor takes shard id, max shards and token.
|
||||
* @param _cluster The owning cluster for this shard
|
||||
* @param _server_id The server id to identify voice connection as
|
||||
* @param _token The voice session token to use for identifying to the websocket
|
||||
* @param _session_id The voice session id to identify with
|
||||
* @param _host The voice server hostname to connect to (hostname:port format)
|
||||
*/
|
||||
discord_voice_client(dpp::cluster* _cluster, snowflake _channel_id, snowflake _server_id, const std::string &_token, const std::string &_session_id, const std::string &_host);
|
||||
|
||||
/** Destructor */
|
||||
virtual ~discord_voice_client();
|
||||
|
||||
/** Handle JSON from the websocket.
|
||||
* @param buffer The entire buffer content from the websocket client
|
||||
* @returns True if a frame has been handled
|
||||
*/
|
||||
virtual bool HandleFrame(const std::string &buffer);
|
||||
|
||||
/** Handle a websocket error.
|
||||
* @param errorcode The error returned from the websocket
|
||||
*/
|
||||
virtual void Error(uint32_t errorcode);
|
||||
|
||||
/** Start and monitor I/O loop */
|
||||
void Run();
|
||||
|
||||
/**
|
||||
* @brief Send audio to the voice channel.
|
||||
*
|
||||
* You should send an audio packet of n11520 bytes.
|
||||
* Note that this function can be costly as it has to opus encode
|
||||
* the PCM audio on the fly, and also encrypt it with libsodium.
|
||||
*
|
||||
* @note Because this function encrypts and encodes packets before
|
||||
* pushing them onto the output queue, if you have a complete stream
|
||||
* ready to send and know its length it is advisable to call this
|
||||
* method multiple times to enqueue the entire stream audio so that
|
||||
* it is all encoded at once. Constantly calling this from the
|
||||
* dpp::on_voice_buffer_send callback can and will eat a TON of cpu!
|
||||
*
|
||||
* @param audio_data Raw PCM audio data. Channels are interleaved,
|
||||
* with each channel's amplitude being a 16 bit value.
|
||||
* @param length The length of the audio data. The length should
|
||||
* be a multiple of 4 (2x 16 bit stero channels) with a maximum
|
||||
* length of 11520, which is a complete opus frame at highest
|
||||
* quality.
|
||||
* @param use_opus Some containers such as .ogg may contain OPUS
|
||||
* encoded data already. In this case, we don't need to encode the
|
||||
* frames using opus here. We can set use_opus to false and bypass the
|
||||
* codec, only applying libsodium to the stream.
|
||||
*/
|
||||
void send_audio(uint16_t* audio_data, const size_t length, bool use_opus = true);
|
||||
|
||||
/**
|
||||
* @brief Pause sending of audio
|
||||
*
|
||||
* @param pause True to pause, false to resume
|
||||
*/
|
||||
void pause_audio(bool pause);
|
||||
|
||||
/**
|
||||
* @brief Immediately stop all audio.
|
||||
* Clears the packet queue.
|
||||
*/
|
||||
void stop_audio();
|
||||
|
||||
/**
|
||||
* @brief Returns true if we are playing audio
|
||||
*
|
||||
* @return true if audio is playing
|
||||
*/
|
||||
bool is_playing();
|
||||
|
||||
/**
|
||||
* @brief Get the number of seconds remaining
|
||||
* of the audio output buffer
|
||||
*
|
||||
* @return float number of seconds remaining
|
||||
*/
|
||||
float get_secs_remaining();
|
||||
|
||||
/**
|
||||
* @brief Get the number of tracks remaining
|
||||
* in the output buffer.
|
||||
* This is calculated by the number of track
|
||||
* markers plus one.
|
||||
* @return uint32_t Number of tracks in the
|
||||
* buffer
|
||||
*/
|
||||
uint32_t get_tracks_remaining();
|
||||
|
||||
/**
|
||||
* @brief Get the time remaining to send the
|
||||
* audio output buffer in hours:minutes:seconds
|
||||
*
|
||||
* @return dpp::utility::uptime length of buffer
|
||||
*/
|
||||
dpp::utility::uptime get_remaining();
|
||||
|
||||
/**
|
||||
* @brief Insert a track marker into the audio
|
||||
* output buffer.
|
||||
* A track marker is an arbitrary flag in the
|
||||
* buffer contents that indictes the end of some
|
||||
* block of audio of significance to the sender.
|
||||
* This may be a song from a streaming site, or
|
||||
* some voice audio/speech, a sound effect, or
|
||||
* whatever you choose. You can later skip
|
||||
* to the next marker using the
|
||||
* dpp::discord_voice_client::skip_to_next_marker
|
||||
* function.
|
||||
* @param metadata Arbitrary information related to this
|
||||
* track
|
||||
*/
|
||||
void insert_marker(const std::string& metadata = "");
|
||||
|
||||
/**
|
||||
* @brief Skip tp the next track marker,
|
||||
* previously inserted by using the
|
||||
* dpp::discord_voice_client::insert_marker
|
||||
* function. If there are no markers in the
|
||||
* output buffer, then this skips to the end
|
||||
* of the buffer and is equivalent to the
|
||||
* dpp::discord_voice_client::stop_audio
|
||||
* function.
|
||||
* @note It is possible to use this function
|
||||
* while the output stream is paused.
|
||||
*/
|
||||
void skip_to_next_marker();
|
||||
|
||||
/**
|
||||
* @brief Get the metdata string associated with each inserted marker.
|
||||
*
|
||||
* @return const std::vector<std::string>& list of metadata strings
|
||||
*/
|
||||
const std::vector<std::string> get_marker_metadata();
|
||||
|
||||
/**
|
||||
* @brief Returns true if the audio is paused.
|
||||
* You can unpause with
|
||||
* dpp::discord_voice_client::pause_audio.
|
||||
*
|
||||
* @return true if paused
|
||||
*/
|
||||
bool is_paused();
|
||||
|
||||
/**
|
||||
* @brief Discord external IP detection.
|
||||
* @return std::string Your external IP address
|
||||
* @note This is a blocking operation that waits
|
||||
* for a single packet from Discord's voice servers.
|
||||
*/
|
||||
std::string discover_ip();
|
||||
};
|
||||
|
||||
};
|
||||
|
1189
vendor/DPP/include/dpp/dispatcher.h
vendored
1189
vendor/DPP/include/dpp/dispatcher.h
vendored
File diff suppressed because it is too large
Load Diff
36
vendor/DPP/include/dpp/dpp.h
vendored
36
vendor/DPP/include/dpp/dpp.h
vendored
@ -1,36 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/version.h>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/queues.h>
|
||||
#include <dpp/commandhandler.h>
|
94
vendor/DPP/include/dpp/dtemplate.h
vendored
94
vendor/DPP/include/dpp/dtemplate.h
vendored
@ -1,94 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents a guild template
|
||||
*/
|
||||
class CoreExport dtemplate {
|
||||
public:
|
||||
/**
|
||||
* @brief Template code
|
||||
*/
|
||||
std::string code;
|
||||
/**
|
||||
* @brief Template name
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @brief Template description
|
||||
*/
|
||||
std::string description;
|
||||
/**
|
||||
* @brief Usage counter
|
||||
*/
|
||||
uint32_t usage_count;
|
||||
/**
|
||||
* @brief User ID of creator
|
||||
*/
|
||||
snowflake creator_id;
|
||||
/**
|
||||
* @brief Creation date/time
|
||||
*
|
||||
*/
|
||||
time_t created_at;
|
||||
/**
|
||||
* @brief Last update date/time
|
||||
*/
|
||||
time_t updated_at;
|
||||
/**
|
||||
* @brief Guild id the template is created from
|
||||
*/
|
||||
snowflake source_guild_id;
|
||||
/**
|
||||
* @brief True if needs synchronising
|
||||
*/
|
||||
bool is_dirty;
|
||||
|
||||
/**
|
||||
* @brief Construct a new dtemplate object
|
||||
*/
|
||||
dtemplate();
|
||||
|
||||
/**
|
||||
* @brief Destroy the dtemplate object
|
||||
*/
|
||||
~dtemplate();
|
||||
|
||||
/** Read class values from json object
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
dtemplate& fill_from_json(nlohmann::json* j);
|
||||
std::string build_json() const;
|
||||
|
||||
};
|
||||
|
||||
/** A container of invites */
|
||||
typedef std::unordered_map<snowflake, dtemplate> dtemplate_map;
|
||||
|
||||
|
||||
};
|
155
vendor/DPP/include/dpp/emoji.h
vendored
155
vendor/DPP/include/dpp/emoji.h
vendored
@ -1,155 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
#define MAX_EMOJI_SIZE 256 * 1024
|
||||
|
||||
/**
|
||||
* @brief Flags for dpp::emoji
|
||||
*/
|
||||
enum emoji_flags {
|
||||
/// Emoji requires colons
|
||||
e_require_colons = 0b00000001,
|
||||
/// Managed (introduced by application)
|
||||
e_managed = 0b00000010,
|
||||
/// Animated
|
||||
e_animated = 0b00000100,
|
||||
/// Available (false if the guild doesn't meet boosting criteria, etc)
|
||||
e_available = 0b00001000,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents an emoji for a dpp::guild
|
||||
*/
|
||||
class CoreExport emoji : public managed {
|
||||
public:
|
||||
/**
|
||||
* @brief Emoji name
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @brief User id who uploaded the emoji
|
||||
*/
|
||||
snowflake user_id;
|
||||
/**
|
||||
* @brief Flags for the emoji from dpp::emoji_flags
|
||||
*/
|
||||
uint8_t flags;
|
||||
/**
|
||||
* @brief Image data for the emoji if uploading
|
||||
*/
|
||||
std::string* image_data;
|
||||
|
||||
/**
|
||||
* @brief Construct a new emoji object
|
||||
*/
|
||||
emoji();
|
||||
|
||||
/**
|
||||
* @brief Construct a new emoji object with name, ID and flags
|
||||
*
|
||||
* @param name The emoji's name
|
||||
* @param id ID, if it has one (unicode does not)
|
||||
* @param flags Emoji flags (emoji_flags)
|
||||
*/
|
||||
emoji(const std::string, const snowflake = 0, const uint8_t = 0);
|
||||
|
||||
/**
|
||||
* @brief Destroy the emoji object
|
||||
*/
|
||||
virtual ~emoji();
|
||||
|
||||
/**
|
||||
* @brief Read class values from json object
|
||||
*
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
emoji& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build the json for this object
|
||||
*
|
||||
* @param with_id include the id in the JSON
|
||||
* @return std::string json data
|
||||
*/
|
||||
std::string build_json(bool with_id = false) const;
|
||||
|
||||
/**
|
||||
* @brief Emoji requires colons
|
||||
*
|
||||
* @return true Requires colons
|
||||
* @return false Does not require colons
|
||||
*/
|
||||
bool requires_colons() const;
|
||||
|
||||
/**
|
||||
* @brief Emoji is managed
|
||||
*
|
||||
* @return true Is managed
|
||||
* @return false Is not managed
|
||||
*/
|
||||
bool is_managed() const;
|
||||
|
||||
/**
|
||||
* @brief Emoji is animated
|
||||
*
|
||||
* @return true Is animated
|
||||
* @return false Is noy animated
|
||||
*/
|
||||
bool is_animated() const;
|
||||
|
||||
/**
|
||||
* @brief Is available
|
||||
*
|
||||
* @return true Is available
|
||||
* @return false Is unavailable
|
||||
*/
|
||||
bool is_available() const;
|
||||
|
||||
/**
|
||||
* @brief Load an image into the object as base64
|
||||
*
|
||||
* @param image_blob Image binary data
|
||||
* @param type Type of image
|
||||
* @return emoji& Reference to self
|
||||
*/
|
||||
emoji& load_image(const std::string &image_blob, image_type type);
|
||||
|
||||
/**
|
||||
* @brief Format to name if unicode, name:id if has id or a:name:id if animated
|
||||
*
|
||||
* @return Formatted name for reactions
|
||||
*/
|
||||
std::string format() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Group of emojis
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, emoji> emoji_map;
|
||||
|
||||
};
|
139
vendor/DPP/include/dpp/event.h
vendored
139
vendor/DPP/include/dpp/event.h
vendored
@ -1,139 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
|
||||
#define event_decl(x) class x : public event { public: virtual void handle(dpp::discord_client* client, nlohmann::json &j, const std::string &raw); };
|
||||
|
||||
namespace dpp {
|
||||
|
||||
class discord_client;
|
||||
|
||||
/**
|
||||
* @brief The events namespace holds the internal event handlers for each websocket event.
|
||||
* These are handled internally and also dispatched to the user code if the event is hooked.
|
||||
*/
|
||||
namespace events {
|
||||
|
||||
/**
|
||||
* @brief An event object represents an event handled internally, passed from the websocket e.g. MESSAGE_CREATE.
|
||||
*/
|
||||
class CoreExport event {
|
||||
public:
|
||||
/** Pure virtual method for event handler code
|
||||
* @param client The creating shard
|
||||
* @param j The json data of the event
|
||||
* @param raw The raw event json
|
||||
*/
|
||||
virtual void handle(class discord_client* client, nlohmann::json &j, const std::string &raw) = 0;
|
||||
};
|
||||
|
||||
/* Internal logger */
|
||||
event_decl(logger);
|
||||
|
||||
/* Guilds */
|
||||
event_decl(guild_create);
|
||||
event_decl(guild_update);
|
||||
event_decl(guild_delete);
|
||||
event_decl(guild_ban_add);
|
||||
event_decl(guild_ban_remove);
|
||||
event_decl(guild_emojis_update);
|
||||
event_decl(guild_integrations_update);
|
||||
event_decl(guild_join_request_delete);
|
||||
event_decl(guild_stickers_update);
|
||||
|
||||
/* Stage channels */
|
||||
event_decl(stage_instance_create);
|
||||
event_decl(stage_instance_delete);
|
||||
|
||||
/* Guild members */
|
||||
event_decl(guild_member_add);
|
||||
event_decl(guild_member_remove);
|
||||
event_decl(guild_members_chunk);
|
||||
event_decl(guild_member_update);
|
||||
|
||||
/* Guild roles */
|
||||
event_decl(guild_role_create);
|
||||
event_decl(guild_role_update);
|
||||
event_decl(guild_role_delete);
|
||||
|
||||
/* Session state */
|
||||
event_decl(resumed);
|
||||
event_decl(ready);
|
||||
|
||||
/* Channels */
|
||||
event_decl(channel_create);
|
||||
event_decl(channel_update);
|
||||
event_decl(channel_delete);
|
||||
event_decl(channel_pins_update);
|
||||
|
||||
/* Threads */
|
||||
event_decl(thread_create);
|
||||
event_decl(thread_update);
|
||||
event_decl(thread_delete);
|
||||
event_decl(thread_list_sync);
|
||||
event_decl(thread_member_update);
|
||||
event_decl(thread_members_update);
|
||||
|
||||
/* Messages */
|
||||
event_decl(message_create);
|
||||
event_decl(message_update);
|
||||
event_decl(message_delete);
|
||||
event_decl(message_delete_bulk);
|
||||
|
||||
/* Presence/typing */
|
||||
event_decl(presence_update);
|
||||
event_decl(typing_start);
|
||||
|
||||
/* Users (outside of guild) */
|
||||
event_decl(user_update);
|
||||
|
||||
/* Message reactions */
|
||||
event_decl(message_reaction_add);
|
||||
event_decl(message_reaction_remove);
|
||||
event_decl(message_reaction_remove_all);
|
||||
event_decl(message_reaction_remove_emoji);
|
||||
|
||||
/* Invites */
|
||||
event_decl(invite_create);
|
||||
event_decl(invite_delete);
|
||||
|
||||
/* Voice */
|
||||
event_decl(voice_state_update);
|
||||
event_decl(voice_server_update);
|
||||
|
||||
/* Webhooks */
|
||||
event_decl(webhooks_update);
|
||||
|
||||
/* Slash commands */
|
||||
event_decl(application_command_create);
|
||||
event_decl(application_command_update);
|
||||
event_decl(application_command_delete);
|
||||
event_decl(interaction_create);
|
||||
|
||||
/* Integrations */
|
||||
event_decl(integration_create);
|
||||
event_decl(integration_update);
|
||||
event_decl(integration_delete);
|
||||
|
||||
}};
|
43
vendor/DPP/include/dpp/export.h
vendored
43
vendor/DPP/include/dpp/export.h
vendored
@ -1,43 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#ifdef DPP_BUILD
|
||||
#ifdef _WIN32
|
||||
#define CoreExport __declspec(dllexport)
|
||||
#else
|
||||
#define CoreExport
|
||||
#endif
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#define CoreExport __declspec(dllimport)
|
||||
/* This is required otherwise fmt::format requires additional file linkage to your project */
|
||||
#define FMT_HEADER_ONLY
|
||||
#else
|
||||
#define CoreExport
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#define SOCKET int
|
||||
#else
|
||||
#include <WinSock2.h>
|
||||
#endif
|
432
vendor/DPP/include/dpp/guild.h
vendored
432
vendor/DPP/include/dpp/guild.h
vendored
@ -1,432 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <dpp/voicestate.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents voice regions for guilds and channels.
|
||||
* @note Largely deprecated in favour of per-channel regions.
|
||||
*/
|
||||
enum region : uint8_t {
|
||||
r_brazil, //!< Brazil
|
||||
r_central_europe, //!< Central Europe
|
||||
r_hong_kong, //!< Hong Kong
|
||||
r_india, //!< India
|
||||
r_japan, //!< Japan
|
||||
r_russia, //!< Russia
|
||||
r_singapore, //!< Singapore
|
||||
r_south_africa, //!< South Africa
|
||||
r_sydney, //!< Sydney
|
||||
r_us_central, //!< US Central
|
||||
r_us_east, //!< US East Coast
|
||||
r_us_south, //!< US South
|
||||
r_us_west, //!< US West Coast
|
||||
r_western_europe //!< Western Europe
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The various flags that represent the status of a dpp::guild object
|
||||
*/
|
||||
enum guild_flags {
|
||||
/** Large guild */
|
||||
g_large = 0b000000000000000000001,
|
||||
/** Unavailable guild (inaccessible due to an outage) */
|
||||
g_unavailable = 0b000000000000000000010,
|
||||
/** Guild has widget enabled */
|
||||
g_widget_enabled = 0b000000000000000000100,
|
||||
/** Guild can have an invite splash image */
|
||||
g_invite_splash = 0b000000000000000001000,
|
||||
/** Guild can have VIP regions */
|
||||
g_vip_regions = 0b000000000000000010000,
|
||||
/** Guild can have a vanity url */
|
||||
g_vanity_url = 0b000000000000000100000,
|
||||
/** Guild is verified */
|
||||
g_verified = 0b000000000000001000000,
|
||||
/** Guild is partnered */
|
||||
g_partnered = 0b000000000000010000000,
|
||||
/** Community features enabled */
|
||||
g_community = 0b000000000000100000000,
|
||||
/** Guild has commerce features enabled */
|
||||
g_commerce = 0b000000000001000000000,
|
||||
/** Guild has news features enabled */
|
||||
g_news = 0b000000000010000000000,
|
||||
/** Guild is discoverable in discovery */
|
||||
g_discoverable = 0b000000000100000000000,
|
||||
/** Guild is featureable */
|
||||
g_featureable = 0b000000001000000000000,
|
||||
/** Guild can have an animated icon (doesn't mean it actually has one though) */
|
||||
g_animated_icon = 0b000000010000000000000,
|
||||
/** Guild can have a banner image */
|
||||
g_banner = 0b000000100000000000000,
|
||||
/** Guild has a welcome screen */
|
||||
g_welcome_screen_enabled = 0b000001000000000000000,
|
||||
/** Guild has a member verification gate */
|
||||
g_member_verification_gate = 0b000010000000000000000,
|
||||
/** Guild has a preview */
|
||||
g_preview_enabled = 0b000100000000000000000,
|
||||
/** Guild join notifications are off */
|
||||
g_no_join_notifications = 0b001000000000000000000,
|
||||
/** Guild boost notifications are off */
|
||||
g_no_boost_notifications = 0b010000000000000000000,
|
||||
/** Guild has an actual animated icon (set by the icon hash starting with 'a_') */
|
||||
g_has_animated_icon = 0b100000000000000000000
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Various flags that can be used to indicate the status of a guild member
|
||||
*/
|
||||
enum guild_member_flags {
|
||||
/** Member deafened */
|
||||
gm_deaf = 0b00001,
|
||||
/** Member muted */
|
||||
gm_mute = 0b00010,
|
||||
/** Member pending verification by membership screening */
|
||||
gm_pending = 0b00100
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents dpp::user membership upon a dpp::guild
|
||||
*/
|
||||
class CoreExport guild_member {
|
||||
public:
|
||||
/** Nickname, or nullptr if they don't have a nickname on this guild */
|
||||
std::string nickname;
|
||||
/** Guild id */
|
||||
snowflake guild_id;
|
||||
/** User id */
|
||||
snowflake user_id;
|
||||
/** List of roles this user has on this guild */
|
||||
std::vector<snowflake> roles;
|
||||
/** Date and time the user joined the guild */
|
||||
time_t joined_at;
|
||||
/** Boosting since */
|
||||
time_t premium_since;
|
||||
/** A set of flags built from the bitmask defined by dpp::guild_member_flags */
|
||||
uint8_t flags;
|
||||
|
||||
/** Default constructor */
|
||||
guild_member();
|
||||
|
||||
/** Fill this object from a json object.
|
||||
* @param j The json object to get data from
|
||||
* @param g_id The guild id to associate the member with
|
||||
* @param u_id The user id to associate the member with
|
||||
*/
|
||||
guild_member& fill_from_json(nlohmann::json* j, snowflake g_id, snowflake u_id);
|
||||
|
||||
/** Build json string for the member object */
|
||||
std::string build_json() const;
|
||||
|
||||
/** Returns true if the user is deafened */
|
||||
bool is_deaf() const;
|
||||
|
||||
/** Returns true if the user is muted */
|
||||
bool is_muted() const;
|
||||
|
||||
/** Returns true if pending verification by membership screening */
|
||||
bool is_pending() const;
|
||||
|
||||
};
|
||||
|
||||
/** @brief Guild members container
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, guild_member> members_container;
|
||||
|
||||
/**
|
||||
* @brief Represents a guild on Discord (AKA a server)
|
||||
*/
|
||||
class CoreExport guild : public managed {
|
||||
public:
|
||||
/** Shard ID of the guild */
|
||||
uint16_t shard_id;
|
||||
|
||||
/** Flags bitmask as defined by values within dpp::guild_flags */
|
||||
uint32_t flags;
|
||||
|
||||
/** Guild name */
|
||||
std::string name;
|
||||
|
||||
/** Server description for communities */
|
||||
std::string description;
|
||||
|
||||
/** Vanity url code for verified or partnered servers and boost level 3 */
|
||||
std::string vanity_url_code;
|
||||
|
||||
/** Guild icon hash */
|
||||
utility::iconhash icon;
|
||||
|
||||
/** Guild splash hash */
|
||||
utility::iconhash splash;
|
||||
|
||||
/** Guild discovery splash hash */
|
||||
utility::iconhash discovery_splash;
|
||||
|
||||
/** Snowflake id of guild owner */
|
||||
snowflake owner_id;
|
||||
|
||||
/** Guild voice region */
|
||||
region voice_region;
|
||||
|
||||
/** Snowflake ID of AFK voice channel or 0 */
|
||||
snowflake afk_channel_id;
|
||||
|
||||
/** Voice AFK timeout before moving users to AFK channel */
|
||||
uint8_t afk_timeout;
|
||||
|
||||
/** Snowflake ID of widget channel, or 0 */
|
||||
snowflake widget_channel_id;
|
||||
|
||||
/** Verification level of server */
|
||||
uint8_t verification_level;
|
||||
|
||||
/** Setting for how notifications are to be delivered to users */
|
||||
uint8_t default_message_notifications;
|
||||
|
||||
/** Whether or not explicit content filtering is enable and what setting it is */
|
||||
uint8_t explicit_content_filter;
|
||||
|
||||
/** If multi factor authentication is required for moderators or not */
|
||||
uint8_t mfa_level;
|
||||
|
||||
/** ID of creating application, if any, or 0 */
|
||||
snowflake application_id;
|
||||
|
||||
/** ID of system channel where discord update messages are sent */
|
||||
snowflake system_channel_id;
|
||||
|
||||
/** ID of rules channel for communities */
|
||||
snowflake rules_channel_id;
|
||||
|
||||
/** Approximate member count. May be sent as zero */
|
||||
uint32_t member_count;
|
||||
|
||||
/** Server banner hash */
|
||||
utility::iconhash banner;
|
||||
|
||||
/** Boost level */
|
||||
uint8_t premium_tier;
|
||||
|
||||
/** Number of boosters */
|
||||
uint16_t premium_subscription_count;
|
||||
|
||||
/** Public updates channel id or 0 */
|
||||
snowflake public_updates_channel_id;
|
||||
|
||||
/** Maximum users in a video channel, or 0 */
|
||||
uint16_t max_video_channel_users;
|
||||
|
||||
/** Roles defined on this server */
|
||||
std::vector<snowflake> roles;
|
||||
|
||||
/** List of channels on this server */
|
||||
std::vector<snowflake> channels;
|
||||
|
||||
/** List of threads on this server */
|
||||
std::vector<snowflake> threads;
|
||||
|
||||
/** List of guild members. Note that when you first receive the
|
||||
* guild create event, this may be empty or near empty.
|
||||
* This depends upon your dpp::intents and the size of your bot.
|
||||
* It will be filled by guild member chunk requests.
|
||||
*/
|
||||
members_container members;
|
||||
|
||||
/** List of members in voice channels in the guild.
|
||||
*/
|
||||
std::map<snowflake, voicestate> voice_members;
|
||||
|
||||
/** List of emojis
|
||||
*/
|
||||
std::vector<snowflake> emojis;
|
||||
|
||||
/** Default constructor, zeroes all values */
|
||||
guild();
|
||||
|
||||
/**
|
||||
* @brief Destroy the guild object
|
||||
*/
|
||||
virtual ~guild() = default;
|
||||
|
||||
/** Read class values from json object
|
||||
* @param shard originating shard
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
guild& fill_from_json(class discord_client* shard, nlohmann::json* j);
|
||||
|
||||
/** Build a JSON string from this object.
|
||||
* @param with_id True if an ID is to be included in the JSON
|
||||
*/
|
||||
std::string build_json(bool with_id = false) const;
|
||||
|
||||
/**
|
||||
* @brief Get the base permissions for a member on this guild,
|
||||
* before permission overwrites are applied.
|
||||
*
|
||||
* @param member member to get permissions for
|
||||
* @return uint64_t permissions bitmask
|
||||
*/
|
||||
uint64_t base_permissions(const class user* member) const;
|
||||
|
||||
/**
|
||||
* @brief Get the permission overwrites for a member
|
||||
* merged into a bitmask.
|
||||
*
|
||||
* @param base_permissions base permissions before overwrites,
|
||||
* from channel::base_permissions
|
||||
* @param member Member to fetch permissions for
|
||||
* @param channel Channel to fetch permissions against
|
||||
* @return uint64_t Merged permissions bitmask of overwrites.
|
||||
*/
|
||||
uint64_t permission_overwrites(const uint64_t base_permissions, const user* member, const channel* channel) const;
|
||||
|
||||
/**
|
||||
* @brief Rehash members map
|
||||
*/
|
||||
void rehash_members();
|
||||
|
||||
/**
|
||||
* @brief Connect to a voice channel another guild member is in
|
||||
*
|
||||
* @param user_id User id to join
|
||||
* @return True if the user specified is in a vc, false if they aren't
|
||||
*/
|
||||
bool connect_member_voice(snowflake user_id);
|
||||
|
||||
/** Is a large server (>250 users) */
|
||||
bool is_large() const;
|
||||
|
||||
/** Is unavailable due to outage (most other fields will be blank or outdated */
|
||||
bool is_unavailable() const;
|
||||
|
||||
/** Widget is enabled for this server */
|
||||
bool widget_enabled() const;
|
||||
|
||||
/** Guild has an invite splash */
|
||||
bool has_invite_splash() const;
|
||||
|
||||
/** Guild has VIP regions */
|
||||
bool has_vip_regions() const;
|
||||
|
||||
/** Guild can have a vanity url */
|
||||
bool has_vanity_url() const;
|
||||
|
||||
/** Guild is a verified server */
|
||||
bool is_verified() const;
|
||||
|
||||
/** Guild is a discord partner server */
|
||||
bool is_partnered() const;
|
||||
|
||||
/** Guild has enabled community */
|
||||
bool is_community() const;
|
||||
|
||||
/** Guild has enabled commerce channels */
|
||||
bool has_commerce() const;
|
||||
|
||||
/** Guild has news channels */
|
||||
bool has_news() const;
|
||||
|
||||
/** Guild is discoverable */
|
||||
bool is_discoverable() const;
|
||||
|
||||
/** Guild is featureable */
|
||||
bool is_featureable() const;
|
||||
|
||||
/** Guild is allowed an animated icon */
|
||||
bool has_animated_icon() const;
|
||||
|
||||
/** Guild has a banner image */
|
||||
bool has_banner() const;
|
||||
|
||||
/** Guild has enabled welcome screen */
|
||||
bool is_welcome_screen_enabled() const;
|
||||
|
||||
/** Guild has enabled membership screening */
|
||||
bool has_member_verification_gate() const;
|
||||
|
||||
/** Guild has preview enabled */
|
||||
bool is_preview_enabled() const;
|
||||
|
||||
/** Server icon is actually an animated gif */
|
||||
bool has_animated_icon_hash() const;
|
||||
|
||||
};
|
||||
|
||||
/** A container of guilds */
|
||||
typedef std::unordered_map<snowflake, guild> guild_map;
|
||||
|
||||
/**
|
||||
* @brief Represents a guild widget, simple web widget of member list
|
||||
*/
|
||||
class CoreExport guild_widget {
|
||||
public:
|
||||
/**
|
||||
* @brief True if enabled
|
||||
*/
|
||||
bool enabled;
|
||||
/**
|
||||
* @brief Channel widget points to
|
||||
*/
|
||||
snowflake channel_id;
|
||||
|
||||
/**
|
||||
* @brief Construct a new guild widget object
|
||||
*/
|
||||
guild_widget();
|
||||
|
||||
/**
|
||||
* @brief Build a guild widget from json
|
||||
*
|
||||
* @param j json to build from
|
||||
* @return guild_widget& reference to self
|
||||
*/
|
||||
guild_widget& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build json for a guild widget
|
||||
*
|
||||
* @return std::string guild widget stringified json
|
||||
*/
|
||||
std::string build_json() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to deserialize a guild_member from json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param gm guild_member to be deserialized
|
||||
*/
|
||||
void from_json(const nlohmann::json& j, guild_member& gm);
|
||||
|
||||
/** A container of guild members */
|
||||
typedef std::unordered_map<snowflake, guild_member> guild_member_map;
|
||||
|
||||
|
||||
};
|
1452
vendor/DPP/include/dpp/httplib.h
vendored
1452
vendor/DPP/include/dpp/httplib.h
vendored
File diff suppressed because it is too large
Load Diff
132
vendor/DPP/include/dpp/integration.h
vendored
132
vendor/DPP/include/dpp/integration.h
vendored
@ -1,132 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Integration types
|
||||
*/
|
||||
enum integration_type {
|
||||
/// Twitch integration
|
||||
i_twitch,
|
||||
/// YouTube integration
|
||||
i_youtube,
|
||||
/// Discord integration
|
||||
i_discord
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Integration flags
|
||||
*/
|
||||
enum integration_flags {
|
||||
/// Integration enabled
|
||||
if_enabled = 0b00000001,
|
||||
/// Integration synching
|
||||
if_syncing = 0b00000010,
|
||||
/// Emoji integration
|
||||
if_emoticons = 0b00000100,
|
||||
/// Integration revoked
|
||||
if_revoked = 0b00001000,
|
||||
/// Kick users when their subscription expires
|
||||
if_expire_kick = 0b00010000,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief An application that has been integrated
|
||||
*/
|
||||
struct CoreExport integration_app {
|
||||
/// Inegration id
|
||||
snowflake id;
|
||||
/// Name
|
||||
std::string name;
|
||||
/// Icon
|
||||
std::string icon;
|
||||
/// Description
|
||||
std::string description;
|
||||
/// Integration summary
|
||||
std::string summary;
|
||||
/// Pointer to bot user
|
||||
user* bot;
|
||||
};
|
||||
|
||||
/** Represents an integration within a dpp::guild */
|
||||
class CoreExport integration : public managed {
|
||||
public:
|
||||
/** Integration name */
|
||||
std::string name;
|
||||
/** Integration type */
|
||||
integration_type type;
|
||||
/** Integration flags from dpp::integration_flags */
|
||||
uint8_t flags;
|
||||
/** Role id */
|
||||
snowflake role_id;
|
||||
/** User id */
|
||||
snowflake user_id;
|
||||
/** Expiry grace period */
|
||||
uint32_t expire_grace_period;
|
||||
/** Sync time */
|
||||
time_t synced_at;
|
||||
/** Subscriber count */
|
||||
uint32_t subscriber_count;
|
||||
/* Account id */
|
||||
std::string account_id;
|
||||
/* Account name */
|
||||
std::string account_name;
|
||||
/* Integration application */
|
||||
integration_app app;
|
||||
|
||||
/** Default constructor */
|
||||
integration();
|
||||
|
||||
/** Default destructor */
|
||||
~integration();
|
||||
|
||||
/** Read class values from json object
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
integration& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/** Build a json string from this object.
|
||||
* @return JSON string of the object
|
||||
*/
|
||||
std::string build_json() const;
|
||||
|
||||
/** True if emoticons are enabled */
|
||||
bool emoticons_enabled() const;
|
||||
/** True if integration is enabled */
|
||||
bool is_enabled() const;
|
||||
/** True if is syncing */
|
||||
bool is_syncing() const;
|
||||
/** True if has been revoked */
|
||||
bool is_revoked() const;
|
||||
/** True if expiring kicks the user */
|
||||
bool expiry_kicks_user() const;
|
||||
};
|
||||
|
||||
/** A group of integrations */
|
||||
typedef std::unordered_map<snowflake, integration> integration_map;
|
||||
|
||||
};
|
||||
|
71
vendor/DPP/include/dpp/intents.h
vendored
71
vendor/DPP/include/dpp/intents.h
vendored
@ -1,71 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief intents are a bitmask of allowed events on your websocket.
|
||||
*
|
||||
* Some of these are known as Privileged intents (GUILD_MEMBERS and GUILD_PRESENCES)
|
||||
* and require verification of a bot over 100 servers by discord via submission of
|
||||
* your real life ID.
|
||||
*/
|
||||
enum intents {
|
||||
/// Intent for receipt of guild information
|
||||
i_guilds = (1 << 0),
|
||||
/// Intent for receipt of guild members
|
||||
i_guild_members = (1 << 1),
|
||||
/// Intent for receipt of guild bans
|
||||
i_guild_bans = (1 << 2),
|
||||
/// Intent for receipt of guild emojis
|
||||
i_guild_emojis = (1 << 3),
|
||||
/// Intent for receipt of guild integrations
|
||||
i_guild_integrations = (1 << 4),
|
||||
/// Intent for receipt of guild webhooks
|
||||
i_guild_webhooks = (1 << 5),
|
||||
/// Intent for receipt of guild invites
|
||||
i_guild_invites = (1 << 6),
|
||||
/// Intent for receipt of guild voice states
|
||||
i_guild_voice_states = (1 << 7),
|
||||
/// Intent for receipt of guild presences
|
||||
i_guild_presences = (1 << 8),
|
||||
/// Intent for receipt of guild messages
|
||||
i_guild_messages = (1 << 9),
|
||||
/// Intent for receipt of guild message reactions
|
||||
i_guild_message_reactions = (1 << 10),
|
||||
/// Intent for receipt of guild message typing notifications
|
||||
i_guild_message_typing = (1 << 11),
|
||||
/// Intent for receipt of direct messages (DMs)
|
||||
i_direct_messages = (1 << 12),
|
||||
/// Intent for receipt of direct message reactions
|
||||
i_direct_message_reactions = (1 << 13),
|
||||
/// Intent for receipt of direct message typing notifications
|
||||
i_direct_message_typing = (1 << 14),
|
||||
/// Default D++ intents (all non-privileged intents)
|
||||
i_default_intents = dpp::i_guilds | dpp::i_guild_bans | dpp::i_guild_emojis | dpp::i_guild_integrations | dpp::i_guild_webhooks | dpp::i_guild_invites | dpp::i_guild_voice_states | dpp::i_guild_messages | dpp::i_guild_message_reactions | dpp::i_guild_message_typing | dpp::i_direct_messages | dpp::i_direct_message_typing | dpp::i_direct_message_reactions,
|
||||
// Privileged intents requiring ID
|
||||
i_privileged_intents = dpp::i_guild_members | dpp::i_guild_presences,
|
||||
// Every single intent
|
||||
i_all_intents = dpp::i_default_intents | dpp::i_privileged_intents
|
||||
};
|
||||
|
||||
};
|
94
vendor/DPP/include/dpp/invite.h
vendored
94
vendor/DPP/include/dpp/invite.h
vendored
@ -1,94 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2021 Craig Edwards and D++ contributors
|
||||
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
************************************************************************************/
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents an invite to a discord guild or channel
|
||||
*/
|
||||
class CoreExport invite {
|
||||
public:
|
||||
/** Invite code
|
||||
*/
|
||||
std::string code;
|
||||
/** Guild for the invite
|
||||
*/
|
||||
snowflake guild_id;
|
||||
/** Channel id for invite
|
||||
*/
|
||||
snowflake channel_id;
|
||||
/** User ID of invite creator
|
||||
*/
|
||||
snowflake inviter_id;
|
||||
/** Target user ID of invite, for invites sent via DM
|
||||
*/
|
||||
snowflake target_user_id;
|
||||
/** Target user type (generally this is always 1, "stream")
|
||||
*/
|
||||
uint8_t target_user_type;
|
||||
/** Approximate number of online users
|
||||
*/
|
||||
uint32_t approximate_presence_count;
|
||||
/** Approximate total users online and offline
|
||||
*/
|
||||
uint32_t approximate_member_count;
|
||||
/** Maximum age of invite
|
||||
*/
|
||||
uint32_t max_age;
|
||||
/** Maximum number of uses
|
||||
*/
|
||||
uint32_t max_uses;
|
||||
/** True if a temporary invite which grants access for a limited time
|
||||
*/
|
||||
bool temporary;
|
||||
/** True if this invite should not replace or "attach to" similar invites
|
||||
*/
|
||||
bool unique;
|
||||
|
||||
/** Constructor
|
||||
*/
|
||||
invite();
|
||||
|
||||
/** Destructor
|
||||
*/
|
||||
~invite();
|
||||
|
||||
/** Read class values from json object
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
invite& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/** Build JSON from this object.
|
||||
* @return The JSON text of the invite
|
||||
*/
|
||||
std::string build_json() const;
|
||||
|
||||
};
|
||||
|
||||
/** A container of invites */
|
||||
typedef std::unordered_map<std::string, invite> invite_map;
|
||||
|
||||
};
|
78
vendor/DPP/include/dpp/json_fwd.hpp
vendored
78
vendor/DPP/include/dpp/json_fwd.hpp
vendored
@ -1,78 +0,0 @@
|
||||
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
||||
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
||||
|
||||
#include <cstdint> // int64_t, uint64_t
|
||||
#include <map> // map
|
||||
#include <memory> // allocator
|
||||
#include <string> // string
|
||||
#include <vector> // vector
|
||||
|
||||
/*!
|
||||
@brief namespace for Niels Lohmann
|
||||
@see https://github.com/nlohmann
|
||||
@since version 1.0.0
|
||||
*/
|
||||
namespace nlohmann
|
||||
{
|
||||
/*!
|
||||
@brief default JSONSerializer template argument
|
||||
|
||||
This serializer ignores the template arguments and uses ADL
|
||||
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))
|
||||
for serialization.
|
||||
*/
|
||||
template<typename T = void, typename SFINAE = void>
|
||||
struct adl_serializer;
|
||||
|
||||
template<template<typename U, typename V, typename... Args> class ObjectType =
|
||||
std::map,
|
||||
template<typename U, typename... Args> class ArrayType = std::vector,
|
||||
class StringType = std::string, class BooleanType = bool,
|
||||
class NumberIntegerType = std::int64_t,
|
||||
class NumberUnsignedType = std::uint64_t,
|
||||
class NumberFloatType = double,
|
||||
template<typename U> class AllocatorType = std::allocator,
|
||||
template<typename T, typename SFINAE = void> class JSONSerializer =
|
||||
adl_serializer,
|
||||
class BinaryType = std::vector<std::uint8_t>>
|
||||
class basic_json;
|
||||
|
||||
/*!
|
||||
@brief JSON Pointer
|
||||
|
||||
A JSON pointer defines a string syntax for identifying a specific value
|
||||
within a JSON document. It can be used with functions `at` and
|
||||
`operator[]`. Furthermore, JSON pointers are the base for JSON patches.
|
||||
|
||||
@sa [RFC 6901](https://tools.ietf.org/html/rfc6901)
|
||||
|
||||
@since version 2.0.0
|
||||
*/
|
||||
template<typename BasicJsonType>
|
||||
class json_pointer;
|
||||
|
||||
/*!
|
||||
@brief default JSON class
|
||||
|
||||
This type is the default specialization of the @ref basic_json class which
|
||||
uses the standard template types.
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
using json = basic_json<>;
|
||||
|
||||
template<class Key, class T, class IgnoredLess, class Allocator>
|
||||
struct ordered_map;
|
||||
|
||||
/*!
|
||||
@brief ordered JSON class
|
||||
|
||||
This type preserves the insertion order of object keys.
|
||||
|
||||
@since version 3.9.0
|
||||
*/
|
||||
using ordered_json = basic_json<nlohmann::ordered_map>;
|
||||
|
||||
} // namespace nlohmann
|
||||
|
||||
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
1113
vendor/DPP/include/dpp/message.h
vendored
1113
vendor/DPP/include/dpp/message.h
vendored
File diff suppressed because it is too large
Load Diff
26137
vendor/DPP/include/dpp/nlohmann/json.hpp
vendored
26137
vendor/DPP/include/dpp/nlohmann/json.hpp
vendored
File diff suppressed because it is too large
Load Diff
78
vendor/DPP/include/dpp/nlohmann/json_fwd.hpp
vendored
78
vendor/DPP/include/dpp/nlohmann/json_fwd.hpp
vendored
@ -1,78 +0,0 @@
|
||||
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
||||
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
||||
|
||||
#include <cstdint> // int64_t, uint64_t
|
||||
#include <map> // map
|
||||
#include <memory> // allocator
|
||||
#include <string> // string
|
||||
#include <vector> // vector
|
||||
|
||||
/*!
|
||||
@brief namespace for Niels Lohmann
|
||||
@see https://github.com/nlohmann
|
||||
@since version 1.0.0
|
||||
*/
|
||||
namespace nlohmann
|
||||
{
|
||||
/*!
|
||||
@brief default JSONSerializer template argument
|
||||
|
||||
This serializer ignores the template arguments and uses ADL
|
||||
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))
|
||||
for serialization.
|
||||
*/
|
||||
template<typename T = void, typename SFINAE = void>
|
||||
struct adl_serializer;
|
||||
|
||||
template<template<typename U, typename V, typename... Args> class ObjectType =
|
||||
std::map,
|
||||
template<typename U, typename... Args> class ArrayType = std::vector,
|
||||
class StringType = std::string, class BooleanType = bool,
|
||||
class NumberIntegerType = std::int64_t,
|
||||
class NumberUnsignedType = std::uint64_t,
|
||||
class NumberFloatType = double,
|
||||
template<typename U> class AllocatorType = std::allocator,
|
||||
template<typename T, typename SFINAE = void> class JSONSerializer =
|
||||
adl_serializer,
|
||||
class BinaryType = std::vector<std::uint8_t>>
|
||||
class basic_json;
|
||||
|
||||
/*!
|
||||
@brief JSON Pointer
|
||||
|
||||
A JSON pointer defines a string syntax for identifying a specific value
|
||||
within a JSON document. It can be used with functions `at` and
|
||||
`operator[]`. Furthermore, JSON pointers are the base for JSON patches.
|
||||
|
||||
@sa [RFC 6901](https://tools.ietf.org/html/rfc6901)
|
||||
|
||||
@since version 2.0.0
|
||||
*/
|
||||
template<typename BasicJsonType>
|
||||
class json_pointer;
|
||||
|
||||
/*!
|
||||
@brief default JSON class
|
||||
|
||||
This type is the default specialization of the @ref basic_json class which
|
||||
uses the standard template types.
|
||||
|
||||
@since version 1.0.0
|
||||
*/
|
||||
using json = basic_json<>;
|
||||
|
||||
template<class Key, class T, class IgnoredLess, class Allocator>
|
||||
struct ordered_map;
|
||||
|
||||
/*!
|
||||
@brief ordered JSON class
|
||||
|
||||
This type preserves the insertion order of object keys.
|
||||
|
||||
@since version 3.9.0
|
||||
*/
|
||||
using ordered_json = basic_json<nlohmann::ordered_map>;
|
||||
|
||||
} // namespace nlohmann
|
||||
|
||||
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user