1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-06-18 08:07:12 +02:00

Basic Discord library layout.

Foundation for the discord library bindings. To be gradually exposed to the script.
This commit is contained in:
Sandu Liviu Catalin
2021-09-10 20:13:42 +03:00
parent f6cb8ff8a1
commit 4f70f89b78
138 changed files with 60430 additions and 0 deletions

165
vendor/DPP/include/dpp/auditlog.h vendored Normal file
View File

@ -0,0 +1,165 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
#include <optional>
namespace dpp {
/**
* @brief Defines types of audit log entry
*/
enum audit_type {
/// Guild update
ae_guild_update = 1,
/// Channel create
ae_channel_create = 10,
/// Channel update
ae_channel_update = 11,
/// Channel delete
ae_channel_delete = 12,
/// Channel overwrite create
ae_channel_overwrite_create = 13,
/// Channel overwrite update
ae_channel_overwrite_update = 14,
/// Channel overwrite delete
ae_channel_overwrite_delete = 15,
/// Channel member kick
ae_member_kick = 20,
/// Channel member prune
ae_member_prune = 21,
/// Channel member ban add
ae_member_ban_add = 22,
/// Channel member ban remove
ae_member_ban_remove = 23,
/// Guild member update
ae_member_update = 24,
/// Guild member role update
ae_member_role_update = 25,
/// Guild member move
ae_member_move = 26,
/// Guild member voice disconnect
ae_member_disconnect = 27,
/// Guild bot add
ae_bot_add = 28,
/// Guild role create
ae_role_create = 30,
/// Guild role update
ae_role_update = 31,
/// Guild role delete
ae_role_delete = 32,
/// Guild invite create
ae_invite_create = 40,
/// Guild invite update
ae_invite_update = 41,
/// Guild invite delete
ae_invite_delete = 42,
/// Guild webhook create
ae_webhook_create = 50,
/// Guild webhook update
ae_webhook_update = 51,
/// Guild webhook delete
ae_webhook_delete = 52,
/// Guild emoji create
ae_emoji_create = 60,
/// Guild emoji update
ae_emoji_update = 61,
/// Guild emoji delete
ae_emoji_delete = 62,
/// Guild message delete
ae_message_delete = 72,
/// Guild message bulk delete
ae_message_bulk_delete = 73,
/// Guild message pin
ae_message_pin = 74,
/// Guild message unpin
ae_message_unpin = 75,
/// Guild integration create
ae_integration_create = 80,
/// Guild integration update
ae_integration_update = 81,
/// Guild integration delete
ae_integration_delete = 82
};
/**
* @brief Defines audit log changes
*/
struct CoreExport audit_change {
/// Optional: Serialised new value of the key
std::string new_value;
/// Optional: Serialised old value of the key
std::string old_value;
/// name of audit log change key
std::string key;
};
/**
* @brief Extra information for an audit log entry
*/
struct CoreExport audit_extra {
std::string delete_member_days; //!< number of days after which inactive members were kicked
std::string members_removed; //!< number of members removed by the prune
snowflake channel_id; //!< channel in which the entities were targeted
snowflake message_id; //!< id of the message that was targeted
std::string count; //!< number of entities that were targeted
snowflake id; //!< id of the overwritten entity
std::string type; //!< type of overwritten entity - "0" for "role" or "1" for "member"
std::string role_name; //!< name of the role if type is "0" (not present if type is "1")
};
/**
* @brief An individual audit log entry
*/
struct CoreExport audit_entry {
snowflake id; //!< id of the entry
snowflake target_id; //!< id of the affected entity (webhook, user, role, etc.) (may be empty)
std::vector<audit_change> changes; //!< Optional: changes made to the target_id
snowflake user_id; //!< the user who made the changes (may be empty)
audit_type event; //!< type of action that occurred
std::optional<audit_extra> options; //!< Optional: additional info for certain action types
std::string reason; //!< Optional: the reason for the change (0-512 characters)
};
/**
* @brief The auditlog class represents the audit log entry of a guild.
*/
class CoreExport auditlog {
public:
std::vector<audit_entry> entries; //!< Audit log entries
/** Constructor */
auditlog();
/** Destructor */
~auditlog();
/** Read class values from json object
* @param j A json object to read from
* @return A reference to self
*/
auditlog& fill_from_json(nlohmann::json* j);
};
};

64
vendor/DPP/include/dpp/ban.h vendored Normal file
View File

@ -0,0 +1,64 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief The ban class represents a ban on a guild.
*
*/
class CoreExport ban {
public:
/** The ban reason */
std::string reason;
/** User ID the ban applies to */
snowflake user_id;
/** Constructor */
ban();
/** Destructor */
~ban();
/** Read class values from json object
* @param j A json object to read from
* @return A reference to self
*/
ban& fill_from_json(nlohmann::json* j);
/**
* @brief Build json representation of a ban
*
* @return std::string stringified json
*/
std::string build_json() const;
};
/** A group of bans
*/
typedef std::unordered_map<snowflake, ban> ban_map;
};

127
vendor/DPP/include/dpp/cache.h vendored Normal file
View File

@ -0,0 +1,127 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <map>
#include <mutex>
namespace dpp {
/**
* @brief A set of cached managed objects
*/
typedef std::unordered_map<uint64_t, managed*> cache_container;
/**
* @brief A cache object maintains a cache of dpp::managed objects.
* This is for example users, channels or guilds.
*/
class CoreExport cache {
private:
/** Mutex to protect the cache */
std::mutex cache_mutex;
/** Cached items */
cache_container* cache_map;
public:
/**
* @brief Construct a new cache object
*/
cache();
/**
* @brief Destroy the cache object
*/
~cache();
/** Store an object in the cache.
* @param object object to store
*/
void store(managed* object);
/** Remove an object from the cache.
* @param object object to remove
*/
void remove(managed* object);
/** Find an object in the cache by id.
* @param id Object id to find
*/
managed* find(snowflake id);
/** Return a count of the number of items in the cache.
*/
uint64_t count();
/**
* @brief Return the cache's locking mutex. Use this whenever
* you manipulate or iterate raw elements in the cache!
*
* @return The mutex used to protect the container
*/
std::mutex& get_mutex();
/**
* @brief Get the container map
* @warning Be sure to use cache::get_mutex() correctly if you
* manipulate or iterate the map returned by this method! If you do
* not, this is not thread safe and will casue crashes!
* @see cache::get_mutex
*
* @return cache_container& A reference to the cache's container map
*/
cache_container& get_container();
/**
* @brief "Rehash" a cache by cleaning out used RAM
* @warning May be time consuming!
*/
void rehash();
/**
* @brief Get "real" size in RAM of the cache
*
* @return size_t
*/
size_t bytes();
};
/** Run garbage collection across all caches removing deleted items
* that have been deleted over 60 seconds ago.
*/
void CoreExport garbage_collection();
#define cache_decl(type, setter, getter, counter) CoreExport type * setter (snowflake id); CoreExport cache * getter (); CoreExport uint64_t counter ();
/* Declare major caches */
cache_decl(user, find_user, get_user_cache, get_user_count);
cache_decl(guild, find_guild, get_guild_cache, get_guild_count);
cache_decl(role, find_role, get_role_cache, get_role_count);
cache_decl(channel, find_channel, get_channel_cache, get_channel_count);
cache_decl(emoji, find_emoji, get_emoji_cache, get_emoji_count);
};

302
vendor/DPP/include/dpp/channel.h vendored Normal file
View File

@ -0,0 +1,302 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/** @brief Flag integers as received from and sent to discord */
enum channel_type {
GUILD_TEXT = 0, //!< a text channel within a server
DM = 1, //!< a direct message between users
GUILD_VOICE = 2, //!< a voice channel within a server
GROUP_DM = 3, //!< a direct message between multiple users
GUILD_CATEGORY = 4, //!< an organizational category that contains up to 50 channels
GUILD_NEWS = 5, //!< a channel that users can follow and crosspost into their own server
GUILD_STORE = 6, //!< a channel in which game developers can sell their game on Discord
GUILD_NEWS_THREAD = 10, //!< a temporary sub-channel within a GUILD_NEWS channel
GUILD_PUBLIC_THREAD = 11, //!< a temporary sub-channel within a GUILD_TEXT channel
GUILD_PRIVATE_THREAD = 12, //!< a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission
GUILD_STAGE = 13 //!< a "stage" channel, like a voice channel with one authorised speaker
};
/** @brief Our flags as stored in the object */
enum channel_flags {
/// NSFW Gated Channel
c_nsfw = 0b00000001,
/// Text channel
c_text = 0b00000010,
/// Direct Message
c_dm = 0b00000100,
/// Voice channel
c_voice = 0b00001000,
/// Group
c_group = 0b00010000,
/// Category
c_category = 0b00100000,
/// News channel
c_news = 0b01000000,
/// Store page
c_store = 0b10000000,
/// Stage channel
c_stage = 0b11000000,
/// News thread
c_news_thread = 0b11100000,
/// Public thread
c_public_thread = 0b11110000,
/// Private thread
c_private_thread = 0b11111000
};
/**
* @brief channel permission overwrite types
*/
enum overwrite_type : uint8_t {
/// Role
ot_role = 0,
/// Member
ot_member = 1
};
/**
* @brief channel permission overwrites
*/
struct CoreExport permission_overwrite {
/// Overwrite id
snowflake id;
/// Overwrite type
uint8_t type;
/// Allow mask
uint64_t allow;
/// Deny mask
uint64_t deny;
};
/**
* @brief metadata for threads
*/
struct CoreExport thread_metadata {
/// Whether a thread is archived
bool archived;
/// When the thread was archived
time_t archive_timestamp;
/// The duration after a thread will archive
uint16_t auto_archive_duration;
/// Whether a thread is locked
bool locked;
};
/**
* @brief represents membership of a user with a thread
*/
struct CoreExport thread_member
{
/// ID of the thread member is part of
snowflake thread_id;
/// ID of the member
snowflake user_id;
/// When the user joined the thread
time_t joined;
/// Flags bitmap
uint32_t flags;
/**
* @brief Read struct values from a json object
* @param j json to read values from
* @return A reference to self
*/
thread_member& fill_from_json(nlohmann::json* j);
};
/** @brief A group of thread member objects*/
typedef std::unordered_map<snowflake, thread_member> thread_member_map;
/** @brief A definition of a discord channel */
class CoreExport channel : public managed {
public:
/** Flags bitmap */
uint8_t flags;
/** Guild id of the guild that owns the channel */
snowflake guild_id;
/** Sorting position, lower number means higher up the list */
uint16_t position;
/** Channel name */
std::string name;
/** Channel topic */
std::string topic;
/** ID of last message to be sent to the channel */
snowflake last_message_id;
/** Maximum user limit for voice channels (0-99) */
uint8_t user_limit;
/** Rate limit in kilobits per second for voice channels */
uint16_t rate_limit_per_user;
/** User ID of owner for group DMs */
snowflake owner_id;
/** Parent ID (category) */
snowflake parent_id;
/** Timestamp of last pinned message */
time_t last_pin_timestamp;
/** DM recipients */
std::vector<snowflake> recipients;
/** Permission overwrites to apply to base permissions */
std::vector<permission_overwrite> permission_overwrites;
/** Approximate count of messages in a thread (threads) */
uint8_t message_count;
/** Approximate count of members in a thread (threads) */
uint8_t member_count;
/** Thread metadata (threads) */
thread_metadata metadata;
/** Constructor */
channel();
/** Destructor */
virtual ~channel();
/** Read class values from json object
* @param j A json object to read from
* @return A reference to self
*/
channel& fill_from_json(nlohmann::json* j);
/**
* @brief Build json for this channel object
*
* @param with_id include the ID in the json
* @return std::string JSON string
*/
std::string build_json(bool with_id = false) const;
/**
* @brief Get the user permissions for a user on this channel
*
* @param member The user to return permissions for
* @return uint64_t Permissions bitmask made of bits in role_permissions.
* Note that if the user is not on the channel or the guild is
* not in the cache, the function will always return 0.
*/
uint64_t get_user_permissions(const class user* member) const;
/**
* @brief Return a map of members on the channel, built from the guild's
* member list based on which members have the VIEW_CHANNEL permission.
* Does not return reliable information for voice channels, use
* dpp::channel::get_voice_members() instead for this.
* @return A map of guild members keyed by user id.
*/
std::map<snowflake, class guild_member*> get_members();
/**
* @brief Get a map of members in this channel, if it is a voice channel.
* The map is keyed by snowflake id of the user.
*
* @return std::map<snowflake, voicestate> The voice members of the channel
*/
std::map<snowflake, voicestate> get_voice_members();
/**
* @brief Returns true if the channel is NSFW gated
*
* @return true if NSFW
*/
bool is_nsfw() const;
/**
* @brief Returns true if the channel is a text channel
*
* @return true if text channel
*/
bool is_text_channel() const;
/**
* @brief Returns true if the channel is a DM
*
* @return true if is a DM
*/
bool is_dm() const;
/**
* @brief Returns true if the channel is a voice channel
*
* @return true if voice channel
*/
bool is_voice_channel() const;
/**
* @brief Returns true if the channel is a group DM channel
*
* @return true if group DM
*/
bool is_group_dm() const;
/**
* @brief Returns true if the channel is a category
*
* @return true if a category
*/
bool is_category() const;
/**
* @brief Returns true if the channel is a news channel
*
* @return true if news channel
*/
bool is_news_channel() const;
/**
* @brief Returns true if the channel is a store channel
*
* @return true if store channel
*/
bool is_store_channel() const;
/**
* @brief Returns true if the channel is a stage channel
*
* @return true if stage channel
*/
bool is_stage_channel() const;
};
/**
* @brief A group of channels
*/
typedef std::unordered_map<snowflake, channel> channel_map;
};

2138
vendor/DPP/include/dpp/cluster.h vendored Normal file

File diff suppressed because it is too large Load Diff

285
vendor/DPP/include/dpp/commandhandler.h vendored Normal file
View File

@ -0,0 +1,285 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
#include <unordered_map>
#include <vector>
#include <functional>
#include <variant>
namespace dpp {
/**
* @brief 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;
/**
* @brief Parameter types when registering a command.
* We don't pass these in when triggering the command in the handler, because it is
* expected the developer added the command so they know what types to expect for each named
* parameter.
*/
enum parameter_type {
pt_string, //!< String value
pt_role, //!< Role object
pt_channel, //!< Channel object
pt_user, //!< User object
pt_integer, //!< 32 bit signed integer
pt_boolean //!< boolean
};
/**
* @brief Details of a command parameter used in registration.
* Note that for non-slash commands optional parameters can only be at the end of
* the list of parameters.
*/
struct CoreExport param_info {
/**
* @brief Type of parameter
*/
parameter_type type;
/**
* @brief True if the parameter is optional.
* For non-slash commands optional parameters may only be on the end of the list.
*/
bool optional;
/**
* @brief Description of command. Displayed only for slash commands
*/
std::string description;
/**
* @brief Allowed multiple choice options.
* The key name is the string passed to the command handler
* and the key value is its description displayed to the user.
*/
std::map<std::string, std::string> choices;
/**
* @brief Construct a new param_info object
*
* @param t Type of parameter
* @param o True if parameter is optional
* @param description The parameter description
* @param opts The options for a multiple choice parameter
*/
param_info(parameter_type t, bool o, const std::string &description, const std::map<std::string, std::string> &opts = {});
};
/**
* @brief Parameter list used during registration.
* Note that use of vector/pair is important here to preserve parameter order,
* as opposed to unordered_map (which doesnt guarantee any order at all) and
* std::map, which reorders keys alphabetically.
*/
typedef std::vector<std::pair<std::string, param_info>> parameter_registration_t;
/**
* @brief Parameter list for a called command.
* See dpp::parameter_registration_t for an explaination as to why vector is used.
*/
typedef std::vector<std::pair<std::string, command_parameter>> parameter_list_t;
/**
* @brief Represents the sending source of a command.
* This is passed to any command handler and should be passed back to
* commandhandler::reply(), allowing the reply method to route any replies back
* to the origin, which may be a slash command or a message. Both require different
* response facilities but we want this to be transparent if you use the command
* handler class.
*/
struct CoreExport command_source {
/**
* @brief Sending guild id
*/
snowflake guild_id = 0;
/**
* @brief Source channel id
*/
snowflake channel_id = 0;
/**
* @brief Command ID of a slash command
*/
snowflake command_id = 0;
/**
* @brief Token for sending a slash command reply
*/
std::string command_token;
/**
* @brief The user who issued the command
*/
user* issuer;
};
/**
* @brief The function definition for a command handler. Expects a command name string,
* and a list of command parameters.
*/
typedef std::function<void(const std::string&, const parameter_list_t&, command_source)> command_handler;
/**
* @brief Represents the details of a command added to the command handler class.
*/
struct CoreExport command_info_t {
/**
* @brief Function reference for the handler. This is std::function so it can represent
* a class member, a lambda or a raw C function pointer.
*/
command_handler func;
/**
* @brief Parameters requested for the command, with their types
*/
parameter_registration_t parameters;
/**
* @brief Guild ID the command exists on, or 0 to be present on all guilds
*/
snowflake guild_id;
};
/**
* @brief The commandhandler class represents a group of commands, prefixed or slash commands with handling functions.
*
*/
class CoreExport commandhandler {
/**
* @brief Commands in the handler
*/
std::unordered_map<std::string, command_info_t> commands;
/**
* @brief Valid prefixes
*/
std::vector<std::string> prefixes;
/**
* @brief Set to true automatically if one of the prefixes added is "/"
*/
bool slash_commands_enabled;
/**
* @brief Cluster we are attached to for issuing REST calls
*/
class cluster* owner;
/**
* @brief Application ID
*/
snowflake app_id;
/**
* @brief Returns true if the string has a known prefix on the start.
* Modifies string to remove prefix if it returns true.
*
* @param str String to check and modify
* @return true string contained a prefix, prefix removed from string
* @return false string did not contain a prefix
*/
bool string_has_prefix(std::string &str);
public:
/**
* @brief Construct a new commandhandler object
*
* @param o Owning cluster to attach to
* @param auto_hook_events Set to true to automatically hook the on_interaction_create
* and on_message events. Only do this if you have no other use for these events than
* commands that are handled by the command handler (this is usually the case).
* @param application_id The application id of the bot. If not specified, the class will
* look within the cluster object and use cluster::me::id instead.
*/
commandhandler(class cluster* o, bool auto_hook_events = true, snowflake application_id = 0);
/**
* @brief Destroy the commandhandler object
*/
~commandhandler();
/**
* @brief Set the application id after construction
*
* @param o Owning cluster to attach to
*/
commandhandler& set_owner(class cluster* o);
/**
* @brief Add a prefix to the command handler
*
* @param prefix Prefix to be handled by the command handler
* @return commandhandler& reference to self
*/
commandhandler& add_prefix(const std::string &prefix);
/**
* @brief Add a command to the command handler
*
* @param command Command to be handled.
* Note that if any one of your prefixes is "/" this will attempt to register
* a global command using the API and you will receive notification of this command
* via an interaction event.
*
* @param handler Handler function
* @param parameters Parameters to use for the command
* @return commandhandler& reference to self
*/
commandhandler& add_command(const std::string &command, const parameter_registration_t &parameters, command_handler handler, const std::string &description = "", snowflake guild_id = 0);
/**
* @brief Route a command from the on_message_create function.
* Call this method from within your on_message_create with the received
* dpp::message object.
*
* @param msg message to parse
*/
void route(const class dpp::message& msg);
/**
* @brief Route a command from the on_interaction_create function.
* Call this method from your on_interaction_create with the received
* dpp::interaction_create_t object.
*
* @param event command interaction event to parse
*/
void route(const class interaction_create_t & event);
/**
* @brief Reply to a command.
* You should use this method rather than cluster::message_create as
* the way you reply varies between slash commands and message commands.
* Note you should ALWAYS reply. Slash commands will emit an ugly error
* to the user if you do not emit some form of reply within 3 seconds.
*
* @param m message to reply with.
* @param interaction true if the reply is generated by an interaction
*/
void reply(const dpp::message &m, command_source source);
};
};

283
vendor/DPP/include/dpp/discord.h vendored Normal file
View File

@ -0,0 +1,283 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <string>
#include <vector>
#include <unordered_map>
#include <map>
#include <functional>
/**
* @brief The main namespace for D++ functions. classes and types
*/
namespace dpp {
/** @brief A 64 bit unsigned value representing many things on discord.
* Discord calls the value a 'snowflake' value.
*/
typedef uint64_t snowflake;
/** @brief The managed class is the base class for various types that can
* be stored in a cache that are identified by a dpp::snowflake id
*/
class CoreExport managed {
public:
/** Unique ID of object */
snowflake id;
/** Constructor, initialises id to 0 */
managed(const snowflake = 0);
/** Default destructor */
virtual ~managed() = default;
};
/** @brief Supported image types for profile pictures */
enum image_type {
/// image/png
i_png,
/// image/jpeg
i_jpg,
/// image/gif
i_gif
};
/** @brief Log levels */
enum loglevel {
/// Trace
ll_trace = 0,
/// Debug
ll_debug,
/// Information
ll_info,
/// Warning
ll_warning,
/// Error
ll_error,
/// Critical
ll_critical
};
/** @brief Utility helper functions, generally for logging */
namespace utility {
typedef std::function<void(const std::string& output)> cmd_result_t;
/**
* @brief Run a commandline program asyncronously. The command line program
* is spawned in a separate std::thread, and when complete, its output from
* stdout is passed to the callback function in its string prameter. For eample
* ```
* dpp::utility::exec("ls", [](const std::string& output) {
* std::cout << "Output of 'ls': " << output << "\n";
* });
* ```
*
* @param cmd The command to run.
* @param parameters Command line parameters. Each will be escaped using std::quoted.
* @param callback The callback to call on completion.
*/
void CoreExport exec(const std::string& cmd, std::vector<std::string> parameters = {}, cmd_result_t callback = {});
/**
* @brief Returns urrent date and time
*
* @return std::string Current date and time
*/
std::string CoreExport current_date_time();
/**
* @brief Convert a dpp::loglevel enum value to a string
*
* @param in log level to convert
* @return std::string string form of log level
*/
std::string CoreExport loglevel(dpp::loglevel in);
/**
* @brief Store a 128 bit icon hash (profile picture, server icon etc)
* as a 128 bit binary value made of two uint64_t.
* Has a constructor to build one from a string, and a method to fetch
* the value back in string form.
*/
struct CoreExport iconhash {
uint64_t first; //!< High 64 bits
uint64_t second; //!< Low 64 bits
/**
* @brief Construct a new iconcash object
*/
iconhash();
/**
* @brief Construct a new iconhash object
*
* @param hash String hash to construct from.
* Must contain a 32 character hex string.
*
* @throws std::length_error if the provided
* string is not exactly 32 characters long.
*/
iconhash(const std::string &hash);
/**
* @brief Assign from std::string
*
* @param assignment string to assign from.
*
* @throws std::length_error if the provided
* string is not exactly 32 characters long.
*/
iconhash& operator=(const std::string &assignment);
/**
* @brief Change value of iconhash object
*
* @param hash String hash to change to.
* Must contain a 32 character hex string.
*
* @throws std::length_error if the provided
* string is not exactly 32 characters long.
*/
void set(const std::string &hash);
/**
* @brief Convert iconhash back to 32 character
* string value.
*
* @return std::string Hash value
*/
std::string to_string() const;
};
/**
* @brief Return the current time with fractions of seconds.
* This is a unix epoch time with the fractional seconds part
* after the decimal place.
*
* @return double time with fractional seconds
*/
double CoreExport time_f();
/**
* @brief Returns true if D++ was built with voice support
*
* @return bool True if voice support is compiled in (libsodium/libopus)
*/
bool CoreExport has_voice();
/**
* @brief Convert a byte count to display value
*
* @param c number of bytes
* @return std::string display value suffixed with M, G, T where neccessary
*/
std::string CoreExport bytes(uint64_t c);
/**
* @brief A class used to represent an uptime in hours, minutes,
* seconds and days, with helper functions to convert from time_t
* and display as a string.
*/
struct CoreExport uptime {
uint16_t days; //!< Number of days
uint8_t hours; //!< Number of hours
uint8_t mins; //!< Number of minutes
uint8_t secs; //!< Number of seconds
/**
* @brief Construct a new uptime object
*/
uptime();
/**
* @brief Construct a new uptime object
*
* @param diff A time_t to initialise the object from
*/
uptime(time_t diff);
/**
* @brief Get uptime as string
*
* @return std::string Uptime as string
*/
std::string to_string();
/**
* @brief Get uptime as seconds
*
* @return uint64_t Uptime as seconds
*/
uint64_t to_secs();
/**
* @brief Get uptime as milliseconds
*
* @return uint64_t Uptime as milliseconds
*/
uint64_t to_msecs();
};
/**
* @brief Output hex values of a section of memory for debugging
*
* @param data The start of the data to display
* @param length The length of data to display
*/
void CoreExport debug_dump(uint8_t* data, size_t length);
/**
* @brief Returns the length of a UTF-8 string in codepoints
*
* @param str string to count length of
* @return size_t length of string (0 for invalid utf8)
*/
size_t CoreExport utf8len(const std::string &str);
/**
* @brief Return substring of a UTF-8 encoded string in codepoints
*
* @param str string to return substring from
* @param start start codepoint offset
* @param length length in codepoints
* @return std::string Substring in UTF-8 or emtpy string if invalid UTF-8 passed in
*/
std::string CoreExport utf8substr(const std::string& str, std::string::size_type start, std::string::size_type length);
};
};
#include <dpp/voicestate.h>
#include <dpp/role.h>
#include <dpp/user.h>
#include <dpp/channel.h>
#include <dpp/guild.h>
#include <dpp/invite.h>
#include <dpp/dtemplate.h>
#include <dpp/emoji.h>
#include <dpp/ban.h>
#include <dpp/prune.h>
#include <dpp/voiceregion.h>
#include <dpp/integration.h>
#include <dpp/webhook.h>
#include <dpp/presence.h>
#include <dpp/intents.h>
#include <dpp/slashcommand.h>
#include <dpp/auditlog.h>

358
vendor/DPP/include/dpp/discordclient.h vendored Normal file
View File

@ -0,0 +1,358 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <string>
#include <map>
#include <vector>
#include <dpp/json_fwd.hpp>
#include <dpp/wsclient.h>
#include <dpp/dispatcher.h>
#include <dpp/cluster.h>
#include <dpp/discordvoiceclient.h>
#include <queue>
#include <thread>
#include <deque>
#include <mutex>
using json = nlohmann::json;
#define DISCORD_API_VERSION "9"
#define DEFAULT_GATEWAY "gateway.discord.gg"
#define API_PATH "/api/v" DISCORD_API_VERSION
namespace dpp {
// Forward declarations
class cluster;
/** This is an opaque class containing zlib library specific structures.
* We define it this way so that the public facing D++ library doesnt require
* the zlib headers be available to build against it.
*/
class zlibcontext;
/**
* @brief Represents a connection to a voice channel.
* A client can only connect to one voice channel per guild at a time, so these are stored in a map
* in the dpp::discord_client keyed by guild_id.
*/
class CoreExport voiceconn {
/**
* @brief Owning dpp::discord_client instance
*/
class discord_client* creator;
public:
/**
* @brief Voice Channel ID
*/
snowflake channel_id;
/**
* @brief Websocket hostname for status
*/
std::string websocket_hostname;
/**
* @brief Voice Voice session ID
*/
std::string session_id;
/**
* @brief Voice websocket token
*/
std::string token;
/**
* @brief voice websocket client
*/
class discord_voice_client* voiceclient;
/**
* @brief Construct a new voiceconn object
*/
voiceconn() = default;
/**
* @brief Construct a new voiceconn object
*
* @param o owner
* @param _channel_id voice channel id
*/
voiceconn(class discord_client* o, snowflake _channel_id);
/**
* @brief Destroy the voiceconn object
*/
~voiceconn();
/**
* @brief return true if the connection is ready to connect
* (has hostname, token and session id)
*
* @return true if ready to connect
*/
bool is_ready();
/**
* @brief return true if the connection is active (websocket exists)
*
* @return true if has an active websocket
*/
bool is_active();
/**
* @brief Create websocket object and connect it.
* Needs hosname, token and session_id to be set or does nothing.
*
* @param guild_id Guild to connect to the voice channel on
*/
void connect(snowflake guild_id);
/**
* @brief Disconnect from the currently connected voice channel
*/
void disconnect();
};
/** @brief Implements a discord client. Each discord_client connects to one shard and derives from a websocket client. */
class CoreExport discord_client : public websocket_client
{
/** Mutex for message queue */
std::mutex queue_mutex;
/** Queue of outbound messages */
std::deque<std::string> message_queue;
/** Thread this shard is executing on */
std::thread* runner;
/** Run shard loop under a thread */
void ThreadRun();
/** If true, stream compression is enabled */
bool compressed;
/** ZLib decompression buffer */
unsigned char* decomp_buffer;
/** Decompressed string */
std::string decompressed;
/** Frame decompression stream */
zlibcontext* zlib;
/** Total decompressed received bytes */
uint64_t decompressed_total;
/** Last connect time of cluster */
time_t connect_time;
/** Time last ping sent to websocket */
double ping_start;
/**
* @brief Initialise ZLib
*/
void SetupZLib();
/**
* @brief Shut down ZLib
*/
void EndZLib();
public:
/** Owning cluster */
class dpp::cluster* creator;
/** Heartbeat interval for sending heartbeat keepalive */
uint32_t heartbeat_interval;
/** Last heartbeat */
time_t last_heartbeat;
/** Shard ID of this client */
uint32_t shard_id;
/** Total number of shards */
uint32_t max_shards;
/** Thread ID */
std::thread::native_handle_type thread_id;
/** Last sequence number received, for resumes and pings */
uint64_t last_seq;
/** Discord bot token */
std::string token;
/** Privileged gateway intents */
uint32_t intents;
/** Discord session id */
std::string sessionid;
/** Mutex for voice connections map */
std::mutex voice_mutex;
/** Resume count */
uint32_t resumes;
/** Reconnection count */
uint32_t reconnects;
/** Websocket latency in fractional seconds */
double websocket_ping;
/** True if READY or RESUMED has been received */
bool ready;
/** Last heartbeat ACK (opcode 11) */
time_t last_heartbeat_ack;
/** List of voice channels we are connecting to keyed by guild id */
std::unordered_map<snowflake, voiceconn*> connecting_voice_channels;
/** Log a message to whatever log the user is using.
* The logged message is passed up the chain to the on_log event in user code which can then do whatever
* it wants to do with it.
* @param severity The log level from dpp::loglevel
* @param msg The log message to output
*/
virtual void log(dpp::loglevel severity, const std::string &msg) const;
/** Handle an event (opcode 0)
* @param event Event name, e.g. MESSAGE_CREATE
* @param j JSON object for the event content
* @param raw Raw JSON event string
*/
virtual void HandleEvent(const std::string &event, json &j, const std::string &raw);
/**
* @brief Get the Guild Count for this shard
*
* @return uint64_t guild count
*/
uint64_t get_guild_count();
/**
* @brief Get the Member Count for this shard
*
* @return uint64_t member count
*/
uint64_t get_member_count();
/**
* @brief Get the Channel Count for this shard
*
* @return uint64_t channel count
*/
uint64_t get_channel_count();
/** Fires every second from the underlying socket I/O loop, used for sending heartbeats */
virtual void one_second_timer();
/**
* @brief Queue a message to be sent via the websocket
*
* @param j The JSON data of the message to be sent
* @param to_front If set to true, will place the message at the front of the queue not the back
* (this is for urgent messages such as heartbeat, presence, so they can take precedence over
* chunk requests etc)
*/
void QueueMessage(const std::string &j, bool to_front = false);
/**
* @brief Clear the outbound message queue
*
*/
void ClearQueue();
/**
* @brief Get the size of the outbound message queue
*
* @return The size of the queue
*/
size_t GetQueueSize();
/**
* @brief Returns true if the shard is connected
*
* @return True if connected
*/
bool is_connected();
/**
* @brief Returns the connection time of the shard
*
* @return dpp::utility::uptime Detail of how long the shard has been connected for
*/
dpp::utility::uptime get_uptime();
/** Constructor takes shard id, max shards and token.
* @param _cluster The owning cluster for this shard
* @param _shard_id The ID of the shard to start
* @param _max_shards The total number of shards across all clusters
* @param _token The bot token to use for identifying to the websocket
* @param intents Privileged intents to use, a bitmask of values from dpp::intents
* @param compressed True if the received data will be gzip compressed
*/
discord_client(dpp::cluster* _cluster, uint32_t _shard_id, uint32_t _max_shards, const std::string &_token, uint32_t intents = 0, bool compressed = true);
/** Destructor */
virtual ~discord_client();
/** Get decompressed total bytes received */
uint64_t get_decompressed_bytes_in();
/** Handle JSON from the websocket.
* @param buffer The entire buffer content from the websocket client
* @returns True if a frame has been handled
*/
virtual bool HandleFrame(const std::string &buffer);
/** Handle a websocket error.
* @param errorcode The error returned from the websocket
*/
virtual void Error(uint32_t errorcode);
/** Start and monitor I/O loop */
void Run();
/**
* @brief Connect to a voice channel
*
* @param guild_id Guild where the voice channel is
* @param channel_id Channel ID of the voice channel
*/
void connect_voice(snowflake guild_id, snowflake channel_id);
/**
* @brief Disconnect from the connected voice channel on a guild
*
* @param guild_id The guild who's voice channel you wish to disconnect from
*/
void disconnect_voice(snowflake guild_id);
voiceconn* get_voice(snowflake guild_id);
};
};

148
vendor/DPP/include/dpp/discordevents.h vendored Normal file
View File

@ -0,0 +1,148 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/json_fwd.hpp>
namespace dpp {
/** @brief Returns a snowflake id from a json field value, if defined, else returns 0
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @return found value
*/
uint64_t SnowflakeNotNull(const nlohmann::json* j, const char *keyname);
/** @brief Sets a snowflake id from a json field value, if defined, else does nothing
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @param v Value to change
*/
void SetSnowflakeNotNull(const nlohmann::json* j, const char *keyname, uint64_t &v);
/** @brief Returns a string from a json field value, if defined, else returns an empty string.
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @return found value
*/
std::string StringNotNull(const nlohmann::json* j, const char *keyname);
/** @brief Sets a string from a json field value, if defined, else does nothing
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @param v Value to change
*/
void SetStringNotNull(const nlohmann::json* j, const char *keyname, std::string &v);
/** @brief Returns a 64 bit unsigned integer from a json field value, if defined, else returns 0.
* DO NOT use this for snowflakes, as usually snowflakes are wrapped in a string!
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @return found value
*/
uint64_t Int64NotNull(const nlohmann::json* j, const char *keyname);
/** @brief Sets an unsigned 64 bit integer from a json field value, if defined, else does nothing
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @param v Value to change
*/
void SetInt64NotNull(const nlohmann::json* j, const char *keyname, uint64_t &v);
/** @brief Returns a 32 bit unsigned integer from a json field value, if defined, else returns 0
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @return found value
*/
uint32_t Int32NotNull(const nlohmann::json* j, const char *keyname);
/** @brief Sets an unsigned 32 bit integer from a json field value, if defined, else does nothing
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @param v Value to change
*/
void SetInt32NotNull(const nlohmann::json* j, const char *keyname, uint32_t &v);
/** @brief Returns a 16 bit unsigned integer from a json field value, if defined, else returns 0
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @return found value
*/
uint16_t Int16NotNull(const nlohmann::json* j, const char *keyname);
/** @brief Sets an unsigned 16 bit integer from a json field value, if defined, else does nothing
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @param v Value to change
*/
void SetInt16NotNull(const nlohmann::json* j, const char *keyname, uint16_t &v);
/** @brief Returns an 8 bit unsigned integer from a json field value, if defined, else returns 0
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @return found value
*/
uint8_t Int8NotNull(const nlohmann::json* j, const char *keyname);
/** @brief Sets an unsigned 8 bit integer from a json field value, if defined, else does nothing
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @param v Value to change
*/
void SetInt8NotNull(const nlohmann::json* j, const char *keyname, uint8_t &v);
/** @brief Returns a boolean value from a json field value, if defined, else returns false
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @return found value
*/
bool BoolNotNull(const nlohmann::json* j, const char *keyname);
/** @brief Sets a boolean from a json field value, if defined, else does nothing
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @param v Value to change
*/
void SetBoolNotNull(const nlohmann::json* j, const char *keyname, bool &v);
/** @brief Returns a time_t from an ISO8601 timestamp field in a json value, if defined, else returns
* epoch value of 0.
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @return found value
*/
time_t TimestampNotNull(const nlohmann::json* j, const char *keyname);
/** @brief Sets an timestamp from a json field value containing an ISO8601 string, if defined, else does nothing
* @param j nlohmann::json instance to retrieve value from
* @param keyname key name to check for a value
* @param v Value to change
*/
void SetTimestampNotNull(const nlohmann::json* j, const char *keyname, time_t &v);
/** @brief Base64 encode data into a string.
* @param buf Raw binary buffer
* @param buffer_length Buffer length to encode
* @return The base64 encoded string
*/
std::string base64_encode(unsigned char const* buf, unsigned int buffer_length);
};

View File

@ -0,0 +1,513 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <errno.h>
#ifdef _WIN32
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <io.h>
#else
#include <resolv.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <unistd.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <string>
#include <map>
#include <vector>
#include <dpp/json_fwd.hpp>
#include <dpp/wsclient.h>
#include <dpp/dispatcher.h>
#include <dpp/cluster.h>
#include <queue>
#include <thread>
#include <deque>
#include <mutex>
#ifdef HAVE_VOICE
#include <sodium.h>
#include <opus/opus.h>
#endif
using json = nlohmann::json;
namespace dpp {
// Forward declaration
class cluster;
#define AUDIO_TRACK_MARKER (uint16_t)0xFFFF
/** @brief Implements a discord voice connection.
* Each discord_voice_client connects to one voice channel and derives from a websocket client.
*/
class CoreExport discord_voice_client : public websocket_client
{
/** Mutex for outbound packet stream */
std::mutex stream_mutex;
/** Mutex for message queue */
std::mutex queue_mutex;
/** Queue of outbound messages */
std::deque<std::string> message_queue;
/** Thread this connection is executing on */
std::thread* runner;
/** Run shard loop under a thread */
void ThreadRun();
/** Last connect time of voice session */
time_t connect_time;
/**
* @brief IP of UDP/RTP endpoint
*/
std::string ip;
/**
* @brief Port number of UDP/RTP endpoint
*/
uint16_t port;
/**
* @brief SSRC value
*/
uint64_t ssrc;
/**
* @brief List of supported audio encoding modes
*/
std::vector<std::string> modes;
/** Output buffer. Each string is a UDP packet.
* Generally these will be RTP.
*/
std::vector<std::string> outbuf;
/** Input buffer. Each string is a received UDP
* packet. These will usually be RTP.
*/
std::vector<std::string> inbuf;
/** If true, audio packet sending is paused
*/
bool paused;
#ifdef HAVE_VOICE
/** libopus encoder
*/
OpusEncoder* encoder;
/** libopus decoder
*/
OpusDecoder* decoder;
/** libopus repacketizer
* (merges frames into one packet)
*/
OpusRepacketizer* repacketizer;
#endif
/** File descriptor for UDP connection
*/
SOCKET fd;
/** Socket address of voice server
*/
struct sockaddr_in servaddr;
/** Secret key for encrypting voice.
* If it has been sent, this is non-null and points to a
* sequence of exactly 32 bytes.
*/
uint8_t* secret_key;
/** Sequence number of outbound audio. This is incremented
* once per frame sent.
*/
uint16_t sequence;
/** Timestamp value used in outbound audio. Each packet
* has the timestamp value which is incremented to match
* how many frames are sent.
*/
uint32_t timestamp;
/** This is set to true if we have started sending audio.
* When this moves from false to true, this causes the
* client to send the 'talking' notification to the websocket.
*/
bool sending;
/** Number of track markers in the buffer. For example if there
* are two track markers in the buffer there are 3 tracks.
* Special case:
* If the buffer is empty, there are zero tracks in the
* buffer.
*/
uint32_t tracks;
/** Meta data associated with each track.
* Arbitrary string that the user can set via
* dpp::discord_voice_client::AddMarker
*/
std::vector<std::string> track_meta;
/** Encoding buffer for opus repacketizer and encode
*/
uint8_t encode_buffer[65536];
/**
* @brief Send data to UDP socket immediately.
*
* @param data data to send
* @param length length of data to send
* @return int bytes sent. Will return -1 if we cannot send
*/
int UDPSend(const char* data, size_t length);
/**
* @brief Receieve data from UDP socket immediately.
*
* @param data data to receive
* @param max_length size of data receiving buffer
* @return int bytes received. -1 if there is an error
* (e.g. EAGAIN)
*/
int UDPRecv(char* data, size_t max_length);
/**
* @brief This hooks the ssl_client, returning the file
* descriptor if we want to send buffered data, or
* -1 if there is nothing to send
*
* @return int file descriptor or -1
*/
int WantWrite();
/**
* @brief This hooks the ssl_client, returning the file
* descriptor if we want to receive buffered data, or
* -1 if we are not wanting to receive
*
* @return int file descriptor or -1
*/
int WantRead();
/**
* @brief Called by ssl_client when the socket is ready
* for writing, at this point we pick the head item off
* the buffer and send it. So long as it doesnt error
* completely, we pop it off the head of the queue.
*/
void WriteReady();
/**
* @brief Called by ssl_client when there is data to be
* read. At this point we insert that data into the
* input queue.
*/
void ReadReady();
/**
* @brief Send data to the UDP socket, using the buffer.
*
* @param packet packet data
* @param len length of packet
*/
void Send(const char* packet, size_t len);
/**
* @brief Queue a message to be sent via the websocket
*
* @param j The JSON data of the message to be sent
* @param to_front If set to true, will place the message at the front of the queue not the back
* (this is for urgent messages such as heartbeat, presence, so they can take precedence over
* chunk requests etc)
*/
void QueueMessage(const std::string &j, bool to_front = false);
/**
* @brief Clear the outbound message queue
*
*/
void ClearQueue();
/**
* @brief Get the size of the outbound message queue
*
* @return The size of the queue
*/
size_t GetQueueSize();
/**
* @brief Encode a byte buffer using opus codec.
* Multiple opus frames (2880 bytes each) will be encoded into one packet for sending.
*
* @param input Input data as raw bytes of PCM data
* @param inDataSize Input data length
* @param output Output data as an opus encoded packet
* @param outDataSize Output data length, should be at least equal to the input size.
* Will be adjusted on return to the actual compressed data size.
* @return size_t The compressed data size that was encoded.
*/
size_t encode(uint8_t *input, size_t inDataSize, uint8_t *output, size_t &outDataSize);
public:
/** Owning cluster */
class dpp::cluster* creator;
/* This needs to be static, we only initialise libsodium once per program start,
* so initialising it on first use in a voice connection is best.
*/
static bool sodium_initialised;
/** True when the thread is shutting down */
bool terminating;
/** Heartbeat interval for sending heartbeat keepalive */
uint32_t heartbeat_interval;
/** Last heartbeat */
time_t last_heartbeat;
/** Thread ID */
std::thread::native_handle_type thread_id;
/** Discord voice session token */
std::string token;
/** Discord voice session id */
std::string sessionid;
/** Server ID */
snowflake server_id;
/** Channel ID */
snowflake channel_id;
/** Log a message to whatever log the user is using.
* The logged message is passed up the chain to the on_log event in user code which can then do whatever
* it wants to do with it.
* @param severity The log level from dpp::loglevel
* @param msg The log message to output
*/
virtual void log(dpp::loglevel severity, const std::string &msg);
/** Fires every second from the underlying socket I/O loop, used for sending heartbeats */
virtual void one_second_timer();
/**
* @brief voice client is ready to stream audio.
* The voice client is considered ready if it has a secret key.
*
* @return true if ready to stream audio
*/
bool is_ready();
/**
* @brief Returns true if the voice client is connected to the websocket
*
* @return True if connected
*/
bool is_connected();
/**
* @brief Returns the connection time of the voice client
*
* @return dpp::utility::uptime Detail of how long the voice client has been connected for
*/
dpp::utility::uptime get_uptime();
/** Constructor takes shard id, max shards and token.
* @param _cluster The owning cluster for this shard
* @param _server_id The server id to identify voice connection as
* @param _token The voice session token to use for identifying to the websocket
* @param _session_id The voice session id to identify with
* @param _host The voice server hostname to connect to (hostname:port format)
*/
discord_voice_client(dpp::cluster* _cluster, snowflake _channel_id, snowflake _server_id, const std::string &_token, const std::string &_session_id, const std::string &_host);
/** Destructor */
virtual ~discord_voice_client();
/** Handle JSON from the websocket.
* @param buffer The entire buffer content from the websocket client
* @returns True if a frame has been handled
*/
virtual bool HandleFrame(const std::string &buffer);
/** Handle a websocket error.
* @param errorcode The error returned from the websocket
*/
virtual void Error(uint32_t errorcode);
/** Start and monitor I/O loop */
void Run();
/**
* @brief Send audio to the voice channel.
*
* You should send an audio packet of n11520 bytes.
* Note that this function can be costly as it has to opus encode
* the PCM audio on the fly, and also encrypt it with libsodium.
*
* @note Because this function encrypts and encodes packets before
* pushing them onto the output queue, if you have a complete stream
* ready to send and know its length it is advisable to call this
* method multiple times to enqueue the entire stream audio so that
* it is all encoded at once. Constantly calling this from the
* dpp::on_voice_buffer_send callback can and will eat a TON of cpu!
*
* @param audio_data Raw PCM audio data. Channels are interleaved,
* with each channel's amplitude being a 16 bit value.
* @param length The length of the audio data. The length should
* be a multiple of 4 (2x 16 bit stero channels) with a maximum
* length of 11520, which is a complete opus frame at highest
* quality.
* @param use_opus Some containers such as .ogg may contain OPUS
* encoded data already. In this case, we don't need to encode the
* frames using opus here. We can set use_opus to false and bypass the
* codec, only applying libsodium to the stream.
*/
void send_audio(uint16_t* audio_data, const size_t length, bool use_opus = true);
/**
* @brief Pause sending of audio
*
* @param pause True to pause, false to resume
*/
void pause_audio(bool pause);
/**
* @brief Immediately stop all audio.
* Clears the packet queue.
*/
void stop_audio();
/**
* @brief Returns true if we are playing audio
*
* @return true if audio is playing
*/
bool is_playing();
/**
* @brief Get the number of seconds remaining
* of the audio output buffer
*
* @return float number of seconds remaining
*/
float get_secs_remaining();
/**
* @brief Get the number of tracks remaining
* in the output buffer.
* This is calculated by the number of track
* markers plus one.
* @return uint32_t Number of tracks in the
* buffer
*/
uint32_t get_tracks_remaining();
/**
* @brief Get the time remaining to send the
* audio output buffer in hours:minutes:seconds
*
* @return dpp::utility::uptime length of buffer
*/
dpp::utility::uptime get_remaining();
/**
* @brief Insert a track marker into the audio
* output buffer.
* A track marker is an arbitrary flag in the
* buffer contents that indictes the end of some
* block of audio of significance to the sender.
* This may be a song from a streaming site, or
* some voice audio/speech, a sound effect, or
* whatever you choose. You can later skip
* to the next marker using the
* dpp::discord_voice_client::skip_to_next_marker
* function.
* @param metadata Arbitrary information related to this
* track
*/
void insert_marker(const std::string& metadata = "");
/**
* @brief Skip tp the next track marker,
* previously inserted by using the
* dpp::discord_voice_client::insert_marker
* function. If there are no markers in the
* output buffer, then this skips to the end
* of the buffer and is equivalent to the
* dpp::discord_voice_client::stop_audio
* function.
* @note It is possible to use this function
* while the output stream is paused.
*/
void skip_to_next_marker();
/**
* @brief Get the metdata string associated with each inserted marker.
*
* @return const std::vector<std::string>& list of metadata strings
*/
const std::vector<std::string> get_marker_metadata();
/**
* @brief Returns true if the audio is paused.
* You can unpause with
* dpp::discord_voice_client::pause_audio.
*
* @return true if paused
*/
bool is_paused();
/**
* @brief Discord external IP detection.
* @return std::string Your external IP address
* @note This is a blocking operation that waits
* for a single packet from Discord's voice servers.
*/
std::string discover_ip();
};
};

1189
vendor/DPP/include/dpp/dispatcher.h vendored Normal file

File diff suppressed because it is too large Load Diff

36
vendor/DPP/include/dpp/dpp.h vendored Normal file
View File

@ -0,0 +1,36 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/version.h>
#include <string>
#include <map>
#include <vector>
#include <fstream>
#include <iostream>
#include <ctime>
#include <dpp/dispatcher.h>
#include <dpp/discordclient.h>
#include <dpp/discord.h>
#include <dpp/cluster.h>
#include <dpp/cache.h>
#include <dpp/queues.h>
#include <dpp/commandhandler.h>

94
vendor/DPP/include/dpp/dtemplate.h vendored Normal file
View File

@ -0,0 +1,94 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief Represents a guild template
*/
class CoreExport dtemplate {
public:
/**
* @brief Template code
*/
std::string code;
/**
* @brief Template name
*/
std::string name;
/**
* @brief Template description
*/
std::string description;
/**
* @brief Usage counter
*/
uint32_t usage_count;
/**
* @brief User ID of creator
*/
snowflake creator_id;
/**
* @brief Creation date/time
*
*/
time_t created_at;
/**
* @brief Last update date/time
*/
time_t updated_at;
/**
* @brief Guild id the template is created from
*/
snowflake source_guild_id;
/**
* @brief True if needs synchronising
*/
bool is_dirty;
/**
* @brief Construct a new dtemplate object
*/
dtemplate();
/**
* @brief Destroy the dtemplate object
*/
~dtemplate();
/** Read class values from json object
* @param j A json object to read from
* @return A reference to self
*/
dtemplate& fill_from_json(nlohmann::json* j);
std::string build_json() const;
};
/** A container of invites */
typedef std::unordered_map<snowflake, dtemplate> dtemplate_map;
};

155
vendor/DPP/include/dpp/emoji.h vendored Normal file
View File

@ -0,0 +1,155 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
#define MAX_EMOJI_SIZE 256 * 1024
/**
* @brief Flags for dpp::emoji
*/
enum emoji_flags {
/// Emoji requires colons
e_require_colons = 0b00000001,
/// Managed (introduced by application)
e_managed = 0b00000010,
/// Animated
e_animated = 0b00000100,
/// Available (false if the guild doesn't meet boosting criteria, etc)
e_available = 0b00001000,
};
/**
* @brief Represents an emoji for a dpp::guild
*/
class CoreExport emoji : public managed {
public:
/**
* @brief Emoji name
*/
std::string name;
/**
* @brief User id who uploaded the emoji
*/
snowflake user_id;
/**
* @brief Flags for the emoji from dpp::emoji_flags
*/
uint8_t flags;
/**
* @brief Image data for the emoji if uploading
*/
std::string* image_data;
/**
* @brief Construct a new emoji object
*/
emoji();
/**
* @brief Construct a new emoji object with name, ID and flags
*
* @param name The emoji's name
* @param id ID, if it has one (unicode does not)
* @param flags Emoji flags (emoji_flags)
*/
emoji(const std::string, const snowflake = 0, const uint8_t = 0);
/**
* @brief Destroy the emoji object
*/
virtual ~emoji();
/**
* @brief Read class values from json object
*
* @param j A json object to read from
* @return A reference to self
*/
emoji& fill_from_json(nlohmann::json* j);
/**
* @brief Build the json for this object
*
* @param with_id include the id in the JSON
* @return std::string json data
*/
std::string build_json(bool with_id = false) const;
/**
* @brief Emoji requires colons
*
* @return true Requires colons
* @return false Does not require colons
*/
bool requires_colons() const;
/**
* @brief Emoji is managed
*
* @return true Is managed
* @return false Is not managed
*/
bool is_managed() const;
/**
* @brief Emoji is animated
*
* @return true Is animated
* @return false Is noy animated
*/
bool is_animated() const;
/**
* @brief Is available
*
* @return true Is available
* @return false Is unavailable
*/
bool is_available() const;
/**
* @brief Load an image into the object as base64
*
* @param image_blob Image binary data
* @param type Type of image
* @return emoji& Reference to self
*/
emoji& load_image(const std::string &image_blob, image_type type);
/**
* @brief Format to name if unicode, name:id if has id or a:name:id if animated
*
* @return Formatted name for reactions
*/
std::string format() const;
};
/**
* @brief Group of emojis
*/
typedef std::unordered_map<snowflake, emoji> emoji_map;
};

139
vendor/DPP/include/dpp/event.h vendored Normal file
View File

@ -0,0 +1,139 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
#define event_decl(x) class x : public event { public: virtual void handle(dpp::discord_client* client, nlohmann::json &j, const std::string &raw); };
namespace dpp {
class discord_client;
/**
* @brief The events namespace holds the internal event handlers for each websocket event.
* These are handled internally and also dispatched to the user code if the event is hooked.
*/
namespace events {
/**
* @brief An event object represents an event handled internally, passed from the websocket e.g. MESSAGE_CREATE.
*/
class CoreExport event {
public:
/** Pure virtual method for event handler code
* @param client The creating shard
* @param j The json data of the event
* @param raw The raw event json
*/
virtual void handle(class discord_client* client, nlohmann::json &j, const std::string &raw) = 0;
};
/* Internal logger */
event_decl(logger);
/* Guilds */
event_decl(guild_create);
event_decl(guild_update);
event_decl(guild_delete);
event_decl(guild_ban_add);
event_decl(guild_ban_remove);
event_decl(guild_emojis_update);
event_decl(guild_integrations_update);
event_decl(guild_join_request_delete);
event_decl(guild_stickers_update);
/* Stage channels */
event_decl(stage_instance_create);
event_decl(stage_instance_delete);
/* Guild members */
event_decl(guild_member_add);
event_decl(guild_member_remove);
event_decl(guild_members_chunk);
event_decl(guild_member_update);
/* Guild roles */
event_decl(guild_role_create);
event_decl(guild_role_update);
event_decl(guild_role_delete);
/* Session state */
event_decl(resumed);
event_decl(ready);
/* Channels */
event_decl(channel_create);
event_decl(channel_update);
event_decl(channel_delete);
event_decl(channel_pins_update);
/* Threads */
event_decl(thread_create);
event_decl(thread_update);
event_decl(thread_delete);
event_decl(thread_list_sync);
event_decl(thread_member_update);
event_decl(thread_members_update);
/* Messages */
event_decl(message_create);
event_decl(message_update);
event_decl(message_delete);
event_decl(message_delete_bulk);
/* Presence/typing */
event_decl(presence_update);
event_decl(typing_start);
/* Users (outside of guild) */
event_decl(user_update);
/* Message reactions */
event_decl(message_reaction_add);
event_decl(message_reaction_remove);
event_decl(message_reaction_remove_all);
event_decl(message_reaction_remove_emoji);
/* Invites */
event_decl(invite_create);
event_decl(invite_delete);
/* Voice */
event_decl(voice_state_update);
event_decl(voice_server_update);
/* Webhooks */
event_decl(webhooks_update);
/* Slash commands */
event_decl(application_command_create);
event_decl(application_command_update);
event_decl(application_command_delete);
event_decl(interaction_create);
/* Integrations */
event_decl(integration_create);
event_decl(integration_update);
event_decl(integration_delete);
}};

43
vendor/DPP/include/dpp/export.h vendored Normal file
View File

@ -0,0 +1,43 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#ifdef DPP_BUILD
#ifdef _WIN32
#define CoreExport __declspec(dllexport)
#else
#define CoreExport
#endif
#else
#ifdef _WIN32
#define CoreExport __declspec(dllimport)
/* This is required otherwise fmt::format requires additional file linkage to your project */
#define FMT_HEADER_ONLY
#else
#define CoreExport
#endif
#endif
#ifndef _WIN32
#define SOCKET int
#else
#include <WinSock2.h>
#endif

432
vendor/DPP/include/dpp/guild.h vendored Normal file
View File

@ -0,0 +1,432 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <mutex>
#include <string>
#include <unordered_map>
#include <map>
#include <dpp/voicestate.h>
namespace dpp {
/**
* @brief Represents voice regions for guilds and channels.
* @note Largely deprecated in favour of per-channel regions.
*/
enum region : uint8_t {
r_brazil, //!< Brazil
r_central_europe, //!< Central Europe
r_hong_kong, //!< Hong Kong
r_india, //!< India
r_japan, //!< Japan
r_russia, //!< Russia
r_singapore, //!< Singapore
r_south_africa, //!< South Africa
r_sydney, //!< Sydney
r_us_central, //!< US Central
r_us_east, //!< US East Coast
r_us_south, //!< US South
r_us_west, //!< US West Coast
r_western_europe //!< Western Europe
};
/**
* @brief The various flags that represent the status of a dpp::guild object
*/
enum guild_flags {
/** Large guild */
g_large = 0b000000000000000000001,
/** Unavailable guild (inaccessible due to an outage) */
g_unavailable = 0b000000000000000000010,
/** Guild has widget enabled */
g_widget_enabled = 0b000000000000000000100,
/** Guild can have an invite splash image */
g_invite_splash = 0b000000000000000001000,
/** Guild can have VIP regions */
g_vip_regions = 0b000000000000000010000,
/** Guild can have a vanity url */
g_vanity_url = 0b000000000000000100000,
/** Guild is verified */
g_verified = 0b000000000000001000000,
/** Guild is partnered */
g_partnered = 0b000000000000010000000,
/** Community features enabled */
g_community = 0b000000000000100000000,
/** Guild has commerce features enabled */
g_commerce = 0b000000000001000000000,
/** Guild has news features enabled */
g_news = 0b000000000010000000000,
/** Guild is discoverable in discovery */
g_discoverable = 0b000000000100000000000,
/** Guild is featureable */
g_featureable = 0b000000001000000000000,
/** Guild can have an animated icon (doesn't mean it actually has one though) */
g_animated_icon = 0b000000010000000000000,
/** Guild can have a banner image */
g_banner = 0b000000100000000000000,
/** Guild has a welcome screen */
g_welcome_screen_enabled = 0b000001000000000000000,
/** Guild has a member verification gate */
g_member_verification_gate = 0b000010000000000000000,
/** Guild has a preview */
g_preview_enabled = 0b000100000000000000000,
/** Guild join notifications are off */
g_no_join_notifications = 0b001000000000000000000,
/** Guild boost notifications are off */
g_no_boost_notifications = 0b010000000000000000000,
/** Guild has an actual animated icon (set by the icon hash starting with 'a_') */
g_has_animated_icon = 0b100000000000000000000
};
/**
* @brief Various flags that can be used to indicate the status of a guild member
*/
enum guild_member_flags {
/** Member deafened */
gm_deaf = 0b00001,
/** Member muted */
gm_mute = 0b00010,
/** Member pending verification by membership screening */
gm_pending = 0b00100
};
/**
* @brief Represents dpp::user membership upon a dpp::guild
*/
class CoreExport guild_member {
public:
/** Nickname, or nullptr if they don't have a nickname on this guild */
std::string nickname;
/** Guild id */
snowflake guild_id;
/** User id */
snowflake user_id;
/** List of roles this user has on this guild */
std::vector<snowflake> roles;
/** Date and time the user joined the guild */
time_t joined_at;
/** Boosting since */
time_t premium_since;
/** A set of flags built from the bitmask defined by dpp::guild_member_flags */
uint8_t flags;
/** Default constructor */
guild_member();
/** Fill this object from a json object.
* @param j The json object to get data from
* @param g_id The guild id to associate the member with
* @param u_id The user id to associate the member with
*/
guild_member& fill_from_json(nlohmann::json* j, snowflake g_id, snowflake u_id);
/** Build json string for the member object */
std::string build_json() const;
/** Returns true if the user is deafened */
bool is_deaf() const;
/** Returns true if the user is muted */
bool is_muted() const;
/** Returns true if pending verification by membership screening */
bool is_pending() const;
};
/** @brief Guild members container
*/
typedef std::unordered_map<snowflake, guild_member> members_container;
/**
* @brief Represents a guild on Discord (AKA a server)
*/
class CoreExport guild : public managed {
public:
/** Shard ID of the guild */
uint16_t shard_id;
/** Flags bitmask as defined by values within dpp::guild_flags */
uint32_t flags;
/** Guild name */
std::string name;
/** Server description for communities */
std::string description;
/** Vanity url code for verified or partnered servers and boost level 3 */
std::string vanity_url_code;
/** Guild icon hash */
utility::iconhash icon;
/** Guild splash hash */
utility::iconhash splash;
/** Guild discovery splash hash */
utility::iconhash discovery_splash;
/** Snowflake id of guild owner */
snowflake owner_id;
/** Guild voice region */
region voice_region;
/** Snowflake ID of AFK voice channel or 0 */
snowflake afk_channel_id;
/** Voice AFK timeout before moving users to AFK channel */
uint8_t afk_timeout;
/** Snowflake ID of widget channel, or 0 */
snowflake widget_channel_id;
/** Verification level of server */
uint8_t verification_level;
/** Setting for how notifications are to be delivered to users */
uint8_t default_message_notifications;
/** Wether or not explicit content filtering is enable and what setting it is */
uint8_t explicit_content_filter;
/** If multi factor authentication is required for moderators or not */
uint8_t mfa_level;
/** ID of creating application, if any, or 0 */
snowflake application_id;
/** ID of system channel where discord update messages are sent */
snowflake system_channel_id;
/** ID of rules channel for communities */
snowflake rules_channel_id;
/** Approximate member count. May be sent as zero */
uint32_t member_count;
/** Server banner hash */
utility::iconhash banner;
/** Boost level */
uint8_t premium_tier;
/** Number of boosters */
uint16_t premium_subscription_count;
/** Public updates channel id or 0 */
snowflake public_updates_channel_id;
/** Maximum users in a video channel, or 0 */
uint16_t max_video_channel_users;
/** Roles defined on this server */
std::vector<snowflake> roles;
/** List of channels on this server */
std::vector<snowflake> channels;
/** List of threads on this server */
std::vector<snowflake> threads;
/** List of guild members. Note that when you first receive the
* guild create event, this may be empty or near empty.
* This depends upon your dpp::intents and the size of your bot.
* It will be filled by guild member chunk requests.
*/
members_container members;
/** List of members in voice channels in the guild.
*/
std::map<snowflake, voicestate> voice_members;
/** List of emojis
*/
std::vector<snowflake> emojis;
/** Default constructor, zeroes all values */
guild();
/**
* @brief Destroy the guild object
*/
virtual ~guild() = default;
/** Read class values from json object
* @param shard originating shard
* @param j A json object to read from
* @return A reference to self
*/
guild& fill_from_json(class discord_client* shard, nlohmann::json* j);
/** Build a JSON string from this object.
* @param with_id True if an ID is to be included in the JSON
*/
std::string build_json(bool with_id = false) const;
/**
* @brief Get the base permissions for a member on this guild,
* before permission overwrites are applied.
*
* @param member member to get permissions for
* @return uint64_t permissions bitmask
*/
uint64_t base_permissions(const class user* member) const;
/**
* @brief Get the permission overwrites for a member
* merged into a bitmask.
*
* @param base_permissions base permissions before overwrites,
* from channel::base_permissions
* @param member Member to fetch permissions for
* @param channel Channel to fetch permissions against
* @return uint64_t Merged permissions bitmask of overwrites.
*/
uint64_t permission_overwrites(const uint64_t base_permissions, const user* member, const channel* channel) const;
/**
* @brief Rehash members map
*/
void rehash_members();
/**
* @brief Connect to a voice channel another guild member is in
*
* @param user_id User id to join
* @return True if the user specified is in a vc, false if they aren't
*/
bool connect_member_voice(snowflake user_id);
/** Is a large server (>250 users) */
bool is_large() const;
/** Is unavailable due to outage (most other fields will be blank or outdated */
bool is_unavailable() const;
/** Widget is enabled for this server */
bool widget_enabled() const;
/** Guild has an invite splash */
bool has_invite_splash() const;
/** Guild has VIP regions */
bool has_vip_regions() const;
/** Guild can have a vanity url */
bool has_vanity_url() const;
/** Guild is a verified server */
bool is_verified() const;
/** Guild is a discord partner server */
bool is_partnered() const;
/** Guild has enabled community */
bool is_community() const;
/** Guild has enabled commerce channels */
bool has_commerce() const;
/** Guild has news channels */
bool has_news() const;
/** Guild is discoverable */
bool is_discoverable() const;
/** Guild is featureable */
bool is_featureable() const;
/** Guild is allowed an animated icon */
bool has_animated_icon() const;
/** Guild has a banner image */
bool has_banner() const;
/** Guild has enabled welcome screen */
bool is_welcome_screen_enabled() const;
/** Guild has enabled membership screening */
bool has_member_verification_gate() const;
/** Guild has preview enabled */
bool is_preview_enabled() const;
/** Server icon is actually an animated gif */
bool has_animated_icon_hash() const;
};
/** A container of guilds */
typedef std::unordered_map<snowflake, guild> guild_map;
/**
* @brief Represents a guild widget, simple web widget of member list
*/
class CoreExport guild_widget {
public:
/**
* @brief True if enabled
*/
bool enabled;
/**
* @brief Channel widget points to
*/
snowflake channel_id;
/**
* @brief Construct a new guild widget object
*/
guild_widget();
/**
* @brief Build a guild widget from json
*
* @param j json to build from
* @return guild_widget& reference to self
*/
guild_widget& fill_from_json(nlohmann::json* j);
/**
* @brief Build json for a guild widget
*
* @return std::string guild widget stringified json
*/
std::string build_json() const;
};
/**
* @brief helper function to deserialize a guild_member from json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param gm guild_member to be deserialized
*/
void from_json(const nlohmann::json& j, guild_member& gm);
/** A container of guild members */
typedef std::unordered_map<snowflake, guild_member> guild_member_map;
};

1452
vendor/DPP/include/dpp/httplib.h vendored Normal file

File diff suppressed because it is too large Load Diff

132
vendor/DPP/include/dpp/integration.h vendored Normal file
View File

@ -0,0 +1,132 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief Integration types
*/
enum integration_type {
/// Twitch integration
i_twitch,
/// YouTube integration
i_youtube,
/// Discord integration
i_discord
};
/**
* @brief Integration flags
*/
enum integration_flags {
/// Integration enabled
if_enabled = 0b00000001,
/// Integration synching
if_syncing = 0b00000010,
/// Emoji integration
if_emoticons = 0b00000100,
/// Integration revoked
if_revoked = 0b00001000,
/// Kick users when their subscription expires
if_expire_kick = 0b00010000,
};
/**
* @brief An application that has been integrated
*/
struct CoreExport integration_app {
/// Inegration id
snowflake id;
/// Name
std::string name;
/// Icon
std::string icon;
/// Description
std::string description;
/// Integration summary
std::string summary;
/// Pointer to bot user
user* bot;
};
/** Represents an integration within a dpp::guild */
class CoreExport integration : public managed {
public:
/** Integration name */
std::string name;
/** Integration type */
integration_type type;
/** Integration flags from dpp::integration_flags */
uint8_t flags;
/** Role id */
snowflake role_id;
/** User id */
snowflake user_id;
/** Expiry grace period */
uint32_t expire_grace_period;
/** Sync time */
time_t synced_at;
/** Subscriber count */
uint32_t subscriber_count;
/* Account id */
std::string account_id;
/* Account name */
std::string account_name;
/* Integration application */
integration_app app;
/** Default constructor */
integration();
/** Default destructor */
~integration();
/** Read class values from json object
* @param j A json object to read from
* @return A reference to self
*/
integration& fill_from_json(nlohmann::json* j);
/** Build a json string from this object.
* @return JSON string of the object
*/
std::string build_json() const;
/** True if emoticons are enabled */
bool emoticons_enabled() const;
/** True if integration is enabled */
bool is_enabled() const;
/** True if is syncing */
bool is_syncing() const;
/** True if has been revoked */
bool is_revoked() const;
/** True if expiring kicks the user */
bool expiry_kicks_user() const;
};
/** A group of integrations */
typedef std::unordered_map<snowflake, integration> integration_map;
};

71
vendor/DPP/include/dpp/intents.h vendored Normal file
View File

@ -0,0 +1,71 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
namespace dpp {
/**
* @brief intents are a bitmask of allowed events on your websocket.
*
* Some of these are known as Privileged intents (GUILD_MEMBERS and GUILD_PRESENCES)
* and require verification of a bot over 100 servers by discord via submission of
* your real life ID.
*/
enum intents {
/// Intent for receipt of guild information
i_guilds = (1 << 0),
/// Intent for receipt of guild members
i_guild_members = (1 << 1),
/// Intent for receipt of guild bans
i_guild_bans = (1 << 2),
/// Intent for receipt of guild emojis
i_guild_emojis = (1 << 3),
/// Intent for receipt of guild integrations
i_guild_integrations = (1 << 4),
/// Intent for receipt of guild webhooks
i_guild_webhooks = (1 << 5),
/// Intent for receipt of guild invites
i_guild_invites = (1 << 6),
/// Intent for receipt of guild voice states
i_guild_voice_states = (1 << 7),
/// Intent for receipt of guild presences
i_guild_presences = (1 << 8),
/// Intent for receipt of guild messages
i_guild_messages = (1 << 9),
/// Intent for receipt of guild message reactions
i_guild_message_reactions = (1 << 10),
/// Intent for receipt of guild message typing notifications
i_guild_message_typing = (1 << 11),
/// Intent for receipt of direct messages (DMs)
i_direct_messages = (1 << 12),
/// Intent for receipt of direct message reactions
i_direct_message_reactions = (1 << 13),
/// Intent for receipt of direct message typing notifications
i_direct_message_typing = (1 << 14),
/// Default D++ intents (all non-privileged intents)
i_default_intents = dpp::i_guilds | dpp::i_guild_bans | dpp::i_guild_emojis | dpp::i_guild_integrations | dpp::i_guild_webhooks | dpp::i_guild_invites | dpp::i_guild_voice_states | dpp::i_guild_messages | dpp::i_guild_message_reactions | dpp::i_guild_message_typing | dpp::i_direct_messages | dpp::i_direct_message_typing | dpp::i_direct_message_reactions,
// Privileged intents requiring ID
i_privileged_intents = dpp::i_guild_members | dpp::i_guild_presences,
// Every single intent
i_all_intents = dpp::i_default_intents | dpp::i_privileged_intents
};
};

94
vendor/DPP/include/dpp/invite.h vendored Normal file
View File

@ -0,0 +1,94 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief Represents an invite to a discord guild or channel
*/
class CoreExport invite {
public:
/** Invite code
*/
std::string code;
/** Guild for the invite
*/
snowflake guild_id;
/** Channel id for invite
*/
snowflake channel_id;
/** User ID of invite creator
*/
snowflake inviter_id;
/** Target user ID of invite, for invites sent via DM
*/
snowflake target_user_id;
/** Target user type (generally this is always 1, "stream")
*/
uint8_t target_user_type;
/** Approximate number of online users
*/
uint32_t approximate_presence_count;
/** Approximate total users online and offline
*/
uint32_t approximate_member_count;
/** Maximum age of invite
*/
uint32_t max_age;
/** Maximum number of uses
*/
uint32_t max_uses;
/** True if a temporary invite which grants access for a limited time
*/
bool temporary;
/** True if this invite should not replace or "attach to" similar invites
*/
bool unique;
/** Constructor
*/
invite();
/** Destructor
*/
~invite();
/** Read class values from json object
* @param j A json object to read from
* @return A reference to self
*/
invite& fill_from_json(nlohmann::json* j);
/** Build JSON from this object.
* @return The JSON text of the invite
*/
std::string build_json() const;
};
/** A container of invites */
typedef std::unordered_map<std::string, invite> invite_map;
};

78
vendor/DPP/include/dpp/json_fwd.hpp vendored Normal file
View File

@ -0,0 +1,78 @@
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
#include <cstdint> // int64_t, uint64_t
#include <map> // map
#include <memory> // allocator
#include <string> // string
#include <vector> // vector
/*!
@brief namespace for Niels Lohmann
@see https://github.com/nlohmann
@since version 1.0.0
*/
namespace nlohmann
{
/*!
@brief default JSONSerializer template argument
This serializer ignores the template arguments and uses ADL
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))
for serialization.
*/
template<typename T = void, typename SFINAE = void>
struct adl_serializer;
template<template<typename U, typename V, typename... Args> class ObjectType =
std::map,
template<typename U, typename... Args> class ArrayType = std::vector,
class StringType = std::string, class BooleanType = bool,
class NumberIntegerType = std::int64_t,
class NumberUnsignedType = std::uint64_t,
class NumberFloatType = double,
template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer =
adl_serializer,
class BinaryType = std::vector<std::uint8_t>>
class basic_json;
/*!
@brief JSON Pointer
A JSON pointer defines a string syntax for identifying a specific value
within a JSON document. It can be used with functions `at` and
`operator[]`. Furthermore, JSON pointers are the base for JSON patches.
@sa [RFC 6901](https://tools.ietf.org/html/rfc6901)
@since version 2.0.0
*/
template<typename BasicJsonType>
class json_pointer;
/*!
@brief default JSON class
This type is the default specialization of the @ref basic_json class which
uses the standard template types.
@since version 1.0.0
*/
using json = basic_json<>;
template<class Key, class T, class IgnoredLess, class Allocator>
struct ordered_map;
/*!
@brief ordered JSON class
This type preserves the insertion order of object keys.
@since version 3.9.0
*/
using ordered_json = basic_json<nlohmann::ordered_map>;
} // namespace nlohmann
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_

1111
vendor/DPP/include/dpp/message.h vendored Normal file

File diff suppressed because it is too large Load Diff

26137
vendor/DPP/include/dpp/nlohmann/json.hpp vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,78 @@
#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_
#define INCLUDE_NLOHMANN_JSON_FWD_HPP_
#include <cstdint> // int64_t, uint64_t
#include <map> // map
#include <memory> // allocator
#include <string> // string
#include <vector> // vector
/*!
@brief namespace for Niels Lohmann
@see https://github.com/nlohmann
@since version 1.0.0
*/
namespace nlohmann
{
/*!
@brief default JSONSerializer template argument
This serializer ignores the template arguments and uses ADL
([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl))
for serialization.
*/
template<typename T = void, typename SFINAE = void>
struct adl_serializer;
template<template<typename U, typename V, typename... Args> class ObjectType =
std::map,
template<typename U, typename... Args> class ArrayType = std::vector,
class StringType = std::string, class BooleanType = bool,
class NumberIntegerType = std::int64_t,
class NumberUnsignedType = std::uint64_t,
class NumberFloatType = double,
template<typename U> class AllocatorType = std::allocator,
template<typename T, typename SFINAE = void> class JSONSerializer =
adl_serializer,
class BinaryType = std::vector<std::uint8_t>>
class basic_json;
/*!
@brief JSON Pointer
A JSON pointer defines a string syntax for identifying a specific value
within a JSON document. It can be used with functions `at` and
`operator[]`. Furthermore, JSON pointers are the base for JSON patches.
@sa [RFC 6901](https://tools.ietf.org/html/rfc6901)
@since version 2.0.0
*/
template<typename BasicJsonType>
class json_pointer;
/*!
@brief default JSON class
This type is the default specialization of the @ref basic_json class which
uses the standard template types.
@since version 1.0.0
*/
using json = basic_json<>;
template<class Key, class T, class IgnoredLess, class Allocator>
struct ordered_map;
/*!
@brief ordered JSON class
This type preserves the insertion order of object keys.
@since version 3.9.0
*/
using ordered_json = basic_json<nlohmann::ordered_map>;
} // namespace nlohmann
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_

252
vendor/DPP/include/dpp/presence.h vendored Normal file
View File

@ -0,0 +1,252 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief Presence flags bitmask
*/
enum presence_flags {
/// Desktop: Online
p_desktop_online = 0b00000001,
/// Desktop: DND
p_desktop_dnd = 0b00000010,
/// Desktop: Idle
p_desktop_idle = 0b00000011,
/// Web: Online
p_web_online = 0b00000100,
/// Web: DND
p_web_dnd = 0b00001000,
/// Web: Idle
p_web_idle = 0b00001100,
/// Mobile: Online
p_mobile_online = 0b00010000,
/// Mobile: DND
p_mobile_dnd = 0b00100000,
/// Mobile: Idle
p_mobile_idle = 0b00110000,
/// General: Online
p_status_online = 0b01000000,
/// General: DND
p_status_dnd = 0b10000000,
/// General: Idle
p_status_idle = 0b11000000
};
/**
* @brief Online presence status values
*/
enum presence_status : uint8_t {
/// Offline
ps_offline = 0,
/// Online
ps_online = 1,
/// DND
ps_dnd = 2,
/// Idle
ps_idle = 3
};
/**
* @brief Bit shift for desktop status
*/
#define PF_SHIFT_DESKTOP 0
/** Bit shift for web status */
#define PF_SHIFT_WEB 2
/** Bit shift for mobile status */
#define PF_SHIFT_MOBILE 4
/** Bit shift for main status */
#define PF_SHIFT_MAIN 6
/** Bit mask for status */
#define PF_STATUS_MASK 0b00000011
/** Bit mask for clearing desktop status */
#define PF_CLEAR_DESKTOP 0b11111100
/** Bit mask for clearing web status */
#define PF_CLEAR_WEB 0b11110011
/** Bit mask for clearing mobile status */
#define PF_CLEAR_MOBILE 0b11001111
/** Bit mask for clearing main status */
#define PF_CLEAR_STATUS 0b00111111
/**
* @brief Game types
*/
enum activity_type : uint8_t {
/// "Playing ..."
at_game = 0,
/// "Streaming ..."
at_streaming = 1,
/// "Listening to..."
at_listening = 2,
/// "Watching..."
at_custom = 3,
/// "Competing in..."
at_competing = 4
};
/**
* @brief Activity types for rich presence
*/
enum activity_flags {
/// In an instance
af_instance = 0b00000001,
/// Joining
af_join = 0b00000010,
/// Spectating
af_spectate = 0b00000100,
/// Sending join request
af_join_request = 0b00001000,
/// Synchronising
af_sync = 0b00010000,
/// Playing
af_play = 0b00100000
};
/**
* @brief An activity is a representation of what a user is doing. It might be a game, or a website, or a movie. Whatever.
*/
class CoreExport activity {
public:
/** Name of ativity
* e.g. "Fortnite"
*/
std::string name;
/** State of activity.
* e.g. "Waiting in lobby"
*/
std::string state;
/** URL.
* Only applicable for certain sites such a YouTube
* Alias: details
*/
std::string url;
/** Activity type
*/
activity_type type;
/** Time activity was created
*/
time_t created_at;
/** Start time. e.g. when game was started
*/
time_t start;
/** End time, e.g. for songs on spotify
*/
time_t end;
/** Creating application (e.g. a linked account on the user's client)
*/
snowflake application_id;
/** Flags bitmask from activity_flags
*/
uint8_t flags;
activity() = default;
/**
* @brief Construct a new activity
*
* @param typ
* @param nam
* @param stat
* @param url_
*/
activity(const activity_type typ, const std::string& nam, const std::string& stat, const std::string& url_);
};
/**
* @brief Represents user presence, e.g. what game they are playing and if they are online
*/
class CoreExport presence {
public:
/** The user the presence applies to */
snowflake user_id;
/** Guild ID. Apparently, Discord supports this internally but the client doesnt... */
snowflake guild_id;
/** Flags bitmask containing presence_flags */
uint8_t flags;
/** List of activities */
std::vector<activity> activities;
/** Constructor */
presence();
/**
* @brief Construct a new presence object with some parameters for sending to a websocket
*
* @param status
* @param type
* @param activity_description
*/
presence(presence_status status, activity_type type, const std::string& activity_description);
/**
* @brief Construct a new presence object with some parameters for sending to a websocket
*
* @param status
* @param a Activity itself
*/
presence(presence_status status, activity a);
/** Destructor */
~presence();
/** Fill this object from json.
* @param j JSON object to fill from
* @return A reference to self
*/
presence& fill_from_json(nlohmann::json* j);
/** Build JSON from this object.
* @return The JSON text of the presence
*/
std::string build_json() const;
/** The users status on desktop
* @return The user's status on desktop
*/
presence_status desktop_status() const;
/** The user's status on web
* @return The user's status on web
*/
presence_status web_status() const;
/** The user's status on mobile
* @return The user's status on mobile
*/
presence_status mobile_status() const;
/** The user's status as shown to other users
* @return The user's status as shown to other users
*/
presence_status status() const;
};
/** A container of presences */
typedef std::unordered_map<std::string, presence> presence_map;
};

57
vendor/DPP/include/dpp/prune.h vendored Normal file
View File

@ -0,0 +1,57 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief Defines a request to count prunable users, or start a prune operation
*/
struct CoreExport prune {
/** Number of days to include in the prune
*/
uint32_t days = 0;
/** Roles to include in the prune (empty to include everyone)
*/
std::vector<snowflake> include_roles;
/** True if the count of pruneable users should be returned
* (discord recommend not using this on big guilds)
*/
bool compute_prune_count;
/** Fill this object from json.
* @param j JSON object to fill from
* @return A reference to self
*/
prune& fill_from_json(nlohmann::json* j);
/** Build JSON from this object.
* @param with_prune_count True if the prune count boolean is to be set in the built JSON
* @return The JSON text of the prune object
*/
std::string build_json(bool with_prune_count) const;
};
};

270
vendor/DPP/include/dpp/queues.h vendored Normal file
View File

@ -0,0 +1,270 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <unordered_map>
#include <string>
#include <queue>
#include <map>
#include <thread>
#include <mutex>
#include <vector>
#include <functional>
namespace dpp {
/** Encodes a url parameter similar to php urlencode() */
std::string url_encode(const std::string &value);
/** Error values. Don't change the order or add extra values here,
* as they map onto the error values of cpp-httplib
*/
enum http_error {
/// Request successful
h_success = 0,
/// Status unknown
h_unknown,
/// Connect failed
h_connection,
/// Invalid local ip address
h_bind_ip_address,
/// Read error
h_read,
/// Write error
h_write,
/// Too many 30x redirects
h_exceed_redirect_count,
/// Request cancelled
h_canceled,
/// SSL connection error
h_ssl_connection,
/// SSL cert loading error
h_ssl_loading_certs,
/// SSL server verification error
h_ssl_server_verification,
/// Unsupported multipart boundary characters
h_unsupported_multipart_boundary_chars,
/// Compression error
h_compression,
};
/**
* @brief The result of any HTTP request. Contains the headers, vital
* rate limit figures, and returned request body.
*/
struct CoreExport http_request_completion_t {
/** HTTP headers of response */
std::map<std::string, std::string> headers;
/** HTTP status, e.g. 200 = OK, 404 = Not found, 429 = Rate limited */
uint16_t status = 0;
/** Error status (e.g. if the request could not connect at all) */
http_error error = h_success;
/** Ratelimit bucket */
std::string ratelimit_bucket;
/** Ratelimit limit of requests */
uint64_t ratelimit_limit = 0;
/** Ratelimit remaining requests */
uint64_t ratelimit_remaining = 0;
/** Ratelimit reset after (seconds) */
uint64_t ratelimit_reset_after = 0;
/** Ratelimit retry after (seconds) */
uint64_t ratelimit_retry_after = 0;
/** True if this request has caused us to be globally rate limited */
bool ratelimit_global = false;
/** Reply body */
std::string body;
};
/**
* @brief Results of HTTP requests are called back to these std::function types.
* @note Returned http_completion_events are called ASYNCRONOUSLY in your
* code which means they execute in a separate thread. The completion events
* arrive in order.
*/
typedef std::function<void(const http_request_completion_t&)> http_completion_event;
/** Various types of http method supported by the Discord API
*/
enum http_method {
/// GET
m_get,
/// POST
m_post,
/// PUT
m_put,
/// PATCH
m_patch,
/// DELETE
m_delete
};
/**
* @brief A HTTP request.
*
* You should instantiate one of these objects via its constructor,
* and pass a pointer to it into an instance of request_queue. Although you can
* directly call the Run() method of the object and it will make a HTTP call, be
* aware that if you do this, it will be a **BLOCKING call** (not asynchronous) and
* will not respect rate limits, as both of these functions are managed by the
* request_queue class.
*/
class CoreExport http_request {
/** Completion callback */
http_completion_event complete_handler;
/** True if request has been made */
bool completed;
public:
/** Endpoint name e.g. /api/users */
std::string endpoint;
/** Major and minor parameters */
std::string parameters;
/** Postdata for POST and PUT */
std::string postdata;
/** HTTP method for request */
http_method method;
/** Upload file name (server side) */
std::string file_name;
/** Upload file contents (binary) */
std::string file_content;
/** Constructor. When constructing one of these objects it should be passed to request_queue::post_request().
* @param _endpoint The API endpoint, e.g. /api/guilds
* @param _parameters Major and minor parameters for the endpoint e.g. a user id or guild id
* @param completion completion event to call when done
* @param _postdata Data to send in POST and PUT requests
* @param method The HTTP method to use from dpp::http_method
* @param filename The filename (server side) of any uploaded file
* @param filecontent The binary content of any uploaded file for the request
*/
http_request(const std::string &_endpoint, const std::string &_parameters, http_completion_event completion, const std::string &_postdata = "", http_method method = m_get, const std::string &filename = "", const std::string &filecontent = "");
/** Destructor */
~http_request();
/** Call the completion callback, if the request is complete.
* @param c callback to call
*/
void complete(const http_request_completion_t &c);
/** Execute the HTTP request and mark the request complete.
* @param owner creating cluster
*/
http_request_completion_t Run(const class cluster* owner);
/** Returns true if the request is complete */
bool is_completed();
};
/** A rate limit bucket. The library builds one of these for
* each endpoint.
*/
struct CoreExport bucket_t {
/** Request limit */
uint64_t limit;
/** Requests remaining */
uint64_t remaining;
/** Ratelimit of this bucket resets after this many seconds */
uint64_t reset_after;
/** Ratelimit of this bucket can be retried after this many seconds */
uint64_t retry_after;
/** Timestamp this buckets counters were updated */
time_t timestamp;
};
/**
* @brief The request_queue class manages rate limits and marshalls HTTP requests that have
* been built as http_request objects.
*
* It ensures asynchronous delivery of events and queueing of requests.
*
* It will spawn two threads, one to make outbound HTTP requests and push the returned
* results into a queue, and the second to call the callback methods with these results.
* They are separated so that if the user decides to take a long time processing a reply
* in their callback it won't affect when other requests are sent, and if a HTTP request
* takes a long time due to latency, it won't hold up user processing.
*
* There is usually only one request_queue object in each dpp::cluster, which is used
* internally for the various REST methods such as sending messages.
*/
class CoreExport request_queue {
private:
/** The cluster that owns this request_queue */
const class cluster* creator;
/** Mutexes for thread safety */
std::mutex in_mutex;
std::mutex out_mutex;
/** In and out threads */
std::thread* in_thread;
std::thread* out_thread;
/** Ratelimit bucket counters */
std::map<std::string, bucket_t> buckets;
/** Queue of requests to be made */
std::map<std::string, std::vector<http_request*>> requests_in;
/** Completed requests queue */
std::queue<std::pair<http_request_completion_t*, http_request*>> responses_out;
/** Completed requests to delete */
std::multimap<time_t, std::pair<http_request_completion_t*, http_request*>> responses_to_delete;
/** Set to true if the threads should terminate */
bool terminating;
/** True if globally rate limited - makes the entire request thread wait */
bool globally_ratelimited;
/** How many seconds we are globally rate limited for, if globally_ratelimited is true */
uint64_t globally_limited_for;
/** Ports for notifications of request completion.
* Why are we using sockets here instead of std::condition_variable? Because
* in the future we will want to notify across clusters of completion and state,
* and we can't do this across processes with condition variables.
*/
int in_queue_port;
int out_queue_port;
int in_queue_listen_sock;
int in_queue_connect_sock;
int out_queue_listen_sock;
int out_queue_connect_sock;
/** Thread loop functions */
void in_loop();
void out_loop();
/** Notify request thread of a new request */
void emit_in_queue_signal();
/** Notify completion thread of new completed request */
void emit_out_queue_signal();
public:
/** Constructor
* @param owner The creating cluster
*/
request_queue(const class cluster* owner);
/** Destructor */
~request_queue();
/** Put a http_request into the request queue. You should ALWAYS "new" an object
* to pass to here -- don't submit an object that's on the stack!
* @param req request to add
*/
void post_request(http_request *req);
};
};

202
vendor/DPP/include/dpp/role.h vendored Normal file
View File

@ -0,0 +1,202 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/** Various flags related to dpp::role */
enum role_flags {
r_hoist = 0b00000001, //!< Hoisted role
r_managed = 0b00000010, //!< Managed role (introduced by a bot or application)
r_mentionable = 0b00000100, //!< Mentionable with an @ping
r_premium_subscriber = 0b00001000, //!< This is set for the role given to nitro
};
/**
* @brief Represents the various discord permissions
*/
enum role_permissions : uint64_t {
p_create_instant_invite = 0x00000001, //!< allows creationboosters of instant invites
p_kick_members = 0x00000002, //!< allows kicking members
p_ban_members = 0x00000004, //!< allows banning members
p_administrator = 0x00000008, //!< allows all permissions and bypasses channel permission overwrites
p_manage_channels = 0x00000010, //!< allows management and editing of channels
p_manage_guild = 0x00000020, //!< allows management and editing of the guild
p_add_reactions = 0x00000040, //!< allows for the addition of reactions to messages
p_view_audit_log = 0x00000080, //!< allows for viewing of audit logs
p_priority_speaker = 0x00000100, //!< allows for using priority speaker in a voice channel
p_stream = 0x00000200, //!< allows the user to go live
p_view_channel = 0x00000400, //!< allows guild members to view a channel, which includes reading messages in text channels
p_send_messages = 0x00000800, //!< allows for sending messages in a channel
p_send_tts_messages = 0x00001000, //!< allows for sending of /tts messages
p_manage_messages = 0x00002000, //!< allows for deletion of other users messages
p_embed_links = 0x00004000, //!< links sent by users with this permission will be auto-embedded
p_attach_files = 0x0000008000, //!< allows for uploading images and files
p_read_message_history = 0x0000010000, //!< allows for reading of message history
p_mention_everyone = 0x0000020000, //!< allows for using the @everyone and the @here tag to notify users in a channel
p_use_external_emojis = 0x0000040000, //!< allows the usage of custom emojis from other servers
p_view_guild_insights = 0x0000080000, //!< allows for viewing guild insights
p_connect = 0x0000100000, //!< allows for joining of a voice channel
p_speak = 0x0000200000, //!< allows for speaking in a voice channel
p_mute_members = 0x0000400000, //!< allows for muting members in a voice channel
p_deafen_members = 0x0000800000, //!< allows for deafening of members in a voice channel
p_move_members = 0x0001000000, //!< allows for moving of members between voice channels
p_use_vad = 0x0002000000, //!< allows for using voice-activity-detection in a voice channel
p_change_nickname = 0x0004000000, //!< allows for modification of own nickname
p_manage_nicknames = 0x0008000000, //!< allows for modification of other users nicknames
p_manage_roles = 0x0010000000, //!< allows management and editing of roles
p_manage_webhooks = 0x0020000000, //!< allows management and editing of webhooks
p_manage_emojis = 0x0040000000, //!< allows management and editing of emojis
p_use_slash_commands = 0x0080000000, //!< allows members to use slash commands
p_request_to_speak = 0x0100000000, //!< allows for requesting to speak in stage channels. (Discord: This permission is under active development and may be changed or removed.)
p_manage_threads = 0x0400000000, //!< allows for deleting and archiving threads, and viewing all private threads
p_use_public_threads = 0x0800000000, //!< allows for creating and participating in thread
p_use_private_threads = 0x1000000000, //!< allows for creating and participating in private thread
};
/**
* @brief Represents a role within a dpp::guild
*/
class CoreExport role : public managed {
public:
/** Role name */
std::string name;
/** Guild id */
snowflake guild_id;
/** Role colour */
uint32_t colour;
/** Role position */
uint8_t position;
/** Role permissions bitmask values from dpp::role_permissions */
uint64_t permissions;
/** Role flags from dpp::role_flags */
uint8_t flags;
/** Integration id if any (e.g. role is a bot's role created when it was invited) */
snowflake integration_id;
/** Bot id if any (e.g. role is a bot's role created when it was invited) */
snowflake bot_id;
/** Default constructor */
role();
/** Default destructor */
virtual ~role();
/** Fill this role from json.
* @param guild_id the guild id to place in the json
* @param j The json data
* @return A reference to self
*/
role& fill_from_json(snowflake guild_id, nlohmann::json* j);
/** Build a json string from this object.
* @param with_id true if the ID is to be included in the json text
* @return The json of the role
*/
std::string build_json(bool with_id = false) const;
/** True if the role is hoisted */
bool is_hoisted() const;
/** True if the role is mentionable */
bool is_mentionable() const;
/** True if the role is managed (belongs to a bot or application) */
bool is_managed() const;
/** True if has create instant invite permission */
bool has_create_instant_invite() const;
/** True if has the kick members permission */
bool has_kick_members() const;
/** True if has the ban members permission */
bool has_ban_members() const;
/** True if has the administrator permission */
bool has_administrator() const;
/** True if has the manage channels permission */
bool has_manage_channels() const;
/** True if has the manage guild permission */
bool has_manage_guild() const;
/** True if has the add reactions permission */
bool has_add_reactions() const;
/** True if has the view audit log permission */
bool has_view_audit_log() const;
/** True if has the priority speaker permission */
bool has_priority_speaker() const;
/** True if has the stream permission */
bool has_stream() const;
/** True if has the view channel permission */
bool has_view_channel() const;
/** True if has the send messages permission */
bool has_send_messages() const;
/** True if has the send TTS messages permission */
bool has_send_tts_messages() const;
/** True if has the manage messages permission */
bool has_manage_messages() const;
/** True if has the embed links permission */
bool has_embed_links() const;
/** True if has the attach files permission */
bool has_attach_files() const;
/** True if has the read message history permission */
bool has_read_message_history() const;
/** True if has the mention \@everyone and \@here permission */
bool has_mention_everyone() const;
/** True if has the use external emojis permission */
bool has_use_external_emojis() const;
/** True if has the view guild insights permission */
bool has_view_guild_insights() const;
/** True if has the connect voice permission */
bool has_connect() const;
/** True if has the speak permission */
bool has_speak() const;
/** True if has the mute members permission */
bool has_mute_members() const;
/** True if has the deafen members permission */
bool has_deafen_members() const;
/** True if has the move members permission */
bool has_move_members() const;
/** True if has use voice activity detection permission */
bool has_use_vad() const;
/** True if has the change nickname permission */
bool has_change_nickname() const;
/** True if has the manage nicknames permission */
bool has_manage_nicknames() const;
/** True if has the manage roles permission */
bool has_manage_roles() const;
/** True if has the manage webhooks permission */
bool has_manage_webhooks() const;
/** True if has the manage emojis permission */
bool has_manage_emojis() const;
/** True if has the use slash commands permission*/
bool has_use_slash_commands() const;
/** True if has the request to speak permission*/
bool has_request_to_speak() const;
/** True if has the manage threads permission*/
bool has_manage_threads() const;
/** True if has the use public threads permission*/
bool has_use_public_threads() const;
/** True if has the use private threads permission*/
bool has_use_private_threads() const;
};
/** A group of roles */
typedef std::unordered_map<snowflake, role> role_map;
};

555
vendor/DPP/include/dpp/slashcommand.h vendored Normal file
View File

@ -0,0 +1,555 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <variant>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
#include <dpp/message.h>
namespace dpp {
/**
* @brief Represents command option types.
* These are the possible parameter value types.
*/
enum command_option_type : uint8_t {
/** A sub-command */
co_sub_command = 1,
/** A sub-command group */
co_sub_command_group = 2,
/** A string value */
co_string = 3,
/** An integer value */
co_integer = 4,
/** A boolean value */
co_boolean = 5,
/** A user snowflake id */
co_user = 6,
/** A channel snowflake id */
co_channel = 7,
/** A role snowflake id */
co_role = 8
};
/**
* @brief This type is a variant that can hold any of the potential
* native data types represented by the enum above.
* It is used in interactions.
*/
typedef std::variant<std::string, int32_t, bool, snowflake> command_value;
/**
* @brief This struct represents choices in a multiple choice option
* for a command parameter.
* It has both a string name, and a value parameter which is a variant,
* meaning it can hold different potential types (see dpp::command_value)
* that you can retrieve with std::get().
*/
struct CoreExport command_option_choice {
std::string name; //!< Option name (1-32 chars)
command_value value; //!< Option value
/**
* @brief Construct a new command option choice object
*/
command_option_choice() = default;
/**
* @brief Construct a new command option choice object
*
* @param n name to initialise with
* @param v value to initialise with
*/
command_option_choice(const std::string &n, command_value v);
};
/**
* @brief helper function to serialize a command_option_choice to json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param choice command_option_choice to be serialized
*/
void to_json(nlohmann::json& j, const command_option_choice& choice);
/**
* @brief Each command option is a command line parameter.
* It can have a type (see dpp::command_option_type), a name,
* a description, can be required or optional, and can have
* zero or more choices (for multiple choice), plus options.
* Adding options acts like sub-commands and can contain more
* options.
*/
struct CoreExport command_option {
command_option_type type; //!< Option type (what type of value is accepted)
std::string name; //!< Option name (1-32 chars)
std::string description; //!< Option description (1-100 chars)
bool required; //!< True if this is a mandatory parameter
std::vector<command_option_choice> choices; //!< List of choices for multiple choice command
std::vector<command_option> options; //!< Sub-commands
/**
* @brief Construct a new command option object
*/
command_option() = default;
/**
* @brief Construct a new command option object
*
* @param t Option type
* @param name Option name
* @param description Option description
* @param required True if this is a mandatory parameter
*/
command_option(command_option_type t, const std::string &name, const std::string &description, bool required = false);
/**
* @brief Add a multiple choice option
*
* @param o choice to add
* @return command_option& returns a reference to self for chaining of calls
*/
command_option& add_choice(const command_option_choice &o);
/**
* @brief Add a sub-command option
*
* @param o Sub-command option to add
* @return command_option& return a reference to self for chaining of calls
*/
command_option& add_option(const command_option &o);
};
/**
* @brief helper function to serialize a command_option to json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param opt command_option to be serialized
*/
void to_json(nlohmann::json& j, const command_option& opt);
/**
* @brief Response types when responding to an interaction within on_interaction_create.
* Do not use ir_acknowledge or ir::channel_message, as these are deprecated in the
* Discord API spec. They are listed in this enum for completeness.
*/
enum interaction_response_type {
ir_pong = 1, //!< ACK a Ping
ir_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
ir_update_message = 7 //!< for components, edit the message the component was attached to
};
/**
* @brief A response to an interaction, used to reply to a command and initiate
* a message, which can be hidden from others (ephemeral) or visible to all.
*
* The dpp::interaction_response object wraps a dpp::message object. To set the
* message as 'ephemeral' (e.g. only the command issuer can see it) you should
* add the dpp::m_ephemeral flag to the dpp::message::flags field. e.g.:
*
* `mymessage.flags |= dpp::m_ephemeral;`
*/
struct CoreExport interaction_response {
/**
* @brief Response type from dpp::interaction_response_type.
* Should be one of ir_pong, ir_channel_message_with_source,
* or ir_deferred_channel_message_with_source.
*/
interaction_response_type type;
/**
* @brief A message object. This pointer is always valid
* while the containing interaction_response exists.
*/
struct message* msg;
/**
* @brief Construct a new interaction response object
*/
interaction_response();
/**
* @brief Construct a new interaction response object
*
* @param t Type of reply
* @param m Message to reply with
*/
interaction_response(interaction_response_type t, const struct message& m);
/**
* @brief Fill object properties from JSON
*
* @param j JSON to fill from
* @return interaction_response& Reference to self
*/
interaction_response& fill_from_json(nlohmann::json* j);
/**
* @brief Build a json string for this object
*
* @return std::string JSON string
*/
std::string build_json() const;
/**
* @brief Destroy the interaction response object
*/
~interaction_response();
};
/**
* @brief Resolved snowflake ids to usernames.
* TODO: Needs implementation. Not needed something that
* functions as we have cache.
*/
struct CoreExport command_resolved {
};
/**
* @brief Values in the command interaction.
* These are the values specified by the user when actually issuing
* the command on a channel or in DM.
*/
struct CoreExport command_data_option {
std::string name; //!< the name of the parameter
command_option_type type; //!< value of ApplicationCommandOptionType
command_value value; //!< Optional: the value of the pair
std::vector<command_data_option> options; //!< Optional: present if this option is a group or subcommand
dpp::snowflake target_id; //!< Non-zero target ID for context menu actions
};
/**
* @brief helper function to deserialize a command_data_option from json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param cdo command_data_option to be deserialized
*/
void from_json(const nlohmann::json& j, command_data_option& cdo);
/** Types of interaction in the dpp::interaction class
*/
enum interaction_type {
it_ping = 1, //!< ping
it_application_command = 2, //!< application command (slash command)
it_component_button = 3 //!< button click (component interaction)
};
/**
* @brief Details of a command within an interaction.
* This subobject represents the application command associated
* with the interaction.
*/
struct CoreExport command_interaction {
snowflake id; //!< the ID of the invoked command
std::string name; //!< the name of the invoked command
command_resolved resolved; //!< Optional: converted users + roles + channels
std::vector<command_data_option> options; //!< Optional: the params + values from the user
};
/**
* @brief helper function to deserialize a command_interaction from json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param ci command_interaction to be deserialized
*/
void from_json(const nlohmann::json& j, command_interaction& ci);
enum component_type_t {
cotype_button = 2,
cotype_select = 3
};
/**
* @brief A button click for a button component
*/
struct CoreExport component_interaction {
uint8_t component_type;
std::string custom_id;
std::vector<std::string> values;
};
/**
* @brief helper function to deserialize a component_interaction from json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param bi button_interaction to be deserialized
*/
void from_json(const nlohmann::json& j, component_interaction& bi);
/**
* @brief An interaction represents a user running a command and arrives
* via the dpp::cluster::on_interaction_create event.
*/
class CoreExport interaction : public managed {
public:
snowflake application_id; //!< id of the application this interaction is for
uint8_t type; //!< the type of interaction
std::variant<command_interaction, component_interaction> data; //!< Optional: the command data payload
snowflake guild_id; //!< Optional: the guild it was sent from
snowflake channel_id; //!< Optional: the channel it was sent from
snowflake message_id; //!< Originating message id
guild_member member; //!< Optional: guild member data for the invoking user, including permissions
user usr; //!< Optional: user object for the invoking user, if invoked in a DM
std::string token; //!< a continuation token for responding to the interaction
uint8_t version; //!< read-only property, always 1
/**
* @brief Fill object properties from JSON
*
* @param j JSON to fill from
* @return interaction& Reference to self
*/
interaction& fill_from_json(nlohmann::json* j);
/**
* @brief Build a json string for this object
*
* @param with_id True if to include the ID in the JSON
* @return std::string JSON string
*/
std::string build_json(bool with_id = false) const;
};
/**
* @brief helper function to deserialize an interaction from json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param i interaction to be deserialized
*/
void from_json(const nlohmann::json& j, interaction& i);
/**
* @brief type of permission in the dpp::command_permission class
*/
enum command_permission_type {
cpt_role = 1,
cpt_user = 2,
};
/**
* @brief Application command permissions allow you to enable or
* disable commands for specific users or roles within a guild
*/
class CoreExport command_permission {
public:
snowflake id; //!< the ID of the role or uses
command_permission_type type; //!< the type of permission
bool permission; //!< true to allow, false, to disallow
};
/**
* @brief helper function to serialize a command_permission to json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param cp command_permission to be serialized
*/
void to_json(nlohmann::json& j, const command_permission& cp);
/**
* @brief Returned when fetching the permissions for a command in a guild.
*/
class CoreExport guild_command_permissions {
public:
snowflake id; //!< the id of the command
snowflake application_id; //!< the id of the application the command belongs to
snowflake guild_id; //!< the id of the guild
std::vector<command_permission> permissions; //!< the permissions for the command in the guild
};
/**
* @brief helper function to serialize a guild_command_permissions to json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param gcp guild_command_permissions to be serialized
*/
void to_json(nlohmann::json& j, const guild_command_permissions& gcp);
enum slashcommand_contextmenu_type {
ctxm_none = 0,
ctxm_chat_input = 1, //!< DEFAULT, these are the slash commands you're used to
ctxm_user = 2, //!< Add command to user context menu
ctxm_message = 3 //!< Add command to message context menu
};
/**
* @brief Represents an application command, created by your bot
* either globally, or on a guild.
*/
class CoreExport slashcommand : public managed {
public:
/**
* @brief Application id (usually matches your bots id)
*/
snowflake application_id;
/**
* @brief Context menu type, defaults to none
*
*/
slashcommand_contextmenu_type type;
/**
* @brief Command name (1-32 chars)
*/
std::string name;
/**
* @brief Command description (1-100 chars)
*/
std::string description;
/**
* @brief Command options (parameters)
*/
std::vector<command_option> options;
/**
* @brief whether the command is enabled by default when the app is added to a guild
*/
bool default_permission;
/**
* @brief command permissions
*/
std::vector<command_permission> permissions;
/**
* @brief Construct a new slashcommand object
*/
slashcommand();
/**
* @brief Destroy the slashcommand object
*/
~slashcommand();
/**
* @brief Add an option (parameter)
*
* @param o option (parameter) to add
* @return slashcommand& reference to self for chaining of calls
*/
slashcommand& add_option(const command_option &o);
/**
* @brief Set the type of the slash command (only for context menu entries)
*
* @param _type Type of context menu entry this command represents
* @return slashcommand& reference to self for chaining of calls
*/
slashcommand& set_type(slashcommand_contextmenu_type _type);
/**
* @brief Set the name of the command
*
* @param n name of command
* @return slashcommand& reference to self for chaining of calls
*/
slashcommand& set_name(const std::string &n);
/**
* @brief Set the description of the command
*
* @param d description
* @return slashcommand& reference to self for chaining of calls
*/
slashcommand& set_description(const std::string &d);
/**
* @brief Set the application id of the command
*
* @param i application id
* @return slashcommand& reference to self for chaining of calls
*/
slashcommand& set_application_id(snowflake i);
/**
* @brief Adds a permission to the command
*
* @param p permission to add
* @return slashcommand& reference to self for chaining of calls
*/
slashcommand& add_permission(const command_permission& p);
/**
* @brief Disable default permissions, command will be unusable unless
* permissions are overriden with add_permission and
* dpp::guild_command_edit_permissions
*
* @return slashcommand& reference to self for chaining of calls
*/
slashcommand& disable_default_permissions();
/**
* @brief Fill object properties from JSON
*
* @param j JSON to fill from
* @return slashcommand& Reference to self
*/
slashcommand& fill_from_json(nlohmann::json* j);
/**
* @brief Build a json string for this object
*
* @param with_id True if to include the ID in the JSON
* @return std::string JSON string
*/
std::string build_json(bool with_id = false) const;
};
/**
* @brief helper function to serialize a slashcommand to json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param cmd slashcommand to be serialized
*/
void to_json(nlohmann::json& j, const slashcommand& cmd);
/**
* @brief A group of application slash commands
*/
typedef std::unordered_map<snowflake, slashcommand> slashcommand_map;
};

165
vendor/DPP/include/dpp/sslclient.h vendored Normal file
View File

@ -0,0 +1,165 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <string>
#include <functional>
#include <dpp/discord.h>
namespace dpp {
/** This is an opaque class containing openssl library specific structures.
* We define it this way so that the public facing D++ library doesnt require
* the openssl headers be available to build against it.
*/
class opensslcontext;
/**
* @brief Implements a simple non-blocking SSL stream client.
*
* Note that although the design is non-blocking the Run() method will
* execute in an infinite loop until the socket disconnects. This is intended
* to be run within a std::thread.
*/
class CoreExport ssl_client
{
protected:
/** Input buffer received from openssl */
std::string buffer;
/** Output buffer for sending to openssl */
std::string obuffer;
/** True if in nonblocking mode. The socket switches to nonblocking mode
* once ReadLoop is called.
*/
bool nonblocking;
/** Raw file descriptor of connection */
SOCKET sfd;
/** Openssl opaque contexts */
opensslcontext* ssl;
/** SSL cipher in use */
std::string cipher;
/** For timers */
time_t last_tick;
/** Hostname connected to */
std::string hostname;
/** Port connected to */
std::string port;
/** Bytes out */
uint64_t bytes_out;
/** Bytes in */
uint64_t bytes_in;
/** Called every second */
virtual void one_second_timer();
/** Start connection */
virtual void Connect();
public:
/** Get total bytes sent */
uint64_t get_bytes_out();
/** Get total bytes received */
uint64_t get_bytes_in();
/** Get SSL cipher name */
std::string get_cipher();
/**
* @brief Attaching an additional file descriptor to this function will send notifications when there is data to read.
*
* NOTE: Only hook this if you NEED it as it can increase CPU usage of the thread!
* Returning -1 means that you don't want to be notified.
*/
std::function<int()> custom_readable_fd;
/**
* @brief Attaching an additional file descriptor to this function will send notifications when you are able to write
* to the socket.
*
* NOTE: Only hook this if you NEED it as it can increase CPU usage of the thread! You should toggle this
* to -1 when you do not have anything to write otherwise it'll keep triggering repeatedly (it is level triggered).
*/
std::function<int()> custom_writeable_fd;
/**
* @brief This event will be called when you can read from the custom fd
*/
std::function<void()> custom_readable_ready;
/**
* @brief This event will be called when you can write to a custom fd
*/
std::function<void()> custom_writeable_ready;
/**
* @brief Connect to a specified host and port. Throws std::runtime_error on fatal error.
* @param _hostname The hostname to connect to
* @param _port the Port number to connect to
*/
ssl_client(const std::string &_hostname, const std::string &_port = "443");
/**
* @brief Nonblocking I/O loop
*/
void read_loop();
/**
* @brief Destroy the ssl_client object
*/
virtual ~ssl_client();
/**
* @brief Handle input from the input buffer.
* @param buffer the buffer content. Will be modified removing any processed front elements
*/
virtual bool handle_buffer(std::string &buffer);
/**
* @brief Write to the output buffer.
* @param data Data to be written to the buffer
*/
virtual void write(const std::string &data);
/**
* @brief Close SSL connection
*/
virtual void close();
/**
* @brief Log a message
*
* @param severity severity of log message
* @param msg Log message to send
*/
virtual void log(dpp::loglevel severity, const std::string &msg) const;
};
};

128
vendor/DPP/include/dpp/stringops.h vendored Normal file
View File

@ -0,0 +1,128 @@
/************************************************************************************
*
* D++ - A Lightweight C++ Library for Discord
*
* stringops.h taken from TriviaBot
*
* Copyright 2004 Craig Edwards <support@sporks.gg>
*
* Core based on Sporks, the Learning Discord Bot, Craig Edwards (c) 2019.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <string>
#include <iomanip>
#include <locale>
#include <algorithm>
#include <sstream>
#include <iostream>
/**
* @brief Convert a string to lowercase using tolower()
*
* @tparam T type of string
* @param s String to lowercase
* @return std::basic_string<T> lowercased string
*/
template <typename T> std::basic_string<T> lowercase(const std::basic_string<T>& s)
{
std::basic_string<T> s2 = s;
std::transform(s2.begin(), s2.end(), s2.begin(), tolower);
return std::move(s2);
}
/**
* @brief Convert a string to uppercase using toupper()
*
* @tparam T type of string
* @param s String to uppercase
* @return std::basic_string<T> uppercased string
*/
template <typename T> std::basic_string<T> uppercase(const std::basic_string<T>& s)
{
std::basic_string<T> s2 = s;
std::transform(s2.begin(), s2.end(), s2.begin(), toupper);
return std::move(s2);
}
/**
* @brief trim from end of string (right)
*
* @param s String to trim
* @return std::string trimmed string
*/
inline std::string rtrim(std::string s)
{
s.erase(s.find_last_not_of(" \t\n\r\f\v") + 1);
return s;
}
/**
* @brief trim from beginning of string (left)
*
* @param s string to trim
* @return std::string trimmed string
*/
inline std::string ltrim(std::string s)
{
s.erase(0, s.find_first_not_of(" \t\n\r\f\v"));
return s;
}
/**
* @brief Trim from both ends of string (right then left)
*
* @param s string to trim
* @return std::string trimmed string
*/
inline std::string trim(std::string s)
{
return ltrim(rtrim(s));
}
/**
* @brief Add commas to a string (or dots) based on current locale server-side
*
* @tparam T type of numeric value
* @param value Value
* @return std::string number with commas added
*/
template<class T> std::string Comma(T value)
{
std::stringstream ss;
ss.imbue(std::locale(""));
ss << std::fixed << value;
return ss.str();
}
/**
* @brief Convert any value from a string to another type using stringstream.
* The optional second parameter indicates the format of the input string,
* e.g. std::dec for decimal, std::hex for hex, std::oct for octal.
*
* @tparam T Type to convert to
* @param s String to convert from
* @param f Numeric base, e.g. `std::dec` or `std::hex`
* @return T Returned numeric value
*/
template <typename T> T from_string(const std::string &s, std::ios_base & (*f)(std::ios_base&))
{
T t;
std::istringstream iss(s);
iss >> f, iss >> t;
return t;
}

249
vendor/DPP/include/dpp/user.h vendored Normal file
View File

@ -0,0 +1,249 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief Various bitmask flags used to represent information about a dpp::user
*/
enum user_flags {
/// User is a bot
u_bot = 0b00000000000000000000001,
/// User is a system user (Clyde!)
u_system = 0b00000000000000000000010,
/// User has multi-factor authentication enabled
u_mfa_enabled = 0b00000000000000000000100,
/// User is verified (verified email address)
u_verified = 0b00000000000000000001000,
/// User has full nitro
u_nitro_full = 0b00000000000000000010000,
/// User has nitro classic
u_nitro_classic = 0b00000000000000000100000,
/// User is discord staff
u_discord_employee = 0b00000000000000001000000,
/// User owns a partnered server
u_partnered_owner = 0b00000000000000010000000,
/// User is a member of hypesquad events
u_hypesquad_events = 0b00000000000000100000000,
/// User has BugHunter level 1
u_bughunter_1 = 0b00000000000001000000000,
/// User is a member of House Bravery
u_house_bravery = 0b00000000000010000000000,
/// User is a member of House Brilliance
u_house_brilliance = 0b00000000000100000000000,
/// User is a member of House Balance
u_house_balanace = 0b00000000001000000000000,
/// User is an early supporter
u_early_supporter = 0b00000000010000000000000,
/// User is a team user
u_team_user = 0b00000000100000000000000,
/// User is has Bug Hunter level 2
u_bughunter_2 = 0b00000001000000000000000,
/// User is a verified bot
u_verified_bot = 0b00000010000000000000000,
/// User has the Early Verified Bot Developer badge
u_verified_bot_dev = 0b00000100000000000000000,
/// User's icon is animated
u_animated_icon = 0b00001000000000000000000,
/// User is a certified moderator
u_certified_moderator = 0b00010000000000000000000
};
/**
* @brief Represents a user on discord. May or may not be a member of a dpp::guild.
*/
class CoreExport user : public managed {
public:
/** Discord username */
std::string username;
/** Discriminator (aka tag), 4 digits usually displayed with leading zeroes */
uint16_t discriminator;
/** Avatar hash */
utility::iconhash avatar;
/** Flags built from a bitmask of values in dpp::user_flags */
uint32_t flags;
/** Reference count of how many guilds this user is in */
uint8_t refcount;
/**
* @brief Construct a new user object
*/
user();
/**
* @brief Destroy the user object
*/
virtual ~user();
/** Fill this record from json.
* @param j The json to fill this record from
* @return Reference to self
*/
user& fill_from_json(nlohmann::json* j);
/**
* @brief Get the avatar url of the user object
*
* @return std::string avatar url
*/
std::string get_avatar_url() const;
/**
* @brief User is a bot
*
* @return True if the user is a bot
*/
bool is_bot() const;
/**
* @brief User is a system user (Clyde)
*
* @return true if user is a system user
*/
bool is_system() const;
/**
* @brief User has multi-factor authentication enabled
*
* @return true if multi-factor is enabled
*/
bool is_mfa_enabled() const;
/**
* @brief Return true if user has verified account
*
* @return true if verified
*/
bool is_verified() const;
/**
* @brief Return true if user has full nitro.
* This is mutually exclusive with full nitro.
*
* @return true if user has full nitro
*/
bool has_nitro_full() const;
/**
* @brief Return true if user has nitro classic.
* This is mutually exclusive with nitro classic.
*
* @return true if user has nitro classic
*/
bool has_nitro_classic() const;
/**
* @brief Return true if user is a discord employee
*
* @return true if user is discord staff
*/
bool is_discord_employee() const;
/**
* @brief Return true if user owns a partnered server
*
* @return true if user has partnered server
*/
bool is_partnered_owner() const;
/**
* @brief Return true if user has hypesquad events
*
* @return true if has hypesquad events
*/
bool has_hypesquad_events() const;
/**
* @brief Return true if user has the bughunter level 1 badge
*
* @return true if has bughunter level 1
*/
bool is_bughunter_1() const;
/**
* @brief Return true if user is in house bravery
*
* @return true if in house bravery
*/
bool is_house_bravery() const;
/**
* @brief Return true if user is in house brilliance
*
* @return true if in house brilliance
*/
bool is_house_brilliance() const;
/**
* @brief Return true if user is in house balance
*
* @return true if in house brilliance
*/
bool is_house_balanace() const;
/**
* @brief Return true if user is an early supporter
*
* @return true if early supporter
*/
bool is_early_supporter() const;
/**
* @brief Return true if user is a team user
*
* @return true if a team user
*/
bool is_team_user() const;
/**
* @brief Return true if user has the bughunter level 2 badge
*
* @return true if has bughunter level 2
*/
bool is_bughunter_2() const;
/**
* @brief Return true if user has the verified bot badge
*
* @return true if verified bot
*/
bool is_verified_bot() const;
/**
* @brief Return true if user is an early verified bot developer
*
* @return true if verified bot developer
*/
bool is_verified_bot_dev() const;
/**
* @brief Return true if user is a certified moderator
*
* @return true if certified moderator
*/
bool is_certified_moderator() const;
/**
* @brief Return true if user has an animated icon
*
* @return true if icon is animated (gif)
*/
bool has_animated_icon() const;
};
/**
* @brief helper function to deserialize a user from json
*
* @see https://github.com/nlohmann/json#arbitrary-types-conversions
*
* @param j output json object
* @param u user to be deserialized
*/
void from_json(const nlohmann::json& j, user& u);
/** A group of users */
typedef std::unordered_map<snowflake, user> user_map;
};

31
vendor/DPP/include/dpp/version.h vendored Normal file
View File

@ -0,0 +1,31 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#if !defined(DPP_VERSION_LONG)
#define DPP_VERSION_LONG 0x00090003
#define DPP_VERSION_SHORT 090003
#define DPP_VERSION_TEXT "D++ 9.0.3 (05-Sep-2021)"
#define DPP_VERSION_MAJOR ((DPP_VERSION_LONG & 0x00ff0000) >> 16)
#define DPP_VERSION_MINOR ((DPP_VERSION_LONG & 0x0000ff00) >> 8)
#define DPP_VERSION_PATCH (DPP_VERSION_LONG & 0x000000ff)
#endif

117
vendor/DPP/include/dpp/voiceregion.h vendored Normal file
View File

@ -0,0 +1,117 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief Flags related to a voice region
*/
enum voiceregion_flags {
v_optimal = 0x00000001,
v_deprecated = 0x00000010,
v_custom = 0x00000100,
v_vip = 0x00001000
};
/**
* @brief Represents a voice region on discord
*/
class CoreExport voiceregion {
public:
/**
* @brief Voice server ID
*/
std::string id;
/**
* @brief Voice server name
*/
std::string name;
/**
* @brief Flags bitmap
*/
uint8_t flags;
/**
* @brief Construct a new voiceregion object
*/
voiceregion();
/**
* @brief Destroy the voiceregion object
*/
~voiceregion();
/**
* @brief Fill object properties from JSON
*
* @param j JSON to fill from
* @return voiceregion& Reference to self
*/
voiceregion& fill_from_json(nlohmann::json* j);
/**
* @brief Build a json string for this object
*
* @return std::string JSON string
*/
std::string build_json() const;
/**
* @brief True if is the optimal voice server
*
* @return true if optimal
*/
bool is_optimal() const;
/**
* @brief True if is a deprecated voice server
*
* @return true if deprecated
*/
bool is_deprecated() const;
/**
* @brief True if is a custom voice server
*
* @return true if custom
*/
bool is_custom() const;
/**
* @brief True if is a VIP voice server
*
* @return true if VIP
*/
bool is_vip() const;
};
/**
* @brief A group of voice regions
*/
typedef std::unordered_map<std::string, voiceregion> voiceregion_map;
};

105
vendor/DPP/include/dpp/voicestate.h vendored Normal file
View File

@ -0,0 +1,105 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief Bit mask flags relating to voice states
*/
enum voicestate_flags {
vs_deaf = 0b00000001, //!< Deafened
vs_mute = 0b00000010, //!< Muted
vs_self_mute = 0b00000100, //!< Self Muted
vs_self_deaf = 0b00001000, //!< Self Deafened
vs_self_stream = 0b00010000, //!< Self Streaming
vs_self_video = 0b00100000, //!< Self Video
vs_supress = 0b01000000 //!< Supression
};
/**
* @brief Represents the voice state of a user on a guild
* These are stored in the dpp::guild object, and accessible there,
* or via dpp::channel::get_voice_members
*/
class CoreExport voicestate {
public:
class discord_client* shard; //!< Owning shard
snowflake guild_id; //!< Optional: the guild id this voice state is for
snowflake channel_id; //!< the channel id this user is connected to (may be empty)
snowflake user_id; //!< the user id this voice state is for
std::string session_id; //!< the session id for this voice state
uint8_t flags; //!< Voice state flags
/**
* @brief Construct a new voicestate object
*/
voicestate();
/**
* @brief Destroy the voicestate object
*/
~voicestate();
/**
* @brief Fill voicestate object from json data
*
* @param j JSON data to fill from
* @return voicestate& Reference to self
*/
voicestate& fill_from_json(nlohmann::json* j);
/**
* @brief Build json representation of the object
*
* @return std::string JSON string
*/
std::string build_json() const;
/// Return true if user is deafened
bool is_deaf() const;
/// Return true if user is muted
bool is_mute() const;
/// Return true if user muted themselves
bool is_self_mute() const;
/// Return true if user deafened themselves
bool is_self_deaf() const;
/// Return true if the user is streamig
bool self_stream() const;
/// Return true if the user is in video
bool self_video() const;
/// Return true if user is surpressed.
/// "HELP HELP I'M BEING SUPRESSED!"
bool is_supressed() const;
};
/** A container of voicestates */
typedef std::unordered_map<std::string, voicestate> voicestate_map;
};

92
vendor/DPP/include/dpp/webhook.h vendored Normal file
View File

@ -0,0 +1,92 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/discord.h>
#include <dpp/json_fwd.hpp>
namespace dpp {
/**
* @brief Defines types of webhook
*/
enum webhook_type {
w_incoming = 1, //!< Incoming webhook
w_channel_follower = 2 //!< Channel following webhook
};
/**
* @brief Represents a discord webhook
*/
class CoreExport webhook : public managed {
public:
uint8_t type; //!< the type of the webhook
snowflake guild_id; //!< Optional: the guild id this webhook is for
snowflake channel_id; //!< the channel id this webhook is for
snowflake user_id; //!< Optional: the user this webhook was created by (not returned when getting a webhook with its token)
std::string name; //!< the default name of the webhook (may be empty)
std::string avatar; //!< the default avatar of the webhook (may be empty)
std::string token; //!< Optional: the secure token of the webhook (returned for Incoming Webhooks)
snowflake application_id; //!< the bot/OAuth2 application that created this webhook (may be empty)
std::string* image_data; //!< base64 encoded image data if uploading a new image
/**
* @brief Construct a new webhook object
*/
webhook();
/**
* @brief Destroy the webhook object
*/
~webhook();
/**
* @brief Fill in object from json data
*
* @param j JSON data
* @return webhook& Reference to self
*/
webhook& fill_from_json(nlohmann::json* j);
/**
* @brief Build JSON string from object
*
* @param with_id Include the ID of the webhook in the json
* @return std::string JSON encoded object
*/
std::string build_json(bool with_id = false) const;
/**
* @brief Base64 encode image data and allocate it to image_data
*
* @param image_blob Binary image data
* @param type Image type
* @return webhook& Reference to self
*/
webhook& load_image(const std::string &image_blob, image_type type);
};
/**
* @brief A group of webhooks
*/
typedef std::unordered_map<snowflake, webhook> webhook_map;
};

156
vendor/DPP/include/dpp/wsclient.h vendored Normal file
View File

@ -0,0 +1,156 @@
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <string>
#include <map>
#include <vector>
#include <variant>
#include <dpp/sslclient.h>
namespace dpp {
/**
* @brief Websocket connection status
*/
enum ws_state {
/** Sending/receiving HTTP headers prior to protocol switch */
HTTP_HEADERS,
/** Connected, upgraded and sending/receiving frames */
CONNECTED
};
/**
* @brief Low-level websocket opcodes for frames
*/
enum ws_opcode
{
OP_CONTINUATION = 0x00, //!< Continuation
OP_TEXT = 0x01, //!< Text frame
OP_BINARY = 0x02, //!< Binary frame
OP_CLOSE = 0x08, //!< Close notification with close code
OP_PING = 0x09, //!< Low level ping
OP_PONG = 0x0a //!< Low level pong
};
/**
* @brief Implements a websocket client based on the SSL client
*/
class CoreExport websocket_client : public ssl_client
{
/** Connection key used in the HTTP headers */
std::string key;
/** Current websocket state */
ws_state state;
/** Path part of URL for websocket */
std::string path;
/** HTTP headers received on connecting/upgrading */
std::map<std::string, std::string> HTTPHeaders;
/** Parse headers for a websocket frame from the buffer.
* @param buffer The buffer to operate on. Will modify the string removing completed items from the head of the queue
*/
bool parseheader(std::string &buffer);
/** Unpack a frame and pass completed frames up the stack.
* @param buffer The buffer to operate on. Gets modified to remove completed frames on the head of the buffer
* @param offset The offset to start at (reserved for future use)
* @param first True if is the first element (reserved for future use)
*/
bool unpack(std::string &buffer, uint32_t offset, bool first = true);
/** Fill a header for outbound messages
* @param outbuf The raw frame to fill
* @param sendlength The size of the data to encapsulate
* @param ws_opcode the opcode to send in the header
*/
size_t FillHeader(unsigned char* outbuf, size_t sendlength, ws_opcode opcode);
/** Handle ping and pong requests.
* @param ping True if this is a ping, false if it is a pong
* @param payload The ping payload, to be returned as-is for a ping
*/
void HandlePingPong(bool ping, const std::string &payload);
protected:
/** (Re)connect */
virtual void Connect();
/** Get websocket state
* @return websocket state
*/
ws_state GetState();
public:
/** Connect to a specific websocket server.
* @param hostname Hostname to connect to
* @param port Port to connect to
* @param urlpath The URL path components of the HTTP request to send
*/
websocket_client(const std::string &hostname, const std::string &port = "443", const std::string &urlpath = "");
/** Destructor */
virtual ~websocket_client();
/**
* @brief Write to websocket. Encapsulates data in frames if the status is CONNECTED.
*
* @param data The data to send.
*/
virtual void write(const std::string &data);
/**
* @brief Processes incoming frames from the SSL socket input buffer.
*
* @param buffer The buffer contents. Can modify this value removing the head elements when processed.
*/
virtual bool handle_buffer(std::string &buffer);
/**
* @brief Close websocket
*/
virtual void close();
/**
* @brief Receives raw frame content only without headers
*
* @param buffer The buffer contents
* @return True if the frame was successfully handled. False if no valid frame is in the buffer.
*/
virtual bool HandleFrame(const std::string &buffer);
/**
* @brief Called upon error frame.
*
* @param errorcode The error code from the websocket server
*/
virtual void Error(uint32_t errorcode);
/** Fires every second from the underlying socket I/O loop, used for sending webscocket pings */
virtual void one_second_timer();
};
};