mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
This commit is contained in:
parent
1d85603dfb
commit
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)
|
||||
|
@ -133,27 +133,6 @@ if(WIN32 OR MINGW)
|
||||
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()
|
||||
# Link to POCO libraries
|
||||
target_link_libraries(SqModule Poco::Foundation Poco::Crypto Poco::Data Poco::Net)
|
||||
# Does POCO have SQLite support?
|
||||
|
@ -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");
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -45,9 +45,6 @@ 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
|
||||
@ -115,9 +112,6 @@ bool RegisterAPI(HSQUIRRELVM 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
|
||||
|
4
vendor/CMakeLists.txt
vendored
4
vendor/CMakeLists.txt
vendored
@ -70,7 +70,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_
|
252
vendor/DPP/include/dpp/presence.h
vendored
252
vendor/DPP/include/dpp/presence.h
vendored
@ -1,252 +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 Presence flags bitmask
|
||||
*/
|
||||
enum presence_flags {
|
||||
/// Desktop: Online
|
||||
p_desktop_online = 0b00000001,
|
||||
/// Desktop: DND
|
||||
p_desktop_dnd = 0b00000010,
|
||||
/// Desktop: Idle
|
||||
p_desktop_idle = 0b00000011,
|
||||
/// Web: Online
|
||||
p_web_online = 0b00000100,
|
||||
/// Web: DND
|
||||
p_web_dnd = 0b00001000,
|
||||
/// Web: Idle
|
||||
p_web_idle = 0b00001100,
|
||||
/// Mobile: Online
|
||||
p_mobile_online = 0b00010000,
|
||||
/// Mobile: DND
|
||||
p_mobile_dnd = 0b00100000,
|
||||
/// Mobile: Idle
|
||||
p_mobile_idle = 0b00110000,
|
||||
/// General: Online
|
||||
p_status_online = 0b01000000,
|
||||
/// General: DND
|
||||
p_status_dnd = 0b10000000,
|
||||
/// General: Idle
|
||||
p_status_idle = 0b11000000
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Online presence status values
|
||||
*/
|
||||
enum presence_status : uint8_t {
|
||||
/// Offline
|
||||
ps_offline = 0,
|
||||
/// Online
|
||||
ps_online = 1,
|
||||
/// DND
|
||||
ps_dnd = 2,
|
||||
/// Idle
|
||||
ps_idle = 3
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Bit shift for desktop status
|
||||
*/
|
||||
#define PF_SHIFT_DESKTOP 0
|
||||
/** Bit shift for web status */
|
||||
#define PF_SHIFT_WEB 2
|
||||
/** Bit shift for mobile status */
|
||||
#define PF_SHIFT_MOBILE 4
|
||||
/** Bit shift for main status */
|
||||
#define PF_SHIFT_MAIN 6
|
||||
/** Bit mask for status */
|
||||
#define PF_STATUS_MASK 0b00000011
|
||||
/** Bit mask for clearing desktop status */
|
||||
#define PF_CLEAR_DESKTOP 0b11111100
|
||||
/** Bit mask for clearing web status */
|
||||
#define PF_CLEAR_WEB 0b11110011
|
||||
/** Bit mask for clearing mobile status */
|
||||
#define PF_CLEAR_MOBILE 0b11001111
|
||||
/** Bit mask for clearing main status */
|
||||
#define PF_CLEAR_STATUS 0b00111111
|
||||
|
||||
/**
|
||||
* @brief Game types
|
||||
*/
|
||||
enum activity_type : uint8_t {
|
||||
/// "Playing ..."
|
||||
at_game = 0,
|
||||
/// "Streaming ..."
|
||||
at_streaming = 1,
|
||||
/// "Listening to..."
|
||||
at_listening = 2,
|
||||
/// "Watching..."
|
||||
at_custom = 3,
|
||||
/// "Competing in..."
|
||||
at_competing = 4
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Activity types for rich presence
|
||||
*/
|
||||
enum activity_flags {
|
||||
/// In an instance
|
||||
af_instance = 0b00000001,
|
||||
/// Joining
|
||||
af_join = 0b00000010,
|
||||
/// Spectating
|
||||
af_spectate = 0b00000100,
|
||||
/// Sending join request
|
||||
af_join_request = 0b00001000,
|
||||
/// Synchronising
|
||||
af_sync = 0b00010000,
|
||||
/// Playing
|
||||
af_play = 0b00100000
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief An activity is a representation of what a user is doing. It might be a game, or a website, or a movie. Whatever.
|
||||
*/
|
||||
class CoreExport activity {
|
||||
public:
|
||||
/** Name of ativity
|
||||
* e.g. "Fortnite"
|
||||
*/
|
||||
std::string name;
|
||||
/** State of activity.
|
||||
* e.g. "Waiting in lobby"
|
||||
*/
|
||||
std::string state;
|
||||
/** URL.
|
||||
* Only applicable for certain sites such a YouTube
|
||||
* Alias: details
|
||||
*/
|
||||
std::string url;
|
||||
/** Activity type
|
||||
*/
|
||||
activity_type type;
|
||||
/** Time activity was created
|
||||
*/
|
||||
time_t created_at;
|
||||
/** Start time. e.g. when game was started
|
||||
*/
|
||||
time_t start;
|
||||
/** End time, e.g. for songs on spotify
|
||||
*/
|
||||
time_t end;
|
||||
/** Creating application (e.g. a linked account on the user's client)
|
||||
*/
|
||||
snowflake application_id;
|
||||
/** Flags bitmask from activity_flags
|
||||
*/
|
||||
uint8_t flags;
|
||||
|
||||
activity() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new activity
|
||||
*
|
||||
* @param typ
|
||||
* @param nam
|
||||
* @param stat
|
||||
* @param url_
|
||||
*/
|
||||
activity(const activity_type typ, const std::string& nam, const std::string& stat, const std::string& url_);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents user presence, e.g. what game they are playing and if they are online
|
||||
*/
|
||||
class CoreExport presence {
|
||||
public:
|
||||
/** The user the presence applies to */
|
||||
snowflake user_id;
|
||||
|
||||
/** Guild ID. Apparently, Discord supports this internally but the client doesnt... */
|
||||
snowflake guild_id;
|
||||
|
||||
/** Flags bitmask containing presence_flags */
|
||||
uint8_t flags;
|
||||
|
||||
/** List of activities */
|
||||
std::vector<activity> activities;
|
||||
|
||||
/** Constructor */
|
||||
presence();
|
||||
|
||||
/**
|
||||
* @brief Construct a new presence object with some parameters for sending to a websocket
|
||||
*
|
||||
* @param status
|
||||
* @param type
|
||||
* @param activity_description
|
||||
*/
|
||||
presence(presence_status status, activity_type type, const std::string& activity_description);
|
||||
|
||||
/**
|
||||
* @brief Construct a new presence object with some parameters for sending to a websocket
|
||||
*
|
||||
* @param status
|
||||
* @param a Activity itself
|
||||
*/
|
||||
presence(presence_status status, activity a);
|
||||
|
||||
/** Destructor */
|
||||
~presence();
|
||||
|
||||
/** Fill this object from json.
|
||||
* @param j JSON object to fill from
|
||||
* @return A reference to self
|
||||
*/
|
||||
presence& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/** Build JSON from this object.
|
||||
* @return The JSON text of the presence
|
||||
*/
|
||||
std::string build_json() const;
|
||||
|
||||
/** The users status on desktop
|
||||
* @return The user's status on desktop
|
||||
*/
|
||||
presence_status desktop_status() const;
|
||||
|
||||
/** The user's status on web
|
||||
* @return The user's status on web
|
||||
*/
|
||||
presence_status web_status() const;
|
||||
|
||||
/** The user's status on mobile
|
||||
* @return The user's status on mobile
|
||||
*/
|
||||
presence_status mobile_status() const;
|
||||
|
||||
/** The user's status as shown to other users
|
||||
* @return The user's status as shown to other users
|
||||
*/
|
||||
presence_status status() const;
|
||||
};
|
||||
|
||||
/** A container of presences */
|
||||
typedef std::unordered_map<std::string, presence> presence_map;
|
||||
|
||||
};
|
57
vendor/DPP/include/dpp/prune.h
vendored
57
vendor/DPP/include/dpp/prune.h
vendored
@ -1,57 +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 Defines a request to count prunable users, or start a prune operation
|
||||
*/
|
||||
struct CoreExport prune {
|
||||
/** Number of days to include in the prune
|
||||
*/
|
||||
uint32_t days = 0;
|
||||
/** Roles to include in the prune (empty to include everyone)
|
||||
*/
|
||||
std::vector<snowflake> include_roles;
|
||||
/** True if the count of pruneable users should be returned
|
||||
* (discord recommend not using this on big guilds)
|
||||
*/
|
||||
bool compute_prune_count;
|
||||
|
||||
/** Fill this object from json.
|
||||
* @param j JSON object to fill from
|
||||
* @return A reference to self
|
||||
*/
|
||||
prune& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/** Build JSON from this object.
|
||||
* @param with_prune_count True if the prune count boolean is to be set in the built JSON
|
||||
* @return The JSON text of the prune object
|
||||
*/
|
||||
std::string build_json(bool with_prune_count) const;
|
||||
|
||||
};
|
||||
|
||||
};
|
270
vendor/DPP/include/dpp/queues.h
vendored
270
vendor/DPP/include/dpp/queues.h
vendored
@ -1,270 +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 <unordered_map>
|
||||
#include <string>
|
||||
#include <queue>
|
||||
#include <map>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/** Encodes a url parameter similar to php urlencode() */
|
||||
std::string url_encode(const std::string &value);
|
||||
|
||||
/** Error values. Don't change the order or add extra values here,
|
||||
* as they map onto the error values of cpp-httplib
|
||||
*/
|
||||
enum http_error {
|
||||
/// Request successful
|
||||
h_success = 0,
|
||||
/// Status unknown
|
||||
h_unknown,
|
||||
/// Connect failed
|
||||
h_connection,
|
||||
/// Invalid local ip address
|
||||
h_bind_ip_address,
|
||||
/// Read error
|
||||
h_read,
|
||||
/// Write error
|
||||
h_write,
|
||||
/// Too many 30x redirects
|
||||
h_exceed_redirect_count,
|
||||
/// Request cancelled
|
||||
h_canceled,
|
||||
/// SSL connection error
|
||||
h_ssl_connection,
|
||||
/// SSL cert loading error
|
||||
h_ssl_loading_certs,
|
||||
/// SSL server verification error
|
||||
h_ssl_server_verification,
|
||||
/// Unsupported multipart boundary characters
|
||||
h_unsupported_multipart_boundary_chars,
|
||||
/// Compression error
|
||||
h_compression,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The result of any HTTP request. Contains the headers, vital
|
||||
* rate limit figures, and returned request body.
|
||||
*/
|
||||
struct CoreExport http_request_completion_t {
|
||||
/** HTTP headers of response */
|
||||
std::map<std::string, std::string> headers;
|
||||
/** HTTP status, e.g. 200 = OK, 404 = Not found, 429 = Rate limited */
|
||||
uint16_t status = 0;
|
||||
/** Error status (e.g. if the request could not connect at all) */
|
||||
http_error error = h_success;
|
||||
/** Ratelimit bucket */
|
||||
std::string ratelimit_bucket;
|
||||
/** Ratelimit limit of requests */
|
||||
uint64_t ratelimit_limit = 0;
|
||||
/** Ratelimit remaining requests */
|
||||
uint64_t ratelimit_remaining = 0;
|
||||
/** Ratelimit reset after (seconds) */
|
||||
uint64_t ratelimit_reset_after = 0;
|
||||
/** Ratelimit retry after (seconds) */
|
||||
uint64_t ratelimit_retry_after = 0;
|
||||
/** True if this request has caused us to be globally rate limited */
|
||||
bool ratelimit_global = false;
|
||||
/** Reply body */
|
||||
std::string body;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Results of HTTP requests are called back to these std::function types.
|
||||
* @note Returned http_completion_events are called ASYNCRONOUSLY in your
|
||||
* code which means they execute in a separate thread. The completion events
|
||||
* arrive in order.
|
||||
*/
|
||||
typedef std::function<void(const http_request_completion_t&)> http_completion_event;
|
||||
|
||||
/** Various types of http method supported by the Discord API
|
||||
*/
|
||||
enum http_method {
|
||||
/// GET
|
||||
m_get,
|
||||
/// POST
|
||||
m_post,
|
||||
/// PUT
|
||||
m_put,
|
||||
/// PATCH
|
||||
m_patch,
|
||||
/// DELETE
|
||||
m_delete
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A HTTP request.
|
||||
*
|
||||
* You should instantiate one of these objects via its constructor,
|
||||
* and pass a pointer to it into an instance of request_queue. Although you can
|
||||
* directly call the Run() method of the object and it will make a HTTP call, be
|
||||
* aware that if you do this, it will be a **BLOCKING call** (not asynchronous) and
|
||||
* will not respect rate limits, as both of these functions are managed by the
|
||||
* request_queue class.
|
||||
*/
|
||||
class CoreExport http_request {
|
||||
/** Completion callback */
|
||||
http_completion_event complete_handler;
|
||||
/** True if request has been made */
|
||||
bool completed;
|
||||
public:
|
||||
/** Endpoint name e.g. /api/users */
|
||||
std::string endpoint;
|
||||
/** Major and minor parameters */
|
||||
std::string parameters;
|
||||
/** Postdata for POST and PUT */
|
||||
std::string postdata;
|
||||
/** HTTP method for request */
|
||||
http_method method;
|
||||
/** Upload file name (server side) */
|
||||
std::string file_name;
|
||||
/** Upload file contents (binary) */
|
||||
std::string file_content;
|
||||
|
||||
/** Constructor. When constructing one of these objects it should be passed to request_queue::post_request().
|
||||
* @param _endpoint The API endpoint, e.g. /api/guilds
|
||||
* @param _parameters Major and minor parameters for the endpoint e.g. a user id or guild id
|
||||
* @param completion completion event to call when done
|
||||
* @param _postdata Data to send in POST and PUT requests
|
||||
* @param method The HTTP method to use from dpp::http_method
|
||||
* @param filename The filename (server side) of any uploaded file
|
||||
* @param filecontent The binary content of any uploaded file for the request
|
||||
*/
|
||||
http_request(const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata = "", http_method method = m_get, const std::string &filename = "", const std::string &filecontent = "");
|
||||
|
||||
/** Destructor */
|
||||
~http_request();
|
||||
|
||||
/** Call the completion callback, if the request is complete.
|
||||
* @param c callback to call
|
||||
*/
|
||||
void complete(const http_request_completion_t &c);
|
||||
|
||||
/** Execute the HTTP request and mark the request complete.
|
||||
* @param owner creating cluster
|
||||
*/
|
||||
http_request_completion_t Run(const class cluster* owner);
|
||||
|
||||
/** Returns true if the request is complete */
|
||||
bool is_completed();
|
||||
};
|
||||
|
||||
/** A rate limit bucket. The library builds one of these for
|
||||
* each endpoint.
|
||||
*/
|
||||
struct CoreExport bucket_t {
|
||||
/** Request limit */
|
||||
uint64_t limit;
|
||||
/** Requests remaining */
|
||||
uint64_t remaining;
|
||||
/** Ratelimit of this bucket resets after this many seconds */
|
||||
uint64_t reset_after;
|
||||
/** Ratelimit of this bucket can be retried after this many seconds */
|
||||
uint64_t retry_after;
|
||||
/** Timestamp this buckets counters were updated */
|
||||
time_t timestamp;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The request_queue class manages rate limits and marshalls HTTP requests that have
|
||||
* been built as http_request objects.
|
||||
*
|
||||
* It ensures asynchronous delivery of events and queueing of requests.
|
||||
*
|
||||
* It will spawn two threads, one to make outbound HTTP requests and push the returned
|
||||
* results into a queue, and the second to call the callback methods with these results.
|
||||
* They are separated so that if the user decides to take a long time processing a reply
|
||||
* in their callback it won't affect when other requests are sent, and if a HTTP request
|
||||
* takes a long time due to latency, it won't hold up user processing.
|
||||
*
|
||||
* There is usually only one request_queue object in each dpp::cluster, which is used
|
||||
* internally for the various REST methods such as sending messages.
|
||||
*/
|
||||
class CoreExport request_queue {
|
||||
private:
|
||||
/** The cluster that owns this request_queue */
|
||||
const class cluster* creator;
|
||||
/** Mutexes for thread safety */
|
||||
std::mutex in_mutex;
|
||||
std::mutex out_mutex;
|
||||
/** In and out threads */
|
||||
std::thread* in_thread;
|
||||
std::thread* out_thread;
|
||||
/** Ratelimit bucket counters */
|
||||
std::map<std::string, bucket_t> buckets;
|
||||
/** Queue of requests to be made */
|
||||
std::map<std::string, std::vector<http_request*>> requests_in;
|
||||
/** Completed requests queue */
|
||||
std::queue<std::pair<http_request_completion_t*, http_request*>> responses_out;
|
||||
/** Completed requests to delete */
|
||||
std::multimap<time_t, std::pair<http_request_completion_t*, http_request*>> responses_to_delete;
|
||||
|
||||
/** Set to true if the threads should terminate */
|
||||
bool terminating;
|
||||
/** True if globally rate limited - makes the entire request thread wait */
|
||||
bool globally_ratelimited;
|
||||
/** How many seconds we are globally rate limited for, if globally_ratelimited is true */
|
||||
uint64_t globally_limited_for;
|
||||
|
||||
/** Ports for notifications of request completion.
|
||||
* Why are we using sockets here instead of std::condition_variable? Because
|
||||
* in the future we will want to notify across clusters of completion and state,
|
||||
* and we can't do this across processes with condition variables.
|
||||
*/
|
||||
int in_queue_port;
|
||||
int out_queue_port;
|
||||
int in_queue_listen_sock;
|
||||
int in_queue_connect_sock;
|
||||
int out_queue_listen_sock;
|
||||
int out_queue_connect_sock;
|
||||
|
||||
/** Thread loop functions */
|
||||
void in_loop();
|
||||
void out_loop();
|
||||
|
||||
/** Notify request thread of a new request */
|
||||
void emit_in_queue_signal();
|
||||
|
||||
/** Notify completion thread of new completed request */
|
||||
void emit_out_queue_signal();
|
||||
public:
|
||||
/** Constructor
|
||||
* @param owner The creating cluster
|
||||
*/
|
||||
request_queue(const class cluster* owner);
|
||||
|
||||
/** Destructor */
|
||||
~request_queue();
|
||||
|
||||
/** Put a http_request into the request queue. You should ALWAYS "new" an object
|
||||
* to pass to here -- don't submit an object that's on the stack!
|
||||
* @param req request to add
|
||||
*/
|
||||
void post_request(http_request *req);
|
||||
};
|
||||
|
||||
};
|
202
vendor/DPP/include/dpp/role.h
vendored
202
vendor/DPP/include/dpp/role.h
vendored
@ -1,202 +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 {
|
||||
|
||||
/** Various flags related to dpp::role */
|
||||
enum role_flags {
|
||||
r_hoist = 0b00000001, //!< Hoisted role
|
||||
r_managed = 0b00000010, //!< Managed role (introduced by a bot or application)
|
||||
r_mentionable = 0b00000100, //!< Mentionable with an @ping
|
||||
r_premium_subscriber = 0b00001000, //!< This is set for the role given to nitro
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents the various discord permissions
|
||||
*/
|
||||
enum role_permissions : uint64_t {
|
||||
p_create_instant_invite = 0x00000001, //!< allows creationboosters of instant invites
|
||||
p_kick_members = 0x00000002, //!< allows kicking members
|
||||
p_ban_members = 0x00000004, //!< allows banning members
|
||||
p_administrator = 0x00000008, //!< allows all permissions and bypasses channel permission overwrites
|
||||
p_manage_channels = 0x00000010, //!< allows management and editing of channels
|
||||
p_manage_guild = 0x00000020, //!< allows management and editing of the guild
|
||||
p_add_reactions = 0x00000040, //!< allows for the addition of reactions to messages
|
||||
p_view_audit_log = 0x00000080, //!< allows for viewing of audit logs
|
||||
p_priority_speaker = 0x00000100, //!< allows for using priority speaker in a voice channel
|
||||
p_stream = 0x00000200, //!< allows the user to go live
|
||||
p_view_channel = 0x00000400, //!< allows guild members to view a channel, which includes reading messages in text channels
|
||||
p_send_messages = 0x00000800, //!< allows for sending messages in a channel
|
||||
p_send_tts_messages = 0x00001000, //!< allows for sending of /tts messages
|
||||
p_manage_messages = 0x00002000, //!< allows for deletion of other users messages
|
||||
p_embed_links = 0x00004000, //!< links sent by users with this permission will be auto-embedded
|
||||
p_attach_files = 0x0000008000, //!< allows for uploading images and files
|
||||
p_read_message_history = 0x0000010000, //!< allows for reading of message history
|
||||
p_mention_everyone = 0x0000020000, //!< allows for using the @everyone and the @here tag to notify users in a channel
|
||||
p_use_external_emojis = 0x0000040000, //!< allows the usage of custom emojis from other servers
|
||||
p_view_guild_insights = 0x0000080000, //!< allows for viewing guild insights
|
||||
p_connect = 0x0000100000, //!< allows for joining of a voice channel
|
||||
p_speak = 0x0000200000, //!< allows for speaking in a voice channel
|
||||
p_mute_members = 0x0000400000, //!< allows for muting members in a voice channel
|
||||
p_deafen_members = 0x0000800000, //!< allows for deafening of members in a voice channel
|
||||
p_move_members = 0x0001000000, //!< allows for moving of members between voice channels
|
||||
p_use_vad = 0x0002000000, //!< allows for using voice-activity-detection in a voice channel
|
||||
p_change_nickname = 0x0004000000, //!< allows for modification of own nickname
|
||||
p_manage_nicknames = 0x0008000000, //!< allows for modification of other users nicknames
|
||||
p_manage_roles = 0x0010000000, //!< allows management and editing of roles
|
||||
p_manage_webhooks = 0x0020000000, //!< allows management and editing of webhooks
|
||||
p_manage_emojis = 0x0040000000, //!< allows management and editing of emojis
|
||||
p_use_slash_commands = 0x0080000000, //!< allows members to use slash commands
|
||||
p_request_to_speak = 0x0100000000, //!< allows for requesting to speak in stage channels. (Discord: This permission is under active development and may be changed or removed.)
|
||||
p_manage_threads = 0x0400000000, //!< allows for deleting and archiving threads, and viewing all private threads
|
||||
p_use_public_threads = 0x0800000000, //!< allows for creating and participating in thread
|
||||
p_use_private_threads = 0x1000000000, //!< allows for creating and participating in private thread
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a role within a dpp::guild
|
||||
*/
|
||||
class CoreExport role : public managed {
|
||||
public:
|
||||
/** Role name */
|
||||
std::string name;
|
||||
/** Guild id */
|
||||
snowflake guild_id;
|
||||
/** Role colour */
|
||||
uint32_t colour;
|
||||
/** Role position */
|
||||
uint8_t position;
|
||||
/** Role permissions bitmask values from dpp::role_permissions */
|
||||
uint64_t permissions;
|
||||
/** Role flags from dpp::role_flags */
|
||||
uint8_t flags;
|
||||
/** Integration id if any (e.g. role is a bot's role created when it was invited) */
|
||||
snowflake integration_id;
|
||||
/** Bot id if any (e.g. role is a bot's role created when it was invited) */
|
||||
snowflake bot_id;
|
||||
|
||||
/** Default constructor */
|
||||
role();
|
||||
|
||||
/** Default destructor */
|
||||
virtual ~role();
|
||||
|
||||
/** Fill this role from json.
|
||||
* @param guild_id the guild id to place in the json
|
||||
* @param j The json data
|
||||
* @return A reference to self
|
||||
*/
|
||||
role& fill_from_json(snowflake guild_id, nlohmann::json* j);
|
||||
|
||||
/** Build a json string from this object.
|
||||
* @param with_id true if the ID is to be included in the json text
|
||||
* @return The json of the role
|
||||
*/
|
||||
std::string build_json(bool with_id = false) const;
|
||||
|
||||
/** True if the role is hoisted */
|
||||
bool is_hoisted() const;
|
||||
/** True if the role is mentionable */
|
||||
bool is_mentionable() const;
|
||||
/** True if the role is managed (belongs to a bot or application) */
|
||||
bool is_managed() const;
|
||||
/** True if has create instant invite permission */
|
||||
bool has_create_instant_invite() const;
|
||||
/** True if has the kick members permission */
|
||||
bool has_kick_members() const;
|
||||
/** True if has the ban members permission */
|
||||
bool has_ban_members() const;
|
||||
/** True if has the administrator permission */
|
||||
bool has_administrator() const;
|
||||
/** True if has the manage channels permission */
|
||||
bool has_manage_channels() const;
|
||||
/** True if has the manage guild permission */
|
||||
bool has_manage_guild() const;
|
||||
/** True if has the add reactions permission */
|
||||
bool has_add_reactions() const;
|
||||
/** True if has the view audit log permission */
|
||||
bool has_view_audit_log() const;
|
||||
/** True if has the priority speaker permission */
|
||||
bool has_priority_speaker() const;
|
||||
/** True if has the stream permission */
|
||||
bool has_stream() const;
|
||||
/** True if has the view channel permission */
|
||||
bool has_view_channel() const;
|
||||
/** True if has the send messages permission */
|
||||
bool has_send_messages() const;
|
||||
/** True if has the send TTS messages permission */
|
||||
bool has_send_tts_messages() const;
|
||||
/** True if has the manage messages permission */
|
||||
bool has_manage_messages() const;
|
||||
/** True if has the embed links permission */
|
||||
bool has_embed_links() const;
|
||||
/** True if has the attach files permission */
|
||||
bool has_attach_files() const;
|
||||
/** True if has the read message history permission */
|
||||
bool has_read_message_history() const;
|
||||
/** True if has the mention \@everyone and \@here permission */
|
||||
bool has_mention_everyone() const;
|
||||
/** True if has the use external emojis permission */
|
||||
bool has_use_external_emojis() const;
|
||||
/** True if has the view guild insights permission */
|
||||
bool has_view_guild_insights() const;
|
||||
/** True if has the connect voice permission */
|
||||
bool has_connect() const;
|
||||
/** True if has the speak permission */
|
||||
bool has_speak() const;
|
||||
/** True if has the mute members permission */
|
||||
bool has_mute_members() const;
|
||||
/** True if has the deafen members permission */
|
||||
bool has_deafen_members() const;
|
||||
/** True if has the move members permission */
|
||||
bool has_move_members() const;
|
||||
/** True if has use voice activity detection permission */
|
||||
bool has_use_vad() const;
|
||||
/** True if has the change nickname permission */
|
||||
bool has_change_nickname() const;
|
||||
/** True if has the manage nicknames permission */
|
||||
bool has_manage_nicknames() const;
|
||||
/** True if has the manage roles permission */
|
||||
bool has_manage_roles() const;
|
||||
/** True if has the manage webhooks permission */
|
||||
bool has_manage_webhooks() const;
|
||||
/** True if has the manage emojis permission */
|
||||
bool has_manage_emojis() const;
|
||||
/** True if has the use slash commands permission*/
|
||||
bool has_use_slash_commands() const;
|
||||
/** True if has the request to speak permission*/
|
||||
bool has_request_to_speak() const;
|
||||
/** True if has the manage threads permission*/
|
||||
bool has_manage_threads() const;
|
||||
/** True if has the use public threads permission*/
|
||||
bool has_use_public_threads() const;
|
||||
/** True if has the use private threads permission*/
|
||||
bool has_use_private_threads() const;
|
||||
};
|
||||
|
||||
/** A group of roles */
|
||||
typedef std::unordered_map<snowflake, role> role_map;
|
||||
|
||||
};
|
||||
|
569
vendor/DPP/include/dpp/slashcommand.h
vendored
569
vendor/DPP/include/dpp/slashcommand.h
vendored
@ -1,569 +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 <variant>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/json_fwd.hpp>
|
||||
#include <dpp/message.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents command option types.
|
||||
* These are the possible parameter value types.
|
||||
*/
|
||||
enum command_option_type : uint8_t {
|
||||
/** A sub-command */
|
||||
co_sub_command = 1,
|
||||
/** A sub-command group */
|
||||
co_sub_command_group = 2,
|
||||
/** A string value */
|
||||
co_string = 3,
|
||||
/** An integer value */
|
||||
co_integer = 4,
|
||||
/** A boolean value */
|
||||
co_boolean = 5,
|
||||
/** A user snowflake id */
|
||||
co_user = 6,
|
||||
/** A channel snowflake id */
|
||||
co_channel = 7,
|
||||
/** A role snowflake id */
|
||||
co_role = 8
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief This type is a variant that can hold any of the potential
|
||||
* native data types represented by the enum above.
|
||||
* It is used in interactions.
|
||||
*
|
||||
* std::monostate indicates an invalid parameter value, e.g. an unfilled optional parameter.
|
||||
*/
|
||||
typedef std::variant<std::monostate, std::string, int32_t, bool, snowflake> command_value;
|
||||
|
||||
/**
|
||||
* @brief This struct represents choices in a multiple choice option
|
||||
* for a command parameter.
|
||||
* It has both a string name, and a value parameter which is a variant,
|
||||
* meaning it can hold different potential types (see dpp::command_value)
|
||||
* that you can retrieve with std::get().
|
||||
*/
|
||||
struct CoreExport command_option_choice {
|
||||
std::string name; //!< Option name (1-32 chars)
|
||||
command_value value; //!< Option value
|
||||
|
||||
/**
|
||||
* @brief Construct a new command option choice object
|
||||
*/
|
||||
command_option_choice() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new command option choice object
|
||||
*
|
||||
* @param n name to initialise with
|
||||
* @param v value to initialise with
|
||||
*/
|
||||
command_option_choice(const std::string &n, command_value v);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to serialize a command_option_choice to json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param choice command_option_choice to be serialized
|
||||
*/
|
||||
void to_json(nlohmann::json& j, const command_option_choice& choice);
|
||||
|
||||
/**
|
||||
* @brief Each command option is a command line parameter.
|
||||
* It can have a type (see dpp::command_option_type), a name,
|
||||
* a description, can be required or optional, and can have
|
||||
* zero or more choices (for multiple choice), plus options.
|
||||
* Adding options acts like sub-commands and can contain more
|
||||
* options.
|
||||
*/
|
||||
struct CoreExport command_option {
|
||||
command_option_type type; //!< Option type (what type of value is accepted)
|
||||
std::string name; //!< Option name (1-32 chars)
|
||||
std::string description; //!< Option description (1-100 chars)
|
||||
bool required; //!< True if this is a mandatory parameter
|
||||
std::vector<command_option_choice> choices; //!< List of choices for multiple choice command
|
||||
std::vector<command_option> options; //!< Sub-commands
|
||||
|
||||
/**
|
||||
* @brief Construct a new command option object
|
||||
*/
|
||||
command_option() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new command option object
|
||||
*
|
||||
* @param t Option type
|
||||
* @param name Option name
|
||||
* @param description Option description
|
||||
* @param required True if this is a mandatory parameter
|
||||
*/
|
||||
command_option(command_option_type t, const std::string &name, const std::string &description, bool required = false);
|
||||
|
||||
/**
|
||||
* @brief Add a multiple choice option
|
||||
*
|
||||
* @param o choice to add
|
||||
* @return command_option& returns a reference to self for chaining of calls
|
||||
*/
|
||||
command_option& add_choice(const command_option_choice &o);
|
||||
|
||||
/**
|
||||
* @brief Add a sub-command option
|
||||
*
|
||||
* @param o Sub-command option to add
|
||||
* @return command_option& return a reference to self for chaining of calls
|
||||
*/
|
||||
command_option& add_option(const command_option &o);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to serialize a command_option to json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param opt command_option to be serialized
|
||||
*/
|
||||
void to_json(nlohmann::json& j, const command_option& opt);
|
||||
|
||||
/**
|
||||
* @brief Response types when responding to an interaction within on_interaction_create.
|
||||
* Do not use ir_acknowledge or ir::channel_message, as these are deprecated in the
|
||||
* Discord API spec. They are listed in this enum for completeness.
|
||||
*/
|
||||
enum interaction_response_type {
|
||||
ir_pong = 1, //!< ACK a Ping
|
||||
ir_channel_message_with_source = 4, //!< respond to an interaction with a message
|
||||
ir_deferred_channel_message_with_source = 5, //!< ACK an interaction and edit a response later, the user sees a loading state
|
||||
ir_deferred_update_message = 6, //!< for components, ACK an interaction and edit the original message later; the user does not see a loading state
|
||||
ir_update_message = 7 //!< for components, edit the message the component was attached to
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A response to an interaction, used to reply to a command and initiate
|
||||
* a message, which can be hidden from others (ephemeral) or visible to all.
|
||||
*
|
||||
* The dpp::interaction_response object wraps a dpp::message object. To set the
|
||||
* message as 'ephemeral' (e.g. only the command issuer can see it) you should
|
||||
* add the dpp::m_ephemeral flag to the dpp::message::flags field. e.g.:
|
||||
*
|
||||
* `mymessage.flags |= dpp::m_ephemeral;`
|
||||
*/
|
||||
struct CoreExport interaction_response {
|
||||
|
||||
/**
|
||||
* @brief Response type from dpp::interaction_response_type.
|
||||
* Should be one of ir_pong, ir_channel_message_with_source,
|
||||
* or ir_deferred_channel_message_with_source.
|
||||
*/
|
||||
interaction_response_type type;
|
||||
|
||||
/**
|
||||
* @brief A message object. This pointer is always valid
|
||||
* while the containing interaction_response exists.
|
||||
*/
|
||||
struct message* msg;
|
||||
|
||||
/**
|
||||
* @brief Construct a new interaction response object
|
||||
*/
|
||||
interaction_response();
|
||||
|
||||
/**
|
||||
* @brief Construct a new interaction response object
|
||||
*
|
||||
* @param t Type of reply
|
||||
* @param m Message to reply with
|
||||
*/
|
||||
interaction_response(interaction_response_type t, const struct message& m);
|
||||
|
||||
/**
|
||||
* @brief Fill object properties from JSON
|
||||
*
|
||||
* @param j JSON to fill from
|
||||
* @return interaction_response& Reference to self
|
||||
*/
|
||||
interaction_response& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build a json string for this object
|
||||
*
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
std::string build_json() const;
|
||||
|
||||
/**
|
||||
* @brief Destroy the interaction response object
|
||||
*/
|
||||
~interaction_response();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Resolved snowflake ids to users, guild members, roles and channels.
|
||||
*/
|
||||
struct CoreExport command_resolved {
|
||||
/**
|
||||
* @brief Resolved users
|
||||
*/
|
||||
std::map<dpp::snowflake, dpp::user> users;
|
||||
/**
|
||||
* @brief Resolved guild members
|
||||
*/
|
||||
std::map<dpp::snowflake, dpp::guild_member> members;
|
||||
/**
|
||||
* @brief Resolved roles
|
||||
*/
|
||||
std::map<dpp::snowflake, dpp::role> roles;
|
||||
/**
|
||||
* @brief Resolved channels
|
||||
*/
|
||||
std::map<dpp::snowflake, dpp::channel> channels;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Values in the command interaction.
|
||||
* These are the values specified by the user when actually issuing
|
||||
* the command on a channel or in DM.
|
||||
*/
|
||||
struct CoreExport command_data_option {
|
||||
std::string name; //!< the name of the parameter
|
||||
command_option_type type; //!< value of ApplicationCommandOptionType
|
||||
command_value value; //!< Optional: the value of the pair
|
||||
std::vector<command_data_option> options; //!< Optional: present if this option is a group or subcommand
|
||||
dpp::snowflake target_id; //!< Non-zero target ID for context menu actions
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to deserialize a command_data_option from json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param cdo command_data_option to be deserialized
|
||||
*/
|
||||
void from_json(const nlohmann::json& j, command_data_option& cdo);
|
||||
|
||||
/** Types of interaction in the dpp::interaction class
|
||||
*/
|
||||
enum interaction_type {
|
||||
it_ping = 1, //!< ping
|
||||
it_application_command = 2, //!< application command (slash command)
|
||||
it_component_button = 3 //!< button click (component interaction)
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Details of a command within an interaction.
|
||||
* This subobject represents the application command associated
|
||||
* with the interaction.
|
||||
*/
|
||||
struct CoreExport command_interaction {
|
||||
snowflake id; //!< the ID of the invoked command
|
||||
std::string name; //!< the name of the invoked command
|
||||
std::vector<command_data_option> options; //!< Optional: the params + values from the user
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to deserialize a command_interaction from json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param ci command_interaction to be deserialized
|
||||
*/
|
||||
void from_json(const nlohmann::json& j, command_interaction& ci);
|
||||
|
||||
enum component_type_t {
|
||||
cotype_button = 2,
|
||||
cotype_select = 3
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A button click for a button component
|
||||
*/
|
||||
struct CoreExport component_interaction {
|
||||
uint8_t component_type;
|
||||
std::string custom_id;
|
||||
std::vector<std::string> values;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to deserialize a component_interaction from json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param bi button_interaction to be deserialized
|
||||
*/
|
||||
void from_json(const nlohmann::json& j, component_interaction& bi);
|
||||
|
||||
/**
|
||||
* @brief An interaction represents a user running a command and arrives
|
||||
* via the dpp::cluster::on_interaction_create event.
|
||||
*/
|
||||
class CoreExport interaction : public managed {
|
||||
public:
|
||||
snowflake application_id; //!< id of the application this interaction is for
|
||||
uint8_t type; //!< the type of interaction
|
||||
std::variant<command_interaction, component_interaction> data; //!< Optional: the command data payload
|
||||
snowflake guild_id; //!< Optional: the guild it was sent from
|
||||
snowflake channel_id; //!< Optional: the channel it was sent from
|
||||
snowflake message_id; //!< Originating message id
|
||||
guild_member member; //!< Optional: guild member data for the invoking user, including permissions
|
||||
user usr; //!< Optional: user object for the invoking user, if invoked in a DM
|
||||
std::string token; //!< a continuation token for responding to the interaction
|
||||
uint8_t version; //!< read-only property, always 1
|
||||
command_resolved resolved; //!< Resolved user/role etc
|
||||
|
||||
/**
|
||||
* @brief Fill object properties from JSON
|
||||
*
|
||||
* @param j JSON to fill from
|
||||
* @return interaction& Reference to self
|
||||
*/
|
||||
interaction& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build a json string for this object
|
||||
*
|
||||
* @param with_id True if to include the ID in the JSON
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
std::string build_json(bool with_id = false) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to deserialize an interaction from json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param i interaction to be deserialized
|
||||
*/
|
||||
void from_json(const nlohmann::json& j, interaction& i);
|
||||
|
||||
/**
|
||||
* @brief type of permission in the dpp::command_permission class
|
||||
*/
|
||||
enum command_permission_type {
|
||||
cpt_role = 1,
|
||||
cpt_user = 2,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Application command permissions allow you to enable or
|
||||
* disable commands for specific users or roles within a guild
|
||||
*/
|
||||
class CoreExport command_permission {
|
||||
public:
|
||||
snowflake id; //!< the ID of the role or uses
|
||||
command_permission_type type; //!< the type of permission
|
||||
bool permission; //!< true to allow, false, to disallow
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to serialize a command_permission to json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param cp command_permission to be serialized
|
||||
*/
|
||||
void to_json(nlohmann::json& j, const command_permission& cp);
|
||||
|
||||
/**
|
||||
* @brief Returned when fetching the permissions for a command in a guild.
|
||||
*/
|
||||
class CoreExport guild_command_permissions {
|
||||
public:
|
||||
snowflake id; //!< the id of the command
|
||||
snowflake application_id; //!< the id of the application the command belongs to
|
||||
snowflake guild_id; //!< the id of the guild
|
||||
std::vector<command_permission> permissions; //!< the permissions for the command in the guild
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to serialize a guild_command_permissions to json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param gcp guild_command_permissions to be serialized
|
||||
*/
|
||||
void to_json(nlohmann::json& j, const guild_command_permissions& gcp);
|
||||
|
||||
enum slashcommand_contextmenu_type {
|
||||
ctxm_none = 0,
|
||||
ctxm_chat_input = 1, //!< DEFAULT, these are the slash commands you're used to
|
||||
ctxm_user = 2, //!< Add command to user context menu
|
||||
ctxm_message = 3 //!< Add command to message context menu
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents an application command, created by your bot
|
||||
* either globally, or on a guild.
|
||||
*/
|
||||
class CoreExport slashcommand : public managed {
|
||||
public:
|
||||
/**
|
||||
* @brief Application id (usually matches your bots id)
|
||||
*/
|
||||
snowflake application_id;
|
||||
|
||||
/**
|
||||
* @brief Context menu type, defaults to none
|
||||
*
|
||||
*/
|
||||
slashcommand_contextmenu_type type;
|
||||
|
||||
/**
|
||||
* @brief Command name (1-32 chars)
|
||||
*/
|
||||
std::string name;
|
||||
|
||||
/**
|
||||
* @brief Command description (1-100 chars)
|
||||
*/
|
||||
std::string description;
|
||||
|
||||
/**
|
||||
* @brief Command options (parameters)
|
||||
*/
|
||||
std::vector<command_option> options;
|
||||
|
||||
/**
|
||||
* @brief whether the command is enabled by default when the app is added to a guild
|
||||
*/
|
||||
bool default_permission;
|
||||
|
||||
/**
|
||||
* @brief command permissions
|
||||
*/
|
||||
std::vector<command_permission> permissions;
|
||||
|
||||
/**
|
||||
* @brief Construct a new slashcommand object
|
||||
*/
|
||||
slashcommand();
|
||||
|
||||
/**
|
||||
* @brief Destroy the slashcommand object
|
||||
*/
|
||||
~slashcommand();
|
||||
|
||||
/**
|
||||
* @brief Add an option (parameter)
|
||||
*
|
||||
* @param o option (parameter) to add
|
||||
* @return slashcommand& reference to self for chaining of calls
|
||||
*/
|
||||
slashcommand& add_option(const command_option &o);
|
||||
|
||||
/**
|
||||
* @brief Set the type of the slash command (only for context menu entries)
|
||||
*
|
||||
* @param _type Type of context menu entry this command represents
|
||||
* @return slashcommand& reference to self for chaining of calls
|
||||
*/
|
||||
slashcommand& set_type(slashcommand_contextmenu_type _type);
|
||||
|
||||
/**
|
||||
* @brief Set the name of the command
|
||||
*
|
||||
* @param n name of command
|
||||
* @return slashcommand& reference to self for chaining of calls
|
||||
*/
|
||||
slashcommand& set_name(const std::string &n);
|
||||
|
||||
/**
|
||||
* @brief Set the description of the command
|
||||
*
|
||||
* @param d description
|
||||
* @return slashcommand& reference to self for chaining of calls
|
||||
*/
|
||||
slashcommand& set_description(const std::string &d);
|
||||
|
||||
/**
|
||||
* @brief Set the application id of the command
|
||||
*
|
||||
* @param i application id
|
||||
* @return slashcommand& reference to self for chaining of calls
|
||||
*/
|
||||
slashcommand& set_application_id(snowflake i);
|
||||
|
||||
/**
|
||||
* @brief Adds a permission to the command
|
||||
*
|
||||
* @param p permission to add
|
||||
* @return slashcommand& reference to self for chaining of calls
|
||||
*/
|
||||
slashcommand& add_permission(const command_permission& p);
|
||||
|
||||
/**
|
||||
* @brief Disable default permissions, command will be unusable unless
|
||||
* permissions are overridden with add_permission and
|
||||
* dpp::guild_command_edit_permissions
|
||||
*
|
||||
* @return slashcommand& reference to self for chaining of calls
|
||||
*/
|
||||
slashcommand& disable_default_permissions();
|
||||
|
||||
/**
|
||||
* @brief Fill object properties from JSON
|
||||
*
|
||||
* @param j JSON to fill from
|
||||
* @return slashcommand& Reference to self
|
||||
*/
|
||||
slashcommand& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build a json string for this object
|
||||
*
|
||||
* @param with_id True if to include the ID in the JSON
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
std::string build_json(bool with_id = false) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to serialize a slashcommand to json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param cmd slashcommand to be serialized
|
||||
*/
|
||||
void to_json(nlohmann::json& j, const slashcommand& cmd);
|
||||
|
||||
/**
|
||||
* @brief A group of application slash commands
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, slashcommand> slashcommand_map;
|
||||
|
||||
};
|
165
vendor/DPP/include/dpp/sslclient.h
vendored
165
vendor/DPP/include/dpp/sslclient.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 <string>
|
||||
#include <functional>
|
||||
#include <dpp/discord.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/** This is an opaque class containing openssl library specific structures.
|
||||
* We define it this way so that the public facing D++ library doesnt require
|
||||
* the openssl headers be available to build against it.
|
||||
*/
|
||||
class opensslcontext;
|
||||
|
||||
/**
|
||||
* @brief Implements a simple non-blocking SSL stream client.
|
||||
*
|
||||
* Note that although the design is non-blocking the Run() method will
|
||||
* execute in an infinite loop until the socket disconnects. This is intended
|
||||
* to be run within a std::thread.
|
||||
*/
|
||||
class CoreExport ssl_client
|
||||
{
|
||||
protected:
|
||||
/** Input buffer received from openssl */
|
||||
std::string buffer;
|
||||
|
||||
/** Output buffer for sending to openssl */
|
||||
std::string obuffer;
|
||||
|
||||
/** True if in nonblocking mode. The socket switches to nonblocking mode
|
||||
* once ReadLoop is called.
|
||||
*/
|
||||
bool nonblocking;
|
||||
|
||||
/** Raw file descriptor of connection */
|
||||
SOCKET sfd;
|
||||
|
||||
/** Openssl opaque contexts */
|
||||
opensslcontext* ssl;
|
||||
|
||||
/** SSL cipher in use */
|
||||
std::string cipher;
|
||||
|
||||
/** For timers */
|
||||
time_t last_tick;
|
||||
|
||||
/** Hostname connected to */
|
||||
std::string hostname;
|
||||
|
||||
/** Port connected to */
|
||||
std::string port;
|
||||
|
||||
/** Bytes out */
|
||||
uint64_t bytes_out;
|
||||
|
||||
/** Bytes in */
|
||||
uint64_t bytes_in;
|
||||
|
||||
/** Called every second */
|
||||
virtual void one_second_timer();
|
||||
|
||||
/** Start connection */
|
||||
virtual void Connect();
|
||||
public:
|
||||
/** Get total bytes sent */
|
||||
uint64_t get_bytes_out();
|
||||
|
||||
/** Get total bytes received */
|
||||
uint64_t get_bytes_in();
|
||||
|
||||
/** Get SSL cipher name */
|
||||
std::string get_cipher();
|
||||
|
||||
/**
|
||||
* @brief Attaching an additional file descriptor to this function will send notifications when there is data to read.
|
||||
*
|
||||
* NOTE: Only hook this if you NEED it as it can increase CPU usage of the thread!
|
||||
* Returning -1 means that you don't want to be notified.
|
||||
*/
|
||||
std::function<int()> custom_readable_fd;
|
||||
|
||||
/**
|
||||
* @brief Attaching an additional file descriptor to this function will send notifications when you are able to write
|
||||
* to the socket.
|
||||
*
|
||||
* NOTE: Only hook this if you NEED it as it can increase CPU usage of the thread! You should toggle this
|
||||
* to -1 when you do not have anything to write otherwise it'll keep triggering repeatedly (it is level triggered).
|
||||
*/
|
||||
std::function<int()> custom_writeable_fd;
|
||||
|
||||
/**
|
||||
* @brief This event will be called when you can read from the custom fd
|
||||
*/
|
||||
std::function<void()> custom_readable_ready;
|
||||
|
||||
/**
|
||||
* @brief This event will be called when you can write to a custom fd
|
||||
*/
|
||||
std::function<void()> custom_writeable_ready;
|
||||
|
||||
/**
|
||||
* @brief Connect to a specified host and port. Throws std::runtime_error on fatal error.
|
||||
* @param _hostname The hostname to connect to
|
||||
* @param _port the Port number to connect to
|
||||
*/
|
||||
ssl_client(const std::string &_hostname, const std::string &_port = "443");
|
||||
|
||||
/**
|
||||
* @brief Nonblocking I/O loop
|
||||
*/
|
||||
void read_loop();
|
||||
|
||||
/**
|
||||
* @brief Destroy the ssl_client object
|
||||
*/
|
||||
virtual ~ssl_client();
|
||||
|
||||
/**
|
||||
* @brief Handle input from the input buffer.
|
||||
* @param buffer the buffer content. Will be modified removing any processed front elements
|
||||
*/
|
||||
virtual bool handle_buffer(std::string &buffer);
|
||||
|
||||
/**
|
||||
* @brief Write to the output buffer.
|
||||
* @param data Data to be written to the buffer
|
||||
*/
|
||||
virtual void write(const std::string &data);
|
||||
|
||||
/**
|
||||
* @brief Close SSL connection
|
||||
*/
|
||||
virtual void close();
|
||||
|
||||
/**
|
||||
* @brief Log a message
|
||||
*
|
||||
* @param severity severity of log message
|
||||
* @param msg Log message to send
|
||||
*/
|
||||
virtual void log(dpp::loglevel severity, const std::string &msg) const;
|
||||
};
|
||||
|
||||
};
|
128
vendor/DPP/include/dpp/stringops.h
vendored
128
vendor/DPP/include/dpp/stringops.h
vendored
@ -1,128 +0,0 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++ - A Lightweight C++ Library for Discord
|
||||
*
|
||||
* stringops.h taken from TriviaBot
|
||||
*
|
||||
* Copyright 2004 Craig Edwards <support@sporks.gg>
|
||||
*
|
||||
* Core based on Sporks, the Learning Discord Bot, Craig Edwards (c) 2019.
|
||||
*
|
||||
* 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 <string>
|
||||
#include <iomanip>
|
||||
#include <locale>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
/**
|
||||
* @brief Convert a string to lowercase using tolower()
|
||||
*
|
||||
* @tparam T type of string
|
||||
* @param s String to lowercase
|
||||
* @return std::basic_string<T> lowercased string
|
||||
*/
|
||||
template <typename T> std::basic_string<T> lowercase(const std::basic_string<T>& s)
|
||||
{
|
||||
std::basic_string<T> s2 = s;
|
||||
std::transform(s2.begin(), s2.end(), s2.begin(), tolower);
|
||||
return std::move(s2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a string to uppercase using toupper()
|
||||
*
|
||||
* @tparam T type of string
|
||||
* @param s String to uppercase
|
||||
* @return std::basic_string<T> uppercased string
|
||||
*/
|
||||
template <typename T> std::basic_string<T> uppercase(const std::basic_string<T>& s)
|
||||
{
|
||||
std::basic_string<T> s2 = s;
|
||||
std::transform(s2.begin(), s2.end(), s2.begin(), toupper);
|
||||
return std::move(s2);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief trim from end of string (right)
|
||||
*
|
||||
* @param s String to trim
|
||||
* @return std::string trimmed string
|
||||
*/
|
||||
inline std::string rtrim(std::string s)
|
||||
{
|
||||
s.erase(s.find_last_not_of(" \t\n\r\f\v") + 1);
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief trim from beginning of string (left)
|
||||
*
|
||||
* @param s string to trim
|
||||
* @return std::string trimmed string
|
||||
*/
|
||||
inline std::string ltrim(std::string s)
|
||||
{
|
||||
s.erase(0, s.find_first_not_of(" \t\n\r\f\v"));
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Trim from both ends of string (right then left)
|
||||
*
|
||||
* @param s string to trim
|
||||
* @return std::string trimmed string
|
||||
*/
|
||||
inline std::string trim(std::string s)
|
||||
{
|
||||
return ltrim(rtrim(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add commas to a string (or dots) based on current locale server-side
|
||||
*
|
||||
* @tparam T type of numeric value
|
||||
* @param value Value
|
||||
* @return std::string number with commas added
|
||||
*/
|
||||
template<class T> std::string Comma(T value)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss.imbue(std::locale(""));
|
||||
ss << std::fixed << value;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert any value from a string to another type using stringstream.
|
||||
* The optional second parameter indicates the format of the input string,
|
||||
* e.g. std::dec for decimal, std::hex for hex, std::oct for octal.
|
||||
*
|
||||
* @tparam T Type to convert to
|
||||
* @param s String to convert from
|
||||
* @param f Numeric base, e.g. `std::dec` or `std::hex`
|
||||
* @return T Returned numeric value
|
||||
*/
|
||||
template <typename T> T from_string(const std::string &s, std::ios_base & (*f)(std::ios_base&))
|
||||
{
|
||||
T t;
|
||||
std::istringstream iss(s);
|
||||
iss >> f, iss >> t;
|
||||
return t;
|
||||
}
|
||||
|
249
vendor/DPP/include/dpp/user.h
vendored
249
vendor/DPP/include/dpp/user.h
vendored
@ -1,249 +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 Various bitmask flags used to represent information about a dpp::user
|
||||
*/
|
||||
enum user_flags {
|
||||
/// User is a bot
|
||||
u_bot = 0b00000000000000000000001,
|
||||
/// User is a system user (Clyde!)
|
||||
u_system = 0b00000000000000000000010,
|
||||
/// User has multi-factor authentication enabled
|
||||
u_mfa_enabled = 0b00000000000000000000100,
|
||||
/// User is verified (verified email address)
|
||||
u_verified = 0b00000000000000000001000,
|
||||
/// User has full nitro
|
||||
u_nitro_full = 0b00000000000000000010000,
|
||||
/// User has nitro classic
|
||||
u_nitro_classic = 0b00000000000000000100000,
|
||||
/// User is discord staff
|
||||
u_discord_employee = 0b00000000000000001000000,
|
||||
/// User owns a partnered server
|
||||
u_partnered_owner = 0b00000000000000010000000,
|
||||
/// User is a member of hypesquad events
|
||||
u_hypesquad_events = 0b00000000000000100000000,
|
||||
/// User has BugHunter level 1
|
||||
u_bughunter_1 = 0b00000000000001000000000,
|
||||
/// User is a member of House Bravery
|
||||
u_house_bravery = 0b00000000000010000000000,
|
||||
/// User is a member of House Brilliance
|
||||
u_house_brilliance = 0b00000000000100000000000,
|
||||
/// User is a member of House Balance
|
||||
u_house_balanace = 0b00000000001000000000000,
|
||||
/// User is an early supporter
|
||||
u_early_supporter = 0b00000000010000000000000,
|
||||
/// User is a team user
|
||||
u_team_user = 0b00000000100000000000000,
|
||||
/// User is has Bug Hunter level 2
|
||||
u_bughunter_2 = 0b00000001000000000000000,
|
||||
/// User is a verified bot
|
||||
u_verified_bot = 0b00000010000000000000000,
|
||||
/// User has the Early Verified Bot Developer badge
|
||||
u_verified_bot_dev = 0b00000100000000000000000,
|
||||
/// User's icon is animated
|
||||
u_animated_icon = 0b00001000000000000000000,
|
||||
/// User is a certified moderator
|
||||
u_certified_moderator = 0b00010000000000000000000
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a user on discord. May or may not be a member of a dpp::guild.
|
||||
*/
|
||||
class CoreExport user : public managed {
|
||||
public:
|
||||
/** Discord username */
|
||||
std::string username;
|
||||
/** Discriminator (aka tag), 4 digits usually displayed with leading zeroes */
|
||||
uint16_t discriminator;
|
||||
/** Avatar hash */
|
||||
utility::iconhash avatar;
|
||||
/** Flags built from a bitmask of values in dpp::user_flags */
|
||||
uint32_t flags;
|
||||
/** Reference count of how many guilds this user is in */
|
||||
uint8_t refcount;
|
||||
|
||||
/**
|
||||
* @brief Construct a new user object
|
||||
*/
|
||||
user();
|
||||
|
||||
/**
|
||||
* @brief Destroy the user object
|
||||
*/
|
||||
virtual ~user();
|
||||
|
||||
/** Fill this record from json.
|
||||
* @param j The json to fill this record from
|
||||
* @return Reference to self
|
||||
*/
|
||||
user& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Get the avatar url of the user object
|
||||
*
|
||||
* @return std::string avatar url
|
||||
*/
|
||||
std::string get_avatar_url() const;
|
||||
|
||||
/**
|
||||
* @brief User is a bot
|
||||
*
|
||||
* @return True if the user is a bot
|
||||
*/
|
||||
bool is_bot() const;
|
||||
/**
|
||||
* @brief User is a system user (Clyde)
|
||||
*
|
||||
* @return true if user is a system user
|
||||
*/
|
||||
bool is_system() const;
|
||||
/**
|
||||
* @brief User has multi-factor authentication enabled
|
||||
*
|
||||
* @return true if multi-factor is enabled
|
||||
*/
|
||||
bool is_mfa_enabled() const;
|
||||
/**
|
||||
* @brief Return true if user has verified account
|
||||
*
|
||||
* @return true if verified
|
||||
*/
|
||||
bool is_verified() const;
|
||||
/**
|
||||
* @brief Return true if user has full nitro.
|
||||
* This is mutually exclusive with full nitro.
|
||||
*
|
||||
* @return true if user has full nitro
|
||||
*/
|
||||
bool has_nitro_full() const;
|
||||
/**
|
||||
* @brief Return true if user has nitro classic.
|
||||
* This is mutually exclusive with nitro classic.
|
||||
*
|
||||
* @return true if user has nitro classic
|
||||
*/
|
||||
bool has_nitro_classic() const;
|
||||
/**
|
||||
* @brief Return true if user is a discord employee
|
||||
*
|
||||
* @return true if user is discord staff
|
||||
*/
|
||||
bool is_discord_employee() const;
|
||||
/**
|
||||
* @brief Return true if user owns a partnered server
|
||||
*
|
||||
* @return true if user has partnered server
|
||||
*/
|
||||
bool is_partnered_owner() const;
|
||||
/**
|
||||
* @brief Return true if user has hypesquad events
|
||||
*
|
||||
* @return true if has hypesquad events
|
||||
*/
|
||||
bool has_hypesquad_events() const;
|
||||
/**
|
||||
* @brief Return true if user has the bughunter level 1 badge
|
||||
*
|
||||
* @return true if has bughunter level 1
|
||||
*/
|
||||
bool is_bughunter_1() const;
|
||||
/**
|
||||
* @brief Return true if user is in house bravery
|
||||
*
|
||||
* @return true if in house bravery
|
||||
*/
|
||||
bool is_house_bravery() const;
|
||||
/**
|
||||
* @brief Return true if user is in house brilliance
|
||||
*
|
||||
* @return true if in house brilliance
|
||||
*/
|
||||
bool is_house_brilliance() const;
|
||||
/**
|
||||
* @brief Return true if user is in house balance
|
||||
*
|
||||
* @return true if in house brilliance
|
||||
*/
|
||||
bool is_house_balanace() const;
|
||||
/**
|
||||
* @brief Return true if user is an early supporter
|
||||
*
|
||||
* @return true if early supporter
|
||||
*/
|
||||
bool is_early_supporter() const;
|
||||
/**
|
||||
* @brief Return true if user is a team user
|
||||
*
|
||||
* @return true if a team user
|
||||
*/
|
||||
bool is_team_user() const;
|
||||
/**
|
||||
* @brief Return true if user has the bughunter level 2 badge
|
||||
*
|
||||
* @return true if has bughunter level 2
|
||||
*/
|
||||
bool is_bughunter_2() const;
|
||||
/**
|
||||
* @brief Return true if user has the verified bot badge
|
||||
*
|
||||
* @return true if verified bot
|
||||
*/
|
||||
bool is_verified_bot() const;
|
||||
/**
|
||||
* @brief Return true if user is an early verified bot developer
|
||||
*
|
||||
* @return true if verified bot developer
|
||||
*/
|
||||
bool is_verified_bot_dev() const;
|
||||
/**
|
||||
* @brief Return true if user is a certified moderator
|
||||
*
|
||||
* @return true if certified moderator
|
||||
*/
|
||||
bool is_certified_moderator() const;
|
||||
/**
|
||||
* @brief Return true if user has an animated icon
|
||||
*
|
||||
* @return true if icon is animated (gif)
|
||||
*/
|
||||
bool has_animated_icon() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief helper function to deserialize a user from json
|
||||
*
|
||||
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
|
||||
*
|
||||
* @param j output json object
|
||||
* @param u user to be deserialized
|
||||
*/
|
||||
void from_json(const nlohmann::json& j, user& u);
|
||||
|
||||
/** A group of users */
|
||||
typedef std::unordered_map<snowflake, user> user_map;
|
||||
|
||||
};
|
31
vendor/DPP/include/dpp/version.h
vendored
31
vendor/DPP/include/dpp/version.h
vendored
@ -1,31 +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
|
||||
|
||||
#if !defined(DPP_VERSION_LONG)
|
||||
#define DPP_VERSION_LONG 0x00090004
|
||||
#define DPP_VERSION_SHORT 090004
|
||||
#define DPP_VERSION_TEXT "D++ 9.0.5 (14-Sep-2021)"
|
||||
|
||||
#define DPP_VERSION_MAJOR ((DPP_VERSION_LONG & 0x00ff0000) >> 16)
|
||||
#define DPP_VERSION_MINOR ((DPP_VERSION_LONG & 0x0000ff00) >> 8)
|
||||
#define DPP_VERSION_PATCH (DPP_VERSION_LONG & 0x000000ff)
|
||||
#endif
|
117
vendor/DPP/include/dpp/voiceregion.h
vendored
117
vendor/DPP/include/dpp/voiceregion.h
vendored
@ -1,117 +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 Flags related to a voice region
|
||||
*/
|
||||
enum voiceregion_flags {
|
||||
v_optimal = 0x00000001,
|
||||
v_deprecated = 0x00000010,
|
||||
v_custom = 0x00000100,
|
||||
v_vip = 0x00001000
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a voice region on discord
|
||||
*/
|
||||
class CoreExport voiceregion {
|
||||
public:
|
||||
/**
|
||||
* @brief Voice server ID
|
||||
*/
|
||||
std::string id;
|
||||
|
||||
/**
|
||||
* @brief Voice server name
|
||||
*/
|
||||
std::string name;
|
||||
|
||||
/**
|
||||
* @brief Flags bitmap
|
||||
*/
|
||||
uint8_t flags;
|
||||
|
||||
/**
|
||||
* @brief Construct a new voiceregion object
|
||||
*/
|
||||
voiceregion();
|
||||
|
||||
/**
|
||||
* @brief Destroy the voiceregion object
|
||||
*/
|
||||
~voiceregion();
|
||||
|
||||
/**
|
||||
* @brief Fill object properties from JSON
|
||||
*
|
||||
* @param j JSON to fill from
|
||||
* @return voiceregion& Reference to self
|
||||
*/
|
||||
voiceregion& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build a json string for this object
|
||||
*
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
std::string build_json() const;
|
||||
|
||||
/**
|
||||
* @brief True if is the optimal voice server
|
||||
*
|
||||
* @return true if optimal
|
||||
*/
|
||||
bool is_optimal() const;
|
||||
|
||||
/**
|
||||
* @brief True if is a deprecated voice server
|
||||
*
|
||||
* @return true if deprecated
|
||||
*/
|
||||
bool is_deprecated() const;
|
||||
|
||||
/**
|
||||
* @brief True if is a custom voice server
|
||||
*
|
||||
* @return true if custom
|
||||
*/
|
||||
bool is_custom() const;
|
||||
|
||||
/**
|
||||
* @brief True if is a VIP voice server
|
||||
*
|
||||
* @return true if VIP
|
||||
*/
|
||||
bool is_vip() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A group of voice regions
|
||||
*/
|
||||
typedef std::unordered_map<std::string, voiceregion> voiceregion_map;
|
||||
|
||||
};
|
105
vendor/DPP/include/dpp/voicestate.h
vendored
105
vendor/DPP/include/dpp/voicestate.h
vendored
@ -1,105 +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 Bit mask flags relating to voice states
|
||||
*/
|
||||
enum voicestate_flags {
|
||||
vs_deaf = 0b00000001, //!< Deafened
|
||||
vs_mute = 0b00000010, //!< Muted
|
||||
vs_self_mute = 0b00000100, //!< Self Muted
|
||||
vs_self_deaf = 0b00001000, //!< Self Deafened
|
||||
vs_self_stream = 0b00010000, //!< Self Streaming
|
||||
vs_self_video = 0b00100000, //!< Self Video
|
||||
vs_suppress = 0b01000000 //!< Suppression
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents the voice state of a user on a guild
|
||||
* These are stored in the dpp::guild object, and accessible there,
|
||||
* or via dpp::channel::get_voice_members
|
||||
*/
|
||||
class CoreExport voicestate {
|
||||
public:
|
||||
class discord_client* shard; //!< Owning shard
|
||||
snowflake guild_id; //!< Optional: the guild id this voice state is for
|
||||
snowflake channel_id; //!< the channel id this user is connected to (may be empty)
|
||||
snowflake user_id; //!< the user id this voice state is for
|
||||
std::string session_id; //!< the session id for this voice state
|
||||
uint8_t flags; //!< Voice state flags
|
||||
|
||||
/**
|
||||
* @brief Construct a new voicestate object
|
||||
*/
|
||||
voicestate();
|
||||
|
||||
/**
|
||||
* @brief Destroy the voicestate object
|
||||
*/
|
||||
~voicestate();
|
||||
|
||||
/**
|
||||
* @brief Fill voicestate object from json data
|
||||
*
|
||||
* @param j JSON data to fill from
|
||||
* @return voicestate& Reference to self
|
||||
*/
|
||||
voicestate& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build json representation of the object
|
||||
*
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
std::string build_json() const;
|
||||
|
||||
/// Return true if user is deafened
|
||||
bool is_deaf() const;
|
||||
|
||||
/// Return true if user is muted
|
||||
bool is_mute() const;
|
||||
|
||||
/// Return true if user muted themselves
|
||||
bool is_self_mute() const;
|
||||
|
||||
/// Return true if user deafened themselves
|
||||
bool is_self_deaf() const;
|
||||
|
||||
/// Return true if the user is streamig
|
||||
bool self_stream() const;
|
||||
|
||||
/// Return true if the user is in video
|
||||
bool self_video() const;
|
||||
|
||||
/// Return true if user is suppressed.
|
||||
/// "HELP HELP I'M BEING SUPPRESSED!"
|
||||
bool is_suppressed() const;
|
||||
};
|
||||
|
||||
/** A container of voicestates */
|
||||
typedef std::unordered_map<std::string, voicestate> voicestate_map;
|
||||
|
||||
};
|
92
vendor/DPP/include/dpp/webhook.h
vendored
92
vendor/DPP/include/dpp/webhook.h
vendored
@ -1,92 +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 Defines types of webhook
|
||||
*/
|
||||
enum webhook_type {
|
||||
w_incoming = 1, //!< Incoming webhook
|
||||
w_channel_follower = 2 //!< Channel following webhook
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a discord webhook
|
||||
*/
|
||||
class CoreExport webhook : public managed {
|
||||
public:
|
||||
uint8_t type; //!< the type of the webhook
|
||||
snowflake guild_id; //!< Optional: the guild id this webhook is for
|
||||
snowflake channel_id; //!< the channel id this webhook is for
|
||||
snowflake user_id; //!< Optional: the user this webhook was created by (not returned when getting a webhook with its token)
|
||||
std::string name; //!< the default name of the webhook (may be empty)
|
||||
std::string avatar; //!< the default avatar of the webhook (may be empty)
|
||||
std::string token; //!< Optional: the secure token of the webhook (returned for Incoming Webhooks)
|
||||
snowflake application_id; //!< the bot/OAuth2 application that created this webhook (may be empty)
|
||||
std::string* image_data; //!< base64 encoded image data if uploading a new image
|
||||
|
||||
/**
|
||||
* @brief Construct a new webhook object
|
||||
*/
|
||||
webhook();
|
||||
|
||||
/**
|
||||
* @brief Destroy the webhook object
|
||||
*/
|
||||
~webhook();
|
||||
|
||||
/**
|
||||
* @brief Fill in object from json data
|
||||
*
|
||||
* @param j JSON data
|
||||
* @return webhook& Reference to self
|
||||
*/
|
||||
webhook& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build JSON string from object
|
||||
*
|
||||
* @param with_id Include the ID of the webhook in the json
|
||||
* @return std::string JSON encoded object
|
||||
*/
|
||||
std::string build_json(bool with_id = false) const;
|
||||
|
||||
/**
|
||||
* @brief Base64 encode image data and allocate it to image_data
|
||||
*
|
||||
* @param image_blob Binary image data
|
||||
* @param type Image type
|
||||
* @return webhook& Reference to self
|
||||
*/
|
||||
webhook& load_image(const std::string &image_blob, image_type type);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A group of webhooks
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, webhook> webhook_map;
|
||||
|
||||
};
|
156
vendor/DPP/include/dpp/wsclient.h
vendored
156
vendor/DPP/include/dpp/wsclient.h
vendored
@ -1,156 +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 <variant>
|
||||
#include <dpp/sslclient.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Websocket connection status
|
||||
*/
|
||||
enum ws_state {
|
||||
/** Sending/receiving HTTP headers prior to protocol switch */
|
||||
HTTP_HEADERS,
|
||||
/** Connected, upgraded and sending/receiving frames */
|
||||
CONNECTED
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Low-level websocket opcodes for frames
|
||||
*/
|
||||
enum ws_opcode
|
||||
{
|
||||
OP_CONTINUATION = 0x00, //!< Continuation
|
||||
OP_TEXT = 0x01, //!< Text frame
|
||||
OP_BINARY = 0x02, //!< Binary frame
|
||||
OP_CLOSE = 0x08, //!< Close notification with close code
|
||||
OP_PING = 0x09, //!< Low level ping
|
||||
OP_PONG = 0x0a //!< Low level pong
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Implements a websocket client based on the SSL client
|
||||
*/
|
||||
class CoreExport websocket_client : public ssl_client
|
||||
{
|
||||
/** Connection key used in the HTTP headers */
|
||||
std::string key;
|
||||
|
||||
/** Current websocket state */
|
||||
ws_state state;
|
||||
|
||||
/** Path part of URL for websocket */
|
||||
std::string path;
|
||||
|
||||
/** HTTP headers received on connecting/upgrading */
|
||||
std::map<std::string, std::string> HTTPHeaders;
|
||||
|
||||
/** Parse headers for a websocket frame from the buffer.
|
||||
* @param buffer The buffer to operate on. Will modify the string removing completed items from the head of the queue
|
||||
*/
|
||||
bool parseheader(std::string &buffer);
|
||||
|
||||
/** Unpack a frame and pass completed frames up the stack.
|
||||
* @param buffer The buffer to operate on. Gets modified to remove completed frames on the head of the buffer
|
||||
* @param offset The offset to start at (reserved for future use)
|
||||
* @param first True if is the first element (reserved for future use)
|
||||
*/
|
||||
bool unpack(std::string &buffer, uint32_t offset, bool first = true);
|
||||
|
||||
/** Fill a header for outbound messages
|
||||
* @param outbuf The raw frame to fill
|
||||
* @param sendlength The size of the data to encapsulate
|
||||
* @param ws_opcode the opcode to send in the header
|
||||
*/
|
||||
size_t FillHeader(unsigned char* outbuf, size_t sendlength, ws_opcode opcode);
|
||||
|
||||
/** Handle ping and pong requests.
|
||||
* @param ping True if this is a ping, false if it is a pong
|
||||
* @param payload The ping payload, to be returned as-is for a ping
|
||||
*/
|
||||
void HandlePingPong(bool ping, const std::string &payload);
|
||||
|
||||
protected:
|
||||
|
||||
/** (Re)connect */
|
||||
virtual void Connect();
|
||||
|
||||
/** Get websocket state
|
||||
* @return websocket state
|
||||
*/
|
||||
ws_state GetState();
|
||||
|
||||
public:
|
||||
|
||||
/** Connect to a specific websocket server.
|
||||
* @param hostname Hostname to connect to
|
||||
* @param port Port to connect to
|
||||
* @param urlpath The URL path components of the HTTP request to send
|
||||
*/
|
||||
websocket_client(const std::string &hostname, const std::string &port = "443", const std::string &urlpath = "");
|
||||
|
||||
/** Destructor */
|
||||
virtual ~websocket_client();
|
||||
|
||||
/**
|
||||
* @brief Write to websocket. Encapsulates data in frames if the status is CONNECTED.
|
||||
*
|
||||
* @param data The data to send.
|
||||
*/
|
||||
virtual void write(const std::string &data);
|
||||
|
||||
/**
|
||||
* @brief Processes incoming frames from the SSL socket input buffer.
|
||||
*
|
||||
* @param buffer The buffer contents. Can modify this value removing the head elements when processed.
|
||||
*/
|
||||
virtual bool handle_buffer(std::string &buffer);
|
||||
|
||||
/**
|
||||
* @brief Close websocket
|
||||
*/
|
||||
virtual void close();
|
||||
|
||||
/**
|
||||
* @brief Receives raw frame content only without headers
|
||||
*
|
||||
* @param buffer The buffer contents
|
||||
* @return True if the frame was successfully handled. False if no valid frame is in the buffer.
|
||||
*/
|
||||
virtual bool HandleFrame(const std::string &buffer);
|
||||
|
||||
/**
|
||||
* @brief Called upon error frame.
|
||||
*
|
||||
* @param errorcode The error code from the websocket server
|
||||
*/
|
||||
virtual void Error(uint32_t errorcode);
|
||||
|
||||
/** Fires every second from the underlying socket I/O loop, used for sending webscocket pings */
|
||||
virtual void one_second_timer();
|
||||
};
|
||||
|
||||
};
|
77
vendor/DPP/src/dpp/auditlog.cpp
vendored
77
vendor/DPP/src/dpp/auditlog.cpp
vendored
@ -1,77 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/auditlog.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
auditlog::auditlog()
|
||||
{
|
||||
}
|
||||
|
||||
auditlog::~auditlog() {
|
||||
}
|
||||
|
||||
auditlog& auditlog::fill_from_json(nlohmann::json* j) {
|
||||
for (auto & ai : (*j)["audit_log_entries"]) {
|
||||
audit_entry ae;
|
||||
ae.id = SnowflakeNotNull(&ai, "id");
|
||||
ae.event = (audit_type)Int8NotNull(&ai, "action_type");
|
||||
ae.user_id = SnowflakeNotNull(&ai, "user_id");
|
||||
ae.target_id = SnowflakeNotNull(&ai, "target_id");
|
||||
ae.reason = StringNotNull(&ai, "reason");
|
||||
if (j->find("changes") != j->end()) {
|
||||
auto &c = ai["changes"];
|
||||
for (auto & change : c) {
|
||||
audit_change ac;
|
||||
ac.key = StringNotNull(&change, "key");
|
||||
if (change.find("new_value") != change.end()) {
|
||||
ac.new_value = change["new_value"].dump();
|
||||
}
|
||||
if (change.find("old_value") != change.end()) {
|
||||
ac.old_value = change["old_value"].dump();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (j->find("options") != j->end()) {
|
||||
auto &o = ai["options"];
|
||||
audit_extra opts;
|
||||
opts.channel_id = SnowflakeNotNull(&o, "channel_id");
|
||||
opts.count = StringNotNull(&o, "count");
|
||||
opts.delete_member_days = StringNotNull(&o, "delete_member_days");
|
||||
opts.id = SnowflakeNotNull(&o, "id");
|
||||
opts.members_removed = StringNotNull(&o, "members_removed");
|
||||
opts.message_id = SnowflakeNotNull(&o, "message_id");
|
||||
opts.role_name = StringNotNull(&o, "role_name");
|
||||
opts.type = StringNotNull(&o, "type");
|
||||
ae.options = opts;
|
||||
}
|
||||
this->entries.push_back(ae);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
};
|
||||
|
52
vendor/DPP/src/dpp/ban.cpp
vendored
52
vendor/DPP/src/dpp/ban.cpp
vendored
@ -1,52 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/ban.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
ban::ban() : user_id(0)
|
||||
{
|
||||
}
|
||||
|
||||
ban::~ban() {
|
||||
}
|
||||
|
||||
ban& ban::fill_from_json(nlohmann::json* j) {
|
||||
reason = StringNotNull(j, "reason");
|
||||
if (j->find("user") != j->end()) {
|
||||
json & user = (*j)["user"];
|
||||
user_id = SnowflakeNotNull(&user, "id");
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string ban::build_json() const {
|
||||
/* This is an unused stub, because sending a ban is simple as a user id and a reason */
|
||||
return "{}";
|
||||
}
|
||||
|
||||
};
|
||||
|
161
vendor/DPP/src/dpp/cache.cpp
vendored
161
vendor/DPP/src/dpp/cache.cpp
vendored
@ -1,161 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
#include <variant>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/guild.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
std::unordered_map<managed*, time_t> deletion_queue;
|
||||
std::mutex deletion_mutex;
|
||||
|
||||
#define cache_helper(type, cache_name, setter, getter, counter) \
|
||||
cache* cache_name = nullptr; \
|
||||
type * setter (snowflake id) { \
|
||||
return cache_name ? ( type * ) cache_name ->find(id) : nullptr; \
|
||||
} \
|
||||
cache* getter () { \
|
||||
if (! cache_name ) { \
|
||||
cache_name = new cache(); \
|
||||
} \
|
||||
return cache_name ; \
|
||||
} \
|
||||
uint64_t counter () { \
|
||||
return ( cache_name ? cache_name ->count() : 0 ); \
|
||||
}
|
||||
|
||||
|
||||
/* Because other threads and systems may run for a short while after an event is received, we don't immediately
|
||||
* delete pointers when objects are replaced. We put them into a queue, and periodically delete pointers in the
|
||||
* queue. This also rehashes unordered_maps to ensure they free their memory.
|
||||
*/
|
||||
void garbage_collection() {
|
||||
time_t now = time(NULL);
|
||||
bool repeat = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> delete_lock(deletion_mutex);
|
||||
do {
|
||||
repeat = false;
|
||||
for (auto g = deletion_queue.begin(); g != deletion_queue.end(); ++g) {
|
||||
if (now > g->second + 60) {
|
||||
delete g->first;
|
||||
deletion_queue.erase(g);
|
||||
repeat = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (repeat);
|
||||
if (deletion_queue.size() == 0) {
|
||||
deletion_queue = {};
|
||||
}
|
||||
}
|
||||
dpp::get_user_cache()->rehash();
|
||||
dpp::get_channel_cache()->rehash();
|
||||
dpp::get_guild_cache()->rehash();
|
||||
dpp::get_role_cache()->rehash();
|
||||
dpp::get_emoji_cache()->rehash();
|
||||
}
|
||||
|
||||
cache::cache() {
|
||||
cache_map = new cache_container();
|
||||
}
|
||||
|
||||
cache::~cache() {
|
||||
delete cache_map;
|
||||
}
|
||||
|
||||
uint64_t cache::count() {
|
||||
std::lock_guard<std::mutex> lock(this->cache_mutex);
|
||||
return cache_map->size();
|
||||
}
|
||||
|
||||
std::mutex& cache::get_mutex() {
|
||||
return this->cache_mutex;
|
||||
}
|
||||
|
||||
cache_container& cache::get_container() {
|
||||
return *(this->cache_map);
|
||||
}
|
||||
|
||||
void cache::store(managed* object) {
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(this->cache_mutex);
|
||||
auto existing = cache_map->find(object->id);
|
||||
if (existing == cache_map->end()) {
|
||||
(*cache_map)[object->id] = object;
|
||||
} else if (object != existing->second) {
|
||||
/* Flag old pointer for deletion and replace */
|
||||
std::lock_guard<std::mutex> delete_lock(deletion_mutex);
|
||||
deletion_queue[existing->second] = time(NULL);
|
||||
(*cache_map)[object->id] = object;
|
||||
}
|
||||
}
|
||||
|
||||
size_t cache::bytes() {
|
||||
std::lock_guard<std::mutex> lock(cache_mutex);
|
||||
return sizeof(this) + (cache_map->bucket_count() * sizeof(size_t));
|
||||
}
|
||||
|
||||
void cache::rehash() {
|
||||
std::lock_guard<std::mutex> lock(cache_mutex);
|
||||
cache_container* n = new cache_container();
|
||||
n->reserve(cache_map->size());
|
||||
for (auto t = cache_map->begin(); t != cache_map->end(); ++t) {
|
||||
n->insert(*t);
|
||||
}
|
||||
delete cache_map;
|
||||
cache_map = n;
|
||||
}
|
||||
|
||||
void cache::remove(managed* object) {
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> lock(cache_mutex);
|
||||
std::lock_guard<std::mutex> delete_lock(deletion_mutex);
|
||||
auto existing = cache_map->find(object->id);
|
||||
if (existing != cache_map->end()) {
|
||||
cache_map->erase(existing);
|
||||
deletion_queue[object] = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
managed* cache::find(snowflake id) {
|
||||
std::lock_guard<std::mutex> lock(cache_mutex);
|
||||
auto r = cache_map->find(id);
|
||||
if (r != cache_map->end()) {
|
||||
return r->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
cache_helper(user, user_cache, find_user, get_user_cache, get_user_count);
|
||||
cache_helper(channel, channel_cache, find_channel, get_channel_cache, get_channel_count);
|
||||
cache_helper(role, role_cache, find_role, get_role_cache, get_role_count);
|
||||
cache_helper(guild, guild_cache, find_guild, get_guild_cache, get_guild_count);
|
||||
cache_helper(emoji, emoji_cache, find_emoji, get_emoji_cache, get_emoji_count);
|
||||
|
||||
};
|
245
vendor/DPP/src/dpp/channel.cpp
vendored
245
vendor/DPP/src/dpp/channel.cpp
vendored
@ -1,245 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/guild.h>
|
||||
#include <dpp/user.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp {
|
||||
|
||||
thread_member& thread_member::fill_from_json(nlohmann::json* j) {
|
||||
SetSnowflakeNotNull(j, "id", this->thread_id);
|
||||
SetSnowflakeNotNull(j, "user_id", this->user_id);
|
||||
SetTimestampNotNull(j, "join_timestamp", this->joined);
|
||||
SetInt32NotNull(j, "flags", this->flags);
|
||||
return *this;
|
||||
}
|
||||
|
||||
channel::channel() :
|
||||
managed(),
|
||||
flags(0),
|
||||
guild_id(0),
|
||||
position(0),
|
||||
last_message_id(0),
|
||||
user_limit(0),
|
||||
rate_limit_per_user(0),
|
||||
owner_id(0),
|
||||
parent_id(0),
|
||||
last_pin_timestamp(0),
|
||||
message_count(0),
|
||||
member_count(0)
|
||||
{
|
||||
}
|
||||
|
||||
channel::~channel()
|
||||
{
|
||||
}
|
||||
|
||||
bool channel::is_nsfw() const {
|
||||
return flags & dpp::c_nsfw;
|
||||
}
|
||||
|
||||
bool channel::is_text_channel() const {
|
||||
return flags & dpp::c_text;
|
||||
}
|
||||
|
||||
bool channel::is_dm() const {
|
||||
return flags & dpp::c_dm;
|
||||
}
|
||||
|
||||
bool channel::is_voice_channel() const {
|
||||
return flags & dpp::c_voice;
|
||||
}
|
||||
|
||||
bool channel::is_group_dm() const {
|
||||
return (flags & (dpp::c_dm | dpp::c_group)) == (dpp::c_dm | dpp::c_group);
|
||||
}
|
||||
|
||||
bool channel::is_category() const {
|
||||
return flags & dpp::c_category;
|
||||
}
|
||||
|
||||
bool channel::is_stage_channel() const {
|
||||
return (flags & dpp::c_stage) == dpp::c_stage;
|
||||
}
|
||||
|
||||
bool channel::is_news_channel() const {
|
||||
/* Important: Stage/News overlap to pack more values in a byte */
|
||||
return !is_stage_channel() && (flags & dpp::c_news);
|
||||
}
|
||||
|
||||
bool channel::is_store_channel() const {
|
||||
/* Important: Stage/Store overlap to pack more values in a byte */
|
||||
return !is_stage_channel() && (flags & dpp::c_store);
|
||||
}
|
||||
|
||||
channel& channel::fill_from_json(json* j) {
|
||||
this->id = SnowflakeNotNull(j, "id");
|
||||
SetSnowflakeNotNull(j, "guild_id", this->guild_id);
|
||||
SetInt16NotNull(j, "position", this->position);
|
||||
SetStringNotNull(j, "name", this->name);
|
||||
SetStringNotNull(j, "topic", this->topic);
|
||||
SetSnowflakeNotNull(j, "last_message_id", this->last_message_id);
|
||||
SetInt8NotNull(j, "user_limit", this->user_limit);
|
||||
SetInt16NotNull(j, "rate_limit_per_user", this->rate_limit_per_user);
|
||||
SetSnowflakeNotNull(j, "owner_id", this->owner_id);
|
||||
SetSnowflakeNotNull(j, "parent_id", this->parent_id);
|
||||
//this->last_pin_timestamp
|
||||
uint8_t type = Int8NotNull(j, "type");
|
||||
this->flags |= BoolNotNull(j, "nsfw") ? dpp::c_nsfw : 0;
|
||||
this->flags |= (type == GUILD_TEXT) ? dpp::c_text : 0;
|
||||
this->flags |= (type == GUILD_VOICE) ? dpp::c_voice : 0;
|
||||
this->flags |= (type == DM) ? dpp::c_dm : 0;
|
||||
this->flags |= (type == GROUP_DM) ? (dpp::c_group | dpp::c_dm) : 0;
|
||||
this->flags |= (type == GUILD_CATEGORY) ? dpp::c_category : 0;
|
||||
this->flags |= (type == GUILD_NEWS) ? dpp::c_news : 0;
|
||||
this->flags |= (type == GUILD_STORE) ? dpp::c_store : 0;
|
||||
this->flags |= (type == GUILD_STAGE) ? dpp::c_stage : 0;
|
||||
this->flags |= (type == GUILD_NEWS_THREAD) ? dpp::c_news_thread : 0;
|
||||
this->flags |= (type == GUILD_PUBLIC_THREAD) ? dpp::c_public_thread : 0;
|
||||
this->flags |= (type == GUILD_PRIVATE_THREAD) ? dpp::c_private_thread : 0;
|
||||
|
||||
if (j->find("recipients") != j->end()) {
|
||||
recipients = {};
|
||||
for (auto & r : (*j)["recipients"]) {
|
||||
recipients.push_back(from_string<uint64_t>(r["id"].get<std::string>(), std::dec));
|
||||
}
|
||||
}
|
||||
|
||||
if (j->find("permission_overwrites") != j->end()) {
|
||||
permission_overwrites = {};
|
||||
for (auto & overwrite : (*j)["permission_overwrites"]) {
|
||||
permission_overwrite po;
|
||||
po.id = SnowflakeNotNull(&overwrite, "id");
|
||||
po.allow = SnowflakeNotNull(&overwrite, "allow");
|
||||
po.deny = SnowflakeNotNull(&overwrite, "deny");
|
||||
po.type = Int8NotNull(&overwrite, "type");
|
||||
permission_overwrites.push_back(po);
|
||||
}
|
||||
}
|
||||
|
||||
if (type == GUILD_NEWS_THREAD || type == GUILD_PUBLIC_THREAD || type == GUILD_PRIVATE_THREAD) {
|
||||
SetInt8NotNull(j, "message_count", this->message_count);
|
||||
SetInt8NotNull(j, "memeber_count", this->member_count);
|
||||
dpp::thread_metadata metadata;
|
||||
auto json_metadata = (*j)["thread_metadata"];
|
||||
metadata.archived = BoolNotNull(&json_metadata, "archived");
|
||||
metadata.archive_timestamp = TimestampNotNull(&json_metadata, "archive_timestamp");
|
||||
metadata.auto_archive_duration = Int16NotNull(&json_metadata, "auto_archive_duration");
|
||||
metadata.locked = BoolNotNull(&json_metadata, "locked");
|
||||
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string channel::build_json(bool with_id) const {
|
||||
json j;
|
||||
if (with_id) {
|
||||
j["id"] = std::to_string(id);
|
||||
}
|
||||
j["guild_id"] = std::to_string(guild_id);
|
||||
j["position"] = position;
|
||||
j["name"] = name;
|
||||
j["topic"] = topic;
|
||||
if (is_voice_channel()) {
|
||||
j["user_limit"] = user_limit;
|
||||
j["rate_limit_per_user"] = rate_limit_per_user;
|
||||
}
|
||||
if (!is_dm()) {
|
||||
if (parent_id) {
|
||||
j["parent_id"] = parent_id;
|
||||
}
|
||||
if (is_text_channel()) {
|
||||
j["type"] = GUILD_TEXT;
|
||||
} else if (is_voice_channel()) {
|
||||
j["type"] = GUILD_VOICE;
|
||||
} else if (is_category()) {
|
||||
j["type"] = GUILD_CATEGORY;
|
||||
} else if (is_stage_channel()) {
|
||||
/* Order is important, as GUILD_STAGE overlaps NEWS and STORE */
|
||||
j["type"] = GUILD_STAGE;
|
||||
} else if (is_news_channel()) {
|
||||
j["type"] = GUILD_NEWS;
|
||||
} else if (is_store_channel()) {
|
||||
j["type"] = GUILD_STORE;
|
||||
}
|
||||
j["nsfw"] = is_nsfw();
|
||||
} else {
|
||||
if (is_group_dm()) {
|
||||
j["type"] = GROUP_DM;
|
||||
} else {
|
||||
j["type"] = DM;
|
||||
}
|
||||
}
|
||||
|
||||
return j.dump();
|
||||
}
|
||||
|
||||
uint64_t channel::get_user_permissions(const user* member) const
|
||||
{
|
||||
if (member == nullptr)
|
||||
return 0;
|
||||
|
||||
guild* g = dpp::find_guild(guild_id);
|
||||
if (g == nullptr)
|
||||
return 0;
|
||||
|
||||
return g->permission_overwrites(g->base_permissions(member), member, this);
|
||||
}
|
||||
|
||||
std::map<snowflake, guild_member*> channel::get_members() {
|
||||
std::map<snowflake, guild_member*> rv;
|
||||
guild* g = dpp::find_guild(guild_id);
|
||||
if (g) {
|
||||
for (auto m = g->members.begin(); m != g->members.end(); ++m) {
|
||||
user* u = dpp::find_user(m->second.user_id);
|
||||
if (u) {
|
||||
if (get_user_permissions(u) & p_view_channel) {
|
||||
rv[m->second.user_id] = &(m->second);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
std::map<snowflake, voicestate> channel::get_voice_members() {
|
||||
std::map<snowflake, voicestate> rv;
|
||||
guild* g = dpp::find_guild(guild_id);
|
||||
if (g) {
|
||||
for (auto & m : g->voice_members) {
|
||||
if (m.second.channel_id == this->id) {
|
||||
rv[m.second.user_id] = m.second;
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
1949
vendor/DPP/src/dpp/cluster.cpp
vendored
1949
vendor/DPP/src/dpp/cluster.cpp
vendored
File diff suppressed because it is too large
Load Diff
417
vendor/DPP/src/dpp/commandhandler.cpp
vendored
417
vendor/DPP/src/dpp/commandhandler.cpp
vendored
@ -1,417 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/commandhandler.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <fmt/format.h>
|
||||
#include <sstream>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
param_info::param_info(parameter_type t, bool o, const std::string &d, const std::map<std::string, std::string> &opts) : type(t), optional(o), description(d), choices(opts)
|
||||
{
|
||||
}
|
||||
|
||||
commandhandler::commandhandler(cluster* o, bool auto_hook_events, snowflake application_id) : slash_commands_enabled(false), owner(o), app_id(application_id)
|
||||
{
|
||||
if (!application_id && o->me.id) {
|
||||
app_id = o->me.id;
|
||||
}
|
||||
if (auto_hook_events) {
|
||||
o->on_interaction_create([this](const dpp::interaction_create_t &event) {
|
||||
this->route(event);
|
||||
});
|
||||
o->on_message_create([this](const dpp::message_create_t & event) {
|
||||
this->route(*event.msg);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
commandhandler& commandhandler::set_owner(cluster* o)
|
||||
{
|
||||
owner = o;
|
||||
return *this;
|
||||
}
|
||||
|
||||
commandhandler::~commandhandler()
|
||||
{
|
||||
}
|
||||
|
||||
commandhandler& commandhandler::add_prefix(const std::string &prefix)
|
||||
{
|
||||
prefixes.push_back(prefix);
|
||||
if (prefix == "/") {
|
||||
if (!slash_commands_enabled) {
|
||||
/* Register existing slash commands */
|
||||
slash_commands_enabled = true;
|
||||
} else {
|
||||
slash_commands_enabled = true;
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
commandhandler& commandhandler::add_command(const std::string &command, const parameter_registration_t ¶meters, command_handler handler, const std::string &description, snowflake guild_id)
|
||||
{
|
||||
command_info_t i;
|
||||
i.func = handler;
|
||||
i.guild_id = guild_id;
|
||||
i.parameters = parameters;
|
||||
commands[lowercase(command)] = i;
|
||||
if (slash_commands_enabled) {
|
||||
if (this->app_id == 0) {
|
||||
if (owner->me.id == 0) {
|
||||
throw dpp::exception("Command handler not ready (i don't know my application ID)");
|
||||
} else {
|
||||
this->app_id = owner->me.id;
|
||||
}
|
||||
}
|
||||
dpp::slashcommand newcommand;
|
||||
/* Create a new global command on ready event */
|
||||
newcommand.set_name(lowercase(command)).set_description(description).set_application_id(this->app_id);
|
||||
|
||||
for (auto& parameter : parameters) {
|
||||
command_option_type cot;
|
||||
switch (parameter.second.type) {
|
||||
case pt_boolean:
|
||||
cot = co_boolean;
|
||||
break;
|
||||
case pt_integer:
|
||||
cot = co_integer;
|
||||
break;
|
||||
case pt_string:
|
||||
cot = co_string;
|
||||
break;
|
||||
case pt_user:
|
||||
cot = co_user;
|
||||
break;
|
||||
case pt_role:
|
||||
cot = co_role;
|
||||
break;
|
||||
case pt_channel:
|
||||
cot = co_channel;
|
||||
break;
|
||||
}
|
||||
|
||||
command_option opt(cot, parameter.first, parameter.second.description, !parameter.second.optional);
|
||||
if (!parameter.second.choices.empty()) {
|
||||
for (auto& c : parameter.second.choices) {
|
||||
opt.add_choice(dpp::command_option_choice(c.second, c.first));
|
||||
}
|
||||
}
|
||||
newcommand.add_option(opt);
|
||||
}
|
||||
/* Register the command */
|
||||
if (guild_id) {
|
||||
owner->guild_command_create(newcommand, guild_id, [command, this](const dpp::confirmation_callback_t &callback) {
|
||||
if (callback.is_error()) {
|
||||
this->owner->log(dpp::ll_error, fmt::format("Failed to register guild slash command '{}': {}", command, callback.http_info.body));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
owner->global_command_create(newcommand, [command, this](const dpp::confirmation_callback_t &callback) {
|
||||
if (callback.is_error()) {
|
||||
this->owner->log(dpp::ll_error, fmt::format("Failed to register global slash command '{}': {}", command, callback.http_info.body));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool commandhandler::string_has_prefix(std::string &str)
|
||||
{
|
||||
size_t str_length = utility::utf8len(str);
|
||||
for (auto& p : prefixes) {
|
||||
size_t prefix_length = utility::utf8len(p);
|
||||
if (utility::utf8substr(str, 0, prefix_length) == p) {
|
||||
str.erase(str.begin(), str.begin() + prefix_length);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Note that message based command routing relies on cache to resolve ping types (e.g. user, channel ping).
|
||||
* There isn't really a way around this for many things because there is no 'resolved' member for it.
|
||||
* We only get resolved information for the user issuing the command.
|
||||
*/
|
||||
void commandhandler::route(const dpp::message& msg)
|
||||
{
|
||||
std::string msg_content = msg.content;
|
||||
if (string_has_prefix(msg_content)) {
|
||||
/* Put the string into stringstream to parse parameters at spaces.
|
||||
* We use stringstream as it handles multiple spaces etc nicely.
|
||||
*/
|
||||
std::stringstream ss(msg_content);
|
||||
std::string command;
|
||||
ss >> command;
|
||||
/* Prefixed command, the prefix was removed */
|
||||
auto found_cmd = commands.find(lowercase(command));
|
||||
if (found_cmd != commands.end()) {
|
||||
/* Filter out guild specific commands that are not for the current guild */
|
||||
if (found_cmd->second.guild_id && found_cmd->second.guild_id != msg.guild_id) {
|
||||
return;
|
||||
}
|
||||
|
||||
parameter_list_t call_params;
|
||||
|
||||
/* Command found; parse parameters */
|
||||
for (auto& p : found_cmd->second.parameters) {
|
||||
command_parameter param;
|
||||
|
||||
/* Check for end of stream */
|
||||
if (!ss) {
|
||||
/* If it's an optional param, we dont care */
|
||||
if (!p.second.optional) {
|
||||
/* Trigger missing parameter handler? */
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (p.second.type) {
|
||||
case pt_string: {
|
||||
std::string x;
|
||||
ss >> x;
|
||||
param = x;
|
||||
}
|
||||
break;
|
||||
case pt_role: {
|
||||
std::string x;
|
||||
ss >> x;
|
||||
if (x.length() > 4 && x[0] == '<' && x[1] == '&') {
|
||||
snowflake rid = from_string<uint64_t>(x.substr(2, x.length() - 1), std::dec);
|
||||
role* r = dpp::find_role(rid);
|
||||
if (r) {
|
||||
param = *r;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case pt_channel: {
|
||||
std::string x;
|
||||
ss >> x;
|
||||
if (x.length() > 4 && x[0] == '<' && x[1] == '#') {
|
||||
snowflake cid = from_string<uint64_t>(x.substr(2, x.length() - 1), std::dec);
|
||||
channel* c = dpp::find_channel(cid);
|
||||
if (c) {
|
||||
param = *c;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case pt_user: {
|
||||
std::string x;
|
||||
ss >> x;
|
||||
if (x.length() > 4 && x[0] == '<' && x[1] == '@') {
|
||||
snowflake uid = from_string<uint64_t>(x.substr(2, x.length() - 1), std::dec);
|
||||
user* u = dpp::find_user(uid);
|
||||
if (u) {
|
||||
dpp::resolved_user m;
|
||||
m.user = *u;
|
||||
dpp::guild* g = dpp::find_guild(msg.guild_id);
|
||||
if (g->members.find(uid) != g->members.end()) {
|
||||
m.member = g->members[uid];
|
||||
}
|
||||
param = m;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case pt_integer: {
|
||||
int32_t x = 0;
|
||||
ss >> x;
|
||||
param = x;
|
||||
}
|
||||
case pt_boolean: {
|
||||
std::string x;
|
||||
bool y = false;
|
||||
ss >> x;
|
||||
x = lowercase(x);
|
||||
if (x == "yes" || x == "1" || x == "true") {
|
||||
y = true;
|
||||
}
|
||||
param = y;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Add parameter to the list */
|
||||
call_params.push_back(std::make_pair(p.first, param));
|
||||
}
|
||||
|
||||
/* Call command handler */
|
||||
command_source source;
|
||||
source.command_id = 0;
|
||||
source.guild_id = msg.guild_id;
|
||||
source.channel_id = msg.channel_id;
|
||||
source.issuer = msg.author;
|
||||
found_cmd->second.func(command, call_params, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void commandhandler::route(const interaction_create_t & event)
|
||||
{
|
||||
/* We don't need to check for prefixes here, slash command interactions
|
||||
* dont have prefixes at all.
|
||||
*/
|
||||
command_interaction cmd = std::get<command_interaction>(event.command.data);
|
||||
|
||||
auto found_cmd = commands.find(lowercase(cmd.name));
|
||||
if (found_cmd != commands.end()) {
|
||||
/* Command found; parse parameters */
|
||||
parameter_list_t call_params;
|
||||
for (auto& p : found_cmd->second.parameters) {
|
||||
command_parameter param;
|
||||
const command_value& slash_parameter = event.get_parameter(p.first);
|
||||
dpp::command_resolved res = event.command.resolved;
|
||||
|
||||
if (p.second.optional && slash_parameter.index() == 0 /* std::monostate */) {
|
||||
/* Missing optional parameter, skip this */
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (p.second.type) {
|
||||
case pt_string: {
|
||||
std::string s = std::get<std::string>(slash_parameter);
|
||||
param = s;
|
||||
}
|
||||
break;
|
||||
case pt_role: {
|
||||
snowflake rid = std::get<snowflake>(slash_parameter);
|
||||
role* r = dpp::find_role(rid);
|
||||
if (r) {
|
||||
/* Use cache if the role is in the cache */
|
||||
param = *r;
|
||||
} else {
|
||||
/* Otherwise use interaction resolved fields */
|
||||
if (res.roles.find(rid) != res.roles.end()) {
|
||||
param = res.roles[rid];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case pt_channel: {
|
||||
snowflake cid = std::get<snowflake>(slash_parameter);
|
||||
channel* c = dpp::find_channel(cid);
|
||||
if (c) {
|
||||
/* Use cache if the channel is in the cache */
|
||||
param = *c;
|
||||
} else {
|
||||
/* Otherwise use interaction resolved fields */
|
||||
if (res.channels.find(cid) != res.channels.end()) {
|
||||
param = res.channels[cid];
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case pt_user: {
|
||||
snowflake uid = std::get<snowflake>(slash_parameter);
|
||||
/* TODO: Make this used resolved, not cache */
|
||||
user* u = dpp::find_user(uid);
|
||||
if (u) {
|
||||
/* Use the cache if the user is in the cache */
|
||||
dpp::resolved_user m;
|
||||
m.user = *u;
|
||||
dpp::guild* g = dpp::find_guild(event.command.guild_id);
|
||||
if (g->members.find(uid) != g->members.end()) {
|
||||
m.member = g->members[uid];
|
||||
}
|
||||
param = m;
|
||||
} else {
|
||||
/* Otherwise use interaction resolved fields */
|
||||
if (
|
||||
event.command.resolved.users.find(uid) != event.command.resolved.users.end()
|
||||
&&
|
||||
event.command.resolved.members.find(uid) != event.command.resolved.members.end()
|
||||
) {
|
||||
/* Fill in both member and user info */
|
||||
dpp::resolved_user m;
|
||||
m.member = res.members[uid];
|
||||
m.user = res.users[uid];
|
||||
param = m;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case pt_integer: {
|
||||
int32_t i = std::get<int32_t>(slash_parameter);
|
||||
param = i;
|
||||
}
|
||||
break;
|
||||
case pt_boolean: {
|
||||
bool b = std::get<bool>(slash_parameter);
|
||||
param = b;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
/* Add parameter to the list */
|
||||
call_params.push_back(std::make_pair(p.first, param));
|
||||
}
|
||||
|
||||
/* Call command handler */
|
||||
command_source source;
|
||||
source.command_id = event.command.id;
|
||||
source.command_token = event.command.token;
|
||||
source.guild_id = event.command.guild_id;
|
||||
source.channel_id = event.command.channel_id;
|
||||
source.issuer = (user*)&event.command.usr;
|
||||
found_cmd->second.func(cmd.name, call_params, source);
|
||||
}
|
||||
}
|
||||
|
||||
void commandhandler::reply(const dpp::message &m, command_source source)
|
||||
{
|
||||
dpp::message msg = m;
|
||||
msg.guild_id = source.guild_id;
|
||||
msg.channel_id = source.channel_id;
|
||||
if (!source.command_token.empty() && source.command_id) {
|
||||
owner->interaction_response_create(source.command_id, source.command_token, dpp::interaction_response(ir_channel_message_with_source, msg));
|
||||
} else {
|
||||
owner->message_create(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void commandhandler::thinking(command_source source)
|
||||
{
|
||||
dpp::message msg;
|
||||
msg.content = "*";
|
||||
msg.guild_id = source.guild_id;
|
||||
msg.channel_id = source.channel_id;
|
||||
if (!source.command_token.empty() && source.command_id) {
|
||||
owner->interaction_response_create(source.command_id, source.command_token, dpp::interaction_response(ir_deferred_channel_message_with_source, msg));
|
||||
}
|
||||
}
|
||||
|
||||
void commandhandler::thonk(command_source source)
|
||||
{
|
||||
thinking(source);
|
||||
}
|
||||
|
||||
};
|
625
vendor/DPP/src/dpp/discordclient.cpp
vendored
625
vendor/DPP/src/dpp/discordclient.cpp
vendored
@ -1,625 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <thread>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <fmt/format.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#define PATH_UNCOMPRESSED "/?v=" DISCORD_API_VERSION "&encoding=json"
|
||||
#define PATH_COMPRESSED "/?v=" DISCORD_API_VERSION "&encoding=json&compress=zlib-stream"
|
||||
#define DECOMP_BUFFER_SIZE 512 * 1024
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/* This is an internal class, defined externally as just a forward declaration for an opaque pointer.
|
||||
* This is because we don't want an external dependency on zlib's headers
|
||||
*/
|
||||
class zlibcontext {
|
||||
public:
|
||||
z_stream d_stream;
|
||||
};
|
||||
|
||||
discord_client::discord_client(dpp::cluster* _cluster, uint32_t _shard_id, uint32_t _max_shards, const std::string &_token, uint32_t _intents, bool comp)
|
||||
: websocket_client(DEFAULT_GATEWAY, "443", comp ? PATH_COMPRESSED : PATH_UNCOMPRESSED),
|
||||
creator(_cluster),
|
||||
shard_id(_shard_id),
|
||||
max_shards(_max_shards),
|
||||
token(_token),
|
||||
last_heartbeat(time(NULL)),
|
||||
heartbeat_interval(0),
|
||||
reconnects(0),
|
||||
resumes(0),
|
||||
last_seq(0),
|
||||
sessionid(""),
|
||||
intents(_intents),
|
||||
runner(nullptr),
|
||||
compressed(comp),
|
||||
decompressed_total(0),
|
||||
decomp_buffer(nullptr),
|
||||
ready(false),
|
||||
ping_start(0.0),
|
||||
websocket_ping(0.0)
|
||||
{
|
||||
zlib = new zlibcontext();
|
||||
Connect();
|
||||
}
|
||||
|
||||
discord_client::~discord_client()
|
||||
{
|
||||
if (runner) {
|
||||
runner->join();
|
||||
delete runner;
|
||||
}
|
||||
delete zlib;
|
||||
}
|
||||
|
||||
uint64_t discord_client::get_decompressed_bytes_in()
|
||||
{
|
||||
return decompressed_total;
|
||||
}
|
||||
|
||||
void discord_client::SetupZLib()
|
||||
{
|
||||
if (compressed) {
|
||||
zlib->d_stream.zalloc = (alloc_func)0;
|
||||
zlib->d_stream.zfree = (free_func)0;
|
||||
zlib->d_stream.opaque = (voidpf)0;
|
||||
if (inflateInit(&(zlib->d_stream)) != Z_OK) {
|
||||
throw dpp::exception("Can't initialise stream compression!");
|
||||
}
|
||||
this->decomp_buffer = new unsigned char[DECOMP_BUFFER_SIZE];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void discord_client::EndZLib()
|
||||
{
|
||||
if (compressed) {
|
||||
inflateEnd(&(zlib->d_stream));
|
||||
if (this->decomp_buffer) {
|
||||
delete[] this->decomp_buffer;
|
||||
this->decomp_buffer = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void discord_client::ThreadRun()
|
||||
{
|
||||
SetupZLib();
|
||||
do {
|
||||
bool error = false;
|
||||
ready = false;
|
||||
message_queue.clear();
|
||||
ssl_client::read_loop();
|
||||
ssl_client::close();
|
||||
EndZLib();
|
||||
SetupZLib();
|
||||
do {
|
||||
error = false;
|
||||
try {
|
||||
ssl_client::Connect();
|
||||
websocket_client::Connect();
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
log(dpp::ll_error, std::string("Error establishing connection, retry in 5 seconds: ") + e.what());
|
||||
ssl_client::close();
|
||||
std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
} while(true);
|
||||
}
|
||||
|
||||
void discord_client::Run()
|
||||
{
|
||||
this->runner = new std::thread(&discord_client::ThreadRun, this);
|
||||
this->thread_id = runner->native_handle();
|
||||
}
|
||||
|
||||
bool discord_client::HandleFrame(const std::string &buffer)
|
||||
{
|
||||
std::string& data = (std::string&)buffer;
|
||||
|
||||
/* gzip compression is a special case */
|
||||
if (compressed) {
|
||||
/* Check that we have a complete compressed frame */
|
||||
if ((uint8_t)buffer[buffer.size() - 4] == 0x00 && (uint8_t)buffer[buffer.size() - 3] == 0x00 && (uint8_t)buffer[buffer.size() - 2] == 0xFF
|
||||
&& (uint8_t)buffer[buffer.size() - 1] == 0xFF) {
|
||||
/* Decompress buffer */
|
||||
decompressed.clear();
|
||||
zlib->d_stream.next_in = (Bytef *)buffer.c_str();
|
||||
zlib->d_stream.avail_in = buffer.size();
|
||||
do {
|
||||
int have = 0;
|
||||
zlib->d_stream.next_out = (Bytef*)decomp_buffer;
|
||||
zlib->d_stream.avail_out = DECOMP_BUFFER_SIZE;
|
||||
int ret = inflate(&(zlib->d_stream), Z_NO_FLUSH);
|
||||
have = DECOMP_BUFFER_SIZE - zlib->d_stream.avail_out;
|
||||
switch (ret)
|
||||
{
|
||||
case Z_NEED_DICT:
|
||||
case Z_STREAM_ERROR:
|
||||
this->Error(6000);
|
||||
this->close();
|
||||
return true;
|
||||
break;
|
||||
case Z_DATA_ERROR:
|
||||
this->Error(6001);
|
||||
this->close();
|
||||
return true;
|
||||
break;
|
||||
case Z_MEM_ERROR:
|
||||
this->Error(6002);
|
||||
this->close();
|
||||
return true;
|
||||
break;
|
||||
case Z_OK:
|
||||
this->decompressed.append((const char*)decomp_buffer, have);
|
||||
this->decompressed_total += have;
|
||||
break;
|
||||
default:
|
||||
/* Stub */
|
||||
break;
|
||||
}
|
||||
} while (zlib->d_stream.avail_out == 0);
|
||||
data = decompressed;
|
||||
} else {
|
||||
/* No complete compressed frame yet */
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
log(dpp::ll_trace, fmt::format("R: {}", data));
|
||||
json j;
|
||||
|
||||
try {
|
||||
j = json::parse(data);
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
log(dpp::ll_error, fmt::format("discord_client::HandleFrame {} [{}]", e.what(), data));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (j.find("s") != j.end() && !j["s"].is_null()) {
|
||||
last_seq = j["s"].get<uint64_t>();
|
||||
}
|
||||
|
||||
if (j.find("op") != j.end()) {
|
||||
uint32_t op = j["op"];
|
||||
|
||||
switch (op) {
|
||||
case 9:
|
||||
/* Reset session state and fall through to 10 */
|
||||
op = 10;
|
||||
log(dpp::ll_debug, fmt::format("Failed to resume session {}, will reidentify", sessionid));
|
||||
this->sessionid = "";
|
||||
this->last_seq = 0;
|
||||
/* No break here, falls through to state 10 to cause a reidentify */
|
||||
case 10:
|
||||
/* Need to check carefully for the existence of this before we try to access it! */
|
||||
if (j.find("d") != j.end() && j["d"].find("heartbeat_interval") != j["d"].end() && !j["d"]["heartbeat_interval"].is_null()) {
|
||||
this->heartbeat_interval = j["d"]["heartbeat_interval"].get<uint32_t>();
|
||||
}
|
||||
|
||||
if (last_seq && !sessionid.empty()) {
|
||||
/* Resume */
|
||||
log(dpp::ll_debug, fmt::format("Resuming session {} with seq={}", sessionid, last_seq));
|
||||
json obj = {
|
||||
{ "op", 6 },
|
||||
{ "d", {
|
||||
{"token", this->token },
|
||||
{"session_id", this->sessionid },
|
||||
{"seq", this->last_seq }
|
||||
}
|
||||
}
|
||||
};
|
||||
this->write(obj.dump());
|
||||
resumes++;
|
||||
} else {
|
||||
/* Full connect */
|
||||
while (time(NULL) < creator->last_identify + 5) {
|
||||
uint32_t wait = (creator->last_identify + 5) - time(NULL);
|
||||
log(dpp::ll_debug, fmt::format("Waiting {} seconds before identifying for session...", wait));
|
||||
std::this_thread::sleep_for(std::chrono::seconds(wait));
|
||||
}
|
||||
log(dpp::ll_debug, "Connecting new session...");
|
||||
json obj = {
|
||||
{ "op", 2 },
|
||||
{
|
||||
"d",
|
||||
{
|
||||
{ "token", this->token },
|
||||
{ "properties",
|
||||
{
|
||||
{ "$os", "Linux" },
|
||||
{ "$browser", "D++" },
|
||||
{ "$device", "D++" }
|
||||
}
|
||||
},
|
||||
{ "shard", json::array({ shard_id, max_shards }) },
|
||||
{ "compress", false },
|
||||
{ "large_threshold", 250 }
|
||||
}
|
||||
}
|
||||
};
|
||||
if (this->intents) {
|
||||
obj["d"]["intents"] = this->intents;
|
||||
}
|
||||
this->write(obj.dump());
|
||||
this->connect_time = creator->last_identify = time(NULL);
|
||||
reconnects++;
|
||||
}
|
||||
this->last_heartbeat_ack = time(nullptr);
|
||||
websocket_ping = 0;
|
||||
break;
|
||||
case 0: {
|
||||
std::string event = j.find("t") != j.end() && !j["t"].is_null() ? j["t"] : "";
|
||||
|
||||
HandleEvent(event, j, data);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
log(dpp::ll_debug, fmt::format("Reconnection requested, closing socket {}", sessionid));
|
||||
message_queue.clear();
|
||||
|
||||
shutdown(sfd, 2);
|
||||
#ifdef _WIN32
|
||||
if (sfd >= 0 && sfd < FD_SETSIZE) {
|
||||
closesocket(sfd);
|
||||
}
|
||||
#else
|
||||
::close(sfd);
|
||||
#endif
|
||||
|
||||
break;
|
||||
/* Heartbeat ack */
|
||||
case 11:
|
||||
this->last_heartbeat_ack = time(nullptr);
|
||||
websocket_ping = utility::time_f() - ping_start;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
dpp::utility::uptime discord_client::get_uptime()
|
||||
{
|
||||
return dpp::utility::uptime(time(NULL) - connect_time);
|
||||
}
|
||||
|
||||
bool discord_client::is_connected()
|
||||
{
|
||||
return (this->GetState() == CONNECTED) && (this->ready);
|
||||
}
|
||||
|
||||
void discord_client::Error(uint32_t errorcode)
|
||||
{
|
||||
std::map<uint32_t, std::string> errortext = {
|
||||
{ 1000, "Socket shutdown" },
|
||||
{ 1001, "Client is leaving" },
|
||||
{ 1002, "Endpoint received a malformed frame" },
|
||||
{ 1003, "Endpoint received an unsupported frame" },
|
||||
{ 1004, "Reserved code" },
|
||||
{ 1005, "Expected close status, received none" },
|
||||
{ 1006, "No close code frame has been received" },
|
||||
{ 1007, "Endpoint received inconsistent message (e.g. malformed UTF-8)" },
|
||||
{ 1008, "Generic error" },
|
||||
{ 1009, "Endpoint won't process large frame" },
|
||||
{ 1010, "Client wanted an extension which server did not negotiate" },
|
||||
{ 1011, "Internal server error while operating" },
|
||||
{ 1012, "Server/service is restarting" },
|
||||
{ 1013, "Temporary server condition forced blocking client's request" },
|
||||
{ 1014, "Server acting as gateway received an invalid response" },
|
||||
{ 1015, "Transport Layer Security handshake failure" },
|
||||
{ 4000, "Unknown error" },
|
||||
{ 4001, "Unknown opcode" },
|
||||
{ 4002, "Decode error" },
|
||||
{ 4003, "Not authenticated" },
|
||||
{ 4004, "Authentication failed" },
|
||||
{ 4005, "Already authenticated" },
|
||||
{ 4007, "Invalid seq" },
|
||||
{ 4008, "Rate limited" },
|
||||
{ 4009, "Session timed out" },
|
||||
{ 4010, "Invalid shard" },
|
||||
{ 4011, "Sharding required" },
|
||||
{ 4012, "Invalid API version" },
|
||||
{ 4013, "Invalid intent(s)" },
|
||||
{ 4014, "Disallowed intent(s)" },
|
||||
{ 6000, "ZLib Stream Error" },
|
||||
{ 6001, "ZLib Data Error" },
|
||||
{ 6002, "ZLib Memory Error" },
|
||||
{ 6666, "Hell freezing over" }
|
||||
};
|
||||
std::string error = "Unknown error";
|
||||
auto i = errortext.find(errorcode);
|
||||
if (i != errortext.end()) {
|
||||
error = i->second;
|
||||
}
|
||||
log(dpp::ll_warning, fmt::format("OOF! Error from underlying websocket: {}: {}", errorcode, error));
|
||||
}
|
||||
|
||||
void discord_client::log(dpp::loglevel severity, const std::string &msg) const
|
||||
{
|
||||
if (creator->dispatch.log) {
|
||||
/* Pass to user if theyve hooked the event */
|
||||
dpp::log_t logmsg(nullptr, msg);
|
||||
logmsg.severity = severity;
|
||||
logmsg.message = msg;
|
||||
creator->dispatch.log(logmsg);
|
||||
}
|
||||
}
|
||||
|
||||
void discord_client::QueueMessage(const std::string &j, bool to_front)
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(queue_mutex);
|
||||
if (to_front) {
|
||||
message_queue.push_front(j);
|
||||
} else {
|
||||
message_queue.push_back(j);
|
||||
}
|
||||
}
|
||||
|
||||
void discord_client::ClearQueue()
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(queue_mutex);
|
||||
message_queue.clear();
|
||||
}
|
||||
|
||||
size_t discord_client::GetQueueSize()
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(queue_mutex);
|
||||
return message_queue.size();
|
||||
}
|
||||
|
||||
void discord_client::one_second_timer()
|
||||
{
|
||||
|
||||
websocket_client::one_second_timer();
|
||||
|
||||
/* Every minute, rehash all containers from first shard.
|
||||
* We can't just get shard with the id 0 because this won't
|
||||
* work on a clustered environment
|
||||
*/
|
||||
auto shards = creator->get_shards();
|
||||
auto first_iter = shards.begin();
|
||||
if (first_iter != shards.end()) {
|
||||
dpp::discord_client* first_shard = first_iter->second;
|
||||
if ((time(NULL) % 60) == 0 && first_shard == this) {
|
||||
dpp::garbage_collection();
|
||||
}
|
||||
}
|
||||
|
||||
/* This all only triggers if we are connected (have completed websocket, and received READY or RESUMED) */
|
||||
if (this->is_connected()) {
|
||||
|
||||
/* If we stopped getting heartbeat acknowledgements, this means the connections is dead.
|
||||
* This can happen to TCP connections which is why we have heartbeats in the first place.
|
||||
* Miss two ACKS, forces a reconnection.
|
||||
*/
|
||||
if ((time(nullptr) - this->last_heartbeat_ack) > heartbeat_interval * 2) {
|
||||
log(dpp::ll_warning, fmt::format("Missed heartbeat ACK, forcing reconnection to session {}", sessionid));
|
||||
message_queue.clear();
|
||||
|
||||
shutdown(sfd, 2);
|
||||
#ifdef _WIN32
|
||||
if (sfd >= 0 && sfd < FD_SETSIZE) {
|
||||
closesocket(sfd);
|
||||
}
|
||||
#else
|
||||
::close(sfd);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Rate limit outbound messages, 1 every odd second, 2 every even second */
|
||||
for (int x = 0; x < (time(NULL) % 2) + 1; ++x) {
|
||||
std::lock_guard<std::mutex> locker(queue_mutex);
|
||||
if (message_queue.size()) {
|
||||
std::string message = message_queue.front();
|
||||
message_queue.pop_front();
|
||||
/* Checking here with .find() saves us having to deserialise the json
|
||||
* to find pings in our queue. The assumption is that the format of the
|
||||
* ping isn't going to change.
|
||||
*/
|
||||
if (message.find("\"op\":1}") != std::string::npos) {
|
||||
ping_start = utility::time_f();
|
||||
}
|
||||
this->write(message);
|
||||
}
|
||||
}
|
||||
|
||||
/* Send pings (heartbeat opcodes) before each interval. We send them slightly more regular than expected,
|
||||
* just to be safe.
|
||||
*/
|
||||
if (this->heartbeat_interval && this->last_seq) {
|
||||
/* Check if we're due to emit a heartbeat */
|
||||
if (time(NULL) > last_heartbeat + ((heartbeat_interval / 1000.0) * 0.75)) {
|
||||
QueueMessage(json({{"op", 1}, {"d", last_seq}}).dump(), true);
|
||||
last_heartbeat = time(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t discord_client::get_guild_count() {
|
||||
uint64_t total = 0;
|
||||
dpp::cache* c = dpp::get_guild_cache();
|
||||
dpp::cache_container& gc = c->get_container();
|
||||
/* IMPORTANT: We must lock the container to iterate it */
|
||||
std::lock_guard<std::mutex> lock(c->get_mutex());
|
||||
for (auto g = gc.begin(); g != gc.end(); ++g) {
|
||||
dpp::guild* gp = (dpp::guild*)g->second;
|
||||
if (gp->shard_id == this->shard_id) {
|
||||
total++;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
uint64_t discord_client::get_member_count() {
|
||||
uint64_t total = 0;
|
||||
dpp::cache* c = dpp::get_guild_cache();
|
||||
dpp::cache_container& gc = c->get_container();
|
||||
/* IMPORTANT: We must lock the container to iterate it */
|
||||
std::lock_guard<std::mutex> lock(c->get_mutex());
|
||||
for (auto g = gc.begin(); g != gc.end(); ++g) {
|
||||
dpp::guild* gp = (dpp::guild*)g->second;
|
||||
if (gp->shard_id == this->shard_id) {
|
||||
if (creator->cache_policy.user_policy == dpp::cp_aggressive) {
|
||||
/* We can use actual member count if we are using full user caching */
|
||||
total += gp->members.size();
|
||||
} else {
|
||||
/* Otherwise we use approximate guild member counts from guild_create */
|
||||
total += gp->member_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
uint64_t discord_client::get_channel_count() {
|
||||
uint64_t total = 0;
|
||||
dpp::cache* c = dpp::get_guild_cache();
|
||||
dpp::cache_container& gc = c->get_container();
|
||||
/* IMPORTANT: We must lock the container to iterate it */
|
||||
std::lock_guard<std::mutex> lock(c->get_mutex());
|
||||
for (auto g = gc.begin(); g != gc.end(); ++g) {
|
||||
dpp::guild* gp = (dpp::guild*)g->second;
|
||||
if (gp->shard_id == this->shard_id) {
|
||||
total += gp->channels.size();
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
void discord_client::connect_voice(snowflake guild_id, snowflake channel_id) {
|
||||
#ifdef HAVE_VOICE
|
||||
std::lock_guard<std::mutex> lock(voice_mutex);
|
||||
if (connecting_voice_channels.find(guild_id) == connecting_voice_channels.end()) {
|
||||
connecting_voice_channels[guild_id] = new voiceconn(this, channel_id);
|
||||
/* Once sent, this expects two events (in any order) on the websocket:
|
||||
* VOICE_SERVER_UPDATE and VOICE_STATUS_UPDATE
|
||||
*/
|
||||
log(ll_debug, fmt::format("Sending op 4, guild {}", guild_id));
|
||||
QueueMessage(json({
|
||||
{ "op", 4 },
|
||||
{ "d", {
|
||||
{ "guild_id", std::to_string(guild_id) },
|
||||
{ "channel_id", std::to_string(channel_id) },
|
||||
{ "self_mute", false },
|
||||
{ "self_deaf", false },
|
||||
}
|
||||
}
|
||||
}).dump(), false);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void discord_client::disconnect_voice(snowflake guild_id) {
|
||||
#ifdef HAVE_VOICE
|
||||
std::lock_guard<std::mutex> lock(voice_mutex);
|
||||
auto v = connecting_voice_channels.find(guild_id);
|
||||
if (v != connecting_voice_channels.end()) {
|
||||
log(ll_debug, fmt::format("Disconnecting voice, guild: {}", guild_id));
|
||||
QueueMessage(json({
|
||||
{ "op", 4 },
|
||||
{ "d", {
|
||||
{ "guild_id", std::to_string(guild_id) },
|
||||
{ "channel_id", json::value_t::null },
|
||||
{ "self_mute", false },
|
||||
{ "self_deaf", false },
|
||||
}
|
||||
}
|
||||
}).dump(), false);
|
||||
delete v->second;
|
||||
v->second = nullptr;
|
||||
connecting_voice_channels.erase(v);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
voiceconn* discord_client::get_voice(snowflake guild_id) {
|
||||
#ifdef HAVE_VOICE
|
||||
std::lock_guard<std::mutex> lock(voice_mutex);
|
||||
auto v = connecting_voice_channels.find(guild_id);
|
||||
if (v != connecting_voice_channels.end()) {
|
||||
return v->second;
|
||||
}
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
voiceconn::voiceconn(discord_client* o, snowflake _channel_id) : creator(o), channel_id(_channel_id), voiceclient(nullptr) {
|
||||
}
|
||||
|
||||
bool voiceconn::is_ready() {
|
||||
return (!websocket_hostname.empty() && !session_id.empty() && !token.empty());
|
||||
}
|
||||
|
||||
bool voiceconn::is_active() {
|
||||
return voiceclient != nullptr;
|
||||
}
|
||||
|
||||
void voiceconn::disconnect() {
|
||||
if (this->is_active()) {
|
||||
voiceclient->terminating = true;
|
||||
voiceclient->close();
|
||||
delete voiceclient;
|
||||
voiceclient = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
voiceconn::~voiceconn() {
|
||||
this->disconnect();
|
||||
}
|
||||
|
||||
void voiceconn::connect(snowflake guild_id) {
|
||||
if (this->is_ready() && !this->is_active()) {
|
||||
/* This is wrapped in a thread because instantiating discord_voice_client can initiate a blocking SSL_connect() */
|
||||
auto t = std::thread([guild_id, this]() {
|
||||
try {
|
||||
this->creator->log(ll_debug, fmt::format("Connecting voice for guild {} channel {}", guild_id, this->channel_id));
|
||||
this->voiceclient = new discord_voice_client(creator->creator, this->channel_id, guild_id, this->token, this->session_id, this->websocket_hostname);
|
||||
/* Note: Spawns thread! */
|
||||
this->voiceclient->Run();
|
||||
}
|
||||
catch (std::exception &e) {
|
||||
this->creator->log(ll_error, fmt::format("Can't connect to voice websocket (guild_id: {}, channel_id: {}): {}", guild_id, this->channel_id, e.what()));
|
||||
}
|
||||
});
|
||||
t.detach();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
325
vendor/DPP/src/dpp/discordevents.cpp
vendored
325
vendor/DPP/src/dpp/discordevents.cpp
vendored
@ -1,325 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#define _XOPEN_SOURCE
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <time.h>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
|
||||
char* strptime(const char* s, const char* f, struct tm* tm) {
|
||||
std::istringstream input(s);
|
||||
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
|
||||
input >> std::get_time(tm, f);
|
||||
if (input.fail()) {
|
||||
return const_cast<char*>("");
|
||||
}
|
||||
return (char*)(s + input.tellg());
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace dpp {
|
||||
|
||||
uint64_t SnowflakeNotNull(const json* j, const char *keyname) {
|
||||
/* Snowflakes are a special case. Pun intended.
|
||||
* Because discord drinks the javascript kool-aid, they have to send 64 bit integers as strings as js can't deal with them
|
||||
* even though we can. So, all snowflakes are sent and received wrapped as string values and must be read by nlohmann::json
|
||||
* as string types, then converted from string to uint64_t. Checks for existence of the value, and that it is a string containing
|
||||
* a number. If not, then this function returns 0.
|
||||
*/
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
return !k->is_null() && k->is_string() ? strtoull(k->get<std::string>().c_str(), nullptr, 10) : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetSnowflakeNotNull(const json* j, const char *keyname, uint64_t &v) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
v = !k->is_null() && k->is_string() ? strtoull(k->get<std::string>().c_str(), nullptr, 10) : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string StringNotNull(const json* j, const char *keyname) {
|
||||
/* Returns empty string if the value is not a string, or is null or not defined */
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
return !k->is_null() && k->is_string() ? k->get<std::string>() : "";
|
||||
} else {
|
||||
return const_cast< char* >("");
|
||||
}
|
||||
}
|
||||
|
||||
void SetStringNotNull(const json* j, const char *keyname, std::string &v) {
|
||||
/* Returns empty string if the value is not a string, or is null or not defined */
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
v = !k->is_null() && k->is_string() ? k->get<std::string>() : "";
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t Int64NotNull(const json* j, const char *keyname) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
return !k->is_null() && !k->is_string() ? k->get<uint64_t>() : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetInt64NotNull(const json* j, const char *keyname, uint64_t &v) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
v = !k->is_null() && !k->is_string() ? k->get<uint64_t>() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint32_t Int32NotNull(const json* j, const char *keyname) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
return !k->is_null() && !k->is_string() ? k->get<uint32_t>() : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetInt32NotNull(const json* j, const char *keyname, uint32_t &v) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
v = !k->is_null() && !k->is_string() ? k->get<uint32_t>() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Int16NotNull(const json* j, const char *keyname) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
return !k->is_null() && !k->is_string() ? k->get<uint16_t>() : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetInt16NotNull(const json* j, const char *keyname, uint16_t &v) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
v = !k->is_null() && !k->is_string() ? k->get<uint16_t>() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Int8NotNull(const json* j, const char *keyname) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
return !k->is_null() && !k->is_string() ? k->get<uint8_t>() : 0;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetInt8NotNull(const json* j, const char *keyname, uint8_t &v) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
v = !k->is_null() && !k->is_string() ? k->get<uint8_t>() : 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool BoolNotNull(const json* j, const char *keyname) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
return !k->is_null() ? (k->get<bool>() == true) : false;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void SetBoolNotNull(const json* j, const char *keyname, bool &v) {
|
||||
auto k = j->find(keyname);
|
||||
if (k != j->end()) {
|
||||
v = !k->is_null() ? (k->get<bool>() == true) : false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string base64_encode(unsigned char const* buf, unsigned int buffer_length) {
|
||||
/* Quick and dirty base64 encode */
|
||||
static const char to_base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
size_t ret_size = buffer_length + 2;
|
||||
|
||||
ret_size = 4 * ret_size / 3;
|
||||
|
||||
std::string ret;
|
||||
ret.reserve(ret_size);
|
||||
|
||||
for (unsigned int i=0; i<ret_size/4; ++i)
|
||||
{
|
||||
size_t index = i*3;
|
||||
unsigned char b3[3];
|
||||
b3[0] = buf[index+0];
|
||||
b3[1] = buf[index+1];
|
||||
b3[2] = buf[index+2];
|
||||
|
||||
ret.push_back(to_base64[ ((b3[0] & 0xfc) >> 2) ]);
|
||||
ret.push_back(to_base64[ ((b3[0] & 0x03) << 4) + ((b3[1] & 0xf0) >> 4) ]);
|
||||
ret.push_back(to_base64[ ((b3[1] & 0x0f) << 2) + ((b3[2] & 0xc0) >> 6) ]);
|
||||
ret.push_back(to_base64[ ((b3[2] & 0x3f)) ]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
time_t TimestampNotNull(const json* j, const char* keyname)
|
||||
{
|
||||
/* Parses discord ISO 8061 timestamps to time_t, accounting for local time adjustment.
|
||||
* Note that discord timestamps contain a decimal seconds part, which time_t and struct tm
|
||||
* can't handle. We strip these out.
|
||||
*/
|
||||
time_t retval = 0;
|
||||
if (j->find(keyname) != j->end() && !(*j)[keyname].is_null() && (*j)[keyname].is_string()) {
|
||||
tm timestamp = {};
|
||||
std::string timedate = (*j)[keyname].get<std::string>();
|
||||
if (timedate.find('+') != std::string::npos && timedate.find('.') != std::string::npos) {
|
||||
std::string tzpart = timedate.substr(timedate.find('+'), timedate.length());
|
||||
timedate = timedate.substr(0, timedate.find('.')) + tzpart ;
|
||||
strptime(timedate.substr(0, 19).c_str(), "%FT%TZ%z", ×tamp);
|
||||
timestamp.tm_isdst = 0;
|
||||
retval = mktime(×tamp);
|
||||
} else {
|
||||
strptime(timedate.substr(0, 19).c_str(), "%F %T", ×tamp);
|
||||
retval = mktime(×tamp);
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
void SetTimestampNotNull(const json* j, const char* keyname, time_t &v)
|
||||
{
|
||||
/* Parses discord ISO 8061 timestamps to time_t, accounting for local time adjustment.
|
||||
* Note that discord timestamps contain a decimal seconds part, which time_t and struct tm
|
||||
* can't handle. We strip these out.
|
||||
*/
|
||||
time_t retval = 0;
|
||||
if (j->find(keyname) != j->end() && !(*j)[keyname].is_null() && (*j)[keyname].is_string()) {
|
||||
tm timestamp = {};
|
||||
std::string timedate = (*j)[keyname].get<std::string>();
|
||||
if (timedate.find('+') != std::string::npos && timedate.find('.') != std::string::npos) {
|
||||
std::string tzpart = timedate.substr(timedate.find('+'), timedate.length());
|
||||
timedate = timedate.substr(0, timedate.find('.')) + tzpart ;
|
||||
strptime(timedate.substr(0, 19).c_str(), "%FT%TZ%z", ×tamp);
|
||||
timestamp.tm_isdst = 0;
|
||||
retval = mktime(×tamp);
|
||||
} else {
|
||||
strptime(timedate.substr(0, 19).c_str(), "%F %T", ×tamp);
|
||||
retval = mktime(×tamp);
|
||||
}
|
||||
v = retval;
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, dpp::events::event*> eventmap = {
|
||||
{ "__LOG__", new dpp::events::logger() },
|
||||
{ "GUILD_CREATE", new dpp::events::guild_create() },
|
||||
{ "GUILD_UPDATE", new dpp::events::guild_update() },
|
||||
{ "GUILD_DELETE", new dpp::events::guild_delete() },
|
||||
{ "GUILD_MEMBER_UPDATE", new dpp::events::guild_member_update() },
|
||||
{ "RESUMED", new dpp::events::resumed() },
|
||||
{ "READY", new dpp::events::ready() },
|
||||
{ "CHANNEL_CREATE", new dpp::events::channel_create() },
|
||||
{ "CHANNEL_UPDATE", new dpp::events::channel_update() },
|
||||
{ "CHANNEL_DELETE", new dpp::events::channel_delete() },
|
||||
{ "PRESENCE_UPDATE", new dpp::events::presence_update() },
|
||||
{ "TYPING_START", new dpp::events::typing_start() },
|
||||
{ "MESSAGE_CREATE", new dpp::events::message_create() },
|
||||
{ "MESSAGE_UPDATE", new dpp::events::message_update() },
|
||||
{ "MESSAGE_DELETE", new dpp::events::message_delete() },
|
||||
{ "MESSAGE_DELETE_BULK", new dpp::events::message_delete_bulk() },
|
||||
{ "MESSAGE_REACTION_ADD", new dpp::events::message_reaction_add() },
|
||||
{ "MESSAGE_REACTION_REMOVE", new dpp::events::message_reaction_remove() },
|
||||
{ "MESSAGE_REACTION_REMOVE_ALL", new dpp::events::message_reaction_remove_all() },
|
||||
{ "MESSAGE_REACTION_REMOVE_EMOJI", new dpp::events::message_reaction_remove_emoji() },
|
||||
{ "CHANNEL_PINS_UPDATE", new dpp::events::channel_pins_update() },
|
||||
{ "GUILD_BAN_ADD", new dpp::events::guild_ban_add() },
|
||||
{ "GUILD_BAN_REMOVE", new dpp::events::guild_ban_remove() },
|
||||
{ "GUILD_EMOJIS_UPDATE", new dpp::events::guild_emojis_update() },
|
||||
{ "GUILD_INTEGRATIONS_UPDATE", new dpp::events::guild_integrations_update() },
|
||||
{ "INTEGRATION_CREATE", new dpp::events::integration_create() },
|
||||
{ "INTEGRATION_UPDATE", new dpp::events::integration_update() },
|
||||
{ "INTEGRATION_DELETE", new dpp::events::integration_delete() },
|
||||
{ "GUILD_MEMBER_ADD", new dpp::events::guild_member_add() },
|
||||
{ "GUILD_MEMBER_REMOVE", new dpp::events::guild_member_remove() },
|
||||
{ "GUILD_MEMBERS_CHUNK", new dpp::events::guild_members_chunk() },
|
||||
{ "GUILD_ROLE_CREATE", new dpp::events::guild_role_create() },
|
||||
{ "GUILD_ROLE_UPDATE", new dpp::events::guild_role_update() },
|
||||
{ "GUILD_ROLE_DELETE", new dpp::events::guild_role_delete() },
|
||||
{ "VOICE_STATE_UPDATE", new dpp::events::voice_state_update() },
|
||||
{ "VOICE_SERVER_UPDATE", new dpp::events::voice_server_update() },
|
||||
{ "WEBHOOKS_UPDATE", new dpp::events::webhooks_update() },
|
||||
{ "INVITE_CREATE", new dpp::events::invite_create() },
|
||||
{ "INVITE_DELETE", new dpp::events::invite_delete() },
|
||||
{ "APPLICATION_COMMAND_CREATE", new dpp::events::application_command_create() },
|
||||
{ "APPLICATION_COMMAND_UPDATE", new dpp::events::application_command_update() },
|
||||
{ "APPLICATION_COMMAND_DELETE", new dpp::events::application_command_delete() },
|
||||
{ "INTERACTION_CREATE", new dpp::events::interaction_create() },
|
||||
{ "USER_UPDATE", new dpp::events::user_update() },
|
||||
{ "GUILD_JOIN_REQUEST_DELETE", new dpp::events::guild_join_request_delete() },
|
||||
{ "STAGE_INSTANCE_CREATE", new dpp::events::stage_instance_create() },
|
||||
{ "STAGE_INSTANCE_DELETE", new dpp::events::stage_instance_delete() },
|
||||
{ "THREAD_CREATE", new dpp::events::thread_create() },
|
||||
{ "THREAD_UPDATE", new dpp::events::thread_update() },
|
||||
{ "THREAD_DELETE", new dpp::events::thread_delete() },
|
||||
{ "THREAD_LIST_SYNC", new dpp::events::thread_list_sync() },
|
||||
{ "THREAD_MEMBER_UPDATE", new dpp::events::thread_member_update() },
|
||||
{ "THREAD_MEMBERS_UPDATE", new dpp::events::thread_members_update() },
|
||||
{ "GUILD_APPLICATION_COMMAND_COUNTS_UPDATE", nullptr },
|
||||
{ "GUILD_STICKERS_UPDATE", new dpp::events::guild_stickers_update() },
|
||||
{ "APPLICATION_COMMAND_PERMISSIONS_UPDATE", nullptr },
|
||||
};
|
||||
|
||||
void discord_client::HandleEvent(const std::string &event, json &j, const std::string &raw)
|
||||
{
|
||||
auto ev_iter = eventmap.find(event);
|
||||
if (ev_iter != eventmap.end()) {
|
||||
/* A handler with nullptr is silently ignored. We don't plan to make a handler for it
|
||||
* so this usually some user-only thing that's crept into the API and shown to bots
|
||||
* that we dont care about.
|
||||
*/
|
||||
if (ev_iter->second != nullptr) {
|
||||
ev_iter->second->handle(this, j, raw);
|
||||
}
|
||||
} else {
|
||||
log(dpp::ll_debug, fmt::format("Unhandled event: {}, {}", event, j.dump()));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
747
vendor/DPP/src/dpp/discordvoiceclient.cpp
vendored
747
vendor/DPP/src/dpp/discordvoiceclient.cpp
vendored
@ -1,747 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#ifndef WIN32
|
||||
#include <unistd.h>
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#include <dpp/discordvoiceclient.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <thread>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <fmt/format.h>
|
||||
#include <zlib.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
std::string external_ip;
|
||||
|
||||
/**
|
||||
* @brief Represents an RTP packet. Size should always be exactly 12.
|
||||
*/
|
||||
struct rtp_header {
|
||||
uint16_t constant;
|
||||
uint16_t sequence;
|
||||
uint32_t timestamp;
|
||||
uint32_t ssrc;
|
||||
|
||||
rtp_header(uint16_t _seq, uint32_t _ts, uint32_t _ssrc) : constant(htons(0x8078)), sequence(htons(_seq)), timestamp(htonl(_ts)), ssrc(htonl(_ssrc)) {
|
||||
}
|
||||
};
|
||||
|
||||
bool discord_voice_client::sodium_initialised = false;
|
||||
|
||||
discord_voice_client::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)
|
||||
: websocket_client(_host.substr(0, _host.find(":")), _host.substr(_host.find(":") + 1, _host.length()), "/?v=4"),
|
||||
creator(_cluster),
|
||||
channel_id(_channel_id),
|
||||
server_id(_server_id),
|
||||
token(_token),
|
||||
last_heartbeat(time(NULL)),
|
||||
heartbeat_interval(0),
|
||||
sessionid(_session_id),
|
||||
runner(nullptr),
|
||||
terminating(false),
|
||||
fd(-1),
|
||||
secret_key(nullptr),
|
||||
sequence(0),
|
||||
timestamp(0),
|
||||
sending(false),
|
||||
paused(false),
|
||||
tracks(0)
|
||||
{
|
||||
#if HAVE_VOICE
|
||||
if (!discord_voice_client::sodium_initialised) {
|
||||
if (sodium_init() < 0) {
|
||||
throw dpp::exception("discord_voice_client::discord_voice_client; sodium_init() failed");
|
||||
}
|
||||
int opusError = 0;
|
||||
encoder = opus_encoder_create(48000, 2, OPUS_APPLICATION_VOIP, &opusError);
|
||||
if (opusError) {
|
||||
throw dpp::exception(fmt::format("discord_voice_client::discord_voice_client; opus_encoder_create() failed: {}", opusError));
|
||||
}
|
||||
opusError = 0;
|
||||
decoder = opus_decoder_create(48000, 2, &opusError);
|
||||
if (opusError) {
|
||||
throw dpp::exception(fmt::format("discord_voice_client::discord_voice_client; opus_decoder_create() failed: {}", opusError));
|
||||
}
|
||||
repacketizer = opus_repacketizer_create();
|
||||
discord_voice_client::sodium_initialised = true;
|
||||
}
|
||||
Connect();
|
||||
#endif
|
||||
}
|
||||
|
||||
discord_voice_client::~discord_voice_client()
|
||||
{
|
||||
if (runner) {
|
||||
this->terminating = true;
|
||||
runner->join();
|
||||
delete runner;
|
||||
runner = nullptr;
|
||||
}
|
||||
#if HAVE_VOICE
|
||||
if (encoder) {
|
||||
opus_encoder_destroy(encoder);
|
||||
encoder = nullptr;
|
||||
}
|
||||
if (decoder) {
|
||||
opus_decoder_destroy(decoder);
|
||||
decoder = nullptr;
|
||||
}
|
||||
if (repacketizer) {
|
||||
opus_repacketizer_destroy(repacketizer);
|
||||
repacketizer = nullptr;
|
||||
}
|
||||
#endif
|
||||
if (secret_key) {
|
||||
delete[] secret_key;
|
||||
secret_key = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool discord_voice_client::is_ready() {
|
||||
return secret_key != nullptr;
|
||||
}
|
||||
|
||||
bool discord_voice_client::is_playing() {
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
return (!this->outbuf.empty());
|
||||
}
|
||||
|
||||
void discord_voice_client::ThreadRun()
|
||||
{
|
||||
do {
|
||||
ssl_client::read_loop();
|
||||
ssl_client::close();
|
||||
if (!terminating) {
|
||||
ssl_client::Connect();
|
||||
websocket_client::Connect();
|
||||
}
|
||||
} while(!terminating);
|
||||
}
|
||||
|
||||
void discord_voice_client::Run()
|
||||
{
|
||||
this->runner = new std::thread(&discord_voice_client::ThreadRun, this);
|
||||
this->thread_id = runner->native_handle();
|
||||
}
|
||||
|
||||
int discord_voice_client::UDPSend(const char* data, size_t length)
|
||||
{
|
||||
memset(&servaddr, 0, sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons(this->port);
|
||||
servaddr.sin_addr.s_addr = inet_addr(this->ip.c_str());
|
||||
return sendto(this->fd, data, length, 0, (const struct sockaddr*)&servaddr, sizeof(sockaddr_in));
|
||||
}
|
||||
|
||||
int discord_voice_client::UDPRecv(char* data, size_t max_length)
|
||||
{
|
||||
struct sockaddr sa;
|
||||
socklen_t sl;
|
||||
return recvfrom(this->fd, data, max_length, 0, (struct sockaddr*)&sa, &sl);
|
||||
}
|
||||
|
||||
bool discord_voice_client::HandleFrame(const std::string &data)
|
||||
{
|
||||
log(dpp::ll_trace, fmt::format("R: {}", data));
|
||||
json j;
|
||||
|
||||
try {
|
||||
j = json::parse(data);
|
||||
}
|
||||
catch (const std::exception &e) {
|
||||
log(dpp::ll_error, fmt::format("discord_voice_client::HandleFrame {} [{}]", e.what(), data));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (j.find("op") != j.end()) {
|
||||
uint32_t op = j["op"];
|
||||
|
||||
switch (op) {
|
||||
/* Voice resume */
|
||||
case 9:
|
||||
log(ll_debug, "Voice connection resumed");
|
||||
break;
|
||||
/* Voice HELLO */
|
||||
case 8: {
|
||||
if (j.find("d") != j.end() && j["d"].find("heartbeat_interval") != j["d"].end() && !j["d"]["heartbeat_interval"].is_null()) {
|
||||
this->heartbeat_interval = j["d"]["heartbeat_interval"].get<uint32_t>();
|
||||
}
|
||||
|
||||
if (modes.size()) {
|
||||
log(dpp::ll_debug, "Resuming voice session...");
|
||||
json obj = {
|
||||
{ "op", 7 },
|
||||
{
|
||||
"d",
|
||||
{
|
||||
{ "server_id", std::to_string(this->server_id) },
|
||||
{ "session_id", this->sessionid },
|
||||
{ "token", this->token },
|
||||
}
|
||||
}
|
||||
};
|
||||
this->write(obj.dump());
|
||||
} else {
|
||||
log(dpp::ll_debug, "Connecting new voice session...");
|
||||
json obj = {
|
||||
{ "op", 0 },
|
||||
{
|
||||
"d",
|
||||
{
|
||||
{ "user_id", creator->me.id },
|
||||
{ "server_id", std::to_string(this->server_id) },
|
||||
{ "session_id", this->sessionid },
|
||||
{ "token", this->token },
|
||||
}
|
||||
}
|
||||
};
|
||||
this->write(obj.dump());
|
||||
}
|
||||
this->connect_time = time(NULL);
|
||||
}
|
||||
break;
|
||||
/* Session description */
|
||||
case 4: {
|
||||
json &d = j["d"];
|
||||
secret_key = new uint8_t[32];
|
||||
size_t ofs = 0;
|
||||
for (auto & c : d["secret_key"]) {
|
||||
*(secret_key + ofs) = (uint8_t)c;
|
||||
ofs++;
|
||||
if (ofs > 31) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (creator->dispatch.voice_ready) {
|
||||
voice_ready_t rdy(nullptr, data);
|
||||
rdy.voice_client = this;
|
||||
rdy.voice_channel_id = this->channel_id;
|
||||
creator->dispatch.voice_ready(rdy);
|
||||
}
|
||||
}
|
||||
break;
|
||||
/* Voice ready */
|
||||
case 2: {
|
||||
/* Video stream stuff comes in this frame too, but we can't use it (YET!) */
|
||||
json &d = j["d"];
|
||||
this->ip = d["ip"].get<std::string>();
|
||||
this->port = d["port"].get<uint16_t>();
|
||||
this->ssrc = d["ssrc"].get<uint64_t>();
|
||||
// Modes
|
||||
for (auto & m : d["modes"]) {
|
||||
this->modes.push_back(m.get<std::string>());
|
||||
}
|
||||
log(ll_debug, fmt::format("Voice websocket established; UDP endpoint: {}:{} [ssrc={}] with {} modes", ip, port, ssrc, modes.size()));
|
||||
|
||||
external_ip = discover_ip();
|
||||
|
||||
int newfd = -1;
|
||||
if ((newfd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
|
||||
|
||||
sockaddr_in servaddr;
|
||||
memset(&servaddr, 0, sizeof(sockaddr_in));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servaddr.sin_port = htons(0);
|
||||
|
||||
if (bind(newfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) {
|
||||
throw dpp::exception("Can't bind() client UDP socket");
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
u_long mode = 1;
|
||||
int result = ioctlsocket(newfd, FIONBIO, &mode);
|
||||
if (result != NO_ERROR)
|
||||
throw dpp::exception("Can't switch socket to non-blocking mode!");
|
||||
#else
|
||||
int ofcmode;
|
||||
ofcmode = fcntl(newfd, F_GETFL, 0);
|
||||
ofcmode |= O_NDELAY;
|
||||
if (fcntl(newfd, F_SETFL, ofcmode)) {
|
||||
throw dpp::exception("Can't switch socket to non-blocking mode!");
|
||||
}
|
||||
#endif
|
||||
/* Hook select() in the ssl_client to add a new file descriptor */
|
||||
this->fd = newfd;
|
||||
this->custom_writeable_fd = std::bind(&discord_voice_client::WantWrite, this);
|
||||
this->custom_readable_fd = std::bind(&discord_voice_client::WantRead, this);
|
||||
this->custom_writeable_ready = std::bind(&discord_voice_client::WriteReady, this);
|
||||
this->custom_readable_ready = std::bind(&discord_voice_client::ReadReady, this);
|
||||
|
||||
int bound_port = 0;
|
||||
struct sockaddr_in sin;
|
||||
socklen_t len = sizeof(sin);
|
||||
if (getsockname(this->fd, (struct sockaddr *)&sin, &len) > -1) {
|
||||
bound_port = ntohs(sin.sin_port);
|
||||
}
|
||||
|
||||
log(ll_debug, fmt::format("External IP address: {}", external_ip));
|
||||
|
||||
this->write(json({
|
||||
{ "op", 1 },
|
||||
{ "d", {
|
||||
{ "protocol", "udp" },
|
||||
{ "data", {
|
||||
{ "address", external_ip },
|
||||
{ "port", bound_port },
|
||||
{ "mode", "xsalsa20_poly1305" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}).dump());
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void discord_voice_client::pause_audio(bool pause) {
|
||||
this->paused = pause;
|
||||
}
|
||||
|
||||
bool discord_voice_client::is_paused() {
|
||||
return this->paused;
|
||||
}
|
||||
|
||||
float discord_voice_client::get_secs_remaining() {
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
/* Audio stream sends one packet every 60ms which means there are 16.666 packets per second */
|
||||
return (outbuf.size() / 16.666666);
|
||||
}
|
||||
|
||||
dpp::utility::uptime discord_voice_client::get_remaining() {
|
||||
float fp_secs = get_secs_remaining();
|
||||
return dpp::utility::uptime((time_t)ceil(fp_secs));
|
||||
}
|
||||
|
||||
void discord_voice_client::stop_audio() {
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
outbuf.clear();
|
||||
}
|
||||
|
||||
void discord_voice_client::Send(const char* packet, size_t len) {
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
outbuf.push_back(std::string(packet, len));
|
||||
}
|
||||
|
||||
void discord_voice_client::ReadReady()
|
||||
{
|
||||
/* XXX Decoding of voice not currently supported.
|
||||
* Audio stream will always be a nullptr until then.
|
||||
* See: https://github.com/discord/discord-api-docs/issues/365
|
||||
* See also: https://github.com/discord/discord-api-docs/issues/1337
|
||||
*/
|
||||
uint8_t buffer[65535];
|
||||
int r = this->UDPRecv((char*)buffer, sizeof(buffer));
|
||||
if (r > 0 && creator->dispatch.voice_receive) {
|
||||
voice_receive_t vr(nullptr, std::string((const char*)buffer, r));
|
||||
vr.voice_client = this;
|
||||
vr.audio = nullptr;
|
||||
vr.audio_size = 0;
|
||||
creator->dispatch.voice_receive(vr);
|
||||
}
|
||||
}
|
||||
|
||||
void discord_voice_client::WriteReady()
|
||||
{
|
||||
bool call_event = false;
|
||||
bool track_marker_found = false;
|
||||
uint64_t bufsize = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
if (!this->paused && outbuf.size()) {
|
||||
|
||||
if (outbuf[0].size() == 2 && ((uint16_t)(*(outbuf[0].data()))) == AUDIO_TRACK_MARKER) {
|
||||
outbuf.erase(outbuf.begin());
|
||||
track_marker_found = true;
|
||||
if (tracks > 0)
|
||||
tracks--;
|
||||
}
|
||||
if (outbuf.size()) {
|
||||
if (this->UDPSend(outbuf[0].data(), outbuf[0].length()) == outbuf[0].length()) {
|
||||
outbuf.erase(outbuf.begin());
|
||||
call_event = true;
|
||||
bufsize = outbuf.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (call_event) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(60));
|
||||
if (creator->dispatch.voice_buffer_send) {
|
||||
voice_buffer_send_t snd(nullptr, "");
|
||||
snd.buffer_size = bufsize;
|
||||
snd.voice_client = this;
|
||||
creator->dispatch.voice_buffer_send(snd);
|
||||
}
|
||||
}
|
||||
if (track_marker_found) {
|
||||
if (creator->dispatch.voice_track_marker) {
|
||||
voice_track_marker_t vtm(nullptr, "");
|
||||
vtm.voice_client = this;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
if (track_meta.size()) {
|
||||
vtm.track_meta = track_meta[0];
|
||||
track_meta.erase(track_meta.begin());
|
||||
}
|
||||
}
|
||||
creator->dispatch.voice_track_marker(vtm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dpp::utility::uptime discord_voice_client::get_uptime()
|
||||
{
|
||||
return dpp::utility::uptime(time(NULL) - connect_time);
|
||||
}
|
||||
|
||||
bool discord_voice_client::is_connected()
|
||||
{
|
||||
return (this->GetState() == CONNECTED);
|
||||
}
|
||||
|
||||
int discord_voice_client::WantWrite() {
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
if (!this->paused && outbuf.size()) {
|
||||
return fd;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int discord_voice_client::WantRead() {
|
||||
return fd;
|
||||
}
|
||||
|
||||
void discord_voice_client::Error(uint32_t errorcode)
|
||||
{
|
||||
std::map<uint32_t, std::string> errortext = {
|
||||
{ 1000, "Socket shutdown" },
|
||||
{ 1001, "Client is leaving" },
|
||||
{ 1002, "Endpoint received a malformed frame" },
|
||||
{ 1003, "Endpoint received an unsupported frame" },
|
||||
{ 1004, "Reserved code" },
|
||||
{ 1005, "Expected close status, received none" },
|
||||
{ 1006, "No close code frame has been received" },
|
||||
{ 1007, "Endpoint received inconsistent message (e.g. malformed UTF-8)" },
|
||||
{ 1008, "Generic error" },
|
||||
{ 1009, "Endpoint won't process large frame" },
|
||||
{ 1010, "Client wanted an extension which server did not negotiate" },
|
||||
{ 1011, "Internal server error while operating" },
|
||||
{ 1012, "Server/service is restarting" },
|
||||
{ 1013, "Temporary server condition forced blocking client's request" },
|
||||
{ 1014, "Server acting as gateway received an invalid response" },
|
||||
{ 1015, "Transport Layer Security handshake failure" },
|
||||
{ 4001, "Unknown opcode" },
|
||||
{ 4002, "Failed to decode payload" },
|
||||
{ 4003, "Not authenticated" },
|
||||
{ 4004, "Authentication failed" },
|
||||
{ 4005, "Already authenticated" },
|
||||
{ 4006, "Session no longer valid" },
|
||||
{ 4009, "Session timeout" },
|
||||
{ 4011, "Server not found" },
|
||||
{ 4012, "Unknown protocol" },
|
||||
{ 4014, "Disconnected" },
|
||||
{ 4015, "Voice server crashed" },
|
||||
{ 4016, "Unknown encryption mode" }
|
||||
};
|
||||
std::string error = "Unknown error";
|
||||
auto i = errortext.find(errorcode);
|
||||
if (i != errortext.end()) {
|
||||
error = i->second;
|
||||
}
|
||||
log(dpp::ll_warning, fmt::format("Voice session error: {} on channel {}: {}", errorcode, channel_id, error));
|
||||
|
||||
/* Errors 4004...4016 except 4014 are fatal and cause termination of the voice session */
|
||||
if (errorcode >= 4003 && errorcode != 4014) {
|
||||
stop_audio();
|
||||
this->terminating = true;
|
||||
log(dpp::ll_error, "This is a non-recoverable error, giving up on voice connection");
|
||||
}
|
||||
}
|
||||
|
||||
void discord_voice_client::log(dpp::loglevel severity, const std::string &msg)
|
||||
{
|
||||
creator->log(severity, msg);
|
||||
}
|
||||
|
||||
void discord_voice_client::QueueMessage(const std::string &j, bool to_front)
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(queue_mutex);
|
||||
if (to_front) {
|
||||
message_queue.push_front(j);
|
||||
} else {
|
||||
message_queue.push_back(j);
|
||||
}
|
||||
}
|
||||
|
||||
void discord_voice_client::ClearQueue()
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(queue_mutex);
|
||||
message_queue.clear();
|
||||
}
|
||||
|
||||
size_t discord_voice_client::GetQueueSize()
|
||||
{
|
||||
std::lock_guard<std::mutex> locker(queue_mutex);
|
||||
return message_queue.size();
|
||||
}
|
||||
|
||||
const std::vector<std::string> discord_voice_client::get_marker_metadata() {
|
||||
std::lock_guard<std::mutex> locker(queue_mutex);
|
||||
return track_meta;
|
||||
}
|
||||
|
||||
void discord_voice_client::one_second_timer()
|
||||
{
|
||||
if (terminating) {
|
||||
throw dpp::exception("Terminating voice connection");
|
||||
}
|
||||
/* Rate limit outbound messages, 1 every odd second, 2 every even second */
|
||||
if (this->GetState() == CONNECTED) {
|
||||
for (int x = 0; x < (time(NULL) % 2) + 1; ++x) {
|
||||
std::lock_guard<std::mutex> locker(queue_mutex);
|
||||
if (message_queue.size()) {
|
||||
std::string message = message_queue.front();
|
||||
message_queue.pop_front();
|
||||
this->write(message);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->heartbeat_interval) {
|
||||
/* Check if we're due to emit a heartbeat */
|
||||
if (time(NULL) > last_heartbeat + ((heartbeat_interval / 1000.0) * 0.75)) {
|
||||
QueueMessage(json({{"op", 3}, {"d", rand()}}).dump(), true);
|
||||
last_heartbeat = time(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t discord_voice_client::encode(uint8_t *input, size_t inDataSize, uint8_t *output, size_t &outDataSize)
|
||||
{
|
||||
#if HAVE_VOICE
|
||||
outDataSize = 0;
|
||||
int mEncFrameBytes = 11520;
|
||||
int mEncFrameSize = 2880;
|
||||
if (0 == (inDataSize % mEncFrameBytes)) {
|
||||
bool isOk = true;
|
||||
size_t cur = 0;
|
||||
uint8_t *out = encode_buffer;
|
||||
|
||||
memset(out, 0, sizeof(encode_buffer));
|
||||
repacketizer = opus_repacketizer_init(repacketizer);
|
||||
for (size_t i = 0; i < (inDataSize / mEncFrameBytes); ++ i) {
|
||||
const opus_int16* pcm = (opus_int16*)(input + i * mEncFrameBytes);
|
||||
int ret = opus_encode(encoder, pcm, mEncFrameSize, out, 65536);
|
||||
if (ret > 0) {
|
||||
int retval = opus_repacketizer_cat(repacketizer, out, ret);
|
||||
if (retval != OPUS_OK) {
|
||||
isOk = false;
|
||||
log(ll_warning, fmt::format("opus_repacketizer_cat(): {}", opus_strerror(retval)));
|
||||
break;
|
||||
}
|
||||
out += ret;
|
||||
cur += ret;
|
||||
} else {
|
||||
isOk = false;
|
||||
log(ll_warning, fmt::format("opus_encode(): {}", opus_strerror(ret)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (isOk) {
|
||||
int ret = opus_repacketizer_out(repacketizer, output, 65536);
|
||||
if (ret > 0) {
|
||||
outDataSize = ret;
|
||||
} else {
|
||||
log(ll_warning, fmt::format("opus_repacketizer_out(): {}", opus_strerror(ret)));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw dpp::exception(fmt::format("Invalid input data length: {}, must be n times of {}", inDataSize, mEncFrameBytes));
|
||||
}
|
||||
#endif
|
||||
return outDataSize;
|
||||
}
|
||||
|
||||
void discord_voice_client::insert_marker(const std::string& metadata) {
|
||||
/* Insert a track marker. A track marker is a single 16 bit value of 0xFFFF.
|
||||
* This is too small to be a valid RTP packet so the send function knows not
|
||||
* to actually send it, and instead to skip it
|
||||
*/
|
||||
uint16_t tm = AUDIO_TRACK_MARKER;
|
||||
Send((const char*)&tm, sizeof(uint16_t));
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
track_meta.push_back(metadata);
|
||||
tracks++;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t discord_voice_client::get_tracks_remaining() {
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
if (outbuf.size() == 0)
|
||||
return 0;
|
||||
else
|
||||
return tracks + 1;
|
||||
}
|
||||
|
||||
void discord_voice_client::skip_to_next_marker() {
|
||||
std::lock_guard<std::mutex> lock(this->stream_mutex);
|
||||
/* Keep popping the first entry off the outbuf until the first entry is a track marker */
|
||||
while (outbuf.size() && outbuf[0].size() != sizeof(uint16_t) && ((uint16_t)(*(outbuf[0].data()))) != AUDIO_TRACK_MARKER) {
|
||||
outbuf.erase(outbuf.begin());
|
||||
}
|
||||
if (outbuf.size()) {
|
||||
/* Remove the actual track marker out of the buffer */
|
||||
outbuf.erase(outbuf.begin());
|
||||
}
|
||||
if (tracks > 0)
|
||||
tracks--;
|
||||
if (track_meta.size()) {
|
||||
track_meta.erase(track_meta.begin());
|
||||
}
|
||||
}
|
||||
|
||||
void discord_voice_client::send_audio(uint16_t* audio_data, const size_t length, bool use_opus) {
|
||||
#if HAVE_VOICE
|
||||
|
||||
const size_t max_frame_bytes = 11520;
|
||||
uint8_t pad[max_frame_bytes] = { 0 };
|
||||
if (length > max_frame_bytes && use_opus) {
|
||||
std::string s_audio_data((const char*)audio_data, length);
|
||||
while (s_audio_data.length() > max_frame_bytes) {
|
||||
std::string packet(s_audio_data.substr(0, max_frame_bytes));
|
||||
s_audio_data.erase(s_audio_data.begin(), s_audio_data.begin() + max_frame_bytes);
|
||||
if (packet.size() < max_frame_bytes) {
|
||||
packet.resize(max_frame_bytes, 0);
|
||||
}
|
||||
send_audio((uint16_t*)packet.data(), max_frame_bytes, use_opus);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int frameSize = 2880;
|
||||
opus_int32 encodedAudioMaxLength = length;
|
||||
std::vector<uint8_t> encodedAudioData(encodedAudioMaxLength);
|
||||
size_t encodedAudioLength = encodedAudioMaxLength;
|
||||
if (use_opus) {
|
||||
encodedAudioLength = this->encode((uint8_t*)audio_data, length, encodedAudioData.data(), encodedAudioLength);
|
||||
} else {
|
||||
}
|
||||
|
||||
++sequence;
|
||||
const int headerSize = 12;
|
||||
const int nonceSize = 24;
|
||||
rtp_header header(sequence, timestamp, ssrc);
|
||||
|
||||
int8_t nonce[nonceSize];
|
||||
std::memcpy(nonce, &header, sizeof(header));
|
||||
std::memset(nonce + sizeof(header), 0, sizeof(nonce) - sizeof(header));
|
||||
|
||||
std::vector<uint8_t> audioDataPacket(sizeof(header) + encodedAudioLength + crypto_secretbox_MACBYTES);
|
||||
std::memcpy(audioDataPacket.data(), &header, sizeof(header));
|
||||
|
||||
crypto_secretbox_easy(audioDataPacket.data() + sizeof(header), encodedAudioData.data(), encodedAudioLength, (const unsigned char*)nonce, secret_key);
|
||||
|
||||
Send((const char*)audioDataPacket.data(), audioDataPacket.size());
|
||||
timestamp += frameSize;
|
||||
|
||||
if (!this->sending) {
|
||||
this->QueueMessage(json({
|
||||
{"op", 5},
|
||||
{"d", {
|
||||
{"speaking", 1},
|
||||
{"delay", 0},
|
||||
{"ssrc", ssrc}
|
||||
}}
|
||||
}).dump(), true);
|
||||
sending = true;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string discord_voice_client::discover_ip() {
|
||||
SOCKET newfd = -1;
|
||||
unsigned char packet[74] = { 0 };
|
||||
(*(uint16_t*)(packet)) = htons(0x01);
|
||||
(*(uint16_t*)(packet + 2)) = htons(70);
|
||||
(*(uint32_t*)(packet + 4)) = htonl(this->ssrc);
|
||||
if ((newfd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
|
||||
sockaddr_in servaddr;
|
||||
socklen_t sl = sizeof(servaddr);
|
||||
memset(&servaddr, 0, sizeof(sockaddr_in));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
servaddr.sin_port = htons(0);
|
||||
if (bind(newfd, (struct sockaddr*)&servaddr, sizeof(servaddr)) < 0) {
|
||||
log(ll_warning, "Could not bind socket for IP discovery");
|
||||
return "";
|
||||
}
|
||||
memset(&servaddr, 0, sizeof(servaddr));
|
||||
servaddr.sin_family = AF_INET;
|
||||
servaddr.sin_port = htons(this->port);
|
||||
servaddr.sin_addr.s_addr = inet_addr(this->ip.c_str());
|
||||
if (::connect(newfd, (const struct sockaddr*)&servaddr, sizeof(sockaddr_in)) < 0) {
|
||||
log(ll_warning, "Could not connect socket for IP discovery");
|
||||
return "";
|
||||
}
|
||||
if (send(newfd, (const char*)packet, 74, 0) == -1) {
|
||||
log(ll_warning, "Could not send packet for IP discovery");
|
||||
return "";
|
||||
}
|
||||
if (recv(newfd, (char*)packet, 74, 0) == -1) {
|
||||
log(ll_warning, "Could not receive packet for IP discovery");
|
||||
return "";
|
||||
}
|
||||
|
||||
shutdown(newfd, 2);
|
||||
#ifdef _WIN32
|
||||
if (newfd >= 0 && newfd < FD_SETSIZE) {
|
||||
closesocket(newfd);
|
||||
}
|
||||
#else
|
||||
::close(newfd);
|
||||
#endif
|
||||
|
||||
//utility::debug_dump(packet, 74);
|
||||
return std::string((const char*)(packet + 8));
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
155
vendor/DPP/src/dpp/dispatcher.cpp
vendored
155
vendor/DPP/src/dpp/dispatcher.cpp
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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/slashcommand.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <fmt/format.h>
|
||||
#include <variant>
|
||||
|
||||
#define event_ctor(a, b) a::a(discord_client* client, const std::string &raw) : b(client, raw) {}
|
||||
|
||||
namespace dpp {
|
||||
|
||||
event_dispatch_t::event_dispatch_t(discord_client* client, const std::string &raw) : from(client), raw_event(raw)
|
||||
{
|
||||
}
|
||||
|
||||
void interaction_create_t::reply(interaction_response_type t, const message & m) const
|
||||
{
|
||||
from->creator->interaction_response_create(this->command.id, this->command.token, dpp::interaction_response(t, m));
|
||||
}
|
||||
|
||||
void interaction_create_t::reply(interaction_response_type t, const std::string & mt) const
|
||||
{
|
||||
this->reply(t, dpp::message(this->command.channel_id, mt, mt_application_command));
|
||||
}
|
||||
|
||||
void interaction_create_t::get_original_response(command_completion_event_t callback) const
|
||||
{
|
||||
from->creator->post_rest(API_PATH "/webhooks", std::to_string(command.application_id), command.token + "/messages/@original", m_get, "", [callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t("message", message().fill_from_json(&j), http));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void interaction_create_t::edit_response(const message & m) const
|
||||
{
|
||||
from->creator->interaction_response_edit(this->command.token, m);
|
||||
}
|
||||
|
||||
void interaction_create_t::edit_response(const std::string & mt) const
|
||||
{
|
||||
this->edit_response(dpp::message(this->command.channel_id, mt, mt_application_command));
|
||||
}
|
||||
|
||||
const command_value& interaction_create_t::get_parameter(const std::string& name) const
|
||||
{
|
||||
/* Dummy STATIC return value for unknown options so we arent returning a value off the stack */
|
||||
static command_value dummy_value = {};
|
||||
const command_interaction& ci = std::get<command_interaction>(command.data);
|
||||
for (auto i = ci.options.begin(); i != ci.options.end(); ++i) {
|
||||
if (i->name == name) {
|
||||
return i->value;
|
||||
}
|
||||
}
|
||||
return dummy_value;
|
||||
}
|
||||
|
||||
const command_value& button_click_t::get_parameter(const std::string& name) const
|
||||
{
|
||||
/* Buttons don't have parameters, so override this */
|
||||
static command_value dummy_b_value = {};
|
||||
return dummy_b_value;
|
||||
}
|
||||
|
||||
const command_value& select_click_t::get_parameter(const std::string& name) const
|
||||
{
|
||||
/* Selects don't have parameters, so override this */
|
||||
static command_value dummy_b_value = {};
|
||||
return dummy_b_value;
|
||||
}
|
||||
|
||||
/* Standard default constructors that call the parent constructor, for events */
|
||||
event_ctor(guild_join_request_delete_t, event_dispatch_t);
|
||||
event_ctor(stage_instance_create_t, event_dispatch_t);
|
||||
event_ctor(stage_instance_delete_t, event_dispatch_t);
|
||||
event_ctor(log_t, event_dispatch_t);
|
||||
event_ctor(voice_state_update_t, event_dispatch_t);
|
||||
event_ctor(interaction_create_t, event_dispatch_t);
|
||||
event_ctor(button_click_t, interaction_create_t);
|
||||
event_ctor(select_click_t, interaction_create_t);
|
||||
event_ctor(guild_delete_t, event_dispatch_t);
|
||||
event_ctor(channel_delete_t, event_dispatch_t);
|
||||
event_ctor(channel_update_t, event_dispatch_t);
|
||||
event_ctor(ready_t, event_dispatch_t);
|
||||
event_ctor(message_delete_t, event_dispatch_t);
|
||||
event_ctor(application_command_delete_t, event_dispatch_t);
|
||||
event_ctor(application_command_create_t, event_dispatch_t);
|
||||
event_ctor(resumed_t, event_dispatch_t);
|
||||
event_ctor(guild_role_create_t, event_dispatch_t);
|
||||
event_ctor(typing_start_t, event_dispatch_t);
|
||||
event_ctor(message_reaction_add_t, event_dispatch_t);
|
||||
event_ctor(message_reaction_remove_t, event_dispatch_t);
|
||||
event_ctor(guild_create_t, event_dispatch_t);
|
||||
event_ctor(channel_create_t, event_dispatch_t);
|
||||
event_ctor(message_reaction_remove_emoji_t, event_dispatch_t);
|
||||
event_ctor(message_delete_bulk_t, event_dispatch_t);
|
||||
event_ctor(guild_role_update_t, event_dispatch_t);
|
||||
event_ctor(guild_role_delete_t, event_dispatch_t);
|
||||
event_ctor(channel_pins_update_t, event_dispatch_t);
|
||||
event_ctor(message_reaction_remove_all_t, event_dispatch_t);
|
||||
event_ctor(voice_server_update_t, event_dispatch_t);
|
||||
event_ctor(guild_emojis_update_t, event_dispatch_t);
|
||||
event_ctor(presence_update_t, event_dispatch_t);
|
||||
event_ctor(webhooks_update_t, event_dispatch_t);
|
||||
event_ctor(guild_member_add_t, event_dispatch_t);
|
||||
event_ctor(invite_delete_t, event_dispatch_t);
|
||||
event_ctor(guild_update_t, event_dispatch_t);
|
||||
event_ctor(guild_integrations_update_t, event_dispatch_t);
|
||||
event_ctor(guild_member_update_t, event_dispatch_t);
|
||||
event_ctor(application_command_update_t, event_dispatch_t);
|
||||
event_ctor(invite_create_t, event_dispatch_t);
|
||||
event_ctor(message_update_t, event_dispatch_t);
|
||||
event_ctor(user_update_t, event_dispatch_t);
|
||||
event_ctor(message_create_t, event_dispatch_t);
|
||||
event_ctor(guild_ban_add_t, event_dispatch_t);
|
||||
event_ctor(guild_ban_remove_t, event_dispatch_t);
|
||||
event_ctor(integration_create_t, event_dispatch_t);
|
||||
event_ctor(integration_update_t, event_dispatch_t);
|
||||
event_ctor(integration_delete_t, event_dispatch_t);
|
||||
event_ctor(guild_member_remove_t, event_dispatch_t);
|
||||
event_ctor(guild_members_chunk_t, event_dispatch_t);
|
||||
event_ctor(thread_create_t, event_dispatch_t);
|
||||
event_ctor(thread_update_t, event_dispatch_t);
|
||||
event_ctor(thread_delete_t, event_dispatch_t);
|
||||
event_ctor(thread_list_sync_t, event_dispatch_t);
|
||||
event_ctor(thread_member_update_t, event_dispatch_t);
|
||||
event_ctor(thread_members_update_t, event_dispatch_t);
|
||||
event_ctor(voice_buffer_send_t, event_dispatch_t);
|
||||
event_ctor(voice_user_talking_t, event_dispatch_t);
|
||||
event_ctor(voice_ready_t, event_dispatch_t);
|
||||
event_ctor(voice_receive_t, event_dispatch_t);
|
||||
event_ctor(voice_track_marker_t, event_dispatch_t);
|
||||
event_ctor(guild_stickers_update_t, event_dispatch_t);
|
||||
|
||||
};
|
64
vendor/DPP/src/dpp/dtemplate.cpp
vendored
64
vendor/DPP/src/dpp/dtemplate.cpp
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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/dtemplate.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp {
|
||||
|
||||
dtemplate::dtemplate() : code(""), name(""), description(""), usage_count(0), creator_id(0), source_guild_id(0)
|
||||
{
|
||||
}
|
||||
|
||||
dtemplate::~dtemplate() {
|
||||
}
|
||||
|
||||
|
||||
dtemplate& dtemplate::fill_from_json(nlohmann::json* j) {
|
||||
code = StringNotNull(j, "code");
|
||||
name = StringNotNull(j, "name");
|
||||
description = StringNotNull(j, "description");
|
||||
usage_count = Int32NotNull(j, "usage_count");
|
||||
creator_id = SnowflakeNotNull(j, "creator_id");
|
||||
created_at = TimestampNotNull(j, "created_at");
|
||||
updated_at = TimestampNotNull(j, "updated_at");
|
||||
source_guild_id = SnowflakeNotNull(j, "source_guild_id");
|
||||
is_dirty = BoolNotNull(j, "is_dirty");
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string dtemplate::build_json() const {
|
||||
json j({
|
||||
{"code", code},
|
||||
{"name", name},
|
||||
{"description", description},
|
||||
{"usage_count", usage_count},
|
||||
{"creator_id", creator_id},
|
||||
{"updated_at", updated_at},
|
||||
{"source_guild_id", source_guild_id,
|
||||
"is_dirty", is_dirty}
|
||||
});
|
||||
return j.dump();
|
||||
}
|
||||
|
||||
};
|
116
vendor/DPP/src/dpp/emoji.cpp
vendored
116
vendor/DPP/src/dpp/emoji.cpp
vendored
@ -1,116 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/emoji.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <dpp/dispatcher.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
emoji::emoji() : managed(), user_id(0), flags(0), image_data(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
emoji::emoji(const std::string n, const snowflake i, const uint8_t f)
|
||||
: managed(i), user_id(0), flags(f), image_data(nullptr), name(n)
|
||||
{
|
||||
}
|
||||
|
||||
emoji::~emoji() {
|
||||
if (image_data) {
|
||||
delete image_data;
|
||||
}
|
||||
}
|
||||
|
||||
emoji& emoji::fill_from_json(nlohmann::json* j) {
|
||||
id = SnowflakeNotNull(j, "id");
|
||||
name = StringNotNull(j, "name");
|
||||
if (j->find("user") != j->end()) {
|
||||
json & user = (*j)["user"];
|
||||
user_id = SnowflakeNotNull(&user, "id");
|
||||
}
|
||||
if (BoolNotNull(j, "require_colons"))
|
||||
flags |= e_require_colons;
|
||||
if (BoolNotNull(j, "managed"))
|
||||
flags |= e_managed;
|
||||
if (BoolNotNull(j, "animated"))
|
||||
flags |= e_animated;
|
||||
if (BoolNotNull(j, "available"))
|
||||
flags |= e_available;
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string emoji::build_json(bool with_id) const {
|
||||
json j;
|
||||
if (with_id) {
|
||||
j["id"] = std::to_string(id);
|
||||
}
|
||||
j["name"] = name;
|
||||
if (image_data) {
|
||||
j["image"] = *image_data;
|
||||
}
|
||||
return j.dump();
|
||||
}
|
||||
|
||||
bool emoji::requires_colons() const {
|
||||
return flags & e_require_colons;
|
||||
}
|
||||
|
||||
bool emoji::is_managed() const {
|
||||
return flags & e_managed;
|
||||
}
|
||||
|
||||
bool emoji::is_animated() const {
|
||||
return flags & e_animated;
|
||||
}
|
||||
|
||||
bool emoji::is_available() const {
|
||||
return flags & e_available;
|
||||
}
|
||||
|
||||
emoji& emoji::load_image(const std::string &image_blob, image_type type) {
|
||||
static std::map<image_type, std::string> mimetypes = {
|
||||
{ i_gif, "image/gif" },
|
||||
{ i_jpg, "image/jpeg" },
|
||||
{ i_png, "image/png" }
|
||||
};
|
||||
if (image_blob.size() > MAX_EMOJI_SIZE) {
|
||||
throw dpp::exception("Emoji file exceeds discord limit of 256 kilobytes");
|
||||
}
|
||||
if (image_data) {
|
||||
/* If there's already image data defined, free the old data, to prevent a memory leak */
|
||||
delete image_data;
|
||||
}
|
||||
image_data = new std::string("data:" + mimetypes[type] + ";base64," + base64_encode((unsigned char const*)image_blob.data(), image_blob.length()));
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string emoji::format() const
|
||||
{
|
||||
return id ? (name + ":" + std::to_string(id)) : name;
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -1,48 +0,0 @@
|
||||
#include <dpp/discord.h>
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void application_command_create::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
}
|
||||
|
||||
}};
|
@ -1,48 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void application_command_delete::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
}
|
||||
|
||||
}};
|
@ -1,48 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void application_command_update::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
}
|
||||
|
||||
}};
|
75
vendor/DPP/src/dpp/events/channel_create.cpp
vendored
75
vendor/DPP/src/dpp/events/channel_create.cpp
vendored
@ -1,75 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <fmt/format.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void channel_create::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
json& d = j["d"];
|
||||
|
||||
dpp::channel* c = dpp::find_channel(SnowflakeNotNull(&d, "id"));
|
||||
if (!c) {
|
||||
c = new dpp::channel();
|
||||
}
|
||||
c->fill_from_json(&d);
|
||||
dpp::get_channel_cache()->store(c);
|
||||
if (c->recipients.size()) {
|
||||
for (auto & u : c->recipients) {
|
||||
client->log(dpp::ll_debug, fmt::format("Got a DM channel {} for user {}", c->id, u));
|
||||
client->creator->set_dm_channel(u, c->id);
|
||||
}
|
||||
}
|
||||
dpp::guild* g = dpp::find_guild(c->guild_id);
|
||||
if (g) {
|
||||
g->channels.push_back(c->id);
|
||||
|
||||
if (client->creator->dispatch.channel_create) {
|
||||
dpp::channel_create_t cc(client, raw);
|
||||
cc.created = c;
|
||||
cc.creating_guild = g;
|
||||
client->creator->dispatch.channel_create(cc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
69
vendor/DPP/src/dpp/events/channel_delete.cpp
vendored
69
vendor/DPP/src/dpp/events/channel_delete.cpp
vendored
@ -1,69 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void channel_delete::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
json& d = j["d"];
|
||||
dpp::channel* c = dpp::find_channel(SnowflakeNotNull(&d, "id"));
|
||||
if (c) {
|
||||
dpp::guild* g = dpp::find_guild(c->guild_id);
|
||||
if (g) {
|
||||
auto gc = std::find(g->channels.begin(), g->channels.end(), c->id);
|
||||
if (gc != g->channels.end()) {
|
||||
g->channels.erase(gc);
|
||||
}
|
||||
|
||||
if (client->creator->dispatch.channel_delete) {
|
||||
dpp::channel_delete_t cd(client, raw);
|
||||
cd.deleted = c;
|
||||
cd.deleting_guild = g;
|
||||
client->creator->dispatch.channel_delete(cd);
|
||||
}
|
||||
}
|
||||
dpp::get_channel_cache()->remove(c);
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
@ -1,61 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <dpp/discordevents.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void channel_pins_update::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
|
||||
if (client->creator->dispatch.channel_pins_update) {
|
||||
json& d = j["d"];
|
||||
dpp::channel_pins_update_t cpu(client, raw);
|
||||
cpu.pin_channel = dpp::find_channel(SnowflakeNotNull(&d, "channel_id"));
|
||||
cpu.pin_guild = dpp::find_guild(SnowflakeNotNull(&d, "guild_id"));
|
||||
cpu.timestamp = TimestampNotNull(&d, "last_pin_timestamp");
|
||||
|
||||
client->creator->dispatch.channel_pins_update(cpu);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}};
|
59
vendor/DPP/src/dpp/events/channel_update.cpp
vendored
59
vendor/DPP/src/dpp/events/channel_update.cpp
vendored
@ -1,59 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void channel_update::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
json& d = j["d"];
|
||||
dpp::channel* c = dpp::find_channel(from_string<uint64_t>(d["id"].get<std::string>(), std::dec));
|
||||
if (c) {
|
||||
c->fill_from_json(&d);
|
||||
if (client->creator->dispatch.channel_update) {
|
||||
dpp::channel_update_t cu(client, raw);
|
||||
cu.updated = c;
|
||||
cu.updating_guild = dpp::find_guild(c->guild_id);
|
||||
client->creator->dispatch.channel_update(cu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
57
vendor/DPP/src/dpp/events/guild_ban_add.cpp
vendored
57
vendor/DPP/src/dpp/events/guild_ban_add.cpp
vendored
@ -1,57 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <dpp/discordevents.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void guild_ban_add::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
if (client->creator->dispatch.guild_ban_add) {
|
||||
json &d = j["d"];
|
||||
dpp::guild_ban_add_t gba(client, raw);
|
||||
gba.banning_guild = dpp::find_guild(SnowflakeNotNull(&d, "guild_id"));
|
||||
gba.banned = dpp::user().fill_from_json(&(d["user"]));
|
||||
client->creator->dispatch.guild_ban_add(gba);
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
57
vendor/DPP/src/dpp/events/guild_ban_remove.cpp
vendored
57
vendor/DPP/src/dpp/events/guild_ban_remove.cpp
vendored
@ -1,57 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <dpp/discordevents.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void guild_ban_remove::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
if (client->creator->dispatch.guild_ban_remove) {
|
||||
json &d = j["d"];
|
||||
dpp::guild_ban_remove_t gbr(client, raw);
|
||||
gbr.unbanning_guild = dpp::find_guild(SnowflakeNotNull(&d, "guild_id"));
|
||||
gbr.unbanned = dpp::user().fill_from_json(&(d["user"]));
|
||||
client->creator->dispatch.guild_ban_remove(gbr);
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
149
vendor/DPP/src/dpp/events/guild_create.cpp
vendored
149
vendor/DPP/src/dpp/events/guild_create.cpp
vendored
@ -1,149 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void guild_create::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
json& d = j["d"];
|
||||
bool newguild = false;
|
||||
if (SnowflakeNotNull(&d, "id") == 0)
|
||||
return;
|
||||
dpp::guild* g = dpp::find_guild(SnowflakeNotNull(&d, "id"));
|
||||
if (!g) {
|
||||
g = new dpp::guild();
|
||||
newguild = true;
|
||||
}
|
||||
g->fill_from_json(client, &d);
|
||||
g->shard_id = client->shard_id;
|
||||
if (!g->is_unavailable() && newguild) {
|
||||
if (client->creator->cache_policy.role_policy != dpp::cp_none) {
|
||||
/* Store guild roles */
|
||||
g->roles.clear();
|
||||
g->roles.reserve(d["roles"].size());
|
||||
for (auto & role : d["roles"]) {
|
||||
dpp::role *r = dpp::find_role(SnowflakeNotNull(&role, "id"));
|
||||
if (!r) {
|
||||
r = new dpp::role();
|
||||
}
|
||||
r->fill_from_json(g->id, &role);
|
||||
dpp::get_role_cache()->store(r);
|
||||
g->roles.push_back(r->id);
|
||||
}
|
||||
}
|
||||
|
||||
/* Store guild channels */
|
||||
g->channels.clear();
|
||||
g->channels.reserve(d["channels"].size());
|
||||
for (auto & channel : d["channels"]) {
|
||||
dpp::channel* c = dpp::find_channel(SnowflakeNotNull(&channel, "id"));
|
||||
if (!c) {
|
||||
c = new dpp::channel();
|
||||
}
|
||||
c->fill_from_json(&channel);
|
||||
c->guild_id = g->id;
|
||||
dpp::get_channel_cache()->store(c);
|
||||
g->channels.push_back(c->id);
|
||||
}
|
||||
|
||||
/* Store guild threads */
|
||||
g->threads.clear();
|
||||
g->threads.reserve(d["threads"].size());
|
||||
for (auto & channel : d["threads"]) {
|
||||
g->threads.push_back(SnowflakeNotNull(&channel, "id"));
|
||||
}
|
||||
|
||||
/* Store guild members */
|
||||
if (client->creator->cache_policy.user_policy == cp_aggressive) {
|
||||
g->members.reserve(d["members"].size());
|
||||
for (auto & user : d["members"]) {
|
||||
snowflake userid = SnowflakeNotNull(&(user["user"]), "id");
|
||||
/* Only store ones we don't have already otherwise gm will leak */
|
||||
if (g->members.find(userid) == g->members.end()) {
|
||||
dpp::user* u = dpp::find_user(userid);
|
||||
if (!u) {
|
||||
u = new dpp::user();
|
||||
u->fill_from_json(&(user["user"]));
|
||||
dpp::get_user_cache()->store(u);
|
||||
} else {
|
||||
u->refcount++;
|
||||
}
|
||||
dpp::guild_member gm;
|
||||
gm.fill_from_json(&(user["user"]), g->id, userid);
|
||||
g->members[userid] = gm;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (client->creator->cache_policy.emoji_policy != dpp::cp_none) {
|
||||
/* Store emojis */
|
||||
g->emojis.reserve(d["emojis"].size());
|
||||
g->emojis = {};
|
||||
for (auto & emoji : d["emojis"]) {
|
||||
dpp::emoji* e = dpp::find_emoji(SnowflakeNotNull(&emoji, "id"));
|
||||
if (!e) {
|
||||
e = new dpp::emoji();
|
||||
e->fill_from_json(&emoji);
|
||||
dpp::get_emoji_cache()->store(e);
|
||||
}
|
||||
g->emojis.push_back(e->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
dpp::get_guild_cache()->store(g);
|
||||
if (newguild && g->id && (client->intents & dpp::i_guild_members)) {
|
||||
if (client->creator->cache_policy.user_policy == cp_aggressive) {
|
||||
json chunk_req = json({{"op", 8}, {"d", {{"guild_id",std::to_string(g->id)},{"query",""},{"limit",0}}}});
|
||||
if (client->intents & dpp::i_guild_presences) {
|
||||
chunk_req["d"]["presences"] = true;
|
||||
}
|
||||
client->QueueMessage(chunk_req.dump());
|
||||
}
|
||||
}
|
||||
|
||||
if (client->creator->dispatch.guild_create) {
|
||||
dpp::guild_create_t gc(client, raw);
|
||||
gc.created = g;
|
||||
client->creator->dispatch.guild_create(gc);
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
98
vendor/DPP/src/dpp/events/guild_delete.cpp
vendored
98
vendor/DPP/src/dpp/events/guild_delete.cpp
vendored
@ -1,98 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void guild_delete::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
json& d = j["d"];
|
||||
dpp::guild* g = dpp::find_guild(SnowflakeNotNull(&d, "id"));
|
||||
if (g) {
|
||||
if (!BoolNotNull(&d, "unavailable")) {
|
||||
dpp::get_guild_cache()->remove(g);
|
||||
if (client->creator->cache_policy.emoji_policy != dpp::cp_none) {
|
||||
for (auto & ee : g->emojis) {
|
||||
dpp::emoji* fe = dpp::find_emoji(ee);
|
||||
if (fe) {
|
||||
dpp::get_emoji_cache()->remove(fe);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (client->creator->cache_policy.role_policy != dpp::cp_none) {
|
||||
for (auto & rr : g->roles) {
|
||||
dpp::role* role = dpp::find_role(rr);
|
||||
if (role) {
|
||||
dpp::get_role_cache()->remove(role);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (auto & cc : g->channels) {
|
||||
dpp::channel* ch = dpp::find_channel(cc);
|
||||
if (ch) {
|
||||
dpp::get_channel_cache()->remove(ch);
|
||||
}
|
||||
}
|
||||
if (client->creator->cache_policy.user_policy != dpp::cp_none) {
|
||||
for (auto gm = g->members.begin(); gm != g->members.end(); ++gm) {
|
||||
dpp::user* u = dpp::find_user(gm->second.user_id);
|
||||
if (u) {
|
||||
u->refcount--;
|
||||
if (u->refcount < 1) {
|
||||
dpp::get_user_cache()->remove(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
g->members.clear();
|
||||
} else {
|
||||
g->flags |= dpp::g_unavailable;
|
||||
}
|
||||
|
||||
if (client->creator->dispatch.guild_delete) {
|
||||
dpp::guild_delete_t gd(client, raw);
|
||||
gd.deleted = g;
|
||||
client->creator->dispatch.guild_delete(gd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
@ -1,78 +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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/event.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/discord.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#include <dpp/discordevents.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp { namespace events {
|
||||
|
||||
using namespace dpp;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Handle event
|
||||
*
|
||||
* @param client Websocket client (current shard)
|
||||
* @param j JSON data for the event
|
||||
* @param raw Raw JSON string
|
||||
*/
|
||||
void guild_emojis_update::handle(discord_client* client, json &j, const std::string &raw) {
|
||||
json& d = j["d"];
|
||||
dpp::guild* g = dpp::find_guild(SnowflakeNotNull(&d, "guild_id"));
|
||||
if (g) {
|
||||
if (client->creator->cache_policy.emoji_policy != dpp::cp_none) {
|
||||
for (auto & ee : g->emojis) {
|
||||
dpp::emoji* fe = dpp::find_emoji(ee);
|
||||
if (fe) {
|
||||
dpp::get_emoji_cache()->remove(fe);
|
||||
}
|
||||
}
|
||||
g->emojis.clear();
|
||||
for (auto & emoji : d["emojis"]) {
|
||||
dpp::emoji* e = dpp::find_emoji(SnowflakeNotNull(&emoji, "id"));
|
||||
if (!e) {
|
||||
e = new dpp::emoji();
|
||||
e->fill_from_json(&emoji);
|
||||
dpp::get_emoji_cache()->store(e);
|
||||
}
|
||||
g->emojis.push_back(e->id);
|
||||
}
|
||||
}
|
||||
if (client->creator->dispatch.guild_emojis_update) {
|
||||
dpp::guild_emojis_update_t geu(client, raw);
|
||||
geu.emojis = g->emojis;
|
||||
geu.updating_guild = g;
|
||||
client->creator->dispatch.guild_emojis_update(geu);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user