mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2024-11-08 00:37:15 +01:00
Compare commits
9 Commits
0f235ff6af
...
62b9504d43
Author | SHA1 | Date | |
---|---|---|---|
|
62b9504d43 | ||
|
26ccfa62b9 | ||
|
83f2ab79e0 | ||
|
57321af0c7 | ||
|
8d908208f0 | ||
|
87cb6a2cba | ||
|
0487f26865 | ||
|
e3c32e4788 | ||
|
b978bc5046 |
@ -150,6 +150,7 @@ if(ENABLE_DISCORD)
|
||||
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
|
||||
|
@ -192,7 +192,7 @@ static const EnumElement g_DpVoiceStateFlagsEnum[] = {
|
||||
{_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("Supress"), static_cast< SQInteger >(dpp::vs_supress)},
|
||||
{_SC("Suppress"), static_cast< SQInteger >(dpp::vs_suppress)},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
@ -350,7 +350,7 @@ static const EnumElement g_DpStickerFormatEnum[] = {
|
||||
static const EnumElement g_DpMessageFlagsEnum[] = {
|
||||
{_SC("Crossposted"), static_cast< SQInteger >(dpp::m_crossposted)},
|
||||
{_SC("IsCrosspost"), static_cast< SQInteger >(dpp::m_is_crosspost)},
|
||||
{_SC("SupressEmbeds"), static_cast< SQInteger >(dpp::m_supress_embeds)},
|
||||
{_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)},
|
||||
|
@ -59,11 +59,7 @@ struct DpGuildMember
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpGuildMember() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpGuildMember() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -75,13 +71,24 @@ struct DpGuildMember
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -201,11 +208,7 @@ struct DpGuild
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpGuild() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpGuild() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -217,13 +220,24 @@ struct DpGuild
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
|
@ -6,7 +6,9 @@ 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"))
|
||||
@ -48,14 +50,39 @@ void Register_DPP_Message(HSQUIRRELVM vm, Table & ns)
|
||||
.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)
|
||||
);
|
||||
// --------------------------------------------------------------------------------------------
|
||||
Register_DPP_VectorProxy< dpp::component, DpComponent, SqDppComponent >(vm, ns, _SC("Components"));
|
||||
// --------------------------------------------------------------------------------------------
|
||||
ns.Bind(_SC("EmbedFooter"),
|
||||
Class< DpEmbedFooter, NoConstructor< DpEmbedFooter > >(vm, SqDppEmbedFooter::Str)
|
||||
// Meta-methods
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Core/Utility.hpp"
|
||||
#include "Library/DPP/Utilities.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <chrono>
|
||||
@ -73,11 +73,7 @@ struct DpSelectOption
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpSelectOption() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpSelectOption() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -88,14 +84,24 @@ struct DpSelectOption
|
||||
DpSelectOption & operator = (DpSelectOption && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -213,6 +219,12 @@ struct DpComponent
|
||||
* Whether the referenced pointer is owned.
|
||||
*/
|
||||
bool mOwned{false};
|
||||
// --------------------------------------------------------------------------------------------
|
||||
using Components = DpVectorProxy< dpp::component, DpComponent >;
|
||||
using Options = DpVectorProxy< dpp::select_option, DpSelectOption >;
|
||||
// --------------------------------------------------------------------------------------------
|
||||
LightObj mSqComponents{};
|
||||
LightObj mSqOptions{};
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Default constructor.
|
||||
*/
|
||||
@ -246,11 +258,7 @@ struct DpComponent
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpComponent() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpComponent() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -261,14 +269,38 @@ struct DpComponent
|
||||
DpComponent & operator = (DpComponent && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
Cleanup();
|
||||
// Transfer members values
|
||||
mPtr = std::move(o.mPtr);
|
||||
mOwned = o.mOwned;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Release any referenced resources and default to an empty/invalid state.
|
||||
*/
|
||||
void Cleanup()
|
||||
{
|
||||
// Cleanup components, if any
|
||||
if (!mSqComponents.IsNull())
|
||||
{
|
||||
mSqComponents.CastI< Components >()->Cleanup();
|
||||
// Release script resources
|
||||
mSqComponents.Release();
|
||||
}
|
||||
// Cleanup options, if any
|
||||
if (!mSqOptions.IsNull())
|
||||
{
|
||||
mSqOptions.CastI< Components >()->Cleanup();
|
||||
// Release script resources
|
||||
mSqOptions.Release();
|
||||
}
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) {
|
||||
// Not our job, simply forget about it
|
||||
[[maybe_unused]] auto p = mPtr.release();
|
||||
} else mPtr.reset(); // We own this so delete the instance
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Validate the managed handle.
|
||||
*/
|
||||
@ -281,7 +313,164 @@ struct DpComponent
|
||||
* Check whether a valid instance is managed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
|
||||
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Build JSON string from this object.
|
||||
*/
|
||||
SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated type.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetType() const { return static_cast< SQInteger >(Valid().type); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated type.
|
||||
*/
|
||||
void SetType(SQInteger type) const { Valid().set_type(static_cast< dpp::component_type >(type)); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated label.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetLabel() const { return Valid().label; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated label.
|
||||
*/
|
||||
void SetLabel(StackStrF & label) const { Valid().set_label(label.ToStr()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated label.
|
||||
*/
|
||||
DpComponent & ApplyLabel(StackStrF & label) { SetLabel(label); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated style.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetStyle() const { return static_cast< SQInteger >(Valid().style); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated style.
|
||||
*/
|
||||
void SetStyle(SQInteger style) const { Valid().set_style(static_cast< dpp::component_style >(style)); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated custom id.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetCustomID() const { return Valid().custom_id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated custom id.
|
||||
*/
|
||||
void SetCustomID(StackStrF & custom_id) const { Valid().set_label(custom_id.ToStr()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated custom id.
|
||||
*/
|
||||
DpComponent & ApplyCustomID(StackStrF & custom_id) { SetCustomID(custom_id); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated URL.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetURL() const { return Valid().url; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated URL.
|
||||
*/
|
||||
void SetURL(StackStrF & url) const { Valid().set_label(url.ToStr()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated URL.
|
||||
*/
|
||||
DpComponent & ApplyURL(StackStrF & url) { SetURL(url); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated placeholder.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetPlaceholder() const { return Valid().placeholder; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated placeholder.
|
||||
*/
|
||||
void SetPlaceholder(StackStrF & placeholder) const { Valid().set_label(placeholder.ToStr()); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated placeholder.
|
||||
*/
|
||||
DpComponent & ApplyPlaceholder(StackStrF & placeholder) { SetPlaceholder(placeholder); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated minimum values.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetMinValues() const { return static_cast< SQInteger >(Valid().min_values); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated minimum values.
|
||||
*/
|
||||
void SetMinValues(SQInteger value) const { Valid().set_min_values(static_cast< uint32_t >(value)); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated maximum values.
|
||||
*/
|
||||
SQMOD_NODISCARD SQInteger GetMaxValues() const { return static_cast< SQInteger >(Valid().max_values); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated maximum values.
|
||||
*/
|
||||
void SetMaxValues(SQInteger value) const { Valid().set_max_values(static_cast< uint32_t >(value)); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether this component is disabled.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsDisabled() const { return Valid().disabled; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify whether this component is disabled.
|
||||
*/
|
||||
DpComponent & SetDisabled(bool toggle) { Valid().set_disabled(toggle); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated emoji.
|
||||
*/
|
||||
DpComponent & SetEmoji(StackStrF & name, dpp::snowflake id, bool animated) { Valid().set_emoji(name.ToStr(), id, animated); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check whether the emoji is animated.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsAnimated() const { return Valid().emoji.animated; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify whether the emoji is animated.
|
||||
*/
|
||||
DpComponent & SetAnimated(bool anim) { Valid().emoji.animated = anim; return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated emoji name.
|
||||
*/
|
||||
SQMOD_NODISCARD const String & GetEmojiName() const { return Valid().emoji.name; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated emoji name.
|
||||
*/
|
||||
void SetEmojiName(StackStrF & name) const
|
||||
{
|
||||
if (name.mLen > 0)
|
||||
{
|
||||
Valid().emoji.name.assign(name.mPtr, static_cast< size_t >(name.mLen));
|
||||
}
|
||||
else
|
||||
{
|
||||
Valid().emoji.name.clear();
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated emoji name.
|
||||
*/
|
||||
DpComponent & ApplyEmojiName(StackStrF & name) { SetEmojiName(name); return *this; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated emoji id.
|
||||
*/
|
||||
SQMOD_NODISCARD dpp::snowflake GetEmojiID() const { return Valid().emoji.id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Modify the associated emoji id.
|
||||
*/
|
||||
void SetEmojiID(dpp::snowflake id) const { Valid().emoji.id = id; }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated components.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetComponents()
|
||||
{
|
||||
if (mSqComponents.IsNull())
|
||||
{
|
||||
mSqComponents = LightObj{SqTypeIdentity< Components >{}, SqVM(), &Valid().components, false};
|
||||
}
|
||||
// Return the associated script object
|
||||
return mSqComponents;
|
||||
}
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Retrieve the associated components.
|
||||
*/
|
||||
SQMOD_NODISCARD LightObj & GetOptions()
|
||||
{
|
||||
if (mSqOptions.IsNull())
|
||||
{
|
||||
mSqOptions = LightObj{SqTypeIdentity< Options >{}, SqVM(), &Valid().options, false};
|
||||
}
|
||||
// Return the associated script object
|
||||
return mSqOptions;
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
@ -331,11 +520,7 @@ struct DpEmbedFooter
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpEmbedFooter() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpEmbedFooter() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -346,14 +531,24 @@ struct DpEmbedFooter
|
||||
DpEmbedFooter & operator = (DpEmbedFooter && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -416,11 +611,7 @@ struct DpEmbedImage
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpEmbedImage() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpEmbedImage() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -431,14 +622,24 @@ struct DpEmbedImage
|
||||
DpEmbedImage & operator = (DpEmbedImage && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -501,11 +702,7 @@ struct DpEmbedProvider
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpEmbedProvider() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpEmbedProvider() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -516,14 +713,24 @@ struct DpEmbedProvider
|
||||
DpEmbedProvider & operator = (DpEmbedProvider && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -586,11 +793,7 @@ struct DpEmbedAuthor
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpEmbedAuthor() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpEmbedAuthor() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -601,14 +804,24 @@ struct DpEmbedAuthor
|
||||
DpEmbedAuthor & operator = (DpEmbedAuthor && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -671,11 +884,7 @@ struct DpEmbedField
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpEmbedField() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpEmbedField() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -686,14 +895,24 @@ struct DpEmbedField
|
||||
DpEmbedField & operator = (DpEmbedField && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -756,11 +975,7 @@ struct DpEmbed
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpEmbed() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpEmbed() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -771,14 +986,24 @@ struct DpEmbed
|
||||
DpEmbed & operator = (DpEmbed && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -841,11 +1066,7 @@ struct DpReaction
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpReaction() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpReaction() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -856,14 +1077,24 @@ struct DpReaction
|
||||
DpReaction & operator = (DpReaction && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -926,11 +1157,7 @@ struct DpAttachment
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpAttachment() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpAttachment() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -941,14 +1168,24 @@ struct DpAttachment
|
||||
DpAttachment & operator = (DpAttachment && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -1011,11 +1248,7 @@ struct DpSticker
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpSticker() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpSticker() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -1026,14 +1259,24 @@ struct DpSticker
|
||||
DpSticker & operator = (DpSticker && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -1096,11 +1339,7 @@ struct DpStickerPack
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpStickerPack() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpStickerPack() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -1111,14 +1350,24 @@ struct DpStickerPack
|
||||
DpStickerPack & operator = (DpStickerPack && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -1181,11 +1430,7 @@ struct DpMessage
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpMessage() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpMessage() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -1196,14 +1441,24 @@ struct DpMessage
|
||||
DpMessage & operator = (DpMessage && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
|
@ -134,7 +134,7 @@ void Register_DPP_Other(HSQUIRRELVM vm, Table & ns)
|
||||
.Prop(_SC("IsSelfDeaf"), &DpVoiceState::IsSelfDeaf)
|
||||
.Prop(_SC("SelfStream"), &DpVoiceState::SelfStream)
|
||||
.Prop(_SC("SelfVideo"), &DpVoiceState::SelfVideo)
|
||||
.Prop(_SC("IsSupressed"), &DpVoiceState::IsSupressed)
|
||||
.Prop(_SC("IsSuppressed"), &DpVoiceState::IsSuppressed)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -114,11 +114,7 @@ struct DpActivity
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpActivity() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpActivity() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -129,14 +125,24 @@ struct DpActivity
|
||||
DpActivity & operator = (DpActivity && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -302,11 +308,7 @@ struct DpPresence
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpPresence() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpPresence() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -317,14 +319,24 @@ struct DpPresence
|
||||
DpPresence & operator = (DpPresence && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -489,11 +501,7 @@ struct DpVoiceState
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpVoiceState() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpVoiceState() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -504,14 +512,24 @@ struct DpVoiceState
|
||||
DpVoiceState & operator = (DpVoiceState && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
@ -579,7 +597,7 @@ struct DpVoiceState
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Check if user is surpressed.
|
||||
*/
|
||||
SQMOD_NODISCARD bool IsSupressed() const { return Valid().is_supressed(); }
|
||||
SQMOD_NODISCARD bool IsSuppressed() const { return Valid().is_suppressed(); }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
|
@ -59,11 +59,7 @@ struct DpRole
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpRole() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpRole() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -74,14 +70,24 @@ struct DpRole
|
||||
DpRole & operator = (DpRole && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
|
@ -56,11 +56,7 @@ struct DpUser
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Destructor.
|
||||
*/
|
||||
~DpUser() noexcept
|
||||
{
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
}
|
||||
~DpUser() noexcept { Cleanup(); }
|
||||
/* --------------------------------------------------------------------------------------------
|
||||
* Copy assignment operator (disabled).
|
||||
*/
|
||||
@ -71,14 +67,24 @@ struct DpUser
|
||||
DpUser & operator = (DpUser && o) noexcept
|
||||
{
|
||||
if (this != &o) {
|
||||
// Do we own this to try delete it?
|
||||
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
|
||||
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.
|
||||
*/
|
||||
|
12
module/Library/DPP/Utilities.cpp
Normal file
12
module/Library/DPP/Utilities.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "Library/DPP/Utilities.hpp"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
namespace SqMod {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
} // Namespace:: SqMod
|
415
module/Library/DPP/Utilities.hpp
Normal file
415
module/Library/DPP/Utilities.hpp
Normal file
@ -0,0 +1,415 @@
|
||||
#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) { ValidIdx_(i); 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
|
2
vendor/DPP/include/dpp/cache.h
vendored
2
vendor/DPP/include/dpp/cache.h
vendored
@ -88,7 +88,7 @@ namespace dpp {
|
||||
* @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 casue crashes!
|
||||
* 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
|
||||
|
6
vendor/DPP/include/dpp/cluster.h
vendored
6
vendor/DPP/include/dpp/cluster.h
vendored
@ -290,8 +290,8 @@ public:
|
||||
* @param shards The total number of shards on this bot. If there are multiple clusters, then (shards / clusters) actual shards will run on this cluster.
|
||||
* If you omit this value, the library will attempt to query the Discord API for the correct number of shards to start.
|
||||
* @param cluster_id The ID of this cluster, should be between 0 and MAXCLUSTERS-1
|
||||
* @param maxclusters The total number of clusters that are active, which may be on seperate processes or even separate machines.
|
||||
* @param compressed Wether or not to use compression for shards on this cluster. Saves a ton of bandwidth at the cost of some CPU
|
||||
* @param maxclusters The total number of clusters that are active, which may be on separate processes or even separate machines.
|
||||
* @param compressed Whether or not to use compression for shards on this cluster. Saves a ton of bandwidth at the cost of some CPU
|
||||
* @param policy Set the user caching policy for the cluster, either lazy (only cache users/members when they message the bot) or aggressive (request whole member lists on seeing new guilds too)
|
||||
*/
|
||||
cluster(const std::string &token, uint32_t intents = i_default_intents, uint32_t shards = 0, uint32_t cluster_id = 0, uint32_t maxclusters = 1, bool compressed = true, cache_policy_t policy = {cp_aggressive, cp_aggressive, cp_aggressive});
|
||||
@ -1968,7 +1968,7 @@ public:
|
||||
void thread_create(const std::string& thread_name, snowflake channel_id, uint16_t auto_archive_duration, channel_type thread_type, command_completion_event_t callback = {});
|
||||
|
||||
/**
|
||||
* @brief Create a thread with a message (Discord: ID of a thread is same as mesage ID)
|
||||
* @brief Create a thread with a message (Discord: ID of a thread is same as message ID)
|
||||
*
|
||||
* @param thread_name Name of the thread
|
||||
* @param channel_id Channel in which thread to create
|
||||
|
40
vendor/DPP/include/dpp/commandhandler.h
vendored
40
vendor/DPP/include/dpp/commandhandler.h
vendored
@ -30,11 +30,29 @@
|
||||
|
||||
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::string, dpp::role, dpp::channel, dpp::user, int32_t, bool> command_parameter;
|
||||
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.
|
||||
@ -102,7 +120,7 @@ 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 explaination as to why vector is used.
|
||||
* 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;
|
||||
|
||||
@ -277,9 +295,25 @@ public:
|
||||
* to the user if you do not emit some form of reply within 3 seconds.
|
||||
*
|
||||
* @param m message to reply with.
|
||||
* @param interaction true if the reply is generated by an interaction
|
||||
* @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);
|
||||
|
||||
};
|
||||
|
||||
};
|
4
vendor/DPP/include/dpp/discord.h
vendored
4
vendor/DPP/include/dpp/discord.h
vendored
@ -186,7 +186,7 @@ namespace dpp {
|
||||
* @brief Convert a byte count to display value
|
||||
*
|
||||
* @param c number of bytes
|
||||
* @return std::string display value suffixed with M, G, T where neccessary
|
||||
* @return std::string display value suffixed with M, G, T where necessary
|
||||
*/
|
||||
std::string CoreExport bytes(uint64_t c);
|
||||
|
||||
@ -257,7 +257,7 @@ namespace dpp {
|
||||
* @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 emtpy string if invalid UTF-8 passed in
|
||||
* @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);
|
||||
};
|
||||
|
2
vendor/DPP/include/dpp/discordvoiceclient.h
vendored
2
vendor/DPP/include/dpp/discordvoiceclient.h
vendored
@ -201,7 +201,7 @@ class CoreExport discord_voice_client : public websocket_client
|
||||
int UDPSend(const char* data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Receieve data from UDP socket immediately.
|
||||
* @brief Receive data from UDP socket immediately.
|
||||
*
|
||||
* @param data data to receive
|
||||
* @param max_length size of data receiving buffer
|
||||
|
2
vendor/DPP/include/dpp/dispatcher.h
vendored
2
vendor/DPP/include/dpp/dispatcher.h
vendored
@ -1095,7 +1095,7 @@ public:
|
||||
* @param event Event parameters
|
||||
*/
|
||||
std::function<void(const voice_ready_t& event)> voice_ready;
|
||||
/** @brief Event handler function pointer for voice receieve event
|
||||
/** @brief Event handler function pointer for voice receive event
|
||||
* @param event Event parameters
|
||||
*/
|
||||
std::function<void(const voice_receive_t& event)> voice_receive;
|
||||
|
2
vendor/DPP/include/dpp/guild.h
vendored
2
vendor/DPP/include/dpp/guild.h
vendored
@ -207,7 +207,7 @@ public:
|
||||
/** Setting for how notifications are to be delivered to users */
|
||||
uint8_t default_message_notifications;
|
||||
|
||||
/** Wether or not explicit content filtering is enable and what setting it is */
|
||||
/** 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 */
|
||||
|
18
vendor/DPP/include/dpp/message.h
vendored
18
vendor/DPP/include/dpp/message.h
vendored
@ -474,7 +474,7 @@ struct CoreExport embed {
|
||||
/** Add an embed field. Returns the embed itself so these method calls may be "chained"
|
||||
* @param name The name of the field
|
||||
* @param value The value of the field (max length 1000)
|
||||
* @param is_inline Wether or not to display the field 'inline' or on its own line
|
||||
* @param is_inline Whether or not to display the field 'inline' or on its own line
|
||||
* @return A reference to self
|
||||
*/
|
||||
embed& add_field(const std::string& name, const std::string &value, bool is_inline = false);
|
||||
@ -569,6 +569,8 @@ struct CoreExport attachment {
|
||||
uint32_t height;
|
||||
/** MIME type of the attachment, if applicable */
|
||||
std::string content_type;
|
||||
/** Whether this attachment is ephemeral, if applicable */
|
||||
bool ephemeral;
|
||||
|
||||
/**
|
||||
* @brief Constructs a new attachment object.
|
||||
@ -724,7 +726,7 @@ enum message_flags {
|
||||
/// this message originated from a message in another channel (via Channel Following)
|
||||
m_is_crosspost = 1 << 1,
|
||||
/// do not include any embeds when serializing this message
|
||||
m_supress_embeds = 1 << 2,
|
||||
m_suppress_embeds = 1 << 2,
|
||||
/// the source message for this crosspost has been deleted (via Channel Following)
|
||||
m_source_message_deleted = 1 << 3,
|
||||
/// this message came from the urgent message system
|
||||
@ -736,7 +738,7 @@ enum message_flags {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Mesage types for dpp::message::type
|
||||
* @brief Message types for dpp::message::type
|
||||
*/
|
||||
enum message_type {
|
||||
/// Default
|
||||
@ -970,9 +972,9 @@ struct CoreExport message {
|
||||
/**
|
||||
* @brief Set the allowed mentions object for pings on the message
|
||||
*
|
||||
* @param _parse_users wether or not to parse users in the message content or embeds
|
||||
* @param _parse_roles wether or not to parse roles in the message content or embeds
|
||||
* @param _parse_everyone wether or not to parse everyone/here in the message content or embeds
|
||||
* @param _parse_users whether or not to parse users in the message content or embeds
|
||||
* @param _parse_roles whether or not to parse roles in the message content or embeds
|
||||
* @param _parse_everyone whether or not to parse everyone/here in the message content or embeds
|
||||
* @param _replied_user if set to true and this is a reply, then ping the user we reply to
|
||||
* @param users list of user ids to allow pings for
|
||||
* @param roles list of role ids to allow pings for
|
||||
@ -982,7 +984,7 @@ struct CoreExport message {
|
||||
|
||||
/** Fill this object from json.
|
||||
* @param j JSON object to fill from
|
||||
* @param cp Cache policy for user records, wether or not we cache users when a message is received
|
||||
* @param cp Cache policy for user records, whether or not we cache users when a message is received
|
||||
* @return A reference to self
|
||||
*/
|
||||
message& fill_from_json(nlohmann::json* j, cache_policy_t cp = {cp_aggressive, cp_aggressive, cp_aggressive});
|
||||
@ -1012,7 +1014,7 @@ struct CoreExport message {
|
||||
*
|
||||
* @return true if embeds removed
|
||||
*/
|
||||
bool supress_embeds() const;
|
||||
bool suppress_embeds() const;
|
||||
|
||||
/**
|
||||
* @brief True if source message was deleted
|
||||
|
30
vendor/DPP/include/dpp/slashcommand.h
vendored
30
vendor/DPP/include/dpp/slashcommand.h
vendored
@ -54,8 +54,10 @@ enum command_option_type : uint8_t {
|
||||
* @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::string, int32_t, bool, snowflake> command_value;
|
||||
typedef std::variant<std::monostate, std::string, int32_t, bool, snowflake> command_value;
|
||||
|
||||
/**
|
||||
* @brief This struct represents choices in a multiple choice option
|
||||
@ -157,8 +159,6 @@ void to_json(nlohmann::json& j, const command_option& opt);
|
||||
*/
|
||||
enum interaction_response_type {
|
||||
ir_pong = 1, //!< ACK a Ping
|
||||
ir_acknowledge = 2, //!< DEPRECATED ACK a command without sending a message, eating the user's input
|
||||
ir_channel_message = 3, //!< DEPRECATED respond with a message, eating the user's input
|
||||
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
|
||||
@ -226,11 +226,25 @@ struct CoreExport interaction_response {
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Resolved snowflake ids to usernames.
|
||||
* TODO: Needs implementation. Not needed something that
|
||||
* functions as we have cache.
|
||||
* @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;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -272,7 +286,6 @@ enum interaction_type {
|
||||
struct CoreExport command_interaction {
|
||||
snowflake id; //!< the ID of the invoked command
|
||||
std::string name; //!< the name of the invoked command
|
||||
command_resolved resolved; //!< Optional: converted users + roles + channels
|
||||
std::vector<command_data_option> options; //!< Optional: the params + values from the user
|
||||
};
|
||||
|
||||
@ -326,6 +339,7 @@ public:
|
||||
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
|
||||
@ -513,7 +527,7 @@ public:
|
||||
|
||||
/**
|
||||
* @brief Disable default permissions, command will be unusable unless
|
||||
* permissions are overriden with add_permission and
|
||||
* permissions are overridden with add_permission and
|
||||
* dpp::guild_command_edit_permissions
|
||||
*
|
||||
* @return slashcommand& reference to self for chaining of calls
|
||||
|
6
vendor/DPP/include/dpp/version.h
vendored
6
vendor/DPP/include/dpp/version.h
vendored
@ -21,9 +21,9 @@
|
||||
#pragma once
|
||||
|
||||
#if !defined(DPP_VERSION_LONG)
|
||||
#define DPP_VERSION_LONG 0x00090003
|
||||
#define DPP_VERSION_SHORT 090003
|
||||
#define DPP_VERSION_TEXT "D++ 9.0.3 (05-Sep-2021)"
|
||||
#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)
|
||||
|
8
vendor/DPP/include/dpp/voicestate.h
vendored
8
vendor/DPP/include/dpp/voicestate.h
vendored
@ -34,7 +34,7 @@ enum voicestate_flags {
|
||||
vs_self_deaf = 0b00001000, //!< Self Deafened
|
||||
vs_self_stream = 0b00010000, //!< Self Streaming
|
||||
vs_self_video = 0b00100000, //!< Self Video
|
||||
vs_supress = 0b01000000 //!< Supression
|
||||
vs_suppress = 0b01000000 //!< Suppression
|
||||
};
|
||||
|
||||
/**
|
||||
@ -94,9 +94,9 @@ public:
|
||||
/// Return true if the user is in video
|
||||
bool self_video() const;
|
||||
|
||||
/// Return true if user is surpressed.
|
||||
/// "HELP HELP I'M BEING SUPRESSED!"
|
||||
bool is_supressed() const;
|
||||
/// Return true if user is suppressed.
|
||||
/// "HELP HELP I'M BEING SUPPRESSED!"
|
||||
bool is_suppressed() const;
|
||||
};
|
||||
|
||||
/** A container of voicestates */
|
||||
|
30
vendor/DPP/src/dpp/cluster.cpp
vendored
30
vendor/DPP/src/dpp/cluster.cpp
vendored
@ -327,7 +327,7 @@ void cluster::interaction_response_edit(const std::string &token, const message
|
||||
|
||||
|
||||
void cluster::global_command_create(slashcommand &s, command_completion_event_t callback) {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(me.id), "commands", m_post, s.build_json(false), [s, callback] (json &j, const http_request_completion_t& http) mutable {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(s.application_id ? s.application_id : me.id), "commands", m_post, s.build_json(false), [s, callback] (json &j, const http_request_completion_t& http) mutable {
|
||||
if (j.contains("id")) {
|
||||
s.id = SnowflakeNotNull(&j, "id");
|
||||
}
|
||||
@ -339,7 +339,7 @@ void cluster::global_command_create(slashcommand &s, command_completion_event_t
|
||||
}
|
||||
|
||||
void cluster::guild_command_create(slashcommand &s, snowflake guild_id, command_completion_event_t callback) {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(me.id), "guilds/" + std::to_string(guild_id) + "/commands", m_post, s.build_json(false), [s, this, guild_id, callback] (json &j, const http_request_completion_t& http) mutable {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(s.application_id ? s.application_id : me.id), "guilds/" + std::to_string(guild_id) + "/commands", m_post, s.build_json(false), [s, this, guild_id, callback] (json &j, const http_request_completion_t& http) mutable {
|
||||
if (j.contains("id")) {
|
||||
s.id = SnowflakeNotNull(&j, "id");
|
||||
}
|
||||
@ -355,11 +355,14 @@ void cluster::guild_command_create(slashcommand &s, snowflake guild_id, command_
|
||||
}
|
||||
|
||||
void cluster::guild_bulk_command_create(const std::vector<slashcommand> &commands, snowflake guild_id, command_completion_event_t callback) {
|
||||
if (commands.empty()) {
|
||||
return;
|
||||
}
|
||||
json j = json::array();
|
||||
for (auto & s : commands) {
|
||||
j.push_back(json::parse(s.build_json(false)));
|
||||
}
|
||||
this->post_rest(API_PATH "/applications", std::to_string(me.id), "guilds/" + std::to_string(guild_id) + "/commands", m_put, j.dump(), [this, callback] (json &j, const http_request_completion_t& http) mutable {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(commands[0].application_id ? commands[0].application_id : me.id), "guilds/" + std::to_string(guild_id) + "/commands", m_put, j.dump(), [this, callback] (json &j, const http_request_completion_t& http) mutable {
|
||||
slashcommand_map slashcommands;
|
||||
for (auto & curr_slashcommand : j) {
|
||||
slashcommands[SnowflakeNotNull(&curr_slashcommand, "id")] = slashcommand().fill_from_json(&curr_slashcommand);
|
||||
@ -371,11 +374,14 @@ void cluster::guild_bulk_command_create(const std::vector<slashcommand> &command
|
||||
}
|
||||
|
||||
void cluster::global_bulk_command_create(const std::vector<slashcommand> &commands, command_completion_event_t callback) {
|
||||
if (commands.empty()) {
|
||||
return;
|
||||
}
|
||||
json j = json::array();
|
||||
for (auto & s : commands) {
|
||||
j.push_back(json::parse(s.build_json(false)));
|
||||
}
|
||||
this->post_rest(API_PATH "/applications", std::to_string(me.id), "commands", m_put, j.dump(), [this, callback] (json &j, const http_request_completion_t& http) mutable {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(commands[0].application_id ? commands[0].application_id : me.id), "commands", m_put, j.dump(), [this, callback] (json &j, const http_request_completion_t& http) mutable {
|
||||
slashcommand_map slashcommands;
|
||||
for (auto & curr_slashcommand : j) {
|
||||
slashcommands[SnowflakeNotNull(&curr_slashcommand, "id")] = slashcommand().fill_from_json(&curr_slashcommand);
|
||||
@ -387,7 +393,7 @@ void cluster::global_bulk_command_create(const std::vector<slashcommand> &comman
|
||||
}
|
||||
|
||||
void cluster::global_command_edit(const slashcommand &s, command_completion_event_t callback) {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(me.id), "commands/" + std::to_string(s.id), m_patch, s.build_json(true), [callback](json &j, const http_request_completion_t& http) {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(s.application_id ? s.application_id : me.id), "commands/" + std::to_string(s.id), m_patch, s.build_json(true), [callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t("confirmation", confirmation(), http));
|
||||
}
|
||||
@ -395,7 +401,7 @@ void cluster::global_command_edit(const slashcommand &s, command_completion_even
|
||||
}
|
||||
|
||||
void cluster::guild_command_edit(const slashcommand &s, snowflake guild_id, command_completion_event_t callback) {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(me.id), "guilds/" + std::to_string(guild_id) + "/commands/" + std::to_string(s.id), m_patch, s.build_json(true), [callback](json &j, const http_request_completion_t& http) {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(s.application_id ? s.application_id : me.id), "guilds/" + std::to_string(guild_id) + "/commands/" + std::to_string(s.id), m_patch, s.build_json(true), [callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t("confirmation", confirmation(), http));
|
||||
}
|
||||
@ -414,7 +420,7 @@ void cluster::guild_command_edit_permissions(const slashcommand &s, snowflake gu
|
||||
}
|
||||
}
|
||||
|
||||
this->post_rest(API_PATH "/applications", std::to_string(me.id), "guilds/" + std::to_string(guild_id) + "/commands/" + std::to_string(s.id) + "/permissions", m_put, j.dump(), [callback](json &j, const http_request_completion_t& http) {
|
||||
this->post_rest(API_PATH "/applications", std::to_string(s.application_id ? s.application_id : me.id), "guilds/" + std::to_string(guild_id) + "/commands/" + std::to_string(s.id) + "/permissions", m_put, j.dump(), [callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t("confirmation", confirmation(), http));
|
||||
}
|
||||
@ -1040,7 +1046,7 @@ void cluster::guild_ban_add(snowflake guild_id, snowflake user_id, uint32_t dele
|
||||
j["reason"] = reason;
|
||||
if (delete_message_days)
|
||||
j["delete_message_days"] = delete_message_days;
|
||||
this->post_rest(API_PATH "/guilds", std::to_string(guild_id), "bans/" + std::to_string(user_id), m_put, "", [callback](json &j, const http_request_completion_t& http) {
|
||||
this->post_rest(API_PATH "/guilds", std::to_string(guild_id), "bans/" + std::to_string(user_id), m_put, j.dump(), [callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t("confirmation", confirmation(), http));
|
||||
}
|
||||
@ -1656,7 +1662,7 @@ void cluster::execute_webhook(const class webhook &wh, const struct message& m,
|
||||
if (thread_id) {
|
||||
parameters.append("&thread_id=" + std::to_string(thread_id));
|
||||
}
|
||||
this->post_rest(API_PATH "/webhooks", std::to_string(wh.id), dpp::url_encode(token), m_post, m.build_json(false), [callback](json &j, const http_request_completion_t& http) {
|
||||
this->post_rest(API_PATH "/webhooks", std::to_string(wh.id), dpp::url_encode(!wh.token.empty() ? wh.token: token), m_post, m.build_json(false), [callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t("message", message().fill_from_json(&j), http));
|
||||
}
|
||||
@ -1665,7 +1671,7 @@ void cluster::execute_webhook(const class webhook &wh, const struct message& m,
|
||||
|
||||
void cluster::get_webhook_message(const class webhook &wh, command_completion_event_t callback)
|
||||
{
|
||||
this->post_rest(API_PATH "/webhooks", std::to_string(wh.id), dpp::url_encode(token) + "/messages/@original", m_get, "", [callback](json &j, const http_request_completion_t &http){
|
||||
this->post_rest(API_PATH "/webhooks", std::to_string(wh.id), dpp::url_encode(!wh.token.empty() ? wh.token: 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));
|
||||
}
|
||||
@ -1673,7 +1679,7 @@ void cluster::get_webhook_message(const class webhook &wh, command_completion_ev
|
||||
}
|
||||
|
||||
void cluster::edit_webhook_message(const class webhook &wh, const struct message& m, command_completion_event_t callback) {
|
||||
this->post_rest(API_PATH "/webhooks", std::to_string(wh.id), dpp::url_encode(token) + "/messages/" + std::to_string(m.id), m_patch, m.build_json(false), [callback](json &j, const http_request_completion_t& http) {
|
||||
this->post_rest(API_PATH "/webhooks", std::to_string(wh.id), dpp::url_encode(!wh.token.empty() ? wh.token: token) + "/messages/" + std::to_string(m.id), m_patch, m.build_json(false), [callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t("message", message().fill_from_json(&j), http));
|
||||
}
|
||||
@ -1681,7 +1687,7 @@ void cluster::edit_webhook_message(const class webhook &wh, const struct message
|
||||
}
|
||||
|
||||
void cluster::delete_webhook_message(const class webhook &wh, snowflake message_id, command_completion_event_t callback) {
|
||||
this->post_rest(API_PATH "/webhooks", std::to_string(wh.id), dpp::url_encode(token) + "/messages/" + std::to_string(message_id), m_delete, "", [callback](json &j, const http_request_completion_t& http) {
|
||||
this->post_rest(API_PATH "/webhooks", std::to_string(wh.id), dpp::url_encode(!wh.token.empty() ? wh.token: token) + "/messages/" + std::to_string(message_id), m_delete, "", [callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t("confirmation", confirmation(), http));
|
||||
}
|
||||
|
149
vendor/DPP/src/dpp/commandhandler.cpp
vendored
149
vendor/DPP/src/dpp/commandhandler.cpp
vendored
@ -155,6 +155,10 @@ bool commandhandler::string_has_prefix(std::string &str)
|
||||
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;
|
||||
@ -226,8 +230,15 @@ void commandhandler::route(const dpp::message& msg)
|
||||
snowflake uid = from_string<uint64_t>(x.substr(2, x.length() - 1), std::dec);
|
||||
user* u = dpp::find_user(uid);
|
||||
if (u) {
|
||||
param = *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;
|
||||
@ -270,6 +281,7 @@ void commandhandler::route(const interaction_create_t & event)
|
||||
* 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 */
|
||||
@ -277,57 +289,86 @@ void commandhandler::route(const interaction_create_t & event)
|
||||
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.valueless_by_exception()) {
|
||||
if (p.second.optional && slash_parameter.index() == 0 /* std::monostate */) {
|
||||
/* Missing optional parameter, skip this */
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
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) {
|
||||
param = *r;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case pt_channel: {
|
||||
snowflake cid = std::get<snowflake>(slash_parameter);
|
||||
channel* c = dpp::find_channel(cid);
|
||||
if (c) {
|
||||
param = *c;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case pt_user: {
|
||||
snowflake uid = std::get<snowflake>(slash_parameter);
|
||||
user* u = dpp::find_user(uid);
|
||||
if (u) {
|
||||
param = *u;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case pt_integer: {
|
||||
int32_t i = std::get<int32_t>(slash_parameter);
|
||||
param = i;
|
||||
}
|
||||
case pt_boolean: {
|
||||
bool b = std::get<bool>(slash_parameter);
|
||||
param = b;
|
||||
}
|
||||
break;
|
||||
switch (p.second.type) {
|
||||
case pt_string: {
|
||||
std::string s = std::get<std::string>(slash_parameter);
|
||||
param = s;
|
||||
}
|
||||
}
|
||||
catch (const std::bad_variant_access& e) {
|
||||
/* Missing optional parameter, skip this */
|
||||
continue;
|
||||
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 */
|
||||
@ -357,4 +398,20 @@ void commandhandler::reply(const dpp::message &m, command_source source)
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
};
|
2
vendor/DPP/src/dpp/discordclient.cpp
vendored
2
vendor/DPP/src/dpp/discordclient.cpp
vendored
@ -329,7 +329,7 @@ void discord_client::Error(uint32_t errorcode)
|
||||
{ 1003, "Endpoint received an unsupported frame" },
|
||||
{ 1004, "Reserved code" },
|
||||
{ 1005, "Expected close status, received none" },
|
||||
{ 1006, "No close code frame has been receieved" },
|
||||
{ 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" },
|
||||
|
6
vendor/DPP/src/dpp/discordevents.cpp
vendored
6
vendor/DPP/src/dpp/discordevents.cpp
vendored
@ -42,7 +42,7 @@ char* strptime(const char* s, const char* f, struct tm* tm) {
|
||||
input.imbue(std::locale(setlocale(LC_ALL, nullptr)));
|
||||
input >> std::get_time(tm, f);
|
||||
if (input.fail()) {
|
||||
return const_cast< char* >("");
|
||||
return const_cast<char*>("");
|
||||
}
|
||||
return (char*)(s + input.tellg());
|
||||
}
|
||||
@ -79,7 +79,7 @@ std::string StringNotNull(const json* j, const char *keyname) {
|
||||
if (k != j->end()) {
|
||||
return !k->is_null() && k->is_string() ? k->get<std::string>() : "";
|
||||
} else {
|
||||
return "";
|
||||
return const_cast< char* >("");
|
||||
}
|
||||
}
|
||||
|
||||
@ -311,7 +311,7 @@ void discord_client::HandleEvent(const std::string &event, json &j, const std::s
|
||||
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 thats crept into the API and shown to bots
|
||||
* 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) {
|
||||
|
2
vendor/DPP/src/dpp/discordvoiceclient.cpp
vendored
2
vendor/DPP/src/dpp/discordvoiceclient.cpp
vendored
@ -450,7 +450,7 @@ void discord_voice_client::Error(uint32_t errorcode)
|
||||
{ 1003, "Endpoint received an unsupported frame" },
|
||||
{ 1004, "Reserved code" },
|
||||
{ 1005, "Expected close status, received none" },
|
||||
{ 1006, "No close code frame has been receieved" },
|
||||
{ 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" },
|
||||
|
2
vendor/DPP/src/dpp/httplib.cpp
vendored
2
vendor/DPP/src/dpp/httplib.cpp
vendored
@ -386,6 +386,8 @@ int close_socket(socket_t sock) {
|
||||
if (sock >= 0 && sock < FD_SETSIZE) {
|
||||
return closesocket(sock);
|
||||
}
|
||||
assert(0);
|
||||
return -1;
|
||||
#else
|
||||
return close(sock);
|
||||
#endif
|
||||
|
22
vendor/DPP/src/dpp/message.cpp
vendored
22
vendor/DPP/src/dpp/message.cpp
vendored
@ -517,11 +517,13 @@ reaction::reaction(json* j) {
|
||||
emoji_name = StringNotNull(&emoji, "name");
|
||||
}
|
||||
|
||||
attachment::attachment() {
|
||||
id = 0;
|
||||
size = 0;
|
||||
width = 0;
|
||||
height = 0;
|
||||
attachment::attachment()
|
||||
: id(0)
|
||||
, size(0)
|
||||
, width(0)
|
||||
, height(0)
|
||||
, ephemeral(false)
|
||||
{
|
||||
}
|
||||
|
||||
attachment::attachment(json *j) : attachment() {
|
||||
@ -533,6 +535,7 @@ attachment::attachment(json *j) : attachment() {
|
||||
this->width = Int32NotNull(j, "width");
|
||||
this->height = Int32NotNull(j, "height");
|
||||
this->content_type = StringNotNull(j, "content_type");
|
||||
this->ephemeral = BoolNotNull(j, "ephemeral");
|
||||
}
|
||||
|
||||
std::string message::build_json(bool with_id, bool is_interaction_response) const {
|
||||
@ -553,6 +556,11 @@ std::string message::build_json(bool with_id, bool is_interaction_response) cons
|
||||
j["content"] = content;
|
||||
}
|
||||
|
||||
if(author != nullptr) {
|
||||
/* Used for webhooks */
|
||||
j["username"] = author->username;
|
||||
}
|
||||
|
||||
/* Populate message reference */
|
||||
if (message_reference.channel_id || message_reference.guild_id || message_reference.message_id) {
|
||||
j["message_reference"] = json::object();
|
||||
@ -740,8 +748,8 @@ bool message::is_crosspost() const {
|
||||
|
||||
}
|
||||
|
||||
bool message::supress_embeds() const {
|
||||
return flags & m_supress_embeds;
|
||||
bool message::suppress_embeds() const {
|
||||
return flags & m_suppress_embeds;
|
||||
}
|
||||
|
||||
bool message::is_source_message_deleted() const {
|
||||
|
2
vendor/DPP/src/dpp/queues.cpp
vendored
2
vendor/DPP/src/dpp/queues.cpp
vendored
@ -285,7 +285,7 @@ void request_queue::in_loop()
|
||||
auto currbucket = buckets.find(bucket.first);
|
||||
|
||||
if (currbucket != buckets.end()) {
|
||||
/* Theres a bucket for this request. Check its status. If the bucket says to wait,
|
||||
/* There's a bucket for this request. Check its status. If the bucket says to wait,
|
||||
* skip all requests in this bucket till its ok.
|
||||
*/
|
||||
if (currbucket->second.remaining < 1) {
|
||||
|
43
vendor/DPP/src/dpp/slashcommand.cpp
vendored
43
vendor/DPP/src/dpp/slashcommand.cpp
vendored
@ -125,6 +125,7 @@ void to_json(json& j, const slashcommand& p) {
|
||||
}
|
||||
|
||||
j["default_permission"] = p.default_permission;
|
||||
j["application_id"] = std::to_string(p.application_id);
|
||||
}
|
||||
|
||||
std::string slashcommand::build_json(bool with_id) const {
|
||||
@ -271,7 +272,6 @@ void from_json(const nlohmann::json& j, interaction& i) {
|
||||
SetSnowflakeNotNull(&m, "id", i.message_id);
|
||||
}
|
||||
|
||||
|
||||
i.type = Int8NotNull(&j, "type");
|
||||
i.token = StringNotNull(&j, "token");
|
||||
i.version = Int8NotNull(&j, "version");
|
||||
@ -284,6 +284,47 @@ void from_json(const nlohmann::json& j, interaction& i) {
|
||||
}
|
||||
|
||||
if (j.contains("data") && !j.at("data").is_null()) {
|
||||
|
||||
const json& data = j["data"];
|
||||
|
||||
/* Deal with 'resolved' data, e.g. users, members, roles, channels */
|
||||
if (data.find("resolved") != data.end()) {
|
||||
const json& d_resolved = data["resolved"];
|
||||
/* Users */
|
||||
if (d_resolved.find("users") != d_resolved.end()) {
|
||||
for (auto v = d_resolved["users"].begin(); v != d_resolved["users"].end(); ++v) {
|
||||
json f = *v;
|
||||
dpp::snowflake id = strtoull(v.key().c_str(), nullptr, 10);
|
||||
i.resolved.users[id] = dpp::user().fill_from_json(&f);
|
||||
}
|
||||
}
|
||||
/* Roles */
|
||||
if (d_resolved.find("roles") != d_resolved.end()) {
|
||||
for (auto v = d_resolved["roles"].begin(); v != d_resolved["roles"].end(); ++v) {
|
||||
json f = *v;
|
||||
dpp::snowflake id = strtoull(v.key().c_str(), nullptr, 10);
|
||||
i.resolved.roles[id] = dpp::role().fill_from_json(i.guild_id, &f);
|
||||
}
|
||||
}
|
||||
/* Channels */
|
||||
if (d_resolved.find("channels") != d_resolved.end()) {
|
||||
for (auto v = d_resolved["channels"].begin(); v != d_resolved["channels"].end(); ++v) {
|
||||
json f = *v;
|
||||
dpp::snowflake id = strtoull(v.key().c_str(), nullptr, 10);
|
||||
i.resolved.channels[id] = dpp::channel().fill_from_json(&f);
|
||||
}
|
||||
}
|
||||
/* Members */
|
||||
if (d_resolved.find("members") != d_resolved.end()) {
|
||||
for (auto v = d_resolved["members"].begin(); v != d_resolved["members"].end(); ++v) {
|
||||
json f = *v;
|
||||
dpp::snowflake id = strtoull(v.key().c_str(), nullptr, 10);
|
||||
i.resolved.members[id] = dpp::guild_member().fill_from_json(&f, i.guild_id, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (i.type == it_application_command) {
|
||||
command_interaction ci;
|
||||
j.at("data").get_to(ci);
|
||||
|
4
vendor/DPP/src/dpp/user.cpp
vendored
4
vendor/DPP/src/dpp/user.cpp
vendored
@ -25,7 +25,7 @@
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
/* A mapping of discord's flag values to our bitmap (theyre different bit positions to fit other stuff in) */
|
||||
/* A mapping of discord's flag values to our bitmap (they're different bit positions to fit other stuff in) */
|
||||
std::map<uint32_t, dpp::user_flags> usermap = {
|
||||
{ 1 << 0, dpp::u_discord_employee },
|
||||
{ 1 << 1, dpp::u_partnered_owner },
|
||||
@ -57,7 +57,7 @@ user::~user()
|
||||
}
|
||||
|
||||
std::string user::get_avatar_url() const {
|
||||
/* XXX: Discord were supposed to change their CDN over to discord.com, they havent.
|
||||
/* XXX: Discord were supposed to change their CDN over to discord.com, they haven't.
|
||||
* At some point in the future this URL *will* change!
|
||||
*/
|
||||
return fmt::format("https://cdn.discordapp.com/avatars/{}/{}{}.{}",
|
||||
|
8
vendor/DPP/src/dpp/voicestate.cpp
vendored
8
vendor/DPP/src/dpp/voicestate.cpp
vendored
@ -51,8 +51,8 @@ voicestate& voicestate::fill_from_json(nlohmann::json* j) {
|
||||
flags |= vs_self_stream;
|
||||
if (BoolNotNull(j, "self_video"))
|
||||
flags |= vs_self_video;
|
||||
if (BoolNotNull(j, "supress"))
|
||||
flags |= vs_supress;
|
||||
if (BoolNotNull(j, "suppress"))
|
||||
flags |= vs_suppress;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -80,8 +80,8 @@ bool voicestate::self_video() const {
|
||||
return flags & vs_self_video;
|
||||
}
|
||||
|
||||
bool voicestate::is_supressed() const {
|
||||
return flags & vs_supress;
|
||||
bool voicestate::is_suppressed() const {
|
||||
return flags & vs_suppress;
|
||||
}
|
||||
|
||||
std::string voicestate::build_json() const {
|
||||
|
2
vendor/DPP/src/dpp/wsclient.cpp
vendored
2
vendor/DPP/src/dpp/wsclient.cpp
vendored
@ -304,7 +304,7 @@ void websocket_client::HandlePingPong(bool ping, const std::string &payload)
|
||||
{
|
||||
unsigned char out[MAXHEADERSIZE];
|
||||
if (ping) {
|
||||
/* For receving pings we echo back their payload with the type OP_PONG */
|
||||
/* For receiving pings we echo back their payload with the type OP_PONG */
|
||||
size_t s = this->FillHeader(out, payload.length(), OP_PONG);
|
||||
std::string header((const char*)out, s);
|
||||
ssl_client::write(header);
|
||||
|
Loading…
Reference in New Issue
Block a user