1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Refactor presence and activity types.

This commit is contained in:
Sandu Liviu Catalin 2021-09-11 21:38:46 +03:00
parent a19a171e0d
commit 1d8d31518c
3 changed files with 222 additions and 229 deletions

View File

@ -265,7 +265,7 @@ struct DpCluster : public SqChainedInstances< DpCluster >
*/ */
DpCluster & SetPresence(const DpPresence & p) DpCluster & SetPresence(const DpPresence & p)
{ {
mC->set_presence(p); mC->set_presence(p.Valid());
return *this; return *this;
} }

View File

@ -74,7 +74,7 @@ void Register_DPPTy(HSQUIRRELVM vm, Table & ns)
); );
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
ns.Bind(_SC("Activity"), ns.Bind(_SC("Activity"),
Class< DpActivity >(vm, SqDppActivity::Str) Class< DpActivity, NoCopy< DpActivity > >(vm, SqDppActivity::Str)
// Constructors // Constructors
.Ctor() .Ctor()
.Ctor< SQInteger, StackStrF &, StackStrF &, StackStrF & >() .Ctor< SQInteger, StackStrF &, StackStrF &, StackStrF & >()
@ -99,12 +99,13 @@ void Register_DPPTy(HSQUIRRELVM vm, Table & ns)
); );
// -------------------------------------------------------------------------------------------- // --------------------------------------------------------------------------------------------
ns.Bind(_SC("Presence"), ns.Bind(_SC("Presence"),
Class< DpPresence >(vm, SqDppPresence::Str) Class< DpPresence, NoCopy< DpPresence > >(vm, SqDppPresence::Str)
// Constructors // Constructors
.Ctor() .Ctor()
// Meta-methods // Meta-methods
.SquirrelFunc(_SC("_typename"), &SqDppPresence::Fn) .SquirrelFunc(_SC("_typename"), &SqDppPresence::Fn)
// Member Properties // Member Properties
.Prop(_SC("Valid"), &DpPresence::IsValid)
.Prop(_SC("UserID"), &DpPresence::GetUserID, &DpPresence::SetUserID) .Prop(_SC("UserID"), &DpPresence::GetUserID, &DpPresence::SetUserID)
.Prop(_SC("GuildID"), &DpPresence::GetGuildID, &DpPresence::SetGuildID) .Prop(_SC("GuildID"), &DpPresence::GetGuildID, &DpPresence::SetGuildID)
.Prop(_SC("Flags"), &DpPresence::GetFlags, &DpPresence::SetFlags) .Prop(_SC("Flags"), &DpPresence::GetFlags, &DpPresence::SetFlags)
@ -369,6 +370,17 @@ static const EnumElement g_DpActivityFlagsEnum[] = {
{_SC("Play"), static_cast< SQInteger >(dpp::af_play)} {_SC("Play"), static_cast< SQInteger >(dpp::af_play)}
}; };
// ------------------------------------------------------------------------------------------------
static const EnumElement g_DpVoiceStateFlagsEnum[] = {
{_SC("Deaf"), static_cast< SQInteger >(dpp::vs_deaf)},
{_SC("Mute"), static_cast< SQInteger >(dpp::vs_mute)},
{_SC("SelfMute"), static_cast< SQInteger >(dpp::vs_self_mute)},
{_SC("SelfDeaf"), static_cast< SQInteger >(dpp::vs_self_deaf)},
{_SC("SelfStream"), static_cast< SQInteger >(dpp::vs_self_stream)},
{_SC("SelfVideo"), static_cast< SQInteger >(dpp::vs_self_video)},
{_SC("Supress"), static_cast< SQInteger >(dpp::vs_supress)},
};
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
static const EnumElement g_DpUserFlagsEnum[] = { static const EnumElement g_DpUserFlagsEnum[] = {
{_SC("Bot"), static_cast< SQInteger >(dpp::u_bot)}, {_SC("Bot"), static_cast< SQInteger >(dpp::u_bot)},
@ -464,6 +476,7 @@ static const EnumElements g_EnumList[] = {
{_SC("SqDiscordDesktopStatusBits"), g_DpDesktopStatusBitsEnum}, {_SC("SqDiscordDesktopStatusBits"), g_DpDesktopStatusBitsEnum},
{_SC("SqDiscordActivityType"), g_DpActivityTypeEnum}, {_SC("SqDiscordActivityType"), g_DpActivityTypeEnum},
{_SC("SqDiscordActivityFlags"), g_DpActivityFlagsEnum}, {_SC("SqDiscordActivityFlags"), g_DpActivityFlagsEnum},
{_SC("SqDiscordVoiceStateFlags"), g_DpVoiceStateFlagsEnum},
{_SC("SqDiscordUserFlags"), g_DpUserFlagsEnum}, {_SC("SqDiscordUserFlags"), g_DpUserFlagsEnum},
{_SC("SqDiscordRegion"), g_DpRegionEnum}, {_SC("SqDiscordRegion"), g_DpRegionEnum},
{_SC("SqDiscordGuildFlags"), g_DpGuildFlagsEnum}, {_SC("SqDiscordGuildFlags"), g_DpGuildFlagsEnum},

View File

@ -20,41 +20,32 @@ struct DpCachePolicy
SQInteger mUserPolicy{dpp::cp_aggressive}; SQInteger mUserPolicy{dpp::cp_aggressive};
SQInteger mEmojiPolicy{dpp::cp_aggressive}; SQInteger mEmojiPolicy{dpp::cp_aggressive};
SQInteger mRolePolicy{dpp::cp_aggressive}; SQInteger mRolePolicy{dpp::cp_aggressive};
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Default constructor. * Default constructor.
*/ */
DpCachePolicy() noexcept = default; DpCachePolicy() noexcept = default;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Explicit constructor. * Explicit constructor.
*/ */
explicit DpCachePolicy(SQInteger user) noexcept explicit DpCachePolicy(SQInteger user) noexcept
: mUserPolicy(user), mEmojiPolicy(dpp::cp_aggressive), mRolePolicy(dpp::cp_aggressive) : mUserPolicy(user), mEmojiPolicy(dpp::cp_aggressive), mRolePolicy(dpp::cp_aggressive)
{ { }
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Explicit constructor. * Explicit constructor.
*/ */
DpCachePolicy(SQInteger user, SQInteger emoji) noexcept DpCachePolicy(SQInteger user, SQInteger emoji) noexcept
: mUserPolicy(user), mEmojiPolicy(emoji), mRolePolicy(dpp::cp_aggressive) : mUserPolicy(user), mEmojiPolicy(emoji), mRolePolicy(dpp::cp_aggressive)
{ { }
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Explicit constructor. * Explicit constructor.
*/ */
DpCachePolicy(SQInteger user, SQInteger emoji, SQInteger role) noexcept DpCachePolicy(SQInteger user, SQInteger emoji, SQInteger role) noexcept
: mUserPolicy(user), mEmojiPolicy(emoji), mRolePolicy(role) : mUserPolicy(user), mEmojiPolicy(emoji), mRolePolicy(role)
{ { }
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Copy constructor. * Copy constructor.
*/ */
DpCachePolicy(const DpCachePolicy &) noexcept = default; DpCachePolicy(const DpCachePolicy &) noexcept = default;
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Convert to native cache policy type. * Convert to native cache policy type.
*/ */
@ -71,395 +62,384 @@ struct DpCachePolicy
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* An activity is a representation of what a user is doing. It might be a game, or a website, or a movie. Whatever. * An activity is a representation of what a user is doing. It might be a game, or a website, or a movie. Whatever.
*/ */
struct DpActivity : public dpp::activity struct DpActivity
{ {
using Ptr = std::unique_ptr< dpp::activity >;
/* --------------------------------------------------------------------------------------------
* Referenced voice state instance.
*/
Ptr mPtr{nullptr};
/* --------------------------------------------------------------------------------------------
* Wether the referenced pointer is owned.
*/
bool mOwned{false};
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Default constructor. * Default constructor.
*/ */
DpActivity() DpActivity() noexcept
: dpp::activity() : DpActivity(new Ptr::element_type(), true)
{ { }
} /* --------------------------------------------------------------------------------------------
* Explicit constructor.
*/
explicit DpActivity(Ptr::pointer ptr, bool owned = false) noexcept
: mPtr(ptr), mOwned(owned)
{ }
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
explicit DpActivity(const Ptr::element_type & o) noexcept
: DpActivity(new Ptr::element_type(o), true)
{ }
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
explicit DpActivity(Ptr::element_type && o) noexcept
: DpActivity(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
{ }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Explicit constructor. * Explicit constructor.
*/ */
DpActivity(SQInteger type, StackStrF & name, StackStrF & state, StackStrF & url) DpActivity(SQInteger type, StackStrF & name, StackStrF & state, StackStrF & url)
: dpp::activity(static_cast< dpp::activity_type >(type), name.ToStr(), state.ToStr(), url.ToStr()) : DpActivity(new Ptr::element_type(static_cast< dpp::activity_type >(type), name.ToStr(), state.ToStr(), url.ToStr()), true)
{ { }
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Copy constructor. * Copy constructor (disabled).
*/ */
explicit DpActivity(const dpp::activity & o) DpActivity(const DpActivity & o) = delete;
: dpp::activity(o) /* --------------------------------------------------------------------------------------------
* Move constructor.
*/
DpActivity(DpActivity && o) noexcept = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~DpActivity() noexcept
{ {
// Do we own this to try delete it?
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
} }
/* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled).
*/
DpActivity & operator = (const DpActivity & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
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();
// Transfer members values
mPtr = std::move(o.mPtr);
mOwned = o.mOwned;
}
return *this;
}
/* --------------------------------------------------------------------------------------------
* Validate the managed handle.
*/
void Validate() const { if (!mPtr) STHROWF("Invalid discord activity handle"); }
/* --------------------------------------------------------------------------------------------
* Validate the managed handle and retrieve a const reference to it.
*/
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
/* --------------------------------------------------------------------------------------------
* Check wether a valid instance is managed.
*/
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the name of the activity. * Retrieve the name of the activity.
*/ */
SQMOD_NODISCARD const std::string & GetName() const noexcept SQMOD_NODISCARD const std::string & GetName() const { return Valid().name; }
{
return dpp::activity::name;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the name of the activity. * Modify the name of the activity.
*/ */
void SetName(StackStrF & name) void SetName(StackStrF & name) const { Valid().name = name.ToStr(); }
{
dpp::activity::name = name.ToStr();
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the name of the activity. * Modify the name of the activity.
*/ */
DpActivity & ApplyName(StackStrF & name) DpActivity & ApplyName(StackStrF & name) { SetName(name); return *this; }
{
SetName(name);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the state of the activity. * Retrieve the state of the activity.
*/ */
SQMOD_NODISCARD const std::string & GetState() const noexcept SQMOD_NODISCARD const std::string & GetState() const { return Valid().state; }
{
return dpp::activity::state;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the state of the activity. * Modify the state of the activity.
*/ */
void SetState(StackStrF & state) void SetState(StackStrF & state) const { Valid().state = state.ToStr(); }
{
dpp::activity::state = state.ToStr();
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the state of the activity. * Modify the state of the activity.
*/ */
DpActivity & ApplyState(StackStrF & state) DpActivity & ApplyState(StackStrF & state) { SetState(state); return *this; }
{
SetState(state);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the url of the activity. * Retrieve the url of the activity.
*/ */
SQMOD_NODISCARD const std::string & GetURL() const noexcept SQMOD_NODISCARD const std::string & GetURL() const { return Valid().url; }
{
return dpp::activity::url;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the url of the activity. * Modify the url of the activity.
*/ */
void SetURL(StackStrF & url) void SetURL(StackStrF & url) const { Valid().url = url.ToStr(); }
{
dpp::activity::url = url.ToStr();
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the url of the activity. * Modify the url of the activity.
*/ */
DpActivity & ApplyURL(StackStrF & url) DpActivity & ApplyURL(StackStrF & url) { SetURL(url); return *this; }
{
SetURL(url);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the type of the activity. * Retrieve the type of the activity.
*/ */
SQMOD_NODISCARD SQInteger GetType() const noexcept SQMOD_NODISCARD SQInteger GetType() const { return static_cast< SQInteger >(Valid().type); }
{
return static_cast< SQInteger >(dpp::activity::type);
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the type of the activity. * Modify the type of the activity.
*/ */
void SetType(SQInteger s) void SetType(SQInteger s) const { Valid().type = static_cast< dpp::activity_type >(s); }
{
dpp::activity::type = static_cast< dpp::activity_type >(s);
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the type of the activity. * Modify the type of the activity.
*/ */
DpActivity & ApplyType(SQInteger s) DpActivity & ApplyType(SQInteger s) { SetType(s); return *this; }
{
SetType(s);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve when the activity was created. * Retrieve when the activity was created.
*/ */
SQMOD_NODISCARD SQInteger GetCreatedAt() const noexcept SQMOD_NODISCARD SQInteger GetCreatedAt() const
{ {
return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::from_time_t(dpp::activity::created_at).time_since_epoch()).count()); return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::from_time_t(Valid().created_at).time_since_epoch()).count());
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify when the activity was created. * Modify when the activity was created.
*/ */
void SetCreatedAt(SQInteger s) void SetCreatedAt(SQInteger s) const
{ {
dpp::activity::created_at = std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >{std::chrono::seconds{s}}); Valid().created_at = std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >{std::chrono::seconds{s}});
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify when the activity was created. * Modify when the activity was created.
*/ */
DpActivity & ApplyCreatedAt(SQInteger s) DpActivity & ApplyCreatedAt(SQInteger s) { SetCreatedAt(s); return *this; }
{
SetCreatedAt(s);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve when the activity was started. * Retrieve when the activity was started.
*/ */
SQMOD_NODISCARD SQInteger GetStart() const noexcept SQMOD_NODISCARD SQInteger GetStart() const
{ {
return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::from_time_t(dpp::activity::start).time_since_epoch()).count()); return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::from_time_t(Valid().start).time_since_epoch()).count());
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify when the activity was started. * Modify when the activity was started.
*/ */
void SetStart(SQInteger s) void SetStart(SQInteger s) const
{ {
dpp::activity::start = std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >{std::chrono::seconds{s}}); Valid().start = std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >{std::chrono::seconds{s}});
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify when the activity was started. * Modify when the activity was started.
*/ */
DpActivity & ApplyStart(SQInteger s) DpActivity & ApplyStart(SQInteger s) { SetStart(s); return *this; }
{
SetStart(s);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve when the activity was stopped. * Retrieve when the activity was stopped.
*/ */
SQMOD_NODISCARD SQInteger GetEnd() const noexcept SQMOD_NODISCARD SQInteger GetEnd() const
{ {
return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::from_time_t(dpp::activity::end).time_since_epoch()).count()); return static_cast< SQInteger >(std::chrono::duration_cast< std::chrono::seconds >(std::chrono::system_clock::from_time_t(Valid().end).time_since_epoch()).count());
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify when the activity was stopped. * Modify when the activity was stopped.
*/ */
void SetEnd(SQInteger s) void SetEnd(SQInteger s) const
{ {
dpp::activity::end = std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >{std::chrono::seconds{s}}); Valid().end = std::chrono::system_clock::to_time_t(std::chrono::time_point< std::chrono::system_clock >{std::chrono::seconds{s}});
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify when the activity was stopped. * Modify when the activity was stopped.
*/ */
DpActivity & ApplyEnd(SQInteger s) DpActivity & ApplyEnd(SQInteger s) { SetEnd(s); return *this; }
{
SetEnd(s);
return *this;
}
}; };
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Represents user presence, e.g. what game they are playing and if they are online. * Represents user presence, e.g. what game they are playing and if they are online.
*/ */
struct DpPresence : public dpp::presence struct DpPresence
{ {
using Ptr = std::unique_ptr< dpp::presence >;
/* --------------------------------------------------------------------------------------------
* Referenced voice state instance.
*/
Ptr mPtr{nullptr};
/* --------------------------------------------------------------------------------------------
* Wether the referenced pointer is owned.
*/
bool mOwned{false};
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Default constructor. * Default constructor.
*/ */
DpPresence() DpPresence() noexcept
: dpp::presence() : DpPresence(new Ptr::element_type(), true)
{ }
/* --------------------------------------------------------------------------------------------
* Explicit constructor.
*/
explicit DpPresence(Ptr::pointer ptr, bool owned = false) noexcept
: mPtr(ptr), mOwned(owned)
{ }
/* --------------------------------------------------------------------------------------------
* Copy constructor.
*/
explicit DpPresence(const Ptr::element_type & o) noexcept
: DpPresence(new Ptr::element_type(o), true)
{ }
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
explicit DpPresence(Ptr::element_type && o) noexcept
: DpPresence(new Ptr::element_type(std::forward< Ptr::element_type >(o)), true)
{ }
/* --------------------------------------------------------------------------------------------
* Copy constructor (disabled).
*/
DpPresence(const DpPresence & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move constructor.
*/
DpPresence(DpPresence && o) noexcept = default;
/* --------------------------------------------------------------------------------------------
* Destructor.
*/
~DpPresence() noexcept
{ {
// Do we own this to try delete it?
if (!mOwned && mPtr) [[maybe_unused]] auto p = mPtr.release();
} }
/* --------------------------------------------------------------------------------------------
* Copy assignment operator (disabled).
*/
DpPresence & operator = (const DpPresence & o) = delete;
/* --------------------------------------------------------------------------------------------
* Move assignment operator.
*/
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();
// Transfer members values
mPtr = std::move(o.mPtr);
mOwned = o.mOwned;
}
return *this;
}
/* --------------------------------------------------------------------------------------------
* Validate the managed handle.
*/
void Validate() const { if (!mPtr) STHROWF("Invalid discord presence handle"); }
/* --------------------------------------------------------------------------------------------
* Validate the managed handle and retrieve a const reference to it.
*/
SQMOD_NODISCARD Ptr::element_type & Valid() const { Validate(); return *mPtr; }
/* --------------------------------------------------------------------------------------------
* Check wether a valid instance is managed.
*/
SQMOD_NODISCARD bool IsValid() const { return static_cast< bool >(mPtr); }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the user that the presence applies to. * Retrieve the user that the presence applies to.
*/ */
SQMOD_NODISCARD dpp::snowflake GetUserID() const noexcept SQMOD_NODISCARD dpp::snowflake GetUserID() const { return Valid().user_id; }
{
return dpp::presence::user_id;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the user that the presence applies to. * Modify the user that the presence applies to.
*/ */
void SetUserID(dpp::snowflake id) void SetUserID(dpp::snowflake id) const { Valid().user_id = id; }
{
dpp::presence::user_id = id;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the user that the presence applies to. * Modify the user that the presence applies to.
*/ */
DpPresence & ApplyUserID(dpp::snowflake id) DpPresence & ApplyUserID(dpp::snowflake id) { SetUserID(id); return *this; }
{
SetUserID(id);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the guild that the presence applies to. * Retrieve the guild that the presence applies to.
*/ */
SQMOD_NODISCARD dpp::snowflake GetGuildID() const noexcept SQMOD_NODISCARD dpp::snowflake GetGuildID() const { return Valid().guild_id; }
{
return dpp::presence::guild_id;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the guild that the presence applies to. * Modify the guild that the presence applies to.
*/ */
void SetGuildID(dpp::snowflake id) void SetGuildID(dpp::snowflake id) const { Valid().guild_id = id; }
{
dpp::presence::guild_id = id;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the guild that the presence applies to. * Modify the guild that the presence applies to.
*/ */
DpPresence & ApplyGuildID(dpp::snowflake id) DpPresence & ApplyGuildID(dpp::snowflake id) { SetGuildID(id); return *this; }
{
SetGuildID(id);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the presence bit-mask. * Retrieve the presence bit-mask.
*/ */
SQMOD_NODISCARD SQInteger GetFlags() const noexcept SQMOD_NODISCARD SQInteger GetFlags() const { return static_cast< SQInteger >(Valid().flags); }
{
return static_cast< SQInteger >(dpp::presence::flags);
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the presence bit-mask. * Modify the presence bit-mask.
*/ */
void SetFlags(SQInteger f) void SetFlags(SQInteger f) const { Valid().flags = static_cast< uint8_t >(f); }
{
dpp::presence::flags = static_cast< uint8_t >(f);
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Modify the presence bit-mask. * Modify the presence bit-mask.
*/ */
DpPresence & ApplyFlags(SQInteger f) DpPresence & ApplyFlags(SQInteger f) { SetFlags(f); return *this; }
{
SetFlags(f);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the number of activities. * Retrieve the number of activities.
*/ */
SQMOD_NODISCARD SQInteger ActivityCount() const SQMOD_NODISCARD SQInteger ActivityCount() const { return static_cast< SQInteger >(Valid().activities.size()); }
{
return static_cast< SQInteger >(dpp::presence::activities.size());
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Add a new activity. * Add a new activity.
*/ */
DpPresence & AddActivity(const DpActivity & a) DpPresence & AddActivity(const DpActivity & a) { Valid().activities.push_back(a.Valid()); return *this; }
{
dpp::presence::activities.push_back(a);
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Iterate all activities. * Iterate all activities.
*/ */
DpPresence & EachActivity(Function & fn) DpPresence & EachActivity(Function & fn)
{ {
for (const auto & a : dpp::presence::activities) for (const auto & a : Valid().activities)
{ {
fn.Execute(a); fn.Execute(a);
} }
return *this; return *this;
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the number of activities. * Retrieve the number of activities.
*/ */
DpPresence & ClearActivities(const DpActivity & a) DpPresence & ClearActivities(const DpActivity & a) { Valid().activities.clear(); return *this; }
{
dpp::presence::activities.clear();
return *this;
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Filter activities. * Filter activities.
*/ */
DpPresence & FilterActivities(Function & fn) DpPresence & FilterActivities(Function & fn)
{ {
std::vector< dpp::activity > list; std::vector< dpp::activity > list;
list.reserve(dpp::presence::activities.size()); // Reserve memory in advance
for (const auto & a : dpp::presence::activities) list.reserve(Valid().activities.size());
// Process each activity individually
for (const auto & a : Valid().activities)
{ {
auto ret = fn.Eval(a); auto ret = fn.Eval(a);
// (null || true) == keep & false == skip // (null || true) == keep & false == skip
if (!ret.IsNull() || !ret.template Cast< bool >()) if (!ret.IsNull() || !ret.template Cast< bool >())
{ {
list.push_back(a); list.push_back(a); // Keep this activity
} }
} }
dpp::presence::activities.swap(list); // Use filtered activities
Valid().activities.swap(list);
// Allow chaining
return *this; return *this;
} }
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Build JSON string from this object. * Build JSON string from this object.
*/ */
SQMOD_NODISCARD std::string BuildJSON() const SQMOD_NODISCARD std::string BuildJSON() const { return Valid().build_json(); }
{
return dpp::presence::build_json();
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the users status on desktop. * Retrieve the users status on desktop.
*/ */
SQMOD_NODISCARD SQInteger GetDesktopStatus() const noexcept SQMOD_NODISCARD SQInteger GetDesktopStatus() const { return static_cast< SQInteger >(Valid().desktop_status()); }
{
return static_cast< SQInteger >(dpp::presence::desktop_status());
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the user's status on web. * Retrieve the user's status on web.
*/ */
SQMOD_NODISCARD SQInteger GetWebStatus() const noexcept SQMOD_NODISCARD SQInteger GetWebStatus() const { return static_cast< SQInteger >(Valid().web_status()); }
{
return static_cast< SQInteger >(dpp::presence::web_status());
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the user's status on mobile. * Retrieve the user's status on mobile.
*/ */
SQMOD_NODISCARD SQInteger GetMobileStatus() const noexcept SQMOD_NODISCARD SQInteger GetMobileStatus() const { return static_cast< SQInteger >(Valid().mobile_status()); }
{
return static_cast< SQInteger >(dpp::presence::mobile_status());
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the user's status as shown to other users. * Retrieve the user's status as shown to other users.
*/ */
SQMOD_NODISCARD SQInteger GetStatus() const noexcept SQMOD_NODISCARD SQInteger GetStatus() const { return static_cast< SQInteger >(Valid().status()); }
{
return static_cast< SQInteger >(dpp::presence::status());
}
}; };
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* Represents the voice state of a user on a guild. * Represents the voice state of a user on a guild.
* These are stored in the DpGuild object, and accessible there, or via DpChannel::GetVoiceMembers. * These are stored in the DpGuild object, and accessible there, or via DpChannel::GetVoiceMembers.