mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-22 18:17:11 +02:00
Add D++ library.
This commit is contained in:
1222
vendor/DPP/include/dpp/appcommand.h
vendored
Normal file
1222
vendor/DPP/include/dpp/appcommand.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
166
vendor/DPP/include/dpp/application.h
vendored
Normal file
166
vendor/DPP/include/dpp/application.h
vendored
Normal file
@ -0,0 +1,166 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/utility.h>
|
||||
#include <dpp/user.h>
|
||||
#include <dpp/permissions.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief status of a member of a team who maintain a bot/application
|
||||
*/
|
||||
enum team_member_status : uint8_t {
|
||||
/// User was invited to the team
|
||||
tms_invited = 1,
|
||||
/// User has accepted membership onto the team
|
||||
tms_accepted = 2
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Flags for a bot or application
|
||||
*/
|
||||
enum application_flags : uint32_t {
|
||||
/// Has gateway presence intent
|
||||
apf_gateway_presence = (1 << 12),
|
||||
/// Has gateway presence intent for <100 guilds
|
||||
apf_gateway_presence_limited = (1 << 13),
|
||||
/// Has guild members intent
|
||||
apf_gateway_guild_members = (1 << 14),
|
||||
/// Has guild members intent for <100 guilds
|
||||
apf_gateway_guild_members_limited = (1 << 15),
|
||||
/// Verification is pending
|
||||
apf_verification_pending_guild_limit = (1 << 16),
|
||||
/// Embedded
|
||||
apf_embedded = (1 << 17),
|
||||
/// Has approval for message content
|
||||
apf_gateway_message_content = (1 << 18),
|
||||
/// Has message content, but <100 guilds
|
||||
apf_gateway_message_content_limited = (1 << 19),
|
||||
/// Indicates if the app has registered global application commands
|
||||
apf_application_command_badge = (1 << 23)
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents the settings for the bot/application's in-app authorization link
|
||||
*/
|
||||
struct DPP_EXPORT application_install_params {
|
||||
permission permissions; //!< A bitmask of dpp::permissions to request for the bot role
|
||||
std::vector<std::string> scopes; //!< The [scopes](https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes) as strings to add the application to the server with
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a team member on a team who maintain a bot/application
|
||||
*/
|
||||
class DPP_EXPORT team_member {
|
||||
public:
|
||||
team_member_status membership_state; //!< the user's membership state on the team
|
||||
std::string permissions; //!< will always be [""]
|
||||
snowflake team_id; //!< the id of the parent team of which they are a member
|
||||
user member_user; //!< the avatar, discriminator, id, and username of the user
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a team of users who maintain a bot/application
|
||||
*/
|
||||
class DPP_EXPORT app_team {
|
||||
public:
|
||||
utility::iconhash icon; //!< a hash of the image of the team's icon (may be empty)
|
||||
snowflake id; //!< the unique id of the team
|
||||
std::vector<team_member> members; //!< the members of the team
|
||||
std::string name; //!< the name of the team
|
||||
snowflake owner_user_id; //!< the user id of the current team owner
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The application class represents details of a bot application
|
||||
*/
|
||||
class DPP_EXPORT application : public managed, public json_interface<application> {
|
||||
public:
|
||||
std::string name; //!< the name of the app
|
||||
utility::iconhash icon; //!< the icon hash of the app (may be empty)
|
||||
std::string description; //!< the description of the app
|
||||
std::string rpc_origins; //!< Optional: an array of rpc origin urls, if rpc is enabled
|
||||
bool bot_public; //!< when false only app owner can join the app's bot to guilds
|
||||
bool bot_require_code_grant; //!< when true the app's bot will only join upon completion of the full oauth2 code grant flow
|
||||
std::string terms_of_service_url; //!< Optional: the url of the app's terms of service
|
||||
std::string privacy_policy_url; //!< Optional: the url of the app's privacy policy
|
||||
user owner; //!< Optional: partial user object containing info on the owner of the application
|
||||
std::string summary; //!< if this application is a game sold on Discord, this field will be the summary field for the store page of its primary sku @deprecated Will be removed in v11
|
||||
std::string verify_key; //!< the hex encoded key for verification in interactions and the GameSDK's GetTicket
|
||||
app_team team; //!< if the application belongs to a team, this will be a list of the members of that team (may be empty)
|
||||
snowflake guild_id; //!< Optional: if this application is a game sold on Discord, this field will be the guild to which it has been linked
|
||||
snowflake primary_sku_id; //!< Optional: if this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists
|
||||
std::string slug; //!< Optional: if this application is a game sold on Discord, this field will be the URL slug that links to the store page
|
||||
utility::iconhash cover_image; //!< Optional: the application's default rich presence invite cover image hash
|
||||
uint32_t flags; //!< Optional: the application's public flags
|
||||
std::vector<std::string> tags; //!< Up to 5 tags describing the content and functionality of the application
|
||||
application_install_params install_params; //!< Settings for the application's default in-app authorization link, if enabled
|
||||
std::string custom_install_url; //!< The application's default custom authorization link, if enabled
|
||||
std::string role_connections_verification_url; //!< The application's role connection verification entry point, which when configured will render the app as a verification method in the guild role verification configuration
|
||||
|
||||
/** Constructor */
|
||||
application();
|
||||
|
||||
/** Destructor */
|
||||
~application();
|
||||
|
||||
/** Read class values from json object
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
application& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Get the application's cover image url if they have one, otherwise returns an empty string
|
||||
*
|
||||
* @param size The size of the cover image in pixels. It can be any power of two between 16 and 4096,
|
||||
* otherwise the default sized cover image is returned.
|
||||
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg` or `i_png`.
|
||||
* @return std::string cover image url or an empty string, if required attributes are missing or an invalid format was passed
|
||||
*/
|
||||
std::string get_cover_image_url(uint16_t size = 0, const image_type format = i_png) const;
|
||||
|
||||
/**
|
||||
* @brief Get the application's icon url if they have one, otherwise returns an empty string
|
||||
*
|
||||
* @param size The size of the icon in pixels. It can be any power of two between 16 and 4096,
|
||||
* otherwise the default sized icon is returned.
|
||||
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg` or `i_png`.
|
||||
* @return std::string icon url or an empty string, if required attributes are missing or an invalid format was passed
|
||||
*/
|
||||
std::string get_icon_url(uint16_t size = 0, const image_type format = i_png) const;
|
||||
};
|
||||
|
||||
/** A group of applications.
|
||||
* This is not currently ever sent by Discord API but the DPP standard setup for
|
||||
* objects that can be received by REST has the possibility for this, so this exists.
|
||||
* Don't ever expect to see one at present.
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, application> application_map;
|
||||
|
||||
};
|
214
vendor/DPP/include/dpp/auditlog.h
vendored
Normal file
214
vendor/DPP/include/dpp/auditlog.h
vendored
Normal file
@ -0,0 +1,214 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <optional>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Defines types of audit log entry
|
||||
*/
|
||||
enum audit_type {
|
||||
/// Guild update
|
||||
aut_guild_update = 1,
|
||||
/// Channel create
|
||||
aut_channel_create = 10,
|
||||
/// Channel update
|
||||
aut_channel_update = 11,
|
||||
/// Channel delete
|
||||
aut_channel_delete = 12,
|
||||
/// Channel overwrite create
|
||||
aut_channel_overwrite_create = 13,
|
||||
/// Channel overwrite update
|
||||
aut_channel_overwrite_update = 14,
|
||||
/// Channel overwrite delete
|
||||
aut_channel_overwrite_delete = 15,
|
||||
/// Channel member kick
|
||||
aut_member_kick = 20,
|
||||
/// Channel member prune
|
||||
aut_member_prune = 21,
|
||||
/// Channel member ban add
|
||||
aut_member_ban_add = 22,
|
||||
/// Channel member ban remove
|
||||
aut_member_ban_remove = 23,
|
||||
/// Guild member update
|
||||
aut_member_update = 24,
|
||||
/// Guild member role update
|
||||
aut_member_role_update = 25,
|
||||
/// Guild member move
|
||||
aut_member_move = 26,
|
||||
/// Guild member voice disconnect
|
||||
aut_member_disconnect = 27,
|
||||
/// Guild bot add
|
||||
aut_bot_add = 28,
|
||||
/// Guild role create
|
||||
aut_role_create = 30,
|
||||
/// Guild role update
|
||||
aut_role_update = 31,
|
||||
/// Guild role delete
|
||||
aut_role_delete = 32,
|
||||
/// Guild invite create
|
||||
aut_invite_create = 40,
|
||||
/// Guild invite update
|
||||
aut_invite_update = 41,
|
||||
/// Guild invite delete
|
||||
aut_invite_delete = 42,
|
||||
/// Guild webhook create
|
||||
aut_webhook_create = 50,
|
||||
/// Guild webhook update
|
||||
aut_webhook_update = 51,
|
||||
/// Guild webhook delete
|
||||
aut_webhook_delete = 52,
|
||||
/// Guild emoji create
|
||||
aut_emoji_create = 60,
|
||||
/// Guild emoji update
|
||||
aut_emoji_update = 61,
|
||||
/// Guild emoji delete
|
||||
aut_emoji_delete = 62,
|
||||
/// Guild message delete
|
||||
aut_message_delete = 72,
|
||||
/// Guild message bulk delete
|
||||
aut_message_bulk_delete = 73,
|
||||
/// Guild message pin
|
||||
aut_message_pin = 74,
|
||||
/// Guild message unpin
|
||||
aut_message_unpin = 75,
|
||||
/// Guild integration create
|
||||
aut_integration_create = 80,
|
||||
/// Guild integration update
|
||||
aut_integration_update = 81,
|
||||
/// Guild integration delete
|
||||
aut_integration_delete = 82,
|
||||
/// Stage instance create
|
||||
aut_stage_instance_create = 83,
|
||||
/// Stage instance update
|
||||
aut_stage_instance_update = 84,
|
||||
/// stage instance delete
|
||||
aut_stage_instance_delete = 85,
|
||||
/// Sticker create
|
||||
aut_sticker_create = 90,
|
||||
/// Sticker update
|
||||
aut_sticker_update = 91,
|
||||
/// Sticker delete
|
||||
aut_sticker_delete = 92,
|
||||
/// Scheduled event creation
|
||||
aut_guild_scheduled_event_create = 100,
|
||||
/// Scheduled event update
|
||||
aut_guild_scheduled_event_update = 101,
|
||||
/// Scheduled event deletion
|
||||
aut_guild_scheduled_event_delete = 102,
|
||||
/// Thread create
|
||||
aut_thread_create = 110,
|
||||
/// Thread update
|
||||
aut_thread_update = 111,
|
||||
/// Thread delete
|
||||
aut_thread_delete = 112,
|
||||
/// Application command permissions update
|
||||
aut_appcommand_permission_update = 121,
|
||||
/// Auto moderation rule creation
|
||||
aut_automod_rule_create = 140,
|
||||
/// Auto moderation rule update
|
||||
aut_automod_rule_update = 141,
|
||||
/// Auto moderation rule deletion
|
||||
aut_automod_rule_delete = 142,
|
||||
/// Message was blocked by Auto Moderation
|
||||
aut_automod_block_message = 143,
|
||||
/// Message was flagged by Auto Moderation
|
||||
aut_automod_flag_to_channel = 144,
|
||||
/// Member was timed out by Auto Moderation
|
||||
aut_automod_user_communication_disabled = 145,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Defines audit log changes
|
||||
*/
|
||||
struct DPP_EXPORT audit_change {
|
||||
/// Optional: Serialised new value of the change, e.g. for nicknames, the new nickname
|
||||
std::string new_value;
|
||||
/// Optional: Serialised old value of the change, e.g. for nicknames, the old nickname
|
||||
std::string old_value;
|
||||
/**
|
||||
* The property name that was changed, e.g. `nick` for nickname changes
|
||||
* @note For dpp::aut_appcommand_permission_update updates the key is the id of the user, channel, role, or a permission constant that was updated instead of an actual property name
|
||||
*/
|
||||
std::string key;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Extra information for an audit log entry
|
||||
*/
|
||||
struct DPP_EXPORT audit_extra {
|
||||
std::string automod_rule_name; //!< Name of the Auto Moderation rule that was triggered
|
||||
std::string automod_rule_trigger_type; //!< Trigger type of the Auto Moderation rule that was triggered
|
||||
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")
|
||||
snowflake application_id; //!< ID of the app whose permissions were targeted
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief An individual audit log entry
|
||||
*/
|
||||
struct DPP_EXPORT audit_entry {
|
||||
snowflake id; //!< id of the entry
|
||||
/**
|
||||
* ID of the affected entity (webhook, user, role, etc.) (may be empty)
|
||||
* @note For dpp::audit_type::aut_appcommand_permission_update updates, it's the command ID or the app ID
|
||||
*/
|
||||
snowflake target_id;
|
||||
std::vector<audit_change> changes; //!< Optional: changes made to the target_id
|
||||
snowflake user_id; //!< the user or app that made the changes (may be empty)
|
||||
audit_type type; //!< type of action that occurred
|
||||
std::optional<audit_extra> extra; //!< Optional: additional info for certain action types
|
||||
std::string reason; //!< Optional: the reason for the change (1-512 characters)
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The auditlog class represents the audit log entries of a guild.
|
||||
*/
|
||||
class DPP_EXPORT auditlog : public json_interface<auditlog> {
|
||||
public:
|
||||
std::vector<audit_entry> entries; //!< Audit log entries
|
||||
|
||||
/** Constructor */
|
||||
auditlog() = default;
|
||||
|
||||
/** Destructor */
|
||||
virtual ~auditlog() = default;
|
||||
|
||||
/** 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);
|
||||
};
|
||||
|
||||
};
|
369
vendor/DPP/include/dpp/automod.h
vendored
Normal file
369
vendor/DPP/include/dpp/automod.h
vendored
Normal file
@ -0,0 +1,369 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/utility.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Possible types of preset filter lists
|
||||
*/
|
||||
enum automod_preset_type : uint8_t {
|
||||
/**
|
||||
* @brief Strong swearing
|
||||
*/
|
||||
amod_preset_profanity = 1,
|
||||
/**
|
||||
* @brief Sexual phrases and words
|
||||
*/
|
||||
amod_preset_sexual_content = 2,
|
||||
/**
|
||||
* @brief Racial and other slurs, hate speech
|
||||
*/
|
||||
amod_preset_slurs = 3,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Action types to perform on filtering
|
||||
*/
|
||||
enum automod_action_type : uint8_t {
|
||||
/**
|
||||
* @brief Blocks the message and prevents it from being posted.
|
||||
* A custom explanation can be specified and shown to members whenever their message is blocked
|
||||
*/
|
||||
amod_action_block_message = 1,
|
||||
/**
|
||||
* @brief Send an alert to a given channel
|
||||
*/
|
||||
amod_action_send_alert = 2,
|
||||
/**
|
||||
* @brief timeout the user
|
||||
* @note Can only be set up for rules with trigger types of dpp::amod_type_keyword and dpp::amod_type_mention_spam
|
||||
*/
|
||||
amod_action_timeout = 3,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Event types, only message send is currently supported
|
||||
*/
|
||||
enum automod_event_type : uint8_t {
|
||||
/**
|
||||
* @brief Trigger on message send or edit
|
||||
*/
|
||||
amod_message_send = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Types of moderation to trigger
|
||||
*/
|
||||
enum automod_trigger_type : uint8_t {
|
||||
/**
|
||||
* @brief Check if content contains words from a user defined list of keywords
|
||||
*/
|
||||
amod_type_keyword = 1,
|
||||
/**
|
||||
* @brief Harmful/malware links
|
||||
* @deprecated Removed by Discord
|
||||
*/
|
||||
amod_type_harmful_link = 2,
|
||||
/**
|
||||
* @brief Check if content represents generic spam
|
||||
*/
|
||||
amod_type_spam = 3,
|
||||
/**
|
||||
* @brief Check if content contains words from discord pre-defined wordsets
|
||||
*/
|
||||
amod_type_keyword_preset = 4,
|
||||
/**
|
||||
* @brief Check if content contains more mentions than allowed
|
||||
*/
|
||||
amod_type_mention_spam = 5,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Metadata associated with an automod action
|
||||
*/
|
||||
struct DPP_EXPORT automod_metadata : public json_interface<automod_metadata> {
|
||||
/**
|
||||
* @brief @brief Substrings which will be searched for in content (Maximum of 1000).
|
||||
*
|
||||
* Each keyword can be a phrase which contains multiple words.
|
||||
* All keywords are case insensitive and can be up to 60 characters.
|
||||
*
|
||||
* Wildcard symbols (`*`) can be used to customize how each keyword will be matched.
|
||||
*
|
||||
* **Examples for the `*` wildcard symbol:**
|
||||
*
|
||||
* Prefix - word must start with the keyword
|
||||
*
|
||||
* | keyword | matches |
|
||||
* |----------|-------------------------------------|
|
||||
* | cat* | <u><b>cat</b></u>ch, <u><b>Cat</b></u>apult, <u><b>CAt</b></u>tLE |
|
||||
* | the mat* | <u><b>the mat</b></u>rix |
|
||||
*
|
||||
* Suffix - word must end with the keyword
|
||||
*
|
||||
* | keyword | matches |
|
||||
* |----------|--------------------------|
|
||||
* | *cat | wild<u><b>cat</b></u>, copy<u><b>Cat</b></u> |
|
||||
* | *the mat | brea<u><b>the mat</b></u> |
|
||||
*
|
||||
* Anywhere - keyword can appear anywhere in the content
|
||||
*
|
||||
* | keyword | matches |
|
||||
* |-----------|-----------------------------|
|
||||
* | \*cat* | lo<u><b>cat</b></u>ion, edu<u><b>Cat</b></u>ion |
|
||||
* | \*the mat* | brea<u><b>the mat</b></u>ter |
|
||||
*
|
||||
* Whole Word - keyword is a full word or phrase and must be surrounded by whitespace at the beginning and end
|
||||
*
|
||||
* | keyword | matches |
|
||||
* |---------|-------------|
|
||||
* | cat | <u><b>Cat</b></u> |
|
||||
* | the mat | <u><b>the mat</b></u> |
|
||||
*
|
||||
*/
|
||||
std::vector<std::string> keywords;
|
||||
|
||||
/**
|
||||
* @brief Regular expression patterns which will be matched against content (Maximum of 10).
|
||||
*
|
||||
* Only Rust flavored regex is currently supported, which can be tested in online editors such as [Rustexp](https://rustexp.lpil.uk/).
|
||||
* Each regex pattern can be up to 260 characters.
|
||||
*/
|
||||
std::vector<std::string> regex_patterns;
|
||||
|
||||
/**
|
||||
* @brief Preset keyword list types to moderate
|
||||
* @see automod_preset_type
|
||||
*/
|
||||
std::vector<automod_preset_type> presets;
|
||||
|
||||
/**
|
||||
* @brief Substrings which should not trigger the rule.
|
||||
*
|
||||
* Each keyword can be a phrase which contains multiple words.
|
||||
* All keywords are case insensitive and can be up to 60 characters.
|
||||
*
|
||||
* Wildcard symbols (`*`) can be used to customize how each keyword will be matched.
|
||||
*
|
||||
* **Examples for the `*` wildcard symbol:**
|
||||
*
|
||||
* Prefix - word must start with the keyword
|
||||
*
|
||||
* | keyword | matches |
|
||||
* |----------|-------------------------------------|
|
||||
* | cat* | <u><b>cat</b></u>ch, <u><b>Cat</b></u>apult, <u><b>CAt</b></u>tLE |
|
||||
* | the mat* | <u><b>the mat</b></u>rix |
|
||||
*
|
||||
* Suffix - word must end with the keyword
|
||||
*
|
||||
* | keyword | matches |
|
||||
* |----------|--------------------------|
|
||||
* | *cat | wild<u><b>cat</b></u>, copy<u><b>Cat</b></u> |
|
||||
* | *the mat | brea<u><b>the mat</b></u> |
|
||||
*
|
||||
* Anywhere - keyword can appear anywhere in the content
|
||||
*
|
||||
* | keyword | matches |
|
||||
* |-----------|-----------------------------|
|
||||
* | \*cat* | lo<u><b>cat</b></u>ion, edu<u><b>Cat</b></u>ion |
|
||||
* | \*the mat* | brea<u><b>the mat</b></u>ter |
|
||||
*
|
||||
* Whole Word - keyword is a full word or phrase and must be surrounded by whitespace at the beginning and end
|
||||
*
|
||||
* | keyword | matches |
|
||||
* |---------|-------------|
|
||||
* | cat | <u><b>Cat</b></u> |
|
||||
* | the mat | <u><b>the mat</b></u> |
|
||||
*
|
||||
*/
|
||||
std::vector<std::string> allow_list;
|
||||
|
||||
/**
|
||||
* @brief Total number of unique role and user mentions allowed per message (Maximum of 50)
|
||||
*/
|
||||
uint8_t mention_total_limit;
|
||||
|
||||
/**
|
||||
* @brief Construct a new automod metadata object
|
||||
*/
|
||||
automod_metadata();
|
||||
|
||||
/**
|
||||
* @brief Destroy the automod metadata object
|
||||
*/
|
||||
virtual ~automod_metadata();
|
||||
|
||||
/**
|
||||
* @brief Fill object properties from JSON
|
||||
*
|
||||
* @param j JSON to fill from
|
||||
* @return automod_metadata& Reference to self
|
||||
*/
|
||||
automod_metadata& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build a json string for this object
|
||||
*
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents an automod action
|
||||
*/
|
||||
struct DPP_EXPORT automod_action : public json_interface<automod_action> {
|
||||
/**
|
||||
* @brief Type of action to take
|
||||
*/
|
||||
automod_action_type type;
|
||||
|
||||
/**
|
||||
* @brief Channel ID to which user content should be logged, for type dpp::amod_action_send_alert
|
||||
*/
|
||||
snowflake channel_id;
|
||||
|
||||
/**
|
||||
* @brief Additional explanation that will be shown to members whenever their message is blocked. For type dpp::amod_action_block_message
|
||||
*/
|
||||
std::string custom_message;
|
||||
|
||||
/**
|
||||
* @brief Timeout duration in seconds (Maximum of 2419200), for dpp::amod_action_timeout
|
||||
*/
|
||||
uint32_t duration_seconds;
|
||||
|
||||
/**
|
||||
* @brief Construct a new automod action object
|
||||
*/
|
||||
automod_action();
|
||||
|
||||
/**
|
||||
* @brief Destroy the automod action object
|
||||
*/
|
||||
virtual ~automod_action();
|
||||
|
||||
/**
|
||||
* @brief Fill object properties from JSON
|
||||
*
|
||||
* @param j JSON to fill from
|
||||
* @return automod_action& Reference to self
|
||||
*/
|
||||
automod_action& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build a json string for this object
|
||||
*
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents an automod rule
|
||||
*/
|
||||
class DPP_EXPORT automod_rule : public managed, public json_interface<automod_rule> {
|
||||
public:
|
||||
/**
|
||||
* @brief the id of this rule
|
||||
*/
|
||||
snowflake id;
|
||||
/**
|
||||
* @brief the guild which this rule belongs to
|
||||
*/
|
||||
snowflake guild_id;
|
||||
/**
|
||||
* @brief the rule name
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @brief The user which first created this rule
|
||||
*/
|
||||
snowflake creator_id;
|
||||
/**
|
||||
* @brief The rule event type
|
||||
*/
|
||||
automod_event_type event_type;
|
||||
/**
|
||||
* @brief The rule trigger type
|
||||
*/
|
||||
automod_trigger_type trigger_type;
|
||||
/**
|
||||
* @brief The rule trigger metadata
|
||||
*/
|
||||
automod_metadata trigger_metadata;
|
||||
/**
|
||||
* @brief the actions which will execute when the rule is triggered
|
||||
*/
|
||||
std::vector<automod_action> actions;
|
||||
/**
|
||||
* @brief Whether the rule is enabled
|
||||
*/
|
||||
bool enabled;
|
||||
/**
|
||||
* @brief the role ids that should not be affected by the rule (Maximum of 20)
|
||||
*/
|
||||
std::vector<snowflake> exempt_roles;
|
||||
/**
|
||||
* @brief the channel ids that should not be affected by the rule (Maximum of 50)
|
||||
*/
|
||||
std::vector<snowflake> exempt_channels;
|
||||
|
||||
/**
|
||||
* @brief Construct a new automod rule object
|
||||
*/
|
||||
automod_rule();
|
||||
|
||||
/**
|
||||
* @brief Destroy the automod rule object
|
||||
*/
|
||||
virtual ~automod_rule();
|
||||
|
||||
/**
|
||||
* @brief Fill object properties from JSON
|
||||
*
|
||||
* @param j JSON to fill from
|
||||
* @return automod_rule& Reference to self
|
||||
*/
|
||||
automod_rule& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build a json string for this object
|
||||
*
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
};
|
||||
|
||||
/** A group of automod rules.
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, automod_rule> automod_rule_map;
|
||||
|
||||
};
|
67
vendor/DPP/include/dpp/ban.h
vendored
Normal file
67
vendor/DPP/include/dpp/ban.h
vendored
Normal file
@ -0,0 +1,67 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/json_interface.h>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief The ban class represents a ban on a guild.
|
||||
*
|
||||
*/
|
||||
class DPP_EXPORT ban : public json_interface<ban> {
|
||||
public:
|
||||
/** The ban reason */
|
||||
std::string reason;
|
||||
/** User ID the ban applies to */
|
||||
snowflake user_id;
|
||||
|
||||
/** Constructor */
|
||||
ban();
|
||||
|
||||
/** Destructor */
|
||||
virtual ~ban() = default;
|
||||
|
||||
/** 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
|
||||
* @param with_id Include ID in json
|
||||
*
|
||||
* @return std::string stringified json
|
||||
*/
|
||||
std::string build_json(bool with_id = false) const;
|
||||
};
|
||||
|
||||
/** A group of bans
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, ban> ban_map;
|
||||
|
||||
};
|
272
vendor/DPP/include/dpp/cache.h
vendored
Normal file
272
vendor/DPP/include/dpp/cache.h
vendored
Normal file
@ -0,0 +1,272 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <unordered_map>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
extern DPP_EXPORT std::unordered_map<managed*, time_t> deletion_queue;
|
||||
extern DPP_EXPORT std::mutex deletion_mutex;
|
||||
|
||||
/** forward declaration */
|
||||
class guild_member;
|
||||
|
||||
/**
|
||||
* @brief A cache object maintains a cache of dpp::managed objects.
|
||||
*
|
||||
* This is for example users, channels or guilds. You may instantiate
|
||||
* your own caches, to contain any type derived from dpp::managed including
|
||||
* your own types.
|
||||
*
|
||||
* @note This class is critical to the operation of the library and therefore
|
||||
* designed with thread safety in mind.
|
||||
* @tparam T class type to store, which should be derived from dpp::managed.
|
||||
*/
|
||||
template<class T> class cache {
|
||||
private:
|
||||
/**
|
||||
* @brief Mutex to protect the cache
|
||||
*
|
||||
* This is a shared mutex so reading is cheap.
|
||||
*/
|
||||
std::shared_mutex cache_mutex;
|
||||
|
||||
/**
|
||||
* @brief Container of pointers to cached items
|
||||
*/
|
||||
std::unordered_map<snowflake, T*>* cache_map;
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Construct a new cache object.
|
||||
*
|
||||
* Caches must contain classes derived from dpp::managed.
|
||||
*/
|
||||
cache() {
|
||||
cache_map = new std::unordered_map<snowflake, T*>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroy the cache object
|
||||
*
|
||||
* @note This does not delete objects stored in the cache.
|
||||
*/
|
||||
~cache() {
|
||||
std::unique_lock l(cache_mutex);
|
||||
delete cache_map;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Store an object in the cache. Passing a nullptr will have no effect.
|
||||
*
|
||||
* The object must be derived from dpp::managed and should be allocated on the heap.
|
||||
* Generally this is done via `new`. Once stored in the cache the lifetime of the stored
|
||||
* object is managed by the cache class unless the cache is deleted (at which point responsibility
|
||||
* for deleting the object returns to its allocator). Objects stored are removed when the
|
||||
* cache::remove() method is called by placing them into a garbage collection queue for deletion
|
||||
* within the next 60 seconds, which are then deleted in bulk for efficiency and to aid thread
|
||||
* safety.
|
||||
*
|
||||
* @note Adding an object to the cache with an ID which already exists replaces that entry.
|
||||
* The previously entered cache item is inserted into the garbage collection queue for deletion
|
||||
* similarly to if cache::remove() was called first.
|
||||
*
|
||||
* @param object object to store. Storing a pointer to the cache relinquishes ownership to the cache object.
|
||||
*/
|
||||
void store(T* object) {
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
std::unique_lock l(cache_mutex);
|
||||
auto existing = cache_map->find(object->id);
|
||||
if (existing == cache_map->end()) {
|
||||
(*cache_map)[object->id] = object;
|
||||
} else if (object != existing->second) {
|
||||
/* Flag old pointer for deletion and replace */
|
||||
std::lock_guard<std::mutex> delete_lock(deletion_mutex);
|
||||
deletion_queue[existing->second] = time(NULL);
|
||||
(*cache_map)[object->id] = object;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove an object from the cache.
|
||||
*
|
||||
* @note The cache class takes ownership of the pointer, and calling this method will
|
||||
* cause deletion of the object within the next 60 seconds by means of a garbage
|
||||
* collection queue. This queue aids in efficiency by freeing memory in bulk, and
|
||||
* assists in thread safety by ensuring that all deletions can be locked and freed
|
||||
* at the same time.
|
||||
*
|
||||
* @param object object to remove. Passing a nullptr will have no effect.
|
||||
*/
|
||||
void remove(T* object) {
|
||||
if (!object) {
|
||||
return;
|
||||
}
|
||||
std::unique_lock l(cache_mutex);
|
||||
std::lock_guard<std::mutex> delete_lock(deletion_mutex);
|
||||
auto existing = cache_map->find(object->id);
|
||||
if (existing != cache_map->end()) {
|
||||
cache_map->erase(existing);
|
||||
deletion_queue[object] = time(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Find an object in the cache by id.
|
||||
*
|
||||
* The cache is searched for the object. All dpp::managed objects have a snowflake id
|
||||
* (this is the only field dpp::managed actually has).
|
||||
*
|
||||
* @warning Do not hang onto objects returned by cache::find() indefinitely. They may be
|
||||
* deleted at a later date if cache::remove() is called. If persistence is required,
|
||||
* take a copy of the object after checking its pointer is non-null.
|
||||
*
|
||||
* @param id Object snowflake id to find
|
||||
* @return Found object or nullptr if the object with this id does not exist.
|
||||
*/
|
||||
T* find(snowflake id) {
|
||||
std::shared_lock l(cache_mutex);
|
||||
auto r = cache_map->find(id);
|
||||
if (r != cache_map->end()) {
|
||||
return r->second;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return a count of the number of items in the cache.
|
||||
*
|
||||
* This is used by the library e.g. to count guilds, users, and roles
|
||||
* stored within caches.
|
||||
* get
|
||||
* @return uint64_t count of items in the cache
|
||||
*/
|
||||
uint64_t count() {
|
||||
std::shared_lock l(cache_mutex);
|
||||
return cache_map->size();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Return the cache's locking mutex.
|
||||
*
|
||||
* Use this whenever you manipulate or iterate raw elements in the cache!
|
||||
*
|
||||
* @note If you are only reading from the cache's container, wrap this
|
||||
* mutex in `std::shared_lock`, else wrap it in a `std::unique_lock`.
|
||||
* Shared locks will allow for multiple readers whilst blocking writers,
|
||||
* and unique locks will allow only one writer whilst blocking readers
|
||||
* and writers.
|
||||
*
|
||||
* **Example:**
|
||||
*
|
||||
* ```cpp
|
||||
* dpp::cache<guild>* c = dpp::get_guild_cache();
|
||||
* std::unordered_map<snowflake, guild*>& gc = c->get_container();
|
||||
* std::shared_lock l(c->get_mutex()); // MUST LOCK HERE
|
||||
* for (auto g = gc.begin(); g != gc.end(); ++g) {
|
||||
* dpp::guild* gp = (dpp::guild*)g->second;
|
||||
* // Do something here with the guild* in 'gp'
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @return The mutex used to protect the container
|
||||
*/
|
||||
std::shared_mutex& get_mutex() {
|
||||
return this->cache_mutex;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the container unordered map
|
||||
*
|
||||
* @warning Be sure to use cache::get_mutex() correctly if you
|
||||
* manipulate or iterate the map returned by this method! If you do
|
||||
* not, this is not thread safe and will cause crashes!
|
||||
*
|
||||
* @see cache::get_mutex
|
||||
*
|
||||
* @return A reference to the cache's container map
|
||||
*/
|
||||
auto & get_container() {
|
||||
return *(this->cache_map);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief "Rehash" a cache by reallocating the map and copying
|
||||
* all elements into the new one.
|
||||
*
|
||||
* Over a long running timeframe, unordered maps can grow in size
|
||||
* due to bucket allocation, this function frees that unused memory
|
||||
* to keep the maps in control over time. If this is an issue which
|
||||
* is apparent with your use of dpp::cache objects, you should periodically
|
||||
* call this method.
|
||||
*
|
||||
* @warning May be time consuming! This function is O(n) in relation to the
|
||||
* number of cached entries.
|
||||
*/
|
||||
void rehash() {
|
||||
std::unique_lock l(cache_mutex);
|
||||
std::unordered_map<snowflake, T*>* n = new std::unordered_map<snowflake, T*>;
|
||||
n->reserve(cache_map->size());
|
||||
for (auto t = cache_map->begin(); t != cache_map->end(); ++t) {
|
||||
n->insert(*t);
|
||||
}
|
||||
delete cache_map;
|
||||
cache_map = n;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get "real" size in RAM of the cached objects
|
||||
*
|
||||
* This does not include metadata used to maintain the unordered map itself.
|
||||
*
|
||||
* @return size_t size of cache in bytes
|
||||
*/
|
||||
size_t bytes() {
|
||||
std::shared_lock l(cache_mutex);
|
||||
return sizeof(this) + (cache_map->bucket_count() * sizeof(size_t));
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/** Run garbage collection across all caches removing deleted items
|
||||
* that have been deleted over 60 seconds ago.
|
||||
*/
|
||||
void DPP_EXPORT garbage_collection();
|
||||
|
||||
#define cache_decl(type, setter, getter, counter) /** Find an object in the cache by id. @return type* Pointer to the object or nullptr when it's not found */ DPP_EXPORT class type * setter (snowflake id); DPP_EXPORT cache<class type> * getter (); /** Get the amount of cached type objects. */ DPP_EXPORT 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);
|
||||
|
||||
};
|
||||
|
813
vendor/DPP/include/dpp/channel.h
vendored
Normal file
813
vendor/DPP/include/dpp/channel.h
vendored
Normal file
@ -0,0 +1,813 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/utility.h>
|
||||
#include <dpp/voicestate.h>
|
||||
#include <dpp/message.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/permissions.h>
|
||||
#include <dpp/json_interface.h>
|
||||
#include <unordered_map>
|
||||
#include <variant>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/** @brief Flag integers as received from and sent to discord */
|
||||
enum channel_type : uint8_t {
|
||||
CHANNEL_TEXT = 0, //!< a text channel within a server
|
||||
DM = 1, //!< a direct message between users
|
||||
CHANNEL_VOICE = 2, //!< a voice channel within a server
|
||||
/**
|
||||
* @brief a direct message between multiple users
|
||||
* @deprecated this channel type was intended to be used with the now deprecated GameBridge SDK. Existing group dms with bots will continue to function, but newly created channels will be unusable
|
||||
*/
|
||||
GROUP_DM = 3,
|
||||
CHANNEL_CATEGORY = 4, //!< an organizational category that contains up to 50 channels
|
||||
CHANNEL_ANNOUNCEMENT = 5, //!< a channel that users can follow and crosspost into their own server
|
||||
/**
|
||||
* @brief a channel in which game developers can sell their game on Discord
|
||||
* @deprecated store channels are deprecated by Discord
|
||||
*/
|
||||
CHANNEL_STORE = 6,
|
||||
CHANNEL_ANNOUNCEMENT_THREAD = 10, //!< a temporary sub-channel within a GUILD_ANNOUNCEMENT channel
|
||||
CHANNEL_PUBLIC_THREAD = 11, //!< a temporary sub-channel within a GUILD_TEXT or GUILD_FORUM channel
|
||||
CHANNEL_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
|
||||
CHANNEL_STAGE = 13, //!< a "stage" channel, like a voice channel with one authorised speaker
|
||||
CHANNEL_DIRECTORY = 14, //!< the channel in a [hub](https://support.discord.com/hc/en-us/articles/4406046651927-Discord-Student-Hubs-FAQ) containing the listed servers
|
||||
CHANNEL_FORUM = 15 //!< forum channel that can only contain threads
|
||||
};
|
||||
|
||||
/** @brief Our flags as stored in the object
|
||||
* @note The bottom four bits of this flag are reserved to contain the channel_type values
|
||||
* listed above as provided by Discord. If discord add another value > 15, we will have to
|
||||
* shuffle these values upwards by one bit.
|
||||
*/
|
||||
enum channel_flags : uint16_t {
|
||||
/// NSFW Gated Channel
|
||||
c_nsfw = 0b0000000000010000,
|
||||
/// Video quality forced to 720p
|
||||
c_video_quality_720p = 0b0000000000100000,
|
||||
/// Lock permissions (only used when updating channel positions)
|
||||
c_lock_permissions = 0b0000000001000000,
|
||||
/// Thread is pinned to the top of its parent forum channel
|
||||
c_pinned_thread = 0b0000000010000000,
|
||||
/// Whether a tag is required to be specified when creating a thread in a forum channel. Tags are specified in the thread::applied_tags field.
|
||||
c_require_tag = 0b0000000100000000,
|
||||
/* Note that the 9th and 10th bit are used for the forum layout type */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The flags in discord channel's raw "flags" field. We use these for serialisation only, right now. Might be better to create a new field than to make the existing channel::flags from uint8_t to uint16_t, if discord adds more flags in future.
|
||||
*/
|
||||
enum discord_channel_flags : uint8_t {
|
||||
/// Thread is pinned to the top of its parent forum channel
|
||||
dc_pinned_thread = 1 << 1,
|
||||
/// Whether a tag is required to be specified when creating a thread in a forum channel. Tags are specified in the thread::applied_tags field.
|
||||
dc_require_tag = 1 << 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Types for sort posts in a forum channel
|
||||
*/
|
||||
enum default_forum_sort_order_t : uint8_t {
|
||||
/// Sort forum posts by activity (default)
|
||||
so_latest_activity = 0,
|
||||
/// Sort forum posts by creation time (from most recent to oldest)
|
||||
so_creation_date = 1,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Types of forum layout views that indicates how the threads in a forum channel will be displayed for users by default
|
||||
*/
|
||||
enum forum_layout_type : uint8_t {
|
||||
fl_not_set = 0, //!< No default has been set for the forum channel
|
||||
fl_list_view = 1, //!< Display posts as a list
|
||||
fl_gallery_view = 2, //!< Display posts as a collection of tiles
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief channel permission overwrite types
|
||||
*/
|
||||
enum overwrite_type : uint8_t {
|
||||
/// Role
|
||||
ot_role = 0,
|
||||
/// Member
|
||||
ot_member = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Channel permission overwrites
|
||||
*/
|
||||
struct DPP_EXPORT permission_overwrite {
|
||||
/// ID of the role or the member
|
||||
snowflake id;
|
||||
/// Bitmask of allowed permissions
|
||||
permission allow;
|
||||
/// Bitmask of denied permissions
|
||||
permission deny;
|
||||
/// Type of overwrite. See dpp::overwrite_type
|
||||
uint8_t type;
|
||||
|
||||
/**
|
||||
* @brief Construct a new permission_overwrite object
|
||||
*/
|
||||
permission_overwrite();
|
||||
|
||||
/**
|
||||
* @brief Construct a new permission_overwrite object
|
||||
* @param id ID of the role or the member to create the overwrite for
|
||||
* @param allow Bitmask of allowed permissions (refer to enum dpp::permissions) for this user/role in this channel
|
||||
* @param deny Bitmask of denied permissions (refer to enum dpp::permissions) for this user/role in this channel
|
||||
* @param type Type of overwrite
|
||||
*/
|
||||
permission_overwrite(snowflake id, uint64_t allow, uint64_t deny, overwrite_type type);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief metadata for threads
|
||||
*/
|
||||
struct DPP_EXPORT thread_metadata {
|
||||
/// Timestamp when the thread's archive status was last changed, used for calculating recent activity
|
||||
time_t archive_timestamp;
|
||||
/// The duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
|
||||
uint16_t auto_archive_duration;
|
||||
/// Whether a thread is archived
|
||||
bool archived;
|
||||
/// Whether a thread is locked. When a thread is locked, only users with `MANAGE_THREADS` can unarchive it
|
||||
bool locked;
|
||||
/// Whether non-moderators can add other non-moderators. Only for private threads
|
||||
bool invitable;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Auto archive duration of threads which will stop showing in the channel list after the specified period of inactivity.
|
||||
* Defined as an enum to fit into 1 byte. Internally it'll be translated to minutes to match the API
|
||||
*/
|
||||
enum auto_archive_duration_t : uint8_t {
|
||||
/// Auto archive duration of 1 hour. (60 minutes)
|
||||
arc_1_hour = 1,
|
||||
/// Auto archive duration of 1 day. (1440 minutes)
|
||||
arc_1_day = 2,
|
||||
/// Auto archive duration of 3 days. (4320 minutes)
|
||||
arc_3_days = 3,
|
||||
/// Auto archive duration of 1 week. (10080 minutes)
|
||||
arc_1_week = 4,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief represents membership of a user with a thread
|
||||
*/
|
||||
struct DPP_EXPORT thread_member
|
||||
{
|
||||
/// ID of the thread member is part of
|
||||
snowflake thread_id;
|
||||
/// ID of the member
|
||||
snowflake user_id;
|
||||
/// The time when user last joined the thread
|
||||
time_t joined;
|
||||
/// Any user-thread settings, currently only used for notifications
|
||||
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 Represents a tag that is able to be applied to a thread in a forum channel
|
||||
*/
|
||||
struct DPP_EXPORT forum_tag : public managed {
|
||||
/** The name of the tag (0-20 characters) */
|
||||
std::string name;
|
||||
/** The emoji of the tag. Contains either nothing, the id of a guild's custom emoji or the unicode character of the emoji */
|
||||
std::variant<std::monostate, snowflake, std::string> emoji;
|
||||
/** Whether this tag can only be added to or removed from threads by a member with the `MANAGE_THREADS` permission */
|
||||
bool moderated;
|
||||
|
||||
/** Constructor */
|
||||
forum_tag();
|
||||
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param name The name of the tag. It will be truncated to the maximum length of 20 UTF-8 characters.
|
||||
*/
|
||||
forum_tag(const std::string& name);
|
||||
|
||||
/** Destructor */
|
||||
virtual ~forum_tag();
|
||||
|
||||
/**
|
||||
* @brief Read struct values from a json object
|
||||
* @param j json to read values from
|
||||
* @return A reference to self
|
||||
*/
|
||||
forum_tag& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build json for this forum_tag 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 Set name of this forum_tag object
|
||||
*
|
||||
* @param name Name to set
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*
|
||||
* @note name will be truncated to 20 chars, if longer
|
||||
*/
|
||||
forum_tag& set_name(const std::string& name);
|
||||
};
|
||||
|
||||
/** @brief A group of thread member objects*/
|
||||
typedef std::unordered_map<snowflake, thread_member> thread_member_map;
|
||||
|
||||
/**
|
||||
* @brief A definition of a discord channel.
|
||||
* There are one of these for every channel type except threads. Threads are
|
||||
* special snowflakes. Get it? A Discord pun. Hahaha. .... I'll get my coat.
|
||||
*/
|
||||
class DPP_EXPORT channel : public managed, public json_interface<channel> {
|
||||
public:
|
||||
/** Channel name (1-100 characters) */
|
||||
std::string name;
|
||||
|
||||
/** Channel topic (0-4096 characters for forum channels, 0-1024 characters for all others) */
|
||||
std::string topic;
|
||||
|
||||
/**
|
||||
* @brief Voice region if set for voice channel, otherwise empty string
|
||||
*/
|
||||
std::string rtc_region;
|
||||
|
||||
/** DM recipients */
|
||||
std::vector<snowflake> recipients;
|
||||
|
||||
/** Permission overwrites to apply to base permissions */
|
||||
std::vector<permission_overwrite> permission_overwrites;
|
||||
|
||||
/** A set of tags that can be used in a forum channel */
|
||||
std::vector<forum_tag> available_tags;
|
||||
|
||||
/**
|
||||
* @brief The emoji to show as the default reaction button on a forum post.
|
||||
* Contains either nothing, the id of a guild's custom emoji or the unicode character of the emoji
|
||||
*/
|
||||
std::variant<std::monostate, snowflake, std::string> default_reaction;
|
||||
|
||||
/**
|
||||
* @brief Channel icon (for group DMs)
|
||||
*/
|
||||
utility::iconhash icon;
|
||||
|
||||
/** User ID of the creator for group DMs or threads */
|
||||
snowflake owner_id;
|
||||
|
||||
/** Parent ID (for guild channels: id of the parent category, for threads: id of the text channel this thread was created) */
|
||||
snowflake parent_id;
|
||||
|
||||
/** Guild id of the guild that owns the channel */
|
||||
snowflake guild_id;
|
||||
|
||||
/** ID of last message to be sent to the channel (may not point to an existing or valid message or thread) */
|
||||
snowflake last_message_id;
|
||||
|
||||
/** Timestamp of last pinned message */
|
||||
time_t last_pin_timestamp;
|
||||
|
||||
/**
|
||||
* @brief This is only filled when the channel is part of the `resolved` set
|
||||
* sent within an interaction. Any other time it contains zero. When filled,
|
||||
* it contains the calculated permission bitmask of the user issuing the command
|
||||
* within this channel.
|
||||
*/
|
||||
permission permissions;
|
||||
|
||||
/** Sorting position, lower number means higher up the list */
|
||||
uint16_t position;
|
||||
|
||||
/** the bitrate (in kilobits) of the voice channel */
|
||||
uint16_t bitrate;
|
||||
|
||||
/** amount of seconds a user has to wait before sending another message (0-21600); bots, as well as users with the permission manage_messages or manage_channel, are unaffected*/
|
||||
uint16_t rate_limit_per_user;
|
||||
|
||||
/** The initial `rate_limit_per_user` to set on newly created threads in a channel. This field is copied to the thread at creation time and does not live update */
|
||||
uint16_t default_thread_rate_limit_per_user;
|
||||
|
||||
/**
|
||||
* @brief Default duration, copied onto newly created threads. Used by the clients, not the API.
|
||||
* Threads will stop showing in the channel list after the specified period of inactivity. Defaults to dpp::arc_1_day
|
||||
*/
|
||||
auto_archive_duration_t default_auto_archive_duration;
|
||||
|
||||
/** the default sort order type used to order posts in forum channels */
|
||||
default_forum_sort_order_t default_sort_order;
|
||||
|
||||
/** Flags bitmap (dpp::channel_flags) */
|
||||
uint16_t flags;
|
||||
|
||||
/** Maximum user limit for voice channels (0-99) */
|
||||
uint8_t user_limit;
|
||||
|
||||
/** Constructor */
|
||||
channel();
|
||||
|
||||
/** Destructor */
|
||||
virtual ~channel();
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable channel.
|
||||
* @param id The ID of the channel.
|
||||
* @return std::string The formatted mention of the channel.
|
||||
*/
|
||||
static std::string get_mention(const snowflake& id);
|
||||
|
||||
/** 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
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
|
||||
/**
|
||||
* @brief Set name of this channel object
|
||||
*
|
||||
* @param name Name to set
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*
|
||||
* @note name will be truncated to 100 chars, if longer
|
||||
* @throw dpp::length_exception if length < 1
|
||||
*/
|
||||
channel& set_name(const std::string& name);
|
||||
|
||||
/**
|
||||
* @brief Set topic of this channel object
|
||||
*
|
||||
* @param topic Topic to set
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*
|
||||
* @note topic will be truncated to 1024 chars, if longer
|
||||
*/
|
||||
channel& set_topic(const std::string& topic);
|
||||
|
||||
/**
|
||||
* @brief Set type of this channel object
|
||||
*
|
||||
* @param type Channel type to set
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_type(channel_type type);
|
||||
|
||||
/**
|
||||
* @brief Set the default forum layout type for the forum channel
|
||||
*
|
||||
* @param layout_type The layout type
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_default_forum_layout(forum_layout_type layout_type);
|
||||
|
||||
/**
|
||||
* @brief Set the default forum sort order for the forum channel
|
||||
*
|
||||
* @param sort_order The sort order
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_default_sort_order(default_forum_sort_order_t sort_order);
|
||||
|
||||
/**
|
||||
* @brief Set flags for this channel object
|
||||
*
|
||||
* @param flags Flag bitmask to set from dpp::channel_flags
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_flags(const uint16_t flags);
|
||||
|
||||
/**
|
||||
* @brief Add (bitwise OR) a flag to this channel object
|
||||
*
|
||||
* @param flag Flag bit to add from dpp::channel_flags
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& add_flag(const channel_flags flag);
|
||||
|
||||
/**
|
||||
* @brief Remove (bitwise NOT AND) a flag from this channel object
|
||||
*
|
||||
* @param flag Flag bit to remove from dpp::channel_flags
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& remove_flag(const channel_flags flag);
|
||||
|
||||
/**
|
||||
* @brief Set position of this channel object
|
||||
*
|
||||
* @param position Position to set
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_position(const uint16_t position);
|
||||
|
||||
/**
|
||||
* @brief Set guild_id of this channel object
|
||||
*
|
||||
* @param guild_id Guild ID to set
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_guild_id(const snowflake guild_id);
|
||||
|
||||
/**
|
||||
* @brief Set parent_id of this channel object
|
||||
*
|
||||
* @param parent_id Parent ID to set
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_parent_id(const snowflake parent_id);
|
||||
|
||||
/**
|
||||
* @brief Set user_limit of this channel object
|
||||
*
|
||||
* @param user_limit Limit to set
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_user_limit(const uint8_t user_limit);
|
||||
|
||||
/**
|
||||
* @brief Set bitrate of this channel object
|
||||
*
|
||||
* @param bitrate Bitrate to set (in kilobits)
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_bitrate(const uint16_t bitrate);
|
||||
|
||||
/**
|
||||
* @brief Set nsfw property of this channel object
|
||||
*
|
||||
* @param is_nsfw true, if channel is nsfw
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_nsfw(const bool is_nsfw);
|
||||
|
||||
/**
|
||||
* @brief Set lock permissions property of this channel object
|
||||
* Used only with the reorder channels method
|
||||
*
|
||||
* @param is_lock_permissions true, if we are to inherit permissions from the category
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_lock_permissions(const bool is_lock_permissions);
|
||||
|
||||
/**
|
||||
* @brief Set rate_limit_per_user of this channel object
|
||||
*
|
||||
* @param rate_limit_per_user rate_limit_per_user (slowmode in sec) to set
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& set_rate_limit_per_user(const uint16_t rate_limit_per_user);
|
||||
|
||||
/**
|
||||
* @brief Add a permission_overwrite to this channel object
|
||||
*
|
||||
* @param id ID of the role or the member you want to add overwrite for
|
||||
* @param type type of overwrite
|
||||
* @param allowed_permissions bitmask of allowed permissions (refer to enum dpp::permissions) for this user/role in this channel
|
||||
* @param denied_permissions bitmask of denied permissions (refer to enum dpp::permissions) for this user/role in this channel
|
||||
*
|
||||
* @return Reference to self, so these method calls may be chained
|
||||
*/
|
||||
channel& add_permission_overwrite(const snowflake id, const overwrite_type type, const uint64_t allowed_permissions, const uint64_t denied_permissions);
|
||||
|
||||
/**
|
||||
* @brief Get the channel type
|
||||
*
|
||||
* @return channel_type Channel type
|
||||
*/
|
||||
channel_type get_type() const;
|
||||
|
||||
/**
|
||||
* @brief Get the default forum layout type used to display posts in forum channels
|
||||
*
|
||||
* @return forum_layout_types Forum layout type
|
||||
*/
|
||||
forum_layout_type get_default_forum_layout() const;
|
||||
|
||||
/**
|
||||
* @brief Get the mention ping for the channel
|
||||
*
|
||||
* @return std::string mention
|
||||
*/
|
||||
std::string get_mention() const;
|
||||
|
||||
/**
|
||||
* @brief Get the overall permissions for a member in this channel, including channel overwrites, role permissions and admin privileges.
|
||||
*
|
||||
* @param user The user to resolve the permissions for
|
||||
* @return permission Permission overwrites for the member. Made of bits in dpp::permissions.
|
||||
* @note Requires role cache to be enabled (it's enabled by default).
|
||||
*
|
||||
* @note This is an alias for guild::permission_overwrites and searches for the guild in the cache,
|
||||
* so consider using guild::permission_overwrites if you already have the guild object.
|
||||
*
|
||||
* @warning The method will search for the guild member in the cache by the users id.
|
||||
* If the guild member is not in cache, the method will always return 0.
|
||||
*/
|
||||
permission get_user_permissions(const class user* user) const;
|
||||
|
||||
/**
|
||||
* @brief Get the overall permissions for a member in this channel, including channel overwrites, role permissions and admin privileges.
|
||||
*
|
||||
* @param member The member to resolve the permissions for
|
||||
* @return permission Permission overwrites for the member. Made of bits in dpp::permissions.
|
||||
* @note Requires role cache to be enabled (it's enabled by default).
|
||||
*
|
||||
* @note This is an alias for guild::permission_overwrites and searches for the guild in the cache,
|
||||
* so consider using guild::permission_overwrites if you already have the guild object.
|
||||
*/
|
||||
permission get_user_permissions(const class guild_member &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.
|
||||
* @note If the guild this channel belongs to is not in the cache, the function will always return 0.
|
||||
*/
|
||||
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 Get the channel's icon url (if its a group DM), otherwise returns an empty string
|
||||
*
|
||||
* @param size The size of the icon in pixels. It can be any power of two between 16 and 4096,
|
||||
* otherwise the default sized icon is returned.
|
||||
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg` or `i_png`.
|
||||
* @return std::string icon url or an empty string, if required attributes are missing or an invalid format was passed
|
||||
*/
|
||||
std::string get_icon_url(uint16_t size = 0, const image_type format = i_png) const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is NSFW gated
|
||||
*
|
||||
* @return true if NSFW
|
||||
*/
|
||||
bool is_nsfw() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the permissions are to be synced with the category it is in.
|
||||
* Used only and set manually when using the reorder channels method.
|
||||
*
|
||||
* @return true if keeping permissions
|
||||
*/
|
||||
bool is_locked_permissions() 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 forum
|
||||
*
|
||||
* @return true if a forum
|
||||
*/
|
||||
bool is_forum() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is an announcement channel
|
||||
*
|
||||
* @return true if announcement channel
|
||||
*/
|
||||
bool is_news_channel() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a store channel
|
||||
* @deprecated store channels are deprecated by Discord
|
||||
*
|
||||
* @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 Returns true if video quality is auto
|
||||
*
|
||||
* @return true if video quality is auto
|
||||
*/
|
||||
bool is_video_auto() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if video quality is 720p
|
||||
*
|
||||
* @return true if video quality is 720p
|
||||
*/
|
||||
bool is_video_720p() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if channel is a pinned thread in forum
|
||||
*
|
||||
* @return true, if channel is a pinned thread in forum
|
||||
*/
|
||||
bool is_pinned_thread() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if a tag is required to be specified when creating a thread in a forum channel
|
||||
*
|
||||
* @return true, if a tag is required to be specified when creating a thread in a forum channel
|
||||
*/
|
||||
bool is_tag_required() const;
|
||||
|
||||
};
|
||||
|
||||
/** @brief A definition of a discord thread.
|
||||
* A thread is a superset of a channel. Not to be confused with `std::thread`!
|
||||
*/
|
||||
class DPP_EXPORT thread : public channel {
|
||||
public:
|
||||
/**
|
||||
* @brief Thread member of current user if joined to the thread.
|
||||
* Note this is only set by certain api calls otherwise contains default data
|
||||
*/
|
||||
thread_member member;
|
||||
|
||||
/** Thread metadata (threads) */
|
||||
thread_metadata metadata;
|
||||
|
||||
/** Created message. Only filled within the cluster::thread_create_in_forum() method */
|
||||
message msg;
|
||||
|
||||
/**
|
||||
* A list of dpp::forum_tag IDs that have been applied to a thread in a forum channel
|
||||
*/
|
||||
std::vector<snowflake> applied_tags;
|
||||
|
||||
/**
|
||||
* @brief Number of messages ever sent in the thread.
|
||||
* It's similar to thread::message_count on message creation, but will not decrement the number when a message is deleted
|
||||
*/
|
||||
uint32_t total_messages_sent;
|
||||
|
||||
/**
|
||||
* @brief Number of messages (not including the initial message or deleted messages) of the thread.
|
||||
* For threads created before July 1, 2022, the message count is inaccurate when it's greater than 50.
|
||||
*/
|
||||
uint8_t message_count;
|
||||
|
||||
/** Approximate count of members in a thread (stops counting at 50) */
|
||||
uint8_t member_count;
|
||||
|
||||
/**
|
||||
* @brief Construct a new thread object
|
||||
*/
|
||||
thread();
|
||||
|
||||
/**
|
||||
* @brief Returns true if the thread is within an announcement channel
|
||||
*
|
||||
* @return true if announcement thread
|
||||
*/
|
||||
bool is_news_thread() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a public thread
|
||||
*
|
||||
* @return true if public thread
|
||||
*/
|
||||
bool is_public_thread() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the channel is a private thread
|
||||
*
|
||||
* @return true if private thread
|
||||
*/
|
||||
bool is_private_thread() const;
|
||||
|
||||
/** Read class values from json object
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
thread& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Destroy the thread object
|
||||
*/
|
||||
virtual ~thread();
|
||||
|
||||
/**
|
||||
* @brief Build json for this thread 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 Serialize a thread_metadata object to json
|
||||
*
|
||||
* @param j JSON object to serialize to
|
||||
* @param tmdata object to serialize
|
||||
*/
|
||||
void to_json(nlohmann::json& j, const thread_metadata& tmdata);
|
||||
|
||||
/**
|
||||
* @brief Serialize a permission_overwrite object to json
|
||||
*
|
||||
* @param j JSON object to serialize to
|
||||
* @param po object to serialize
|
||||
*/
|
||||
void to_json(nlohmann::json& j, const permission_overwrite& po);
|
||||
|
||||
/**
|
||||
* @brief A group of channels
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, channel> channel_map;
|
||||
|
||||
/**
|
||||
* @brief A group of threads
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, thread> thread_map;
|
||||
|
||||
};
|
||||
|
3360
vendor/DPP/include/dpp/cluster.h
vendored
Normal file
3360
vendor/DPP/include/dpp/cluster.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2317
vendor/DPP/include/dpp/cluster_coro_calls.h
vendored
Normal file
2317
vendor/DPP/include/dpp/cluster_coro_calls.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
2523
vendor/DPP/include/dpp/cluster_sync_calls.h
vendored
Normal file
2523
vendor/DPP/include/dpp/cluster_sync_calls.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
435
vendor/DPP/include/dpp/collector.h
vendored
Normal file
435
vendor/DPP/include/dpp/collector.h
vendored
Normal file
@ -0,0 +1,435 @@
|
||||
/*
|
||||
* Discord erlpack - tidied up for D++, Craig Edwards 2021.
|
||||
*
|
||||
* MessagePack system dependencies modified for erlpack.
|
||||
*
|
||||
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
*
|
||||
* 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/cluster.h>
|
||||
#include <dpp/timed_listener.h>
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Collects objects from events during a specified time period.
|
||||
*
|
||||
* This template must be specialised. There are premade specialisations which you can use
|
||||
* such as dpp::reaction_collector and dpp::message_collector. For these specialised instances
|
||||
* all you need to do is derive a simple class from them which implements collector::completed().
|
||||
*
|
||||
* A collector will run for the specified number of seconds, attaching itself to the
|
||||
* given event. During this time any events pass through the collector and collector::filter().
|
||||
* This function can return a pointer to an object to allow a copy of that object to be stored
|
||||
* to a vector, or it can return nullptr to do nothing with that object. For example a collector
|
||||
* attached to on_message_create would receive an event with the type message_create_t, and from
|
||||
* this may decide to extract the message_create_t::msg structure, returning a pointer to it, or
|
||||
* instead may choose to return a nullptr.
|
||||
*
|
||||
* When either the predetermined timeout is reached, or the collector::cancel() method is called,
|
||||
* or the collector is destroyed, the collector::completed() method is called, which will be
|
||||
* passed a list of collected objects in the order they were collected.
|
||||
*
|
||||
* @tparam T parameter type of the event this collector will monitor
|
||||
* @tparam C object type this collector will store
|
||||
*/
|
||||
template<class T, class C> class collector
|
||||
{
|
||||
protected:
|
||||
/// Owning cluster
|
||||
class cluster* owner;
|
||||
private:
|
||||
/// Timed listener
|
||||
timed_listener<event_router_t<T>, std::function<void(const T&)>>* tl;
|
||||
/// stored list
|
||||
std::vector<C> stored;
|
||||
/// Trigger flag
|
||||
bool triggered;
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new collector object.
|
||||
*
|
||||
* The timer for the collector begins immediately on construction of the object.
|
||||
*
|
||||
* @param cl Pointer to cluster which manages this collector
|
||||
* @param duration Duration in seconds to run the collector for
|
||||
* @param event Event to attach to, e.g. cluster::on_message_create
|
||||
*/
|
||||
collector(class cluster* cl, uint64_t duration, event_router_t<T> & event) : owner(cl), triggered(false) {
|
||||
std::function<void(const T&)> f = [this](const T& event) {
|
||||
const C* v = filter(event);
|
||||
if (v) {
|
||||
stored.push_back(*v);
|
||||
}
|
||||
};
|
||||
tl = new dpp::timed_listener<event_router_t<T>, std::function<void(const T&)>>(cl, duration, event, f, [this](dpp::timer timer_handle) {
|
||||
if (!triggered) {
|
||||
triggered = true;
|
||||
completed(stored);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief You must implement this function to receive the completed list of
|
||||
* captured objects.
|
||||
* @param list The list of captured objects in captured order
|
||||
*/
|
||||
virtual void completed(const std::vector<C>& list) = 0;
|
||||
|
||||
/**
|
||||
* @brief Filter the list of elements.
|
||||
*
|
||||
* Every time an event is fired on the collector, this method wil be called
|
||||
* to determine if we should add an object to the list or not. This function
|
||||
* can then process the `element` value, extract the parts which are to be
|
||||
* saved to a list (e.g. a dpp::message out of a dpp::message_create_t) and
|
||||
* return it as the return value. Returning a value of nullptr causes no
|
||||
* object to be stored.
|
||||
*
|
||||
* Here is an example of how to filter messages which have specific text in them.
|
||||
* This should be used with the specialised type dpp::message_collector
|
||||
*
|
||||
* ```cpp
|
||||
* virtual const dpp::message* filter(const dpp::message_create_t& m) {
|
||||
* if (m.msg.content.find("something i want") != std::string::npos) {
|
||||
* return &m.msg;
|
||||
* } else {
|
||||
* return nullptr;
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @param element The event data to filter
|
||||
* @return const C* Returned object or nullptr
|
||||
*/
|
||||
virtual const C* filter(const T& element) = 0;
|
||||
|
||||
/**
|
||||
* @brief Immediately cancels the collector.
|
||||
*
|
||||
* Use this if you have met the conditions for which you are collecting objects
|
||||
* early, e.g. you were watching for a message containing 'yes' or 'no' and have
|
||||
* received it before the time is up.
|
||||
*
|
||||
* @note Causes calling of the completed() method if it has not yet been called.
|
||||
*/
|
||||
virtual void cancel() {
|
||||
delete tl;
|
||||
tl = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroy the collector object.
|
||||
* @note Causes calling of the completed() method if it has not yet been called.
|
||||
*/
|
||||
virtual ~collector() {
|
||||
delete tl;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a reaction.
|
||||
* Can be filled for use in a collector
|
||||
*/
|
||||
class collected_reaction : public managed {
|
||||
public:
|
||||
/// Reacting user
|
||||
user react_user;
|
||||
/// Reacting guild
|
||||
guild* react_guild{};
|
||||
/// Reacting guild member
|
||||
guild_member react_member;
|
||||
/// Reacting channel
|
||||
channel* react_channel{};
|
||||
/// Reacted emoji
|
||||
emoji react_emoji;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Template type for base class of channel collector
|
||||
*/
|
||||
typedef dpp::collector<dpp::channel_create_t, dpp::channel> channel_collector_t;
|
||||
|
||||
/**
|
||||
* @brief Template type for base class of thread collector
|
||||
*/
|
||||
typedef dpp::collector<dpp::thread_create_t, dpp::thread> thread_collector_t;
|
||||
|
||||
/**
|
||||
* @brief Template type for base class of role collector
|
||||
*/
|
||||
typedef dpp::collector<dpp::guild_role_create_t, dpp::role> role_collector_t;
|
||||
|
||||
/**
|
||||
* @brief Template type for base class of scheduled event collector
|
||||
*/
|
||||
typedef dpp::collector<dpp::guild_scheduled_event_create_t, dpp::scheduled_event> scheduled_event_collector_t;
|
||||
|
||||
/**
|
||||
* @brief Template type for base class of message collector
|
||||
*/
|
||||
typedef dpp::collector<dpp::message_create_t, dpp::message> message_collector_t;
|
||||
|
||||
/**
|
||||
* @brief Template type for base class of message reaction collector
|
||||
*/
|
||||
typedef dpp::collector<dpp::message_reaction_add_t, dpp::collected_reaction> reaction_collector_t;
|
||||
|
||||
/**
|
||||
* @brief Message collector.
|
||||
* Collects messages during a set timeframe and returns them in a list via the completed() method.
|
||||
*/
|
||||
class message_collector : public message_collector_t {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new message collector object
|
||||
*
|
||||
* @param cl cluster to associate the collector with
|
||||
* @param duration Duration of time to run the collector for in seconds
|
||||
*/
|
||||
message_collector(cluster* cl, uint64_t duration) : message_collector_t::collector(cl, duration, cl->on_message_create) { }
|
||||
|
||||
/**
|
||||
* @brief Return the completed collection
|
||||
*
|
||||
* @param list items collected during the timeframe specified
|
||||
*/
|
||||
virtual void completed(const std::vector<dpp::message>& list) = 0;
|
||||
|
||||
/**
|
||||
* @brief Select and filter the items which are to appear in the list
|
||||
* This is called every time a new event is fired, to filter the event and determine which
|
||||
* of the items is sent to the list. Returning nullptr excludes the item from the list.
|
||||
*
|
||||
* @param element element to filter
|
||||
* @return Returned item to add to the list, or nullptr to skip adding this element
|
||||
*/
|
||||
virtual const dpp::message* filter(const dpp::message_create_t& element) { return &element.msg; }
|
||||
|
||||
/**
|
||||
* @brief Destroy the message collector object
|
||||
*/
|
||||
virtual ~message_collector() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Reaction collector.
|
||||
* Collects message reactions during a set timeframe and returns them in a list via the completed() method.
|
||||
*/
|
||||
class reaction_collector : public reaction_collector_t {
|
||||
snowflake message_id;
|
||||
collected_reaction react;
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new reaction collector object
|
||||
*
|
||||
* @param cl cluster to associate the collector with
|
||||
* @param duration Duration of time to run the collector for in seconds
|
||||
* @param msg_id Optional message ID. If specified, only collects reactions for the given message
|
||||
*/
|
||||
reaction_collector(cluster* cl, uint64_t duration, snowflake msg_id = 0) : reaction_collector_t::collector(cl, duration, cl->on_message_reaction_add), message_id(msg_id) { }
|
||||
|
||||
/**
|
||||
* @brief Return the completed collection
|
||||
*
|
||||
* @param list items collected during the timeframe specified
|
||||
*/
|
||||
virtual void completed(const std::vector<dpp::collected_reaction>& list) = 0;
|
||||
|
||||
/**
|
||||
* @brief Select and filter the items which are to appear in the list
|
||||
* This is called every time a new event is fired, to filter the event and determine which
|
||||
* of the items is sent to the list. Returning nullptr excludes the item from the list.
|
||||
*
|
||||
* @param element element to filter
|
||||
* @return Returned item to add to the list, or nullptr to skip adding this element
|
||||
*/
|
||||
virtual const dpp::collected_reaction* filter(const dpp::message_reaction_add_t& element) {
|
||||
/* Capture reactions for given message ID only */
|
||||
if (message_id.empty() || element.message_id == message_id) {
|
||||
react.id = element.message_id;
|
||||
react.react_user = element.reacting_user;
|
||||
react.react_guild = element.reacting_guild;
|
||||
react.react_member = element.reacting_member;
|
||||
react.react_channel = element.reacting_channel;
|
||||
react.react_emoji = element.reacting_emoji;
|
||||
return &react;
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroy the reaction collector object
|
||||
*/
|
||||
virtual ~reaction_collector() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Channel collector.
|
||||
* Collects channels during a set timeframe and returns them in a list via the completed() method.
|
||||
*/
|
||||
class channel_collector : public channel_collector_t {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new channel collector object
|
||||
*
|
||||
* @param cl cluster to associate the collector with
|
||||
* @param duration Duration of time to run the collector for in seconds
|
||||
*/
|
||||
channel_collector(cluster* cl, uint64_t duration) : channel_collector_t::collector(cl, duration, cl->on_channel_create) { }
|
||||
|
||||
/**
|
||||
* @brief Return the completed collection
|
||||
*
|
||||
* @param list items collected during the timeframe specified
|
||||
*/
|
||||
virtual void completed(const std::vector<dpp::channel>& list) = 0;
|
||||
|
||||
/**
|
||||
* @brief Select and filter the items which are to appear in the list
|
||||
* This is called every time a new event is fired, to filter the event and determine which
|
||||
* of the items is sent to the list. Returning nullptr excludes the item from the list.
|
||||
*
|
||||
* @param element element to filter
|
||||
* @return Returned item to add to the list, or nullptr to skip adding this element
|
||||
*/
|
||||
virtual const dpp::channel* filter(const dpp::channel_create_t& element) { return element.created; }
|
||||
|
||||
/**
|
||||
* @brief Destroy the channel collector object
|
||||
*/
|
||||
virtual ~channel_collector() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Thread collector.
|
||||
* Collects threads during a set timeframe and returns them in a list via the completed() method.
|
||||
*/
|
||||
class thread_collector : public thread_collector_t {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new thread collector object
|
||||
*
|
||||
* @param cl cluster to associate the collector with
|
||||
* @param duration Duration of time to run the collector for in seconds
|
||||
*/
|
||||
thread_collector(cluster* cl, uint64_t duration) : thread_collector_t::collector(cl, duration, cl->on_thread_create) { }
|
||||
|
||||
/**
|
||||
* @brief Return the completed collection
|
||||
*
|
||||
* @param list items collected during the timeframe specified
|
||||
*/
|
||||
virtual void completed(const std::vector<dpp::thread>& list) = 0;
|
||||
|
||||
/**
|
||||
* @brief Select and filter the items which are to appear in the list
|
||||
* This is called every time a new event is fired, to filter the event and determine which
|
||||
* of the items is sent to the list. Returning nullptr excludes the item from the list.
|
||||
*
|
||||
* @param element element to filter
|
||||
* @return Returned item to add to the list, or nullptr to skip adding this element
|
||||
*/
|
||||
virtual const dpp::thread* filter(const dpp::thread_create_t& element) { return &element.created; }
|
||||
|
||||
/**
|
||||
* @brief Destroy the thread collector object
|
||||
*/
|
||||
virtual ~thread_collector() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Role collector.
|
||||
* Collects guild roles during a set timeframe and returns them in a list via the completed() method.
|
||||
*/
|
||||
class role_collector : public role_collector_t {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new role collector object
|
||||
*
|
||||
* @param cl cluster to associate the collector with
|
||||
* @param duration Duration of time to run the collector for in seconds
|
||||
*/
|
||||
role_collector(cluster* cl, uint64_t duration) : role_collector_t::collector(cl, duration, cl->on_guild_role_create) { }
|
||||
|
||||
/**
|
||||
* @brief Return the completed collection
|
||||
*
|
||||
* @param list items collected during the timeframe specified
|
||||
*/
|
||||
virtual void completed(const std::vector<dpp::role>& list) = 0;
|
||||
|
||||
/**
|
||||
* @brief Select and filter the items which are to appear in the list
|
||||
* This is called every time a new event is fired, to filter the event and determine which
|
||||
* of the items is sent to the list. Returning nullptr excludes the item from the list.
|
||||
*
|
||||
* @param element element to filter
|
||||
* @return Returned item to add to the list, or nullptr to skip adding this element
|
||||
*/
|
||||
virtual const dpp::role* filter(const dpp::guild_role_create_t& element) { return element.created; }
|
||||
|
||||
/**
|
||||
* @brief Destroy the role collector object
|
||||
*/
|
||||
virtual ~role_collector() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Scheduled event collector.
|
||||
* Collects messages during a set timeframe and returns them in a list via the completed() method.
|
||||
*/
|
||||
class scheduled_event_collector : public scheduled_event_collector_t {
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new scheduled event collector object
|
||||
*
|
||||
* @param cl cluster to associate the collector with
|
||||
* @param duration Duration of time to run the collector for in seconds
|
||||
*/
|
||||
scheduled_event_collector(cluster* cl, uint64_t duration) : scheduled_event_collector_t::collector(cl, duration, cl->on_guild_scheduled_event_create) { }
|
||||
|
||||
/**
|
||||
* @brief Return the completed collection
|
||||
*
|
||||
* @param list items collected during the timeframe specified
|
||||
*/
|
||||
virtual void completed(const std::vector<dpp::scheduled_event>& list) = 0;
|
||||
|
||||
/**
|
||||
* @brief Select and filter the items which are to appear in the list
|
||||
* This is called every time a new event is fired, to filter the event and determine which
|
||||
* of the items is sent to the list. Returning nullptr excludes the item from the list.
|
||||
*
|
||||
* @param element element to filter
|
||||
* @return Returned item to add to the list, or nullptr to skip adding this element
|
||||
*/
|
||||
virtual const dpp::scheduled_event* filter(const dpp::guild_scheduled_event_create_t& element) { return &element.created; }
|
||||
|
||||
/**
|
||||
* @brief Destroy the scheduled event collector object
|
||||
*/
|
||||
virtual ~scheduled_event_collector() = default;
|
||||
};
|
||||
|
||||
};
|
80
vendor/DPP/include/dpp/colors.h
vendored
Normal file
80
vendor/DPP/include/dpp/colors.h
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <cstdint>
|
||||
|
||||
/**
|
||||
* @brief The main namespace for D++ functions. classes and types
|
||||
*/
|
||||
namespace dpp {
|
||||
/**
|
||||
* @brief predefined color constants
|
||||
*/
|
||||
namespace colors {
|
||||
const uint32_t
|
||||
white = 0xFFFFFF,
|
||||
discord_white = 0xFFFFFE,
|
||||
light_gray = 0xC0C0C0,
|
||||
gray = 0x808080,
|
||||
dark_gray = 0x404040,
|
||||
black = 0x000000,
|
||||
discord_black = 0x000001,
|
||||
red = 0xFF0000,
|
||||
pink = 0xFFAFAF,
|
||||
orange = 0xFFC800,
|
||||
yellow = 0xFFFF00,
|
||||
green = 0x00FF00,
|
||||
magenta = 0xFF00FF,
|
||||
cyan = 0x00FFFF,
|
||||
blue = 0x0000FF,
|
||||
light_sea_green = 0x1ABC9C,
|
||||
medium_sea_green = 0x2ECC71,
|
||||
summer_sky = 0x3498DB,
|
||||
deep_lilac = 0x9B59B6,
|
||||
ruby = 0xE91E63,
|
||||
moon_yellow = 0xF1C40F,
|
||||
tahiti_gold = 0xE67E22,
|
||||
cinnabar = 0xE74C3C,
|
||||
submarine = 0x95A5A6,
|
||||
blue_aquamarine = 0x607D8B,
|
||||
deep_sea = 0x11806A,
|
||||
sea_green = 0x1F8B4C,
|
||||
endeavour = 0x206694,
|
||||
vivid_violet = 0x71368A,
|
||||
jazzberry_jam = 0xAD1457,
|
||||
dark_goldenrod = 0xC27C0E,
|
||||
rust = 0xA84300,
|
||||
brown = 0x992D22,
|
||||
gray_chateau = 0x979C9F,
|
||||
bismark = 0x546E7A,
|
||||
sti_blue = 0x0E4BEF,
|
||||
wrx_blue = 0x00247D,
|
||||
rallyart_crimson = 0xE60012,
|
||||
lime = 0x00FF00,
|
||||
forest_green = 0x228B22,
|
||||
cadmium_green = 0x097969,
|
||||
aquamarine = 0x7FFFD4,
|
||||
blue_green = 0x088F8F,
|
||||
raspberry = 0xE30B5C,
|
||||
scarlet_red = 0xFF2400;
|
||||
};
|
||||
};
|
392
vendor/DPP/include/dpp/commandhandler.h
vendored
Normal file
392
vendor/DPP/include/dpp/commandhandler.h
vendored
Normal file
@ -0,0 +1,392 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/misc-enum.h>
|
||||
#include <dpp/user.h>
|
||||
#include <dpp/guild.h>
|
||||
#include <dpp/role.h>
|
||||
#include <dpp/appcommand.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/utility.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/event_router.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <variant>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief dpp::resolved_user contains both a dpp::guild_member and a dpp::user.
|
||||
* The user can be used to obtain in-depth user details such as if they are nitro,
|
||||
* and the guild member information to check their roles on a guild etc.
|
||||
* The Discord API provides both if a parameter is a user ping,
|
||||
* so we offer both in a combined structure.
|
||||
*/
|
||||
struct DPP_EXPORT resolved_user {
|
||||
/**
|
||||
* @brief Holds user information
|
||||
*/
|
||||
dpp::user user;
|
||||
/**
|
||||
* @brief Holds member information
|
||||
*/
|
||||
dpp::guild_member member;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a received parameter.
|
||||
* We use variant so that multiple non-related types can be contained within.
|
||||
*/
|
||||
typedef std::variant<std::monostate, std::string, dpp::role, dpp::channel, dpp::resolved_user, int64_t, bool, double> 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, //!< 64 bit signed integer
|
||||
pt_double, //!< double floating point
|
||||
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 DPP_EXPORT 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<command_value, 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<command_value, 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 doesn't guarantee any order at all) and
|
||||
* std::map, which reorders keys alphabetically.
|
||||
*/
|
||||
typedef std::vector<std::pair<std::string, param_info>> parameter_registration_t;
|
||||
|
||||
/**
|
||||
* @brief Parameter list for a called command.
|
||||
* See dpp::parameter_registration_t for an explanation as to why vector is used.
|
||||
*/
|
||||
typedef std::vector<std::pair<std::string, command_parameter>> parameter_list_t;
|
||||
|
||||
/**
|
||||
* @brief Represents the sending source of a command.
|
||||
* This is passed to any command handler and should be passed back to
|
||||
* commandhandler::reply(), allowing the reply method to route any replies back
|
||||
* to the origin, which may be a slash command or a message. Both require different
|
||||
* response facilities but we want this to be transparent if you use the command
|
||||
* handler class.
|
||||
* @deprecated commandhandler and message commands are deprecated and dpp::slashcommand is encouraged as a replacement.
|
||||
*/
|
||||
struct DPP_EXPORT command_source {
|
||||
/**
|
||||
* @brief Sending guild id
|
||||
*/
|
||||
snowflake guild_id;
|
||||
/**
|
||||
* @brief Source channel id
|
||||
*/
|
||||
snowflake channel_id;
|
||||
/**
|
||||
* @brief Command ID of a slash command
|
||||
*/
|
||||
snowflake command_id;
|
||||
/**
|
||||
* @brief Token for sending a slash command reply
|
||||
*/
|
||||
std::string command_token;
|
||||
/**
|
||||
* @brief The user who issued the command
|
||||
*/
|
||||
user issuer;
|
||||
|
||||
/**
|
||||
* @brief Copy of the underlying message_create_t event, if it was a message create event
|
||||
*/
|
||||
std::optional<message_create_t> message_event;
|
||||
|
||||
/**
|
||||
* @brief Copy of the underlying interaction_create_t event, if it was an interaction create event
|
||||
*/
|
||||
std::optional<interaction_create_t> interaction_event;
|
||||
|
||||
/**
|
||||
* @brief Construct a command_source object from a message_create_t event
|
||||
*/
|
||||
command_source(const struct message_create_t& event);
|
||||
|
||||
/**
|
||||
* @brief Construct a command_source object from an interaction_create_t event
|
||||
*/
|
||||
command_source(const struct interaction_create_t& event);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The function definition for a command handler. Expects a command name string,
|
||||
* and a list of command parameters.
|
||||
* @deprecated commandhandler and message commands are deprecated and dpp::slashcommand is encouraged as a replacement.
|
||||
*/
|
||||
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.
|
||||
* @deprecated commandhandler and message commands are deprecated and dpp::slashcommand is encouraged as a replacement.
|
||||
*/
|
||||
struct DPP_EXPORT 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.
|
||||
*
|
||||
* It can automatically register slash commands, and handle routing of messages and interactions to separated command handler
|
||||
* functions.
|
||||
* @deprecated commandhandler and message commands are deprecated and dpp::slashcommand is encouraged as a replacement.
|
||||
*/
|
||||
class DPP_EXPORT commandhandler {
|
||||
private:
|
||||
/**
|
||||
* @brief List of guild commands to bulk register
|
||||
*/
|
||||
std::map<dpp::snowflake, std::vector<dpp::slashcommand>> bulk_registration_list_guild;
|
||||
/**
|
||||
* @brief List of global commands to bulk register
|
||||
*/
|
||||
std::vector<dpp::slashcommand> bulk_registration_list_global;
|
||||
public:
|
||||
/**
|
||||
* @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 Interaction event handle
|
||||
*/
|
||||
event_handle interactions;
|
||||
|
||||
/**
|
||||
* @brief Message event handle
|
||||
*/
|
||||
event_handle messages;
|
||||
|
||||
/**
|
||||
* @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_slashcommand
|
||||
* and on_message events. You should not need to set this to false unless you have a specific
|
||||
* use case, as D++ supports multiple listeners to an event, so will allow the commandhandler
|
||||
* to hook to your command events without disrupting other uses for the events you may have.
|
||||
* @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
|
||||
* @param description The description of the command, shown for slash commands
|
||||
* @param guild_id The guild ID to restrict the command to. For slash commands causes registration of a guild command as opposed to a global command.
|
||||
* @return commandhandler& reference to self
|
||||
* @throw dpp::logic_exception if application ID cannot be determined
|
||||
*/
|
||||
commandhandler& add_command(const std::string &command, const parameter_registration_t ¶meters, command_handler handler, const std::string &description = "", snowflake guild_id = 0);
|
||||
|
||||
/**
|
||||
* @brief Register all slash commands with Discord
|
||||
* This method must be called at least once if you are using the "/" prefix to mark the
|
||||
* end of commands being added to the handler. Note that this uses bulk registration and will replace any
|
||||
* existing slash commands.
|
||||
*
|
||||
* Note that if you have previously registered your commands and they have not changed, you do
|
||||
* not need to call this again. Discord retains a cache of previously added commands.
|
||||
*
|
||||
* @return commandhandler& Reference to self for chaining method calls
|
||||
*/
|
||||
commandhandler& register_commands();
|
||||
|
||||
/**
|
||||
* @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 if you have disabled automatic registration of events.
|
||||
*
|
||||
* @param event message create event to parse
|
||||
*/
|
||||
void route(const struct dpp::message_create_t& event);
|
||||
|
||||
/**
|
||||
* @brief Route a command from the on_slashcommand function.
|
||||
* Call this method from your on_slashcommand with the received
|
||||
* dpp::interaction_create_t object if you have disabled automatic registration of events.
|
||||
*
|
||||
* @param event command interaction event to parse
|
||||
*/
|
||||
void route(const struct slashcommand_t & event);
|
||||
|
||||
/**
|
||||
* @brief Reply to a command.
|
||||
* You should use this method rather than cluster::message_create as
|
||||
* the way you reply varies between slash commands and message commands.
|
||||
* Note you should ALWAYS reply. Slash commands will emit an ugly error
|
||||
* to the user if you do not emit some form of reply within 3 seconds.
|
||||
*
|
||||
* @param m message to reply with.
|
||||
* @param source source of the command
|
||||
* @param callback User function to execute when the api call completes.
|
||||
*/
|
||||
void reply(const dpp::message &m, command_source source, command_completion_event_t callback = utility::log_error());
|
||||
|
||||
/**
|
||||
* @brief Reply to a command without a message, causing the discord client
|
||||
* to display "Bot name is thinking...".
|
||||
* The "thinking" message will persist for a maximum of 15 minutes.
|
||||
* This counts as a reply for a slash command. Slash commands will emit an
|
||||
* ugly error to the user if you do not emit some form of reply within 3
|
||||
* seconds.
|
||||
*
|
||||
* @param source source of the command
|
||||
* @param callback User function to execute when the api call completes.
|
||||
*/
|
||||
void thinking(command_source source, command_completion_event_t callback = utility::log_error());
|
||||
|
||||
/* Easter egg */
|
||||
void thonk(command_source source, command_completion_event_t callback = utility::log_error());
|
||||
|
||||
};
|
||||
|
||||
};
|
158
vendor/DPP/include/dpp/coro.h
vendored
Normal file
158
vendor/DPP/include/dpp/coro.h
vendored
Normal file
@ -0,0 +1,158 @@
|
||||
#ifdef DPP_CORO
|
||||
#pragma once
|
||||
#include <coroutine>
|
||||
#include <dpp/restresults.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Shorthand for the coroutine handle's type
|
||||
*/
|
||||
using handle_type = std::coroutine_handle<struct promise>;
|
||||
|
||||
class cluster;
|
||||
|
||||
/**
|
||||
* @brief Return type for coroutines
|
||||
*/
|
||||
struct task {
|
||||
/**
|
||||
* @brief Required nested promise_type for coroutines
|
||||
*/
|
||||
using promise_type = dpp::promise;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Implementation of promise_type for dpp's coroutines
|
||||
*/
|
||||
struct promise {
|
||||
/**
|
||||
* @brief A pointer to the cluster making the requests in the coroutine
|
||||
*/
|
||||
cluster* bot = nullptr;
|
||||
|
||||
/**
|
||||
* @brief The result of the last co_await-ed function
|
||||
*/
|
||||
confirmation_callback_t callback;
|
||||
|
||||
/**
|
||||
* @brief Construct a new promise object
|
||||
*/
|
||||
promise() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new promise object
|
||||
*
|
||||
* @param ev Base type of all events, only used to get the dpp::cluster pointer
|
||||
*/
|
||||
promise(const dpp::event_dispatch_t& ev) : bot(ev.from->creator) { }
|
||||
|
||||
/**
|
||||
* @brief Get the return object
|
||||
*
|
||||
* @return task dpp::task type
|
||||
*/
|
||||
task get_return_object() {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function called when the coroutine is first suspended, never suspends
|
||||
*
|
||||
* @return std::suspend_never Never suspend this coroutine at the first suspend point
|
||||
*/
|
||||
std::suspend_never initial_suspend() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function called when the coroutine reaches its last suspension point
|
||||
*
|
||||
* @return std::suspend_never Never suspend this coroutine at the final suspend point
|
||||
*/
|
||||
std::suspend_never final_suspend() noexcept {
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function called when the coroutine returns nothing
|
||||
*/
|
||||
void return_void() noexcept {}
|
||||
|
||||
/**
|
||||
* @brief Function called when coroutine throws a un-catch-ed exception. Does nothing
|
||||
*/
|
||||
void unhandled_exception() {
|
||||
/* try { std::rethrow_exception(std::current_exception()); } */
|
||||
/* catch (const std::exception& e) { std::cout << e.what() << '\n'; } */
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A co_await-able struct which returns the result of stored api call when co_await-ed. Meant to be opaque to the user
|
||||
*
|
||||
* @tparam T The type of the function (lambda if auto-generated by the php script) handling the making of api call
|
||||
*/
|
||||
template <typename T>
|
||||
struct awaitable {
|
||||
/**
|
||||
* @brief Pointer to the nested promise object of the coroutine, used for storing and retrieving the result of an api call
|
||||
*/
|
||||
promise* p;
|
||||
|
||||
/**
|
||||
* @brief Pointer to the cluster making the api request
|
||||
*/
|
||||
cluster* bot;
|
||||
|
||||
/**
|
||||
* @brief The function handling the making of request, using the cluster pointer
|
||||
*/
|
||||
T api_req;
|
||||
|
||||
/**
|
||||
* @brief Construct a new awaitable object
|
||||
*
|
||||
* @param cl pointer to the cluster making the api request
|
||||
* @param api_call a function to invoke with the cluster pointer, handles the making of request
|
||||
*/
|
||||
awaitable(cluster* cl, T api_call) : bot{cl}, api_req{api_call} {}
|
||||
|
||||
/**
|
||||
* @brief First function called when this object is co_await-ed, its return type tells if the coroutine should be immediately suspended
|
||||
*
|
||||
* @return bool false, signifying immediate suspension
|
||||
*/
|
||||
bool await_ready() noexcept {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function called when the coroutine is suspended, makes the api request and queues the resumption of the suspended coroutine, storing the result in promise object
|
||||
*
|
||||
* @param handle the handle to the suspended coroutine
|
||||
*/
|
||||
void await_suspend(handle_type handle) {
|
||||
/* p = &handle.promise(); */
|
||||
/* if (!p->bot) p->bot = bot; */
|
||||
api_req([handle](const confirmation_callback_t& cback) { handle.promise().callback = cback; handle.resume(); });
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Function called when the coroutine is resumed by its handle, handles the retrieval and return of result from promise object
|
||||
*
|
||||
* @return confirmation_callback_t the result of the api call
|
||||
*/
|
||||
confirmation_callback_t await_resume() {
|
||||
return p->callback;
|
||||
}
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
/* template<> */
|
||||
/* struct std::coroutine_traits<void, const dpp::interaction_create_t&> { */
|
||||
/* using promise_type = dpp::promise; */
|
||||
/* }; */
|
||||
#endif
|
525
vendor/DPP/include/dpp/discordclient.h
vendored
Normal file
525
vendor/DPP/include/dpp/discordclient.h
vendored
Normal file
@ -0,0 +1,525 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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.h>
|
||||
#include <dpp/wsclient.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/event.h>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#define DISCORD_API_VERSION "10"
|
||||
#define API_PATH "/api/v" DISCORD_API_VERSION
|
||||
namespace dpp {
|
||||
|
||||
// Forward declarations
|
||||
class cluster;
|
||||
|
||||
/**
|
||||
* @brief This is an opaque class containing zlib library specific structures.
|
||||
* We define it this way so that the public facing D++ library doesn't 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 DPP_EXPORT 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 hostname, token and session_id to be set or does nothing.
|
||||
*
|
||||
* @param guild_id Guild to connect to the voice channel on
|
||||
* @return reference to self
|
||||
* @note It can spawn a thread to establish the connection, so this is NOT a synchronous blocking call!
|
||||
* You shouldn't call this directly. Use a wrapper function instead. e.g. dpp::guild::connect_member_voice
|
||||
*/
|
||||
voiceconn& connect(snowflake guild_id);
|
||||
|
||||
/**
|
||||
* @brief Disconnect from the currently connected voice channel
|
||||
* @return reference to self
|
||||
*/
|
||||
voiceconn& disconnect();
|
||||
};
|
||||
|
||||
/** @brief Implements a discord client. Each discord_client connects to one shard and derives from a websocket client. */
|
||||
class DPP_EXPORT discord_client : public websocket_client
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
* @brief Needed so that voice_state_update can call dpp::discord_client::disconnect_voice_internal
|
||||
*/
|
||||
friend class dpp::events::voice_state_update;
|
||||
|
||||
/**
|
||||
* @brief Needed so that guild_create can request member chunks if you have the correct intents
|
||||
*/
|
||||
friend class dpp::events::guild_create;
|
||||
|
||||
/**
|
||||
* @brief Needed to allow cluster::set_presence to use the ETF functions
|
||||
*/
|
||||
friend class dpp::cluster;
|
||||
|
||||
/**
|
||||
* @brief True if the shard is terminating
|
||||
*/
|
||||
bool terminating;
|
||||
|
||||
/**
|
||||
* @brief Disconnect from the connected voice channel on a guild
|
||||
*
|
||||
* @param guild_id The guild who's voice channel you wish to disconnect from
|
||||
* @param send_json True if we should send a json message confirming we are leaving the VC
|
||||
* Should be set to false if we already receive this message in an event.
|
||||
*/
|
||||
void disconnect_voice_internal(snowflake guild_id, bool send_json = true);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* @brief Mutex for message queue
|
||||
*/
|
||||
std::shared_mutex queue_mutex;
|
||||
|
||||
/**
|
||||
* @brief Queue of outbound messages
|
||||
*/
|
||||
std::deque<std::string> message_queue;
|
||||
|
||||
/**
|
||||
* @brief Thread this shard is executing on
|
||||
*/
|
||||
std::thread* runner;
|
||||
|
||||
/**
|
||||
* @brief Run shard loop under a thread.
|
||||
* Calls discord_client::run() from within a std::thread.
|
||||
*/
|
||||
void thread_run();
|
||||
|
||||
/**
|
||||
* @brief If true, stream compression is enabled
|
||||
*/
|
||||
bool compressed;
|
||||
|
||||
/**
|
||||
* @brief ZLib decompression buffer
|
||||
*/
|
||||
unsigned char* decomp_buffer;
|
||||
|
||||
/**
|
||||
* @brief Decompressed string
|
||||
*/
|
||||
std::string decompressed;
|
||||
|
||||
/**
|
||||
* @brief This object contains the various zlib structs which
|
||||
* are not usable by the user of the library directly. They
|
||||
* are wrapped within this opaque object so that this header
|
||||
* file does not bring in a dependency on zlib.h.
|
||||
*/
|
||||
zlibcontext* zlib;
|
||||
|
||||
/**
|
||||
* @brief Total decompressed received bytes
|
||||
*/
|
||||
uint64_t decompressed_total;
|
||||
|
||||
/**
|
||||
* @brief Last connect time of cluster
|
||||
*/
|
||||
time_t connect_time;
|
||||
|
||||
/**
|
||||
* @brief Time last ping sent to websocket, in fractional seconds
|
||||
*/
|
||||
double ping_start;
|
||||
|
||||
/**
|
||||
* @brief ETF parser for when in ws_etf mode
|
||||
*/
|
||||
class etf_parser* etf;
|
||||
|
||||
/**
|
||||
* @brief Convert a JSON object to string.
|
||||
* In JSON protocol mode, call json.dump(), and in ETF mode,
|
||||
* call etf::build().
|
||||
*
|
||||
* @param json nlohmann::json object to convert
|
||||
* @return std::string string output in the correct format
|
||||
*/
|
||||
std::string jsonobj_to_string(const nlohmann::json& json);
|
||||
|
||||
/**
|
||||
* @brief Initialise ZLib (websocket compression)
|
||||
* @throw dpp::exception if ZLib cannot be initialised
|
||||
*/
|
||||
void setup_zlib();
|
||||
|
||||
/**
|
||||
* @brief Shut down ZLib (websocket compression)
|
||||
*/
|
||||
void end_zlib();
|
||||
|
||||
/**
|
||||
* @brief Update the websocket hostname with the resume url
|
||||
* from the last READY event
|
||||
*/
|
||||
void set_resume_hostname();
|
||||
|
||||
/**
|
||||
* @brief Clean up resources
|
||||
*/
|
||||
void cleanup();
|
||||
public:
|
||||
/**
|
||||
* @brief Owning cluster
|
||||
*/
|
||||
class dpp::cluster* creator;
|
||||
|
||||
/**
|
||||
* @brief Heartbeat interval for sending heartbeat keepalive
|
||||
* @note value in milliseconds
|
||||
*/
|
||||
uint32_t heartbeat_interval;
|
||||
|
||||
/**
|
||||
* @brief Last heartbeat
|
||||
*/
|
||||
time_t last_heartbeat;
|
||||
|
||||
/**
|
||||
* @brief Shard ID of this client
|
||||
*/
|
||||
uint32_t shard_id;
|
||||
|
||||
/**
|
||||
* @brief Total number of shards
|
||||
*/
|
||||
uint32_t max_shards;
|
||||
|
||||
/**
|
||||
* @brief Thread ID
|
||||
*/
|
||||
std::thread::native_handle_type thread_id;
|
||||
|
||||
/**
|
||||
* @brief Last sequence number received, for resumes and pings
|
||||
*/
|
||||
uint64_t last_seq;
|
||||
|
||||
/**
|
||||
* @brief Discord bot token
|
||||
*/
|
||||
std::string token;
|
||||
|
||||
/**
|
||||
* @brief Privileged gateway intents
|
||||
* @see dpp::intents
|
||||
*/
|
||||
uint32_t intents;
|
||||
|
||||
/**
|
||||
* @brief Discord session id
|
||||
*/
|
||||
std::string sessionid;
|
||||
|
||||
/**
|
||||
* @brief Mutex for voice connections map
|
||||
*/
|
||||
std::shared_mutex voice_mutex;
|
||||
|
||||
/**
|
||||
* @brief Resume count
|
||||
*/
|
||||
uint32_t resumes;
|
||||
|
||||
/**
|
||||
* @brief Reconnection count
|
||||
*/
|
||||
uint32_t reconnects;
|
||||
|
||||
/**
|
||||
* @brief Websocket latency in fractional seconds
|
||||
*/
|
||||
double websocket_ping;
|
||||
|
||||
/**
|
||||
* @brief True if READY or RESUMED has been received
|
||||
*/
|
||||
bool ready;
|
||||
|
||||
/**
|
||||
* @brief Last heartbeat ACK (opcode 11)
|
||||
*/
|
||||
time_t last_heartbeat_ack;
|
||||
|
||||
/**
|
||||
* @brief Current websocket protocol, currently either ETF or JSON
|
||||
*/
|
||||
websocket_protocol_t protocol;
|
||||
|
||||
/**
|
||||
* @brief List of voice channels we are connecting to keyed by guild id
|
||||
*/
|
||||
std::unordered_map<snowflake, voiceconn*> connecting_voice_channels;
|
||||
|
||||
/**
|
||||
* @brief The gateway address we reconnect to when we resume a session
|
||||
*/
|
||||
std::string resume_gateway_url;
|
||||
|
||||
/**
|
||||
* @brief 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;
|
||||
|
||||
/**
|
||||
* @brief 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 handle_event(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 queue_message(const std::string &j, bool to_front = false);
|
||||
|
||||
/**
|
||||
* @brief Clear the outbound message queue
|
||||
* @return reference to self
|
||||
*/
|
||||
discord_client& clear_queue();
|
||||
|
||||
/**
|
||||
* @brief Get the size of the outbound message queue
|
||||
*
|
||||
* @return The size of the queue
|
||||
*/
|
||||
size_t get_queue_size();
|
||||
|
||||
/**
|
||||
* @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();
|
||||
|
||||
/**
|
||||
* @brief Construct a new discord_client object
|
||||
*
|
||||
* @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
|
||||
* @param ws_protocol Websocket protocol to use for the connection, JSON or ETF
|
||||
*
|
||||
* @throws std::bad_alloc Passed up to the caller if any internal objects fail to allocate, after cleanup has completed
|
||||
*/
|
||||
discord_client(dpp::cluster* _cluster, uint32_t _shard_id, uint32_t _max_shards, const std::string &_token, uint32_t intents = 0, bool compressed = true, websocket_protocol_t ws_protocol = ws_json);
|
||||
|
||||
/**
|
||||
* @brief Destroy the discord client object
|
||||
*/
|
||||
virtual ~discord_client();
|
||||
|
||||
/**
|
||||
* @brief Get the decompressed bytes in objectGet decompressed total bytes received
|
||||
* @return uint64_t bytes received
|
||||
*/
|
||||
uint64_t get_decompressed_bytes_in();
|
||||
|
||||
/**
|
||||
* @brief 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 handle_frame(const std::string &buffer);
|
||||
|
||||
/**
|
||||
* @brief Handle a websocket error.
|
||||
* @param errorcode The error returned from the websocket
|
||||
*/
|
||||
virtual void error(uint32_t errorcode);
|
||||
|
||||
/**
|
||||
* @brief Start and monitor I/O loop.
|
||||
* @note this is a blocking call and is usually executed within a
|
||||
* thread by whatever creates the object.
|
||||
*/
|
||||
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
|
||||
* @param self_mute True if the bot should mute itself
|
||||
* @param self_deaf True if the bot should deafen itself
|
||||
* @return reference to self
|
||||
* @note This is NOT a synchronous blocking call! The bot isn't instantly ready to send or listen for audio,
|
||||
* as we have to wait for the connection to the voice server to be established!
|
||||
* e.g. wait for dpp::cluster::on_voice_ready event, and then send the audio within that event.
|
||||
*/
|
||||
discord_client& connect_voice(snowflake guild_id, snowflake channel_id, bool self_mute = false, bool self_deaf = false);
|
||||
|
||||
/**
|
||||
* @brief Disconnect from the connected voice channel on a guild
|
||||
*
|
||||
* @param guild_id The guild who's voice channel you wish to disconnect from
|
||||
* @return reference to self
|
||||
* @note This is NOT a synchronous blocking call! The bot isn't instantly disconnected.
|
||||
*/
|
||||
discord_client& disconnect_voice(snowflake guild_id);
|
||||
|
||||
/**
|
||||
* @brief Get the dpp::voiceconn object for a specific guild on this shard.
|
||||
*
|
||||
* @param guild_id The guild ID to retrieve the voice connection for
|
||||
* @return voiceconn* The voice connection for the guild, or nullptr if there is no
|
||||
* voice connection to this guild.
|
||||
*/
|
||||
voiceconn* get_voice(snowflake guild_id);
|
||||
};
|
||||
|
||||
};
|
171
vendor/DPP/include/dpp/discordevents.h
vendored
Normal file
171
vendor/DPP/include/dpp/discordevents.h
vendored
Normal file
@ -0,0 +1,171 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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.h>
|
||||
|
||||
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 DPP_EXPORT snowflake_not_null(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 DPP_EXPORT set_snowflake_not_null(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 DPP_EXPORT string_not_null(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 DPP_EXPORT set_string_not_null(const nlohmann::json* j, const char *keyname, std::string &v);
|
||||
|
||||
/** @brief Returns a double 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
|
||||
*/
|
||||
double DPP_EXPORT double_not_null(const nlohmann::json* j, const char *keyname);
|
||||
|
||||
/** @brief Sets a double 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 DPP_EXPORT set_double_not_null(const nlohmann::json* j, const char *keyname, double &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 DPP_EXPORT int64_not_null(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 DPP_EXPORT set_int64_not_null(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 DPP_EXPORT int32_not_null(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 DPP_EXPORT set_int32_not_null(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 DPP_EXPORT int16_not_null(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 DPP_EXPORT set_int16_not_null(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 DPP_EXPORT int8_not_null(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 DPP_EXPORT set_int8_not_null(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 DPP_EXPORT bool_not_null(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 DPP_EXPORT set_bool_not_null(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 DPP_EXPORT ts_not_null(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 DPP_EXPORT set_ts_not_null(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 DPP_EXPORT base64_encode(unsigned char const* buf, unsigned int buffer_length);
|
||||
|
||||
/**
|
||||
* @brief Convert time_t unix epoch to std::string ISO date/time
|
||||
*
|
||||
* @param ts Timestamp to convert
|
||||
* @return std::string Converted time/date string
|
||||
*/
|
||||
std::string DPP_EXPORT ts_to_string(time_t ts);
|
||||
|
||||
};
|
873
vendor/DPP/include/dpp/discordvoiceclient.h
vendored
Normal file
873
vendor/DPP/include/dpp/discordvoiceclient.h
vendored
Normal file
@ -0,0 +1,873 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <cerrno>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <csignal>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/wsclient.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/socket.h>
|
||||
#include <queue>
|
||||
#include <thread>
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <memory>
|
||||
#include <future>
|
||||
#include <functional>
|
||||
#include <chrono>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
struct OpusDecoder;
|
||||
struct OpusEncoder;
|
||||
struct OpusRepacketizer;
|
||||
|
||||
namespace dpp {
|
||||
|
||||
// Forward declaration
|
||||
class cluster;
|
||||
|
||||
/**
|
||||
* @brief An opus-encoded RTP packet to be sent out to a voice channel
|
||||
*/
|
||||
struct DPP_EXPORT voice_out_packet {
|
||||
/**
|
||||
* @brief Each string is a UDP packet.
|
||||
* Generally these will be RTP.
|
||||
*/
|
||||
std::string packet;
|
||||
/**
|
||||
* @brief Duration of packet
|
||||
*/
|
||||
uint64_t duration;
|
||||
};
|
||||
|
||||
#define AUDIO_TRACK_MARKER (uint16_t)0xFFFF
|
||||
|
||||
#define AUDIO_OVERLAP_SLEEP_SAMPLES 30
|
||||
|
||||
/** @brief Implements a discord voice connection.
|
||||
* Each discord_voice_client connects to one voice channel and derives from a websocket client.
|
||||
*/
|
||||
class DPP_EXPORT discord_voice_client : public websocket_client
|
||||
{
|
||||
/**
|
||||
* @brief Clean up resources
|
||||
*/
|
||||
void cleanup();
|
||||
|
||||
/**
|
||||
* @brief Mutex for outbound packet stream
|
||||
*/
|
||||
std::mutex stream_mutex;
|
||||
|
||||
/**
|
||||
* @brief Mutex for message queue
|
||||
*/
|
||||
std::shared_mutex queue_mutex;
|
||||
|
||||
/**
|
||||
* @brief Queue of outbound messages
|
||||
*/
|
||||
std::deque<std::string> message_queue;
|
||||
|
||||
/**
|
||||
* @brief Thread this connection is executing on
|
||||
*/
|
||||
std::thread* runner;
|
||||
|
||||
/**
|
||||
* @brief Run shard loop under a thread
|
||||
*/
|
||||
void thread_run();
|
||||
|
||||
/**
|
||||
* @brief 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;
|
||||
|
||||
/**
|
||||
* @brief Timescale in nanoseconds
|
||||
*/
|
||||
uint64_t timescale;
|
||||
|
||||
/**
|
||||
* @brief Output buffer
|
||||
*/
|
||||
std::vector<voice_out_packet> outbuf;
|
||||
|
||||
/**
|
||||
* @brief Data type of RTP packet sequence number field.
|
||||
*/
|
||||
using rtp_seq_t = uint16_t;
|
||||
using rtp_timestamp_t = uint32_t;
|
||||
|
||||
/**
|
||||
* @brief Keeps track of the voice payload to deliver to voice handlers.
|
||||
*/
|
||||
struct voice_payload {
|
||||
/**
|
||||
* @brief The sequence number of the RTP packet that generated this
|
||||
* voice payload.
|
||||
*/
|
||||
rtp_seq_t seq;
|
||||
/**
|
||||
* @brief The timestamp of the RTP packet that generated this voice
|
||||
* payload.
|
||||
*
|
||||
* The timestamp is used to detect the order around where sequence
|
||||
* number wraps around.
|
||||
*/
|
||||
rtp_timestamp_t timestamp;
|
||||
/**
|
||||
* @brief The event payload that voice handlers receive.
|
||||
*/
|
||||
std::unique_ptr<voice_receive_t> vr;
|
||||
|
||||
/**
|
||||
* @brief For priority_queue sorting.
|
||||
* @return true if "this" has lower priority that "other",
|
||||
* i.e. appears later in the queue; false otherwise.
|
||||
*/
|
||||
bool operator<(const voice_payload& other) const;
|
||||
};
|
||||
|
||||
struct voice_payload_parking_lot {
|
||||
/**
|
||||
* @brief The range of RTP packet sequence number and timestamp in the lot.
|
||||
*
|
||||
* The minimum is used to drop packets that arrive too late. Packets
|
||||
* less than the minimum have been delivered to voice handlers and
|
||||
* there is no going back. Unfortunately we just have to drop them.
|
||||
*
|
||||
* The maximum is used, at flush time, to calculate the minimum for
|
||||
* the next batch. The maximum is also updated every time we receive an
|
||||
* RTP packet with a larger value.
|
||||
*/
|
||||
struct seq_range_t {
|
||||
rtp_seq_t min_seq, max_seq;
|
||||
rtp_timestamp_t min_timestamp, max_timestamp;
|
||||
} range;
|
||||
/**
|
||||
* @brief The queue of parked voice payloads.
|
||||
*
|
||||
* We group payloads and deliver them to handlers periodically as the
|
||||
* handling of out-of-order RTP packets. Payloads in between flushes
|
||||
* are parked and sorted in this queue.
|
||||
*/
|
||||
std::priority_queue<voice_payload> parked_payloads;
|
||||
/**
|
||||
* @brief The decoder ctls to be set on the decoder.
|
||||
*/
|
||||
std::vector<std::function<void(OpusDecoder&)>> pending_decoder_ctls;
|
||||
/**
|
||||
* @brief libopus decoder
|
||||
*
|
||||
* Shared with the voice courier thread that does the decoding.
|
||||
* This is not protected by a mutex because only the courier thread
|
||||
* uses the decoder.
|
||||
*/
|
||||
std::shared_ptr<OpusDecoder> decoder;
|
||||
};
|
||||
/**
|
||||
* @brief Thread used to deliver incoming voice data to handlers.
|
||||
*/
|
||||
std::thread voice_courier;
|
||||
/**
|
||||
* @brief Shared state between this voice client and the courier thread.
|
||||
*/
|
||||
struct courier_shared_state_t {
|
||||
/**
|
||||
* @brief Protects all following members.
|
||||
*/
|
||||
std::mutex mtx;
|
||||
/**
|
||||
* @brief Signaled when there is a new payload to deliver or terminating state has changed.
|
||||
*/
|
||||
std::condition_variable signal_iteration;
|
||||
/**
|
||||
* @brief Voice buffers to be reported to handler, grouped by speaker.
|
||||
*
|
||||
* Buffers are parked here and flushed every 500ms.
|
||||
*/
|
||||
std::map<snowflake, voice_payload_parking_lot> parked_voice_payloads;
|
||||
/**
|
||||
* @brief Used to signal termination.
|
||||
*
|
||||
* @note Pending payloads are delivered first before termination.
|
||||
*/
|
||||
bool terminating = false;
|
||||
} voice_courier_shared_state;
|
||||
/**
|
||||
* @brief The run loop of the voice courier thread.
|
||||
*/
|
||||
static void voice_courier_loop(discord_voice_client&, courier_shared_state_t&);
|
||||
|
||||
/**
|
||||
* @brief If true, audio packet sending is paused
|
||||
*/
|
||||
bool paused;
|
||||
|
||||
#ifdef HAVE_VOICE
|
||||
/**
|
||||
* @brief libopus encoder
|
||||
*/
|
||||
OpusEncoder* encoder;
|
||||
|
||||
/**
|
||||
* @brief libopus repacketizer
|
||||
* (merges frames into one packet)
|
||||
*/
|
||||
OpusRepacketizer* repacketizer;
|
||||
#else
|
||||
/**
|
||||
* @brief libopus encoder
|
||||
*/
|
||||
void* encoder;
|
||||
|
||||
/**
|
||||
* @brief libopus repacketizer
|
||||
* (merges frames into one packet)
|
||||
*/
|
||||
void* repacketizer;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief File descriptor for UDP connection
|
||||
*/
|
||||
dpp::socket fd;
|
||||
|
||||
/**
|
||||
* @brief 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;
|
||||
|
||||
/**
|
||||
* @brief Sequence number of outbound audio. This is incremented
|
||||
* once per frame sent.
|
||||
*/
|
||||
uint16_t sequence;
|
||||
|
||||
/**
|
||||
* @brief 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;
|
||||
|
||||
/**
|
||||
* @brief Last sent packet high-resolution timestamp
|
||||
*/
|
||||
std::chrono::high_resolution_clock::time_point last_timestamp;
|
||||
|
||||
/**
|
||||
* @brief Fraction of the sleep that was not executed after the last audio packet was sent
|
||||
*/
|
||||
std::chrono::nanoseconds last_sleep_remainder;
|
||||
|
||||
/**
|
||||
* @brief Maps receiving ssrc to user id
|
||||
*/
|
||||
std::unordered_map<uint32_t, snowflake> ssrc_map;
|
||||
|
||||
/**
|
||||
* @brief 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;
|
||||
|
||||
/**
|
||||
* @brief 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;
|
||||
|
||||
/**
|
||||
* @brief Meta data associated with each track.
|
||||
* Arbitrary string that the user can set via
|
||||
* dpp::discord_voice_client::add_marker
|
||||
*/
|
||||
std::vector<std::string> track_meta;
|
||||
|
||||
/**
|
||||
* @brief 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 udp_send(const char* data, size_t length);
|
||||
|
||||
/**
|
||||
* @brief Receive data from UDP socket immediately.
|
||||
*
|
||||
* @param data data to receive
|
||||
* @param max_length size of data receiving buffer
|
||||
* @return int bytes received. -1 if there is an error
|
||||
* (e.g. EAGAIN)
|
||||
*/
|
||||
int udp_recv(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
|
||||
*/
|
||||
dpp::socket want_write();
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
dpp::socket want_read();
|
||||
|
||||
/**
|
||||
* @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 doesn't error
|
||||
* completely, we pop it off the head of the queue.
|
||||
*/
|
||||
void write_ready();
|
||||
|
||||
/**
|
||||
* @brief Called by ssl_client when there is data to be
|
||||
* read. At this point we insert that data into the
|
||||
* input queue.
|
||||
*/
|
||||
void read_ready();
|
||||
|
||||
/**
|
||||
* @brief Send data to the UDP socket, using the buffer.
|
||||
*
|
||||
* @param packet packet data
|
||||
* @param len length of packet
|
||||
* @param duration duration of opus packet
|
||||
*/
|
||||
void send(const char* packet, size_t len, uint64_t duration);
|
||||
|
||||
/**
|
||||
* @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 queue_message(const std::string &j, bool to_front = false);
|
||||
|
||||
/**
|
||||
* @brief Clear the outbound message queue
|
||||
*
|
||||
*/
|
||||
void clear_queue();
|
||||
|
||||
/**
|
||||
* @brief Get the size of the outbound message queue
|
||||
*
|
||||
* @return The size of the queue
|
||||
*/
|
||||
size_t get_queue_size();
|
||||
|
||||
/**
|
||||
* @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.
|
||||
* @throw dpp::voice_exception If data length to encode is invalid or voice support not compiled into D++
|
||||
*/
|
||||
size_t encode(uint8_t *input, size_t inDataSize, uint8_t *output, size_t &outDataSize);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Owning cluster
|
||||
*/
|
||||
class dpp::cluster* creator;
|
||||
|
||||
/**
|
||||
* @brief 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;
|
||||
|
||||
/**
|
||||
* @brief True when the thread is shutting down
|
||||
*/
|
||||
bool terminating;
|
||||
|
||||
/**
|
||||
* @brief Heartbeat interval for sending heartbeat keepalive
|
||||
*/
|
||||
uint32_t heartbeat_interval;
|
||||
|
||||
/**
|
||||
* @brief Last voice channel websocket heartbeat
|
||||
*/
|
||||
time_t last_heartbeat;
|
||||
|
||||
/**
|
||||
* @brief Thread ID
|
||||
*/
|
||||
std::thread::native_handle_type thread_id;
|
||||
|
||||
/**
|
||||
* @brief Discord voice session token
|
||||
*/
|
||||
std::string token;
|
||||
|
||||
/**
|
||||
* @brief Discord voice session id
|
||||
*/
|
||||
std::string sessionid;
|
||||
|
||||
/**
|
||||
* @brief Server ID
|
||||
*/
|
||||
snowflake server_id;
|
||||
|
||||
/**
|
||||
* @brief Channel ID
|
||||
*/
|
||||
snowflake channel_id;
|
||||
|
||||
/**
|
||||
* @brief The audio type to be sent. The default type is recorded audio.
|
||||
*
|
||||
* If the audio is recorded, the sending of audio packets is throttled.
|
||||
* Otherwise, if the audio is live, the sending is not throttled.
|
||||
*
|
||||
* Discord voice engine is expecting audio data as if they were from
|
||||
* some audio device, e.g. microphone, where the data become available
|
||||
* as they get captured from the audio device.
|
||||
*
|
||||
* In case of recorded audio, unlike from a device, the audio data are
|
||||
* usually instantly available in large chunks. Throttling is needed to
|
||||
* simulate audio data coming from an audio device. In case of live audio,
|
||||
* the throttling is by nature, so no extra throttling is needed.
|
||||
*
|
||||
* Using live audio mode for recorded audio can cause Discord to skip
|
||||
* audio data because Discord does not expect to receive, say, 3 minutes'
|
||||
* worth of audio data in 1 second.
|
||||
*
|
||||
* There are some inaccuracies in the throttling method used by the recorded
|
||||
* audio mode on some systems (mainly Windows) which causes gaps and stutters
|
||||
* in the resulting audio stream. The overlap audio mode provides a different
|
||||
* implementation that fixes the issue. This method is slightly more CPU
|
||||
* intensive, and should only be used if you encounter issues with recorded audio
|
||||
* on your system.
|
||||
*
|
||||
* Use discord_voice_client::set_send_audio_type to change this value as
|
||||
* it ensures thread safety.
|
||||
*/
|
||||
enum send_audio_type_t
|
||||
{
|
||||
satype_recorded_audio,
|
||||
satype_live_audio,
|
||||
satype_overlap_audio
|
||||
} send_audio_type = satype_recorded_audio;
|
||||
|
||||
/**
|
||||
* @brief Sets the gain for the specified user.
|
||||
*
|
||||
* Similar to the User Volume slider, controls the listening volume per user.
|
||||
* Uses native Opus gain control, so clients don't have to perform extra
|
||||
* audio processing.
|
||||
*
|
||||
* The gain setting will affect the both individual and combined voice audio.
|
||||
*
|
||||
* The gain value can also be set even before the user connects to the voice
|
||||
* channel.
|
||||
*
|
||||
* @param user_id The ID of the user where the gain is to be controlled.
|
||||
* @param factor Nonnegative factor to scale the amplitude by, where 1.f reverts
|
||||
* to the default volume.
|
||||
*/
|
||||
void set_user_gain(snowflake user_id, float factor);
|
||||
|
||||
/**
|
||||
* @brief 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;
|
||||
|
||||
/**
|
||||
* @brief Fires every second from the underlying socket I/O loop, used for sending heartbeats
|
||||
* @throw dpp::exception if the socket needs to disconnect
|
||||
*/
|
||||
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 cluster which owns this voice connection, for related logging, REST requests etc
|
||||
* @param _channel_id The channel id to identify the voice connection as
|
||||
* @param _server_id The server id (guild id) to identify the 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)
|
||||
* @throw dpp::voice_exception Sodium or Opus failed to initialise, or D++ is not compiled with voice support
|
||||
*/
|
||||
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);
|
||||
|
||||
/**
|
||||
* @brief Destroy the discord voice client object
|
||||
*/
|
||||
virtual ~discord_voice_client();
|
||||
|
||||
/**
|
||||
* @brief Handle JSON from the websocket.
|
||||
* @param buffer The entire buffer content from the websocket client
|
||||
* @return bool True if a frame has been handled
|
||||
* @throw dpp::exception If there was an error processing the frame, or connection to UDP socket failed
|
||||
*/
|
||||
virtual bool handle_frame(const std::string &buffer);
|
||||
|
||||
/**
|
||||
* @brief Handle a websocket error.
|
||||
* @param errorcode The error returned from the websocket
|
||||
*/
|
||||
virtual void error(uint32_t errorcode);
|
||||
|
||||
/**
|
||||
* @brief Start and monitor I/O loop
|
||||
*/
|
||||
void run();
|
||||
|
||||
/**
|
||||
* @brief Send raw audio to the voice channel.
|
||||
*
|
||||
* You should send an audio packet of 11520 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 (unless you have set use_opus to false).
|
||||
* 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.
|
||||
*
|
||||
* The audio data should be 48000Hz signed 16 bit audio.
|
||||
*
|
||||
* @param length The length of the audio data. The length should
|
||||
* be a multiple of 4 (2x 16 bit stereo channels) with a maximum
|
||||
* length of 11520, which is a complete opus frame at highest
|
||||
* quality.
|
||||
*
|
||||
* @return discord_voice_client& Reference to self
|
||||
*
|
||||
* @throw dpp::voice_exception If data length is invalid or voice support not compiled into D++
|
||||
*/
|
||||
discord_voice_client& send_audio_raw(uint16_t* audio_data, const size_t length);
|
||||
|
||||
/**
|
||||
* @brief Send opus packets to the voice channel
|
||||
*
|
||||
* 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 bypass the codec, only applying
|
||||
* libsodium to the stream.
|
||||
*
|
||||
* @param opus_packet Opus packets. Discord expects opus frames
|
||||
* to be encoded at 48000Hz
|
||||
*
|
||||
* @param length The length of the audio data.
|
||||
*
|
||||
* @param duration Generally duration is 2.5, 5, 10, 20, 40 or 60
|
||||
* if the timescale is 1000000 (1ms)
|
||||
*
|
||||
* @return discord_voice_client& Reference to self
|
||||
*
|
||||
* @note It is your responsibility to ensure that packets of data
|
||||
* sent to send_audio are correctly repacketized for streaming,
|
||||
* e.g. that audio frames are not too large or contain
|
||||
* an incorrect format. Discord will still expect the same frequency
|
||||
* and bit width of audio and the same signedness.
|
||||
*
|
||||
* @throw dpp::voice_exception If data length is invalid or voice support not compiled into D++
|
||||
*/
|
||||
discord_voice_client& send_audio_opus(uint8_t* opus_packet, const size_t length, uint64_t duration);
|
||||
|
||||
/**
|
||||
* @brief Send opus packets to the voice channel
|
||||
*
|
||||
* 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 bypass the codec, only applying
|
||||
* libsodium to the stream.
|
||||
*
|
||||
* Duration is calculated internally
|
||||
*
|
||||
* @param opus_packet Opus packets. Discord expects opus frames
|
||||
* to be encoded at 48000Hz
|
||||
*
|
||||
* @param length The length of the audio data.
|
||||
*
|
||||
* @return discord_voice_client& Reference to self
|
||||
*
|
||||
* @note It is your responsibility to ensure that packets of data
|
||||
* sent to send_audio are correctly repacketized for streaming,
|
||||
* e.g. that audio frames are not too large or contain
|
||||
* an incorrect format. Discord will still expect the same frequency
|
||||
* and bit width of audio and the same signedness.
|
||||
*
|
||||
* @throw dpp::voice_exception If data length is invalid or voice support not compiled into D++
|
||||
*/
|
||||
discord_voice_client& send_audio_opus(uint8_t* opus_packet, const size_t length);
|
||||
|
||||
/**
|
||||
* @brief Send silence to the voice channel
|
||||
*
|
||||
* @param duration How long to send silence for. With the standard
|
||||
* timescale this is in milliseconds. Allowed values are 2.5,
|
||||
* 5, 10, 20, 40 or 60 milliseconds.
|
||||
* @return discord_voice_client& Reference to self
|
||||
* @throw dpp::voice_exception if voice support is not compiled into D++
|
||||
*/
|
||||
discord_voice_client& send_silence(const uint64_t duration);
|
||||
|
||||
/**
|
||||
* @brief Sets the audio type that will be sent with send_audio_* methods.
|
||||
*
|
||||
* @see send_audio_type_t
|
||||
*/
|
||||
discord_voice_client& set_send_audio_type(send_audio_type_t type);
|
||||
|
||||
/**
|
||||
* @brief Set the timescale in nanoseconds.
|
||||
*
|
||||
* @param new_timescale Timescale to set. This defaults to 1000000,
|
||||
* which means 1 millisecond.
|
||||
* @return discord_voice_client& Reference to self
|
||||
* @throw dpp::voice_exception If data length is invalid or voice support not compiled into D++
|
||||
*/
|
||||
discord_voice_client& set_timescale(uint64_t new_timescale);
|
||||
|
||||
/**
|
||||
* @brief Get the current timescale, this will default to 1000000
|
||||
* which means 1 millisecond.
|
||||
*
|
||||
* @return uint64_t timescale in nanoseconds
|
||||
*/
|
||||
uint64_t get_timescale();
|
||||
|
||||
/**
|
||||
* @brief Mark the voice connection as 'speaking'.
|
||||
* This sends a JSON message to the voice websocket which tells discord
|
||||
* that the user is speaking. The library automatically calls this for you
|
||||
* whenever you send audio.
|
||||
*
|
||||
* @return discord_voice_client& Reference to self
|
||||
*/
|
||||
discord_voice_client& speak();
|
||||
|
||||
/**
|
||||
* @brief Pause sending of audio
|
||||
*
|
||||
* @param pause True to pause, false to resume
|
||||
* @return reference to self
|
||||
*/
|
||||
discord_voice_client& pause_audio(bool pause);
|
||||
|
||||
/**
|
||||
* @brief Immediately stop all audio.
|
||||
* Clears the packet queue.
|
||||
* @return reference to self
|
||||
*/
|
||||
discord_voice_client& 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 indicates 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
|
||||
* @return reference to self
|
||||
*/
|
||||
discord_voice_client& 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.
|
||||
* @return reference to self
|
||||
*/
|
||||
discord_voice_client& skip_to_next_marker();
|
||||
|
||||
/**
|
||||
* @brief Get the metadata 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();
|
||||
};
|
||||
|
||||
};
|
||||
|
1762
vendor/DPP/include/dpp/dispatcher.h
vendored
Normal file
1762
vendor/DPP/include/dpp/dispatcher.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
76
vendor/DPP/include/dpp/dns.h
vendored
Normal file
76
vendor/DPP/include/dpp/dns.h
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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>
|
||||
#ifdef _WIN32
|
||||
#include <WinSock2.h>
|
||||
#include <WS2tcpip.h>
|
||||
#else
|
||||
#include <netinet/in.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents a cached DNS result.
|
||||
* Used by the ssl_client class to store cached copies of dns lookups.
|
||||
*/
|
||||
struct dns_cache_entry {
|
||||
/**
|
||||
* @brief Resolved address information
|
||||
*/
|
||||
addrinfo addr;
|
||||
|
||||
/**
|
||||
* @brief Socket address.
|
||||
* Discord only supports ipv4, but sockaddr_in6 is larger
|
||||
* than sockaddr_in, sockaddr_storage will hold either. This
|
||||
* means that if discord ever do support ipv6 we just flip
|
||||
* one value in dns.cpp and that should be all that is needed.
|
||||
*/
|
||||
sockaddr_storage ai_addr;
|
||||
|
||||
/**
|
||||
* @brief Time at which this cache entry is invalidated
|
||||
*/
|
||||
time_t expire_timestamp;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Cache container type
|
||||
*/
|
||||
using dns_cache_t = std::unordered_map<std::string, dns_cache_entry*>;
|
||||
|
||||
/**
|
||||
* @brief Resolve a hostname to an addrinfo
|
||||
*
|
||||
* @param hostname Hostname to resolve
|
||||
* @param port A port number or named service, e.g. "80"
|
||||
* @return dns_cache_entry* First IP address associated with the hostname DNS record
|
||||
* @throw dpp::connection_exception On failure to resolve hostname
|
||||
*/
|
||||
const dns_cache_entry* resolve_hostname(const std::string& hostname, const std::string& port);
|
||||
};
|
74
vendor/DPP/include/dpp/dpp.h
vendored
Normal file
74
vendor/DPP/include/dpp/dpp.h
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <dpp/exception.h>
|
||||
#include <dpp/snowflake.h>
|
||||
#include <dpp/misc-enum.h>
|
||||
#include <dpp/stringops.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/utility.h>
|
||||
#include <dpp/voicestate.h>
|
||||
#include <dpp/permissions.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/message.h>
|
||||
#include <dpp/appcommand.h>
|
||||
#include <dpp/stage_instance.h>
|
||||
#include <dpp/auditlog.h>
|
||||
#include <dpp/application.h>
|
||||
#include <dpp/scheduled_event.h>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/httpsclient.h>
|
||||
#include <dpp/queues.h>
|
||||
#include <dpp/commandhandler.h>
|
||||
#include <dpp/once.h>
|
||||
#include <dpp/sync.h>
|
||||
#include <dpp/colors.h>
|
||||
#include <dpp/discordevents.h>
|
||||
#include <dpp/timed_listener.h>
|
||||
#include <dpp/collector.h>
|
103
vendor/DPP/include/dpp/dtemplate.h
vendored
Normal file
103
vendor/DPP/include/dpp/dtemplate.h
vendored
Normal file
@ -0,0 +1,103 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <unordered_map>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents a guild template
|
||||
*/
|
||||
class DPP_EXPORT dtemplate : public json_interface<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
|
||||
*/
|
||||
virtual ~dtemplate() = default;
|
||||
|
||||
/** 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);
|
||||
|
||||
/**
|
||||
* @brief Build the JSON for this object
|
||||
*
|
||||
* @param with_id Add ID to output
|
||||
* @return std::string JSON content
|
||||
*/
|
||||
std::string build_json(bool with_id = false) const;
|
||||
|
||||
};
|
||||
|
||||
/** A container of invites */
|
||||
typedef std::unordered_map<snowflake, dtemplate> dtemplate_map;
|
||||
|
||||
|
||||
};
|
177
vendor/DPP/include/dpp/emoji.h
vendored
Normal file
177
vendor/DPP/include/dpp/emoji.h
vendored
Normal file
@ -0,0 +1,177 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/misc-enum.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/utility.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <unordered_map>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
#define MAX_EMOJI_SIZE 256 * 1024
|
||||
|
||||
/**
|
||||
* @brief Flags for dpp::emoji
|
||||
*/
|
||||
enum emoji_flags : uint8_t {
|
||||
/// 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 DPP_EXPORT emoji : public managed, public json_interface<emoji> {
|
||||
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 n The emoji's name
|
||||
* @param i ID, if it has one (unicode does not)
|
||||
* @param f Emoji flags (emoji_flags)
|
||||
*/
|
||||
emoji(const std::string n, const snowflake i = 0, const uint8_t f = 0);
|
||||
|
||||
/**
|
||||
* @brief Destroy the emoji object
|
||||
*/
|
||||
virtual ~emoji();
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable emoji
|
||||
* @param name The name of the emoji.
|
||||
* @param id The ID of the emoji.
|
||||
* @param is_animated is emoji animated.
|
||||
* @return std::string The formatted mention of the emoji.
|
||||
*/
|
||||
static std::string get_mention(const std::string& name, const snowflake& id, bool is_animated = false);
|
||||
|
||||
/**
|
||||
* @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. It can be one of `i_gif`, `i_jpg` or `i_png`.
|
||||
* @return emoji& Reference to self
|
||||
* @throw dpp::length_exception Image content exceeds discord maximum of 256 kilobytes
|
||||
*/
|
||||
emoji& load_image(const std::string &image_blob, const 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 Get the mention/ping for the emoji
|
||||
*
|
||||
* @return std::string mention
|
||||
*/
|
||||
std::string get_mention() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Group of emojis
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, emoji> emoji_map;
|
||||
|
||||
};
|
642
vendor/DPP/include/dpp/etf.h
vendored
Normal file
642
vendor/DPP/include/dpp/etf.h
vendored
Normal file
@ -0,0 +1,642 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Parts of this file inspired by, or outright copied from erlpack:
|
||||
* https://github.com/discord/erlpack/
|
||||
*
|
||||
* Acknowledgements:
|
||||
*
|
||||
* sysdep.h:
|
||||
* Based on work by FURUHASHI Sadayuki in msgpack-python
|
||||
* (https://github.com/msgpack/msgpack-python)
|
||||
*
|
||||
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
* Licensed under the Apache License, Version 2.0 (the "License").
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/snowflake.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/** Current ETF format version in use */
|
||||
const uint8_t FORMAT_VERSION = 131;
|
||||
|
||||
/**
|
||||
* @brief Represents a token which identifies the type of value which follows it
|
||||
* in the ETF binary structure.
|
||||
*/
|
||||
enum etf_token_type : uint8_t {
|
||||
/// 68 [Distribution header]
|
||||
ett_distribution = 'D',
|
||||
/// 70 [Float64:IEEE float]
|
||||
ett_new_float = 'F',
|
||||
/// 77 [UInt32:Len, UInt8:Bits, Len:Data]
|
||||
ett_bit_binary = 'M',
|
||||
/// 80 [UInt4:UncompressedSize, N:ZlibCompressedData]
|
||||
ett_compressed = 'P',
|
||||
/// 97 [UInt8:Int]
|
||||
ett_smallint = 'a',
|
||||
/// 98 [Int32:Int]
|
||||
ett_integer = 'b',
|
||||
/// 99 [31:Float String] Float in string format (formatted "%.20e", sscanf "%lf"). Superseded by ett_new_float
|
||||
ett_float = 'c',
|
||||
/// 100 [UInt16:Len, Len:AtomName] max Len is 255
|
||||
ett_atom = 'd',
|
||||
/// 101 [atom:Node, UInt32:ID, UInt8:Creation]
|
||||
ett_reference = 'e',
|
||||
/// 102 [atom:Node, UInt32:ID, UInt8:Creation]
|
||||
ett_port = 'f',
|
||||
/// 103 [atom:Node, UInt32:ID, UInt32:Serial, UInt8:Creation]
|
||||
ett_pid = 'g',
|
||||
/// 104 [UInt8:Arity, N:Elements]
|
||||
ett_small_tuple = 'h',
|
||||
/// 105 [UInt32:Arity, N:Elements]
|
||||
ett_large_tuple = 'i',
|
||||
/// 106 empty list
|
||||
ett_nil = 'j',
|
||||
/// 107 [UInt16:Len, Len:Characters]
|
||||
ett_string = 'k',
|
||||
/// 108 [UInt32:Len, Elements, Tail]
|
||||
ett_list = 'l',
|
||||
/// 109 [UInt32:Len, Len:Data]
|
||||
ett_binary = 'm',
|
||||
/// 110 [UInt8:n, UInt8:Sign, n:nums]
|
||||
ett_bigint_small = 'n',
|
||||
/// 111 [UInt32:n, UInt8:Sign, n:nums]
|
||||
ett_bigint_large = 'o',
|
||||
/// 112 [UInt32:Size, UInt8:Arity, 16*Uint6-MD5:Uniq, UInt32:Index, UInt32:NumFree, atom:Module, int:OldIndex, int:OldUniq, pid:Pid, NunFree*ext:FreeVars]
|
||||
ett_new_function = 'p',
|
||||
/// 113 [atom:Module, atom:Function, smallint:Arity]
|
||||
ett_export = 'q',
|
||||
/// 114 [UInt16:Len, atom:Node, UInt8:Creation, Len*UInt32:ID]
|
||||
ett_new_reference = 'r',
|
||||
/// 115 [UInt8:Len, Len:AtomName]
|
||||
ett_atom_small = 's',
|
||||
/// 116 [UInt32:Airty, N:Pairs]
|
||||
ett_map = 't',
|
||||
/// 117 [UInt4:NumFree, pid:Pid, atom:Module, int:Index, int:Uniq, NumFree*ext:FreeVars]
|
||||
ett_function = 'u',
|
||||
/// 118 [UInt16:Len, Len:AtomName] max Len is 255 characters (up to 4 bytes per)
|
||||
ett_atom_utf8 = 'v',
|
||||
/// 119 [UInt8:Len, Len:AtomName]
|
||||
ett_atom_utf8_small = 'w'
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A horrible structure used within the ETF parser to convert uint64_t to double and back.
|
||||
* This is horrible, but it is the official way erlang term format does this, so we can't really
|
||||
* mess with it much.
|
||||
*/
|
||||
union type_punner {
|
||||
/**
|
||||
* @brief binary integer value
|
||||
*/
|
||||
uint64_t ui64;
|
||||
/**
|
||||
* @brief double floating point value
|
||||
*/
|
||||
double df;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a buffer of bytes being encoded into ETF
|
||||
*/
|
||||
struct DPP_EXPORT etf_buffer {
|
||||
/**
|
||||
* @brief Raw buffer
|
||||
*/
|
||||
std::vector<char> buf;
|
||||
/**
|
||||
* @brief Current used length of buffer
|
||||
* (this is different from buf.size() as it is pre-allocated
|
||||
* using resize and may not all be in use)
|
||||
*/
|
||||
size_t length;
|
||||
|
||||
/**
|
||||
* @brief Construct a new etf buffer object
|
||||
*
|
||||
* @param initial initial buffer size to allocate
|
||||
*/
|
||||
etf_buffer(size_t initial);
|
||||
|
||||
/**
|
||||
* @brief Destroy the etf buffer object
|
||||
*/
|
||||
~etf_buffer();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The etf_parser class can serialise and deserialise ETF (Erlang Term Format)
|
||||
* into and out of an nlohmann::json object, so that layers above the websocket don't
|
||||
* have to be any different for handling ETF.
|
||||
*/
|
||||
class DPP_EXPORT etf_parser {
|
||||
|
||||
/**
|
||||
* @brief Current size of binary data
|
||||
*/
|
||||
size_t size;
|
||||
|
||||
/**
|
||||
* @brief Current offset into binary data
|
||||
*/
|
||||
size_t offset;
|
||||
|
||||
/**
|
||||
* @brief Pointer to binary ETF data to be decoded
|
||||
*/
|
||||
uint8_t* data;
|
||||
|
||||
/**
|
||||
* @brief Parse a single value, and if that value contains other
|
||||
* values (e.g. an array or map) then call itself recursively.
|
||||
*
|
||||
* @return nlohmann::json JSON value from the ETF
|
||||
*/
|
||||
nlohmann::json inner_parse();
|
||||
|
||||
/**
|
||||
* @brief Read 8 bits of data from the buffer
|
||||
*
|
||||
* @return uint8_t data retrieved
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
uint8_t read_8_bits();
|
||||
|
||||
/**
|
||||
* @brief Read 16 bits of data from the buffer
|
||||
*
|
||||
* @return uint16_t data retrieved
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
uint16_t read_16_bits();
|
||||
|
||||
/**
|
||||
* @brief Read 32 bits of data from the buffer
|
||||
*
|
||||
* @return uint32_t data retrieved
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
uint32_t read_32_bits();
|
||||
|
||||
/**
|
||||
* @brief Read 64 bits of data from the buffer
|
||||
*
|
||||
* @return uint64_t data retrieved
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
uint64_t read_64_bits();
|
||||
|
||||
/**
|
||||
* @brief Read string data from the buffer
|
||||
*
|
||||
* @param length Length of string to retrieve
|
||||
* @return const char* data retrieved
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
const char* read_string(uint32_t length);
|
||||
|
||||
/**
|
||||
* @brief Process an 'atom' value.
|
||||
* An atom is a "label" or constant value within the data,
|
||||
* such as a key name, nullptr, or false.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json process_atom(const char* atom, uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief Decode an 'atom' value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_atom();
|
||||
|
||||
/**
|
||||
* @brief Decode a small 'atom' value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_small_atom();
|
||||
|
||||
/**
|
||||
* @brief Decode a small integer value (0-255).
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_small_integer();
|
||||
|
||||
/**
|
||||
* @brief Decode an integer value (-MAXINT -> MAXINT-1).
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_integer();
|
||||
|
||||
/**
|
||||
* @brief Decode an array of values.
|
||||
*
|
||||
* @return nlohmann::json values converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_array(uint32_t length);
|
||||
|
||||
/**
|
||||
* @brief Decode a list of values.
|
||||
*
|
||||
* @return nlohmann::json values converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_list();
|
||||
|
||||
/**
|
||||
* @brief Decode a 'tuple' value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_tuple(uint32_t length);
|
||||
|
||||
/**
|
||||
* @brief Decode a nil 'atom' value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_nil();
|
||||
|
||||
/**
|
||||
* @brief Decode a map (object) value.
|
||||
* Will recurse to evaluate each member variable.
|
||||
*
|
||||
* @return nlohmann::json values converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_map();
|
||||
|
||||
/**
|
||||
* @brief Decode a floating point numeric value.
|
||||
* (depreciated in erlang but still expected to be supported)
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_float();
|
||||
|
||||
/**
|
||||
* @brief Decode a floating type numeric value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_new_float();
|
||||
|
||||
/**
|
||||
* @brief Decode a 'bigint' value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_bigint(uint32_t digits);
|
||||
|
||||
/**
|
||||
* @brief Decode a small 'bigint' value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_bigint_small();
|
||||
|
||||
/**
|
||||
* @brief Decode a large 'bigint' value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_bigint_large();
|
||||
|
||||
/**
|
||||
* @brief Decode a binary value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_binary();
|
||||
|
||||
/**
|
||||
* @brief Decode a string value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_string();
|
||||
|
||||
/**
|
||||
* @brief Decode a string list value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_string_as_list();
|
||||
|
||||
/**
|
||||
* @brief Decode a 'small tuple' value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_tuple_small();
|
||||
|
||||
/**
|
||||
* @brief Decode a 'large tuple' value.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_tuple_large();
|
||||
|
||||
/**
|
||||
* @brief Decode a compressed value.
|
||||
* This is a zlib-compressed binary blob which contains another
|
||||
* ETF object.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_compressed();
|
||||
|
||||
/**
|
||||
* @brief Decode a 'reference' value.
|
||||
* Erlang expects this to be supported, in practice Discord doesn't send these right now.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_reference();
|
||||
|
||||
/**
|
||||
* @brief Decode a 'new reference' value.
|
||||
* Erlang expects this to be supported, in practice Discord doesn't send these right now.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_new_reference();
|
||||
|
||||
/**
|
||||
* @brief Decode a 'port' value.
|
||||
* Erlang expects this to be supported, in practice Discord doesn't send these right now.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_port();
|
||||
|
||||
/**
|
||||
* @brief Decode a 'PID' value.
|
||||
* Erlang expects this to be supported, in practice Discord doesn't send these right now.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_pid();
|
||||
|
||||
/**
|
||||
* @brief Decode an 'export' value.
|
||||
* Erlang expects this to be supported, in practice Discord doesn't send these right now.
|
||||
*
|
||||
* @return nlohmann::json value converted to JSON
|
||||
* @throw dpp::exception Data stream isn't long enough to fetch requested bits
|
||||
*/
|
||||
nlohmann::json decode_export();
|
||||
|
||||
/**
|
||||
* @brief Write to output buffer for creation of ETF from JSON
|
||||
*
|
||||
* @param pk buffer struct
|
||||
* @param bytes byte buffer to write
|
||||
* @param l number of bytes to write
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void buffer_write(etf_buffer *pk, const char *bytes, size_t l);
|
||||
|
||||
/**
|
||||
* @brief Append version number to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_version(etf_buffer *b);
|
||||
|
||||
/**
|
||||
* @brief Append nil value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_nil(etf_buffer *b);
|
||||
|
||||
/**
|
||||
* @brief Append false value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_false(etf_buffer *b);
|
||||
|
||||
/**
|
||||
* @brief Append true value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_true(etf_buffer *b);
|
||||
|
||||
/**
|
||||
* @brief Append small integer value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param d double to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_small_integer(etf_buffer *b, unsigned char d);
|
||||
|
||||
/**
|
||||
* @brief Append integer value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param d integer to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_integer(etf_buffer *b, int32_t d);
|
||||
|
||||
/**
|
||||
* @brief Append 64 bit integer value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param d integer to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_unsigned_long_long(etf_buffer *b, unsigned long long d);
|
||||
|
||||
/**
|
||||
* @brief Append 64 bit integer value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param d integer to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_long_long(etf_buffer *b, long long d);
|
||||
|
||||
/**
|
||||
* @brief Append double value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param f double to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_double(etf_buffer *b, double f);
|
||||
|
||||
/**
|
||||
* @brief Append atom value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param bytes pointer to string to append
|
||||
* @param size size of string to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_atom(etf_buffer *b, const char *bytes, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Append utf8 atom value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param bytes pointer to string to append
|
||||
* @param size size of string to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_atom_utf8(etf_buffer *b, const char *bytes, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Append binary value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param bytes pointer to string to append
|
||||
* @param size size of string to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_binary(etf_buffer *b, const char *bytes, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Append string value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param bytes pointer to string to append
|
||||
* @param size size of string to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_string(etf_buffer *b, const char *bytes, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Append tuple value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param size size of value to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_tuple_header(etf_buffer *b, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Append list terminator to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_nil_ext(etf_buffer *b);
|
||||
|
||||
/**
|
||||
* @brief Append a list header value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param size size of values to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_list_header(etf_buffer *b, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Append a map header value to ETF buffer
|
||||
*
|
||||
* @param b buffer to append to
|
||||
* @param size size of values to append
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void append_map_header(etf_buffer *b, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Build ETF buffer
|
||||
*
|
||||
* @param j JSON object to build from
|
||||
* @param b Buffer to append to
|
||||
* @throw std::exception Buffer cannot be extended
|
||||
*/
|
||||
void inner_build(const nlohmann::json* j, etf_buffer* b);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new etf parser object
|
||||
*/
|
||||
etf_parser();
|
||||
|
||||
/**
|
||||
* @brief Destroy the etf parser object
|
||||
*/
|
||||
~etf_parser();
|
||||
|
||||
/**
|
||||
* @brief Convert ETF binary content to nlohmann::json
|
||||
*
|
||||
* @param in Raw binary ETF data (generally from a websocket)
|
||||
* @return nlohmann::json JSON data for use in the library
|
||||
* @throw dpp::exception Malformed or otherwise invalid ETF content
|
||||
*/
|
||||
nlohmann::json parse(const std::string& in);
|
||||
|
||||
/**
|
||||
* @brief Create ETF binary data from nlohmann::json
|
||||
*
|
||||
* @param j JSON value to encode to ETF
|
||||
* @return std::string raw ETF data. Note that this can
|
||||
* and probably will contain null values, use std::string::data()
|
||||
* and std::string::size() to manipulate or send it.
|
||||
* @throw std::exception Not enough memory, or invalid data types/values
|
||||
*/
|
||||
std::string build(const nlohmann::json& j);
|
||||
};
|
||||
|
||||
};
|
151
vendor/DPP/include/dpp/event.h
vendored
Normal file
151
vendor/DPP/include/dpp/event.h
vendored
Normal file
@ -0,0 +1,151 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
|
||||
#define event_decl(x,wstype) /** @brief Internal event handler for wstype websocket events. Called for each websocket message of this type. @internal */ \
|
||||
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 DPP_EXPORT 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,LOG);
|
||||
|
||||
/* Guilds */
|
||||
event_decl(guild_create,GUILD_CREATE);
|
||||
event_decl(guild_update,GUILD_UPDATE);
|
||||
event_decl(guild_delete,GUILD_DELETE);
|
||||
event_decl(guild_ban_add,GUILD_BAN_ADD);
|
||||
event_decl(guild_ban_remove,GUILD_BAN_REMOVE);
|
||||
event_decl(guild_emojis_update,GUILD_EMOJIS_UPDATE);
|
||||
event_decl(guild_integrations_update,GUILD_INTEGRATIONS_UPDATE);
|
||||
event_decl(guild_join_request_delete,GUILD_JOIN_REQUEST_DELETE);
|
||||
event_decl(guild_stickers_update,GUILD_STICKERS_UPDATE);
|
||||
|
||||
/* Stage channels */
|
||||
event_decl(stage_instance_create,STAGE_INSTANCE_CREATE);
|
||||
event_decl(stage_instance_update,STAGE_INSTANCE_UPDATE);
|
||||
event_decl(stage_instance_delete,STAGE_INSTANCE_DELETE);
|
||||
|
||||
/* Guild members */
|
||||
event_decl(guild_member_add,GUILD_MEMBER_ADD);
|
||||
event_decl(guild_member_remove,GUILD_MEMBER_REMOVE);
|
||||
event_decl(guild_members_chunk,GUILD_MEMBERS_CHUNK);
|
||||
event_decl(guild_member_update,GUILD_MEMBERS_UPDATE);
|
||||
|
||||
/* Guild roles */
|
||||
event_decl(guild_role_create,GUILD_ROLE_CREATE);
|
||||
event_decl(guild_role_update,GUILD_ROLE_UPDATE);
|
||||
event_decl(guild_role_delete,GUILD_ROLE_DELETE);
|
||||
|
||||
/* Session state */
|
||||
event_decl(resumed,RESUMED);
|
||||
event_decl(ready,READY);
|
||||
|
||||
/* Channels */
|
||||
event_decl(channel_create,CHANNEL_CREATE);
|
||||
event_decl(channel_update,CHANNEL_UPDATE);
|
||||
event_decl(channel_delete,CHANNEL_DELETE);
|
||||
event_decl(channel_pins_update,CHANNEL_PINS_UPDATE);
|
||||
|
||||
/* Threads */
|
||||
event_decl(thread_create,THREAD_CREATE);
|
||||
event_decl(thread_update,THREAD_UPDATE);
|
||||
event_decl(thread_delete,THREAD_DELETE);
|
||||
event_decl(thread_list_sync,THREAD_LIST_SYNC);
|
||||
event_decl(thread_member_update,THREAD_MEMBER_UPDATE);
|
||||
event_decl(thread_members_update,THREAD_MEMBERS_UPDATE);
|
||||
|
||||
/* Messages */
|
||||
event_decl(message_create,MESSAGE_CREATE);
|
||||
event_decl(message_update,MESSAGE_UPDATE);
|
||||
event_decl(message_delete,MESSAGE_DELETE);
|
||||
event_decl(message_delete_bulk,MESSAGE_DELETE_BULK);
|
||||
|
||||
/* Presence/typing */
|
||||
event_decl(presence_update,PRESENCE_UPDATE);
|
||||
event_decl(typing_start,TYPING_START);
|
||||
|
||||
/* Users (outside of guild) */
|
||||
event_decl(user_update,USER_UPDATE);
|
||||
|
||||
/* Message reactions */
|
||||
event_decl(message_reaction_add,MESSAGE_REACTION_ADD);
|
||||
event_decl(message_reaction_remove,MESSAGE_REACTION_REMOVE);
|
||||
event_decl(message_reaction_remove_all,MESSAGE_REACTION_REMOVE_ALL);
|
||||
event_decl(message_reaction_remove_emoji,MESSAGE_REACTION_REMOVE_EMOJI);
|
||||
|
||||
/* Invites */
|
||||
event_decl(invite_create,INVITE_CREATE);
|
||||
event_decl(invite_delete,INVITE_DELETE);
|
||||
|
||||
/* Voice */
|
||||
event_decl(voice_state_update,VOICE_STATE_UPDATE);
|
||||
event_decl(voice_server_update,VOICE_SERVER_UPDATE);
|
||||
|
||||
/* Webhooks */
|
||||
event_decl(webhooks_update,WEBHOOKS_UPDATE);
|
||||
|
||||
/* Application commands */
|
||||
event_decl(interaction_create,INTERACTION_CREATE);
|
||||
|
||||
/* Integrations */
|
||||
event_decl(integration_create,INTEGRATION_CREATE);
|
||||
event_decl(integration_update,INTEGRATION_UPDATE);
|
||||
event_decl(integration_delete,INTEGRATION_DELETE);
|
||||
|
||||
/* Scheduled events */
|
||||
event_decl(guild_scheduled_event_create,GUILD_SCHEDULED_EVENT_CREATE);
|
||||
event_decl(guild_scheduled_event_update,GUILD_SCHEDULED_EVENT_UPDATE);
|
||||
event_decl(guild_scheduled_event_delete,GUILD_SCHEDULED_EVENT_DELETE);
|
||||
event_decl(guild_scheduled_event_user_add,GUILD_SCHEDULED_EVENT_USER_ADD);
|
||||
event_decl(guild_scheduled_event_user_remove,GUILD_SCHEDULED_EVENT_USER_REMOVE);
|
||||
|
||||
/* Auto moderation */
|
||||
event_decl(automod_rule_create, AUTO_MODERATION_RULE_CREATE);
|
||||
event_decl(automod_rule_update, AUTO_MODERATION_RULE_UPDATE);
|
||||
event_decl(automod_rule_delete, AUTO_MODERATION_RULE_DELETE);
|
||||
event_decl(automod_rule_execute, AUTO_MODERATION_ACTION_EXECUTION);
|
||||
|
||||
}};
|
246
vendor/DPP/include/dpp/event_router.h
vendored
Normal file
246
vendor/DPP/include/dpp/event_router.h
vendored
Normal file
@ -0,0 +1,246 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <variant>
|
||||
#include <dpp/snowflake.h>
|
||||
#include <dpp/misc-enum.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <shared_mutex>
|
||||
#include <cstring>
|
||||
#include <dpp/coro.h>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief A returned event handle for an event which was attached
|
||||
*/
|
||||
typedef size_t event_handle;
|
||||
|
||||
/**
|
||||
* @brief Handles routing of an event to multiple listeners.
|
||||
*
|
||||
* Multiple listeners may attach to the event_router_t by means of operator(). Passing a
|
||||
* lambda into operator() attaches to the event.
|
||||
*
|
||||
* Dispatchers of the event may call the event_router_t::call() method to cause all listeners
|
||||
* to receive the event.
|
||||
*
|
||||
* The event_router_t::empty() method will return true if there are no listeners attached
|
||||
* to the event_router_t (this can be used to save time by not constructing objects that
|
||||
* nobody will ever see).
|
||||
*
|
||||
* The event_router_t::detach() method removes an existing listener from the event,
|
||||
* using the event_handle ID returned by operator().
|
||||
*
|
||||
* This class is used by the library to route all websocket events to listening code.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```cpp
|
||||
* // Declare an event that takes log_t as its parameter
|
||||
* event_router_t<log_t> my_event;
|
||||
*
|
||||
* // Attach a listener to the event
|
||||
* event_handle id = my_event([&](const log_t& cc) {
|
||||
* std::cout << cc.message << "\n";
|
||||
* });
|
||||
*
|
||||
* // Construct a log_t and call the event (listeners will receive the log_t object)
|
||||
* log_t lt;
|
||||
* lt.message = "foo";
|
||||
* my_event.call(lt);
|
||||
*
|
||||
* // Detach from an event using the handle returned by operator()
|
||||
* my_event.detach(id);
|
||||
* ```
|
||||
*
|
||||
* @tparam T type of single parameter passed to event lambda derived from event_dispatch_t
|
||||
*/
|
||||
template<class T> class event_router_t {
|
||||
private:
|
||||
friend class cluster;
|
||||
|
||||
event_handle next_handle = 1;
|
||||
|
||||
/**
|
||||
* @brief Thread safety mutex
|
||||
*/
|
||||
mutable std::shared_mutex lock;
|
||||
/**
|
||||
* @brief Container of event listeners keyed by handle,
|
||||
* as handles are handed out sequentially they will always
|
||||
* be called in they order they are bound to the event
|
||||
* as std::map is an ordered container.
|
||||
*/
|
||||
std::map<event_handle, std::function<void(const T&)>> dispatch_container;
|
||||
|
||||
|
||||
#ifdef DPP_CORO
|
||||
/**
|
||||
* @brief Container for event listeners (coroutines only)
|
||||
*/
|
||||
std::map<event_handle, std::function<dpp::task(T)>> coroutine_container;
|
||||
#else
|
||||
/**
|
||||
* @brief Dummy container to keep the struct size same
|
||||
*/
|
||||
std::map<event_handle, std::function<void(T)>> dummy_container;
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief A function to be called whenever the method is called, to check
|
||||
* some condition that is required for this event to trigger correctly.
|
||||
*/
|
||||
std::function<void(const T&)> warning;
|
||||
|
||||
/**
|
||||
* @brief Next handle to be given out by the event router
|
||||
*/
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief Set the warning callback object used to check that this
|
||||
* event is capable of running properly
|
||||
*
|
||||
* @param warning_function A checking function to call
|
||||
*/
|
||||
void set_warning_callback(std::function<void(const T&)> warning_function) {
|
||||
warning = warning_function;
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new event_router_t object.
|
||||
*/
|
||||
event_router_t() = default;
|
||||
|
||||
/**
|
||||
* @brief Call all attached listeners.
|
||||
* Listeners may cancel, by calling the event.cancel method.
|
||||
*
|
||||
* @param event Class to pass as parameter to all listeners.
|
||||
*/
|
||||
void call(const T& event) const {
|
||||
if (warning) {
|
||||
warning(event);
|
||||
}
|
||||
std::shared_lock l(lock);
|
||||
std::for_each(dispatch_container.begin(), dispatch_container.end(), [&](auto &ev) {
|
||||
if (!event.is_cancelled()) {
|
||||
ev.second(event);
|
||||
}
|
||||
});
|
||||
#ifdef DPP_CORO
|
||||
std::for_each(coroutine_container.begin(), coroutine_container.end(), [&](auto &ev) {
|
||||
if (!event.is_cancelled()) {
|
||||
ev.second(event);
|
||||
}
|
||||
});
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Returns true if the container of listeners is empty,
|
||||
* i.e. there is nothing listening for this event right now.
|
||||
*
|
||||
* @return true if there are no listeners
|
||||
* @return false if there are some listeners
|
||||
*/
|
||||
bool empty() const {
|
||||
std::shared_lock l(lock);
|
||||
return dispatch_container.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns true if any listeners are attached.
|
||||
*
|
||||
* This is the boolean opposite of event_router_t::empty().
|
||||
* @return true if listeners are attached
|
||||
* @return false if no listeners are attached
|
||||
*/
|
||||
operator bool() const {
|
||||
return !empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Attach a lambda to the event, adding a listener.
|
||||
* The lambda should follow the signature specified when declaring
|
||||
* the event object and should take exactly one parameter derived
|
||||
* from event_dispatch_t.
|
||||
*
|
||||
* @param func Function lambda to attach to event
|
||||
* @return event_handle An event handle unique to this event, used to
|
||||
* detach the listener from the event later if necessary.
|
||||
*/
|
||||
event_handle operator()(std::function<void(const T&)> func) {
|
||||
return this->attach(func);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Attach a lambda to the event, adding a listener.
|
||||
* The lambda should follow the signature specified when declaring
|
||||
* the event object and should take exactly one parameter derived
|
||||
* from event_dispatch_t.
|
||||
*
|
||||
* @param func Function lambda to attach to event
|
||||
* @return event_handle An event handle unique to this event, used to
|
||||
* detach the listener from the event later if necessary.
|
||||
*/
|
||||
event_handle attach(std::function<void(const T&)> func) {
|
||||
std::unique_lock l(lock);
|
||||
event_handle h = next_handle++;
|
||||
dispatch_container.emplace(h, func);
|
||||
return h;
|
||||
}
|
||||
|
||||
#ifdef DPP_CORO
|
||||
event_handle co_attach(std::function<dpp::task(T)> func) {
|
||||
std::unique_lock l(lock);
|
||||
event_handle h = next_handle++;
|
||||
coroutine_container.emplace(h, func);
|
||||
return h;
|
||||
}
|
||||
#endif
|
||||
/**
|
||||
* @brief Detach a listener from the event using a previously obtained ID.
|
||||
*
|
||||
* @param handle An ID obtained from event_router_t::operator()
|
||||
* @return true The event was successfully detached
|
||||
* @return false The ID is invalid (possibly already detached, or does not exist)
|
||||
*/
|
||||
bool detach(const event_handle& handle) {
|
||||
std::unique_lock l(lock);
|
||||
return this->dispatch_container.erase(handle);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
201
vendor/DPP/include/dpp/exception.h
vendored
Normal file
201
vendor/DPP/include/dpp/exception.h
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <exception>
|
||||
#include <algorithm>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief The dpp::exception class derives from std::exception and supports some other
|
||||
* ways of passing in error details such as via std::string.
|
||||
*/
|
||||
class exception : public std::exception
|
||||
{
|
||||
protected:
|
||||
/**
|
||||
* @brief Exception message
|
||||
*/
|
||||
std::string msg;
|
||||
|
||||
public:
|
||||
|
||||
using std::exception::exception;
|
||||
|
||||
/**
|
||||
* @brief Construct a new exception object
|
||||
*/
|
||||
exception() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new exception object
|
||||
*
|
||||
* @param what reason message
|
||||
*/
|
||||
explicit exception(const char* what) : msg(what) { }
|
||||
|
||||
/**
|
||||
* @brief Construct a new exception object
|
||||
*
|
||||
* @param what reason message
|
||||
* @param len length of reason message
|
||||
*/
|
||||
exception(const char* what, size_t len) : msg(what, len) { }
|
||||
|
||||
/**
|
||||
* @brief Construct a new exception object
|
||||
*
|
||||
* @param what reason message
|
||||
*/
|
||||
explicit exception(const std::string& what) : msg(what) { }
|
||||
|
||||
/**
|
||||
* @brief Construct a new exception object
|
||||
*
|
||||
* @param what reason message
|
||||
*/
|
||||
explicit exception(std::string&& what) : msg(std::move(what)) { }
|
||||
|
||||
/**
|
||||
* @brief Construct a new exception object (copy constructor)
|
||||
*/
|
||||
exception(const exception&) = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new exception object (move constructor)
|
||||
*/
|
||||
exception(exception&&) = default;
|
||||
|
||||
/**
|
||||
* @brief Destroy the exception object
|
||||
*/
|
||||
~exception() override = default;
|
||||
|
||||
/**
|
||||
* @brief Copy assignment operator
|
||||
*
|
||||
* @return exception& reference to self
|
||||
*/
|
||||
exception & operator = (const exception &) = default;
|
||||
|
||||
/**
|
||||
* @brief Move assignment operator
|
||||
*
|
||||
* @return exception& reference to self
|
||||
*/
|
||||
exception & operator = (exception&&) = default;
|
||||
|
||||
/**
|
||||
* @brief Get exception message
|
||||
*
|
||||
* @return const char* error message
|
||||
*/
|
||||
[[nodiscard]] const char* what() const noexcept override { return msg.c_str(); };
|
||||
|
||||
};
|
||||
|
||||
#ifndef _DOXYGEN_
|
||||
#define derived_exception(name, ancestor) class name : public dpp::ancestor { \
|
||||
public: \
|
||||
using dpp::ancestor::ancestor; \
|
||||
name() = default; \
|
||||
explicit name(const char* what) : ancestor(what) { } \
|
||||
name(const char* what, size_t len) : ancestor(what, len) { } \
|
||||
explicit name(const std::string& what) : ancestor(what) { } \
|
||||
explicit name(std::string&& what) : ancestor(what) { } \
|
||||
name(const name&) = default; \
|
||||
name(name&&) = default; \
|
||||
~name() override = default; \
|
||||
name & operator = (const name &) = default; \
|
||||
name & operator = (name&&) = default; \
|
||||
[[nodiscard]] const char* what() const noexcept override { return msg.c_str(); }; \
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef _DOXYGEN_
|
||||
/*
|
||||
* THESE DEFINITIONS ARE NOT THE REAL DEFINITIONS USED BY PROGRAM CODE.
|
||||
*
|
||||
* They exist only to cause Doxygen to emit proper documentation for the derived exception types.
|
||||
* Proper definitions are emitted by the `derived_exception` macro in the "else" section.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Represents an error in logic, e.g. you asked the library to do something the Discord API does not support
|
||||
* @note This is a stub for documentation purposes. For full information on supported methods please see dpp::exception.
|
||||
*/
|
||||
class logic_exception : public dpp::exception { };
|
||||
/**
|
||||
* @brief Represents an error reading or writing to a file
|
||||
* @note This is a stub for documentation purposes. For full information on supported methods please see dpp::exception.
|
||||
*/
|
||||
class file_exception : public dpp::exception { };
|
||||
/**
|
||||
* @brief Represents an error establishing or maintaining a connection
|
||||
* @note This is a stub for documentation purposes. For full information on supported methods please see dpp::exception.
|
||||
*/
|
||||
class connection_exception : public dpp::exception { };
|
||||
/**
|
||||
* @brief Represents an error with voice processing
|
||||
* @note This is a stub for documentation purposes. For full information on supported methods please see dpp::exception.
|
||||
*/
|
||||
class voice_exception : public dpp::exception { };
|
||||
/**
|
||||
* @brief Represents an error on a REST API call, e.g. a HTTPS request
|
||||
* @note This is a stub for documentation purposes. For full information on supported methods please see dpp::exception.
|
||||
*/
|
||||
class rest_exception : public dpp::exception { };
|
||||
/**
|
||||
* @brief Represents invalid length of argument being passed to a function
|
||||
* @note This is a stub for documentation purposes. For full information on supported methods please see dpp::exception.
|
||||
*/
|
||||
class length_exception : public dpp::exception { };
|
||||
/**
|
||||
* @brief Represents inability to parse data, usually caused by malformed JSON or ETF
|
||||
* @note This is a stub for documentation purposes. For full information on supported methods please see dpp::exception.
|
||||
*/
|
||||
class parse_exception : public dpp::exception { };
|
||||
/**
|
||||
* @brief Represents invalid access to dpp's cache or its members, which may or may not exist.
|
||||
* @note This is a stub for documentation purposes. For full information on supported methods please see dpp::exception.
|
||||
*/
|
||||
class cache_exception : public dpp::exception { };
|
||||
/**
|
||||
* @brief Represents an attempt to construct a cluster with an invalid bot token.
|
||||
* @note This is a stub for documentation purposes. For full information on supported methods please see dpp::exception.
|
||||
*/
|
||||
class invalid_token_exception : public dpp::rest_exception { };
|
||||
#else
|
||||
derived_exception(logic_exception, exception);
|
||||
derived_exception(file_exception, exception);
|
||||
derived_exception(connection_exception, exception);
|
||||
derived_exception(voice_exception, exception);
|
||||
derived_exception(rest_exception, exception);
|
||||
derived_exception(invalid_token_exception, rest_exception);
|
||||
derived_exception(length_exception, exception);
|
||||
derived_exception(parse_exception, exception);
|
||||
derived_exception(cache_exception, exception);
|
||||
#endif
|
||||
|
||||
};
|
||||
|
66
vendor/DPP/include/dpp/export.h
vendored
Normal file
66
vendor/DPP/include/dpp/export.h
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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
|
||||
|
||||
/* Compile-time check for C++17.
|
||||
* Either one of the following causes a compile time error:
|
||||
* __cplusplus not defined at all (this means we are being compiled on a C compiler)
|
||||
* MSVC defined and _MSVC_LANG < 201703L (Visual Studio, but not C++17 or newer)
|
||||
* MSVC not defined and __cplusplus < 201703L (Non-visual studio, but not C++17 or newer)
|
||||
* The additional checks are required because MSVC doesn't correctly set __cplusplus to 201703L,
|
||||
* which is hugely non-standard, but apparently "it broke stuff" so they dont ever change it
|
||||
* from C++98. Ugh.
|
||||
*/
|
||||
#if (!defined(__cplusplus) || (defined(_MSC_VER) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201703L)) || (!defined(_MSC_VER) && __cplusplus < 201703L))
|
||||
#error "D++ Requires a C++17 compatible C++ compiler. Please ensure that you have enabled C++17 in your compiler flags."
|
||||
#endif
|
||||
|
||||
#ifndef DPP_STATIC
|
||||
/* Dynamic linked build as shared object or dll */
|
||||
#ifdef DPP_BUILD
|
||||
/* Building the library */
|
||||
#ifdef _WIN32
|
||||
#include <dpp/win32_safe_warnings.h>
|
||||
#define DPP_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DPP_EXPORT
|
||||
#endif
|
||||
#else
|
||||
/* Including the library */
|
||||
#ifdef _WIN32
|
||||
#define DPP_EXPORT __declspec(dllimport)
|
||||
#else
|
||||
#define DPP_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
/* Static linked build */
|
||||
#if defined(_WIN32) && defined(DPP_BUILD)
|
||||
#include <dpp/win32_safe_warnings.h>
|
||||
#endif
|
||||
#define DPP_EXPORT
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#define SOCKET int
|
||||
#else
|
||||
#include <WinSock2.h>
|
||||
#endif
|
1022
vendor/DPP/include/dpp/guild.h
vendored
Normal file
1022
vendor/DPP/include/dpp/guild.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
316
vendor/DPP/include/dpp/httpsclient.h
vendored
Normal file
316
vendor/DPP/include/dpp/httpsclient.h
vendored
Normal file
@ -0,0 +1,316 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 HTTP connection status
|
||||
*/
|
||||
enum http_state : uint8_t {
|
||||
/**
|
||||
* @brief Sending/receiving HTTP headers and request body
|
||||
*/
|
||||
HTTPS_HEADERS,
|
||||
|
||||
/**
|
||||
* @brief Receiving body content.
|
||||
*/
|
||||
HTTPS_CONTENT,
|
||||
|
||||
/**
|
||||
* @brief Completed connection, as it was closed or the body is >= Content-Length
|
||||
*
|
||||
*/
|
||||
HTTPS_DONE,
|
||||
|
||||
/**
|
||||
* @brief Received chunk length
|
||||
*
|
||||
*/
|
||||
HTTPS_CHUNK_LEN,
|
||||
|
||||
/**
|
||||
* @brief Received chunk trailing CRLF
|
||||
*/
|
||||
HTTPS_CHUNK_TRAILER,
|
||||
|
||||
/**
|
||||
* @brief The last received chunk is the final chunk
|
||||
*/
|
||||
HTTPS_CHUNK_LAST,
|
||||
|
||||
/**
|
||||
* @brief Receiving contents of a chunk
|
||||
*/
|
||||
HTTPS_CHUNK_CONTENT
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Request headers
|
||||
*/
|
||||
typedef std::multimap<std::string, std::string> http_headers;
|
||||
|
||||
/**
|
||||
* @brief Represents a multipart mime body and the correct top-level mime type
|
||||
* If a non-multipart request is passed in, this is represented as a plain body
|
||||
* and the application/json mime type.
|
||||
*/
|
||||
struct multipart_content {
|
||||
/**
|
||||
* @brief Multipart body
|
||||
*/
|
||||
std::string body;
|
||||
/**
|
||||
* @brief MIME type
|
||||
*/
|
||||
std::string mimetype;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a HTTP scheme, hostname and port
|
||||
* split into parts for easy use in https_client.
|
||||
*/
|
||||
struct http_connect_info {
|
||||
/**
|
||||
* @brief True if the connection should be SSL
|
||||
*/
|
||||
bool is_ssl;
|
||||
/**
|
||||
* @brief The request scheme, e.g. 'https' or 'http'
|
||||
*/
|
||||
std::string scheme;
|
||||
/**
|
||||
* @brief The request hostname part, e.g. 'discord.com'
|
||||
*/
|
||||
std::string hostname;
|
||||
/**
|
||||
* @brief The port number, either determined from the scheme,
|
||||
* or from the part of the hostname after a colon ":" character
|
||||
*/
|
||||
uint16_t port;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Implements a HTTPS socket client based on the SSL client.
|
||||
* @note plaintext HTTP without SSL is also supported via a "downgrade" setting
|
||||
*/
|
||||
class DPP_EXPORT https_client : public ssl_client
|
||||
{
|
||||
/**
|
||||
* @brief Current connection state
|
||||
*/
|
||||
http_state state;
|
||||
|
||||
/**
|
||||
* @brief The type of the request, e.g. GET, POST
|
||||
*/
|
||||
std::string request_type;
|
||||
|
||||
/**
|
||||
* @brief Path part of URL for HTTPS connection
|
||||
*/
|
||||
std::string path;
|
||||
|
||||
/**
|
||||
* @brief The request body, e.g. form data
|
||||
*/
|
||||
std::string request_body;
|
||||
|
||||
/**
|
||||
* @brief The response body, e.g. file content or JSON
|
||||
*/
|
||||
std::string body;
|
||||
|
||||
/**
|
||||
* @brief The reported length of the content. If this is
|
||||
* UULONG_MAX, then no length was reported by the server.
|
||||
*/
|
||||
uint64_t content_length;
|
||||
|
||||
/**
|
||||
* @brief Headers for the request, e.g. Authorization, etc.
|
||||
*/
|
||||
http_headers request_headers;
|
||||
|
||||
/**
|
||||
* @brief The status of the HTTP request from the server,
|
||||
* e.g. 200 for OK, 404 for not found. A value of 0 means
|
||||
* no request has been completed.
|
||||
*/
|
||||
uint16_t status;
|
||||
|
||||
/**
|
||||
* @brief Time at which the request should be abandoned
|
||||
*/
|
||||
time_t timeout;
|
||||
|
||||
/**
|
||||
* @brief If true the content is chunked encoding
|
||||
*/
|
||||
bool chunked;
|
||||
|
||||
/**
|
||||
* @brief Size of current chunk
|
||||
*/
|
||||
size_t chunk_size;
|
||||
|
||||
/**
|
||||
* @brief Number of bytes received in current chunk
|
||||
*/
|
||||
size_t chunk_receive;
|
||||
|
||||
/**
|
||||
* @brief Headers from the server's response, e.g. RateLimit
|
||||
* headers, cookies, etc.
|
||||
*/
|
||||
std::map<std::string, std::string> response_headers;
|
||||
|
||||
/**
|
||||
* @brief Handle input buffer
|
||||
*
|
||||
* @param buffer Buffer to read
|
||||
* @return returns true if the connection should remain open
|
||||
*/
|
||||
bool do_buffer(std::string& buffer);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief Start the connection
|
||||
*/
|
||||
virtual void connect();
|
||||
|
||||
/**
|
||||
* @brief Get request state
|
||||
* @return request state
|
||||
*/
|
||||
http_state get_state();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief Connect to a specific HTTP(S) server and complete a request.
|
||||
*
|
||||
* The constructor will attempt the connection, and return the content.
|
||||
* By the time the constructor completes, the HTTP request will be stored
|
||||
* in the object.
|
||||
*
|
||||
* @note This is a blocking call. It starts a loop which runs non-blocking
|
||||
* functions within it, but does not return until the request completes.
|
||||
* See queues.cpp for how to make this asynchronous.
|
||||
*
|
||||
* @param hostname Hostname to connect to
|
||||
* @param port Port number to connect to, usually 443 for SSL and 80 for plaintext
|
||||
* @param urlpath path part of URL, e.g. "/api"
|
||||
* @param verb Request verb, e.g. GET or POST
|
||||
* @param req_body Request body, use dpp::https_client::build_multipart() to build a multipart MIME body (e.g. for multiple file upload)
|
||||
* @param extra_headers Additional request headers, e.g. user-agent, authorization, etc
|
||||
* @param plaintext_connection Set to true to make the connection plaintext (turns off SSL)
|
||||
* @param request_timeout How many seconds before the connection is considered failed if not finished
|
||||
*/
|
||||
https_client(const std::string &hostname, uint16_t port = 443, const std::string &urlpath = "/", const std::string &verb = "GET", const std::string &req_body = "", const http_headers& extra_headers = {}, bool plaintext_connection = false, uint16_t request_timeout = 5);
|
||||
|
||||
/**
|
||||
* @brief Destroy the https client object
|
||||
*/
|
||||
virtual ~https_client();
|
||||
|
||||
/**
|
||||
* @brief Build a multipart content from a set of files and some json
|
||||
*
|
||||
* @param json The json content
|
||||
* @param filenames File names of files to send
|
||||
* @param contents Contents of each of the files to send
|
||||
* @return multipart mime content and headers
|
||||
*/
|
||||
static multipart_content build_multipart(const std::string &json, const std::vector<std::string>& filenames = {}, const std::vector<std::string>& contents = {});
|
||||
|
||||
/**
|
||||
* @brief Processes incoming data 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 HTTPS socket
|
||||
*/
|
||||
virtual void close();
|
||||
|
||||
/**
|
||||
* @brief Fires every second from the underlying socket I/O loop, used for timeouts
|
||||
*/
|
||||
virtual void one_second_timer();
|
||||
|
||||
/**
|
||||
* @brief Get a HTTP response header
|
||||
*
|
||||
* @param header_name Header name to find, case insensitive
|
||||
* @return Header content or empty string if not found
|
||||
*/
|
||||
const std::string get_header(std::string header_name) const;
|
||||
|
||||
/**
|
||||
* @brief Get all HTTP response headers
|
||||
*
|
||||
* @return headers as a map
|
||||
*/
|
||||
const std::map<std::string, std::string> get_headers() const;
|
||||
|
||||
/**
|
||||
* @brief Get the response content
|
||||
*
|
||||
* @return response content
|
||||
*/
|
||||
const std::string get_content() const;
|
||||
|
||||
/**
|
||||
* @brief Get the response HTTP status, e.g.
|
||||
* 200 for OK, 404 for not found, 429 for rate limited.
|
||||
* A value of 0 indicates the request was not completed.
|
||||
*
|
||||
* @return uint16_t HTTP status
|
||||
*/
|
||||
uint16_t get_status() const;
|
||||
|
||||
/**
|
||||
* @brief Break down a scheme, hostname and port into
|
||||
* a http_connect_info.
|
||||
*
|
||||
* All but the hostname portion are optional. The path component
|
||||
* should not be passed to this function.
|
||||
*
|
||||
* @param url URL to break down
|
||||
* @return Split URL
|
||||
*/
|
||||
static http_connect_info get_host_info(std::string url);
|
||||
|
||||
};
|
||||
|
||||
};
|
171
vendor/DPP/include/dpp/integration.h
vendored
Normal file
171
vendor/DPP/include/dpp/integration.h
vendored
Normal file
@ -0,0 +1,171 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <unordered_map>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
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 syncing
|
||||
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 DPP_EXPORT integration_app {
|
||||
/// Integration id
|
||||
snowflake id;
|
||||
/// Name
|
||||
std::string name;
|
||||
/// Icon
|
||||
std::string icon;
|
||||
/// Description
|
||||
std::string description;
|
||||
/// Integration summary @deprecated Removed by Discord
|
||||
std::string summary;
|
||||
/// Pointer to bot user
|
||||
class user* bot;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents an integration on a guild, e.g. a connection to twitch.
|
||||
*/
|
||||
class DPP_EXPORT integration : public managed, public json_interface<integration> {
|
||||
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;
|
||||
/** The grace period (in days) before expiring subscribers */
|
||||
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;
|
||||
/** The bot/OAuth2 application for discord integrations */
|
||||
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.
|
||||
* @param with_id Add ID to output
|
||||
* @return JSON string of the object
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) 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;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The connection object that the user has attached.
|
||||
*/
|
||||
class DPP_EXPORT connection {
|
||||
public:
|
||||
std::string id; //!< id of the connection account
|
||||
std::string name; //!< the username of the connection account
|
||||
std::string type; //!< the service of the connection (twitch, youtube, discord, or guild_subscription)
|
||||
bool revoked; //!< Optional: whether the connection is revoked
|
||||
std::vector<integration> integrations; //!< Optional: an array of partial server integrations
|
||||
bool verified; //!< whether the connection is verified
|
||||
bool friend_sync; //!< whether friend sync is enabled for this connection
|
||||
bool show_activity; //!< whether activities related to this connection will be shown in presence updates
|
||||
bool two_way_link; //!< Whether this connection has a corresponding third party OAuth2 token
|
||||
bool visible; //!< visibility of this connection
|
||||
|
||||
/**
|
||||
* @brief Construct a new connection object
|
||||
*/
|
||||
connection();
|
||||
|
||||
/** Read class values from json object
|
||||
* @param j A json object to read from
|
||||
* @return A reference to self
|
||||
*/
|
||||
connection& fill_from_json(nlohmann::json* j);
|
||||
|
||||
};
|
||||
|
||||
/** A group of integrations */
|
||||
typedef std::unordered_map<snowflake, integration> integration_map;
|
||||
|
||||
/** A group of connections */
|
||||
typedef std::unordered_map<snowflake, connection> connection_map;
|
||||
|
||||
};
|
||||
|
86
vendor/DPP/include/dpp/intents.h
vendored
Normal file
86
vendor/DPP/include/dpp/intents.h
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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),
|
||||
/// Intent for receipt of message content
|
||||
i_message_content = (1 << 15),
|
||||
/// Scheduled events
|
||||
i_guild_scheduled_events = (1 << 16),
|
||||
/// Auto moderation configuration
|
||||
i_auto_moderation_configuration = (1 << 20),
|
||||
/// Auto moderation configuration
|
||||
i_auto_moderation_execution = (1 << 21),
|
||||
/// 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 |
|
||||
dpp::i_guild_scheduled_events | dpp::i_auto_moderation_configuration |
|
||||
dpp::i_auto_moderation_execution,
|
||||
/// Privileged intents requiring ID
|
||||
i_privileged_intents = dpp::i_guild_members | dpp::i_guild_presences | dpp::i_message_content,
|
||||
/// Every single intent
|
||||
i_all_intents = dpp::i_default_intents | dpp::i_privileged_intents,
|
||||
/// Unverified bots default intents
|
||||
i_unverified_default_intents = dpp::i_default_intents | dpp::i_message_content
|
||||
};
|
||||
|
||||
};
|
110
vendor/DPP/include/dpp/invite.h
vendored
Normal file
110
vendor/DPP/include/dpp/invite.h
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/stage_instance.h>
|
||||
#include <unordered_map>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents an invite to a discord guild or channel
|
||||
*/
|
||||
class DPP_EXPORT invite : public json_interface<invite> {
|
||||
public:
|
||||
/** Invite code
|
||||
*/
|
||||
std::string code;
|
||||
/** Readonly expiration timestamp of this invite or 0 if the invite doesn't expire
|
||||
*/
|
||||
time_t expires_at;
|
||||
/** 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 (in seconds) 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;
|
||||
/** How many times this invite has been used
|
||||
*
|
||||
* @note Only set when using cluster::channel_invites_get
|
||||
*/
|
||||
uint32_t uses;
|
||||
/** The stage instance data if there is a public stage instance in the stage channel this invite is for
|
||||
* @deprecated Deprecated
|
||||
*/
|
||||
stage_instance stage;
|
||||
|
||||
/** Constructor
|
||||
*/
|
||||
invite();
|
||||
|
||||
/** Destructor
|
||||
*/
|
||||
virtual ~invite() = default;
|
||||
|
||||
/** 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.
|
||||
* @param with_id Include ID in JSON
|
||||
* @return The JSON text of the invite
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
|
||||
};
|
||||
|
||||
/** A container of invites */
|
||||
typedef std::unordered_map<std::string, invite> invite_map;
|
||||
|
||||
};
|
25
vendor/DPP/include/dpp/json.h
vendored
Normal file
25
vendor/DPP/include/dpp/json.h
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#ifdef DPP_USE_EXTERNAL_JSON
|
||||
#include <nlohmann/json.hpp>
|
||||
#else
|
||||
#include <dpp/nlohmann/json.hpp>
|
||||
#endif
|
25
vendor/DPP/include/dpp/json_fwd.h
vendored
Normal file
25
vendor/DPP/include/dpp/json_fwd.h
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
************************************************************************************/
|
||||
#ifdef DPP_USE_EXTERNAL_JSON
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
#else
|
||||
#include <dpp/nlohmann/json_fwd.hpp>
|
||||
#endif
|
61
vendor/DPP/include/dpp/json_interface.h
vendored
Normal file
61
vendor/DPP/include/dpp/json_interface.h
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2022 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/exception.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
|
||||
namespace dpp {
|
||||
/**
|
||||
* @brief Represents an interface for an object that can optionally implement functions
|
||||
* for converting to and from nlohmann::json. In the event either parse_from_json() or
|
||||
* build_json() are not implemented and are called, they will throw at runtime.
|
||||
*
|
||||
* @tparam T Type of class that implements the interface
|
||||
*/
|
||||
template<typename T> struct DPP_EXPORT json_interface {
|
||||
protected:
|
||||
/* Must not destruct through pointer to json_interface. */
|
||||
~json_interface() = default;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Convert object from nlohmann::json
|
||||
*
|
||||
* @param j nlohmann::json object
|
||||
* @return T& Reference to self for fluent calling
|
||||
*/
|
||||
T& fill_from_json(nlohmann::json* j) {
|
||||
throw dpp::logic_exception("JSON interface doesn't implement parse_from_json");
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Build JSON string from the object
|
||||
*
|
||||
* @param with_id Include the ID in the JSON
|
||||
* @return std::string JSON string version of object
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const {
|
||||
throw dpp::logic_exception("JSON interface doesn't implement build_json");
|
||||
}
|
||||
};
|
||||
};
|
76
vendor/DPP/include/dpp/managed.h
vendored
Normal file
76
vendor/DPP/include/dpp/managed.h
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <string>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/** @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 DPP_EXPORT managed {
|
||||
public:
|
||||
/**
|
||||
* @brief Unique ID of object set by Discord.
|
||||
* This value contains a timestamp, worker ID, internal server ID, and an incrementing value.
|
||||
* Only the timestamp is relevant to us as useful metadata.
|
||||
*/
|
||||
snowflake id;
|
||||
/**
|
||||
* @brief Constructor, initialises ID
|
||||
* @param nid ID to set
|
||||
*/
|
||||
managed(const snowflake nid = 0);
|
||||
/**
|
||||
* @brief Destroy the managed object
|
||||
*/
|
||||
virtual ~managed() = default;
|
||||
|
||||
/**
|
||||
* @brief Get the creation time of this object according to Discord.
|
||||
*
|
||||
* @return double creation time inferred from the snowflake ID.
|
||||
* The minimum possible value is the first second of 2015.
|
||||
*/
|
||||
double get_creation_time() const;
|
||||
|
||||
/**
|
||||
* @brief Comparison operator for comparing two managed objects by id
|
||||
*
|
||||
* @param other Other object to compare against
|
||||
* @return true objects are the same id
|
||||
* @return false objects are not the same id
|
||||
*/
|
||||
bool operator==(const managed& other) const noexcept;
|
||||
|
||||
/**
|
||||
* @brief Comparison operator for comparing two managed objects by id
|
||||
*
|
||||
* @param other Other object to compare against
|
||||
* @return true objects are not the same id
|
||||
* @return false objects are the same id
|
||||
*/
|
||||
bool operator!=(const managed& other) const noexcept;
|
||||
};
|
||||
|
||||
};
|
1514
vendor/DPP/include/dpp/message.h
vendored
Normal file
1514
vendor/DPP/include/dpp/message.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
55
vendor/DPP/include/dpp/misc-enum.h
vendored
Normal file
55
vendor/DPP/include/dpp/misc-enum.h
vendored
Normal file
@ -0,0 +1,55 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <stddef.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/** @brief Supported image types for profile pictures and CDN endpoints */
|
||||
enum image_type {
|
||||
/// image/png
|
||||
i_png,
|
||||
/// image/jpeg
|
||||
i_jpg,
|
||||
/// image/gif
|
||||
i_gif,
|
||||
/// WebP
|
||||
i_webp,
|
||||
};
|
||||
|
||||
/** @brief Log levels */
|
||||
enum loglevel {
|
||||
/// Trace
|
||||
ll_trace = 0,
|
||||
/// Debug
|
||||
ll_debug,
|
||||
/// Information
|
||||
ll_info,
|
||||
/// Warning
|
||||
ll_warning,
|
||||
/// Error
|
||||
ll_error,
|
||||
/// Critical
|
||||
ll_critical
|
||||
};
|
||||
|
||||
};
|
22091
vendor/DPP/include/dpp/nlohmann/json.hpp
vendored
Normal file
22091
vendor/DPP/include/dpp/nlohmann/json.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
64
vendor/DPP/include/dpp/nlohmann/json_fwd.hpp
vendored
Normal file
64
vendor/DPP/include/dpp/nlohmann/json_fwd.hpp
vendored
Normal file
@ -0,0 +1,64 @@
|
||||
#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;
|
||||
|
||||
/// a class to store JSON values
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/
|
||||
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 defines a string syntax for identifying a specific value within a JSON document
|
||||
/// @sa https://json.nlohmann.me/api/json_pointer/
|
||||
template<typename BasicJsonType>
|
||||
class json_pointer;
|
||||
|
||||
/*!
|
||||
@brief default specialization
|
||||
@sa https://json.nlohmann.me/api/json/
|
||||
*/
|
||||
using json = basic_json<>;
|
||||
|
||||
/// @brief a minimal map-like container that preserves insertion order
|
||||
/// @sa https://json.nlohmann.me/api/ordered_map/
|
||||
template<class Key, class T, class IgnoredLess, class Allocator>
|
||||
struct ordered_map;
|
||||
|
||||
/// @brief specialization that maintains the insertion order of object keys
|
||||
/// @sa https://json.nlohmann.me/api/ordered_json/
|
||||
using ordered_json = basic_json<nlohmann::ordered_map>;
|
||||
|
||||
} // namespace nlohmann
|
||||
|
||||
#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_
|
46
vendor/DPP/include/dpp/once.h
vendored
Normal file
46
vendor/DPP/include/dpp/once.h
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2022 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 <utility>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Run some code within an if() statement only once.
|
||||
*
|
||||
* Use this template like this:
|
||||
*
|
||||
* ```
|
||||
* if (dpp::run_once<struct any_unique_name_you_like_here>()) {
|
||||
* // Your code here
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @tparam T any unique 'tag' identifier name
|
||||
* @return auto a true/false return to say if we should execute or not
|
||||
*/
|
||||
template <typename T> auto run_once() {
|
||||
static auto called = false;
|
||||
return !std::exchange(called, true);
|
||||
};
|
||||
|
||||
};
|
204
vendor/DPP/include/dpp/permissions.h
vendored
Normal file
204
vendor/DPP/include/dpp/permissions.h
vendored
Normal file
@ -0,0 +1,204 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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.h>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents the various discord permissions
|
||||
*/
|
||||
enum permissions : uint64_t {
|
||||
p_create_instant_invite = 0x00000000001, //!< allows creation of instant invites
|
||||
p_kick_members = 0x00000000002, //!< allows kicking members
|
||||
p_ban_members = 0x00000000004, //!< allows banning members
|
||||
p_administrator = 0x00000000008, //!< allows all permissions and bypasses channel permission overwrites
|
||||
p_manage_channels = 0x00000000010, //!< allows management and editing of channels
|
||||
p_manage_guild = 0x00000000020, //!< allows management and editing of the guild
|
||||
p_add_reactions = 0x00000000040, //!< allows for the addition of reactions to messages
|
||||
p_view_audit_log = 0x00000000080, //!< allows for viewing of audit logs
|
||||
p_priority_speaker = 0x00000000100, //!< allows for using priority speaker in a voice channel
|
||||
p_stream = 0x00000000200, //!< allows the user to go live
|
||||
p_view_channel = 0x00000000400, //!< allows guild members to view a channel, which includes reading messages in text channels and joining voice channels
|
||||
p_send_messages = 0x00000000800, //!< allows for sending messages in a channel
|
||||
p_send_tts_messages = 0x00000001000, //!< allows for sending of /tts messages
|
||||
p_manage_messages = 0x00000002000, //!< allows for deletion of other users messages
|
||||
p_embed_links = 0x00000004000, //!< links sent by users with this permission will be auto-embedded
|
||||
p_attach_files = 0x00000008000, //!< allows for uploading images and files
|
||||
p_read_message_history = 0x00000010000, //!< allows for reading of message history
|
||||
p_mention_everyone = 0x00000020000, //!< allows for using the everyone and the here tag to notify users in a channel
|
||||
p_use_external_emojis = 0x00000040000, //!< allows the usage of custom emojis from other servers
|
||||
p_view_guild_insights = 0x00000080000, //!< allows for viewing guild insights
|
||||
p_connect = 0x00000100000, //!< allows for joining of a voice channel
|
||||
p_speak = 0x00000200000, //!< allows for speaking in a voice channel
|
||||
p_mute_members = 0x00000400000, //!< allows for muting members in a voice channel
|
||||
p_deafen_members = 0x00000800000, //!< allows for deafening of members in a voice channel
|
||||
p_move_members = 0x00001000000, //!< allows for moving of members between voice channels
|
||||
p_use_vad = 0x00002000000, //!< allows for using voice-activity-detection in a voice channel
|
||||
p_change_nickname = 0x00004000000, //!< allows for modification of own nickname
|
||||
p_manage_nicknames = 0x00008000000, //!< allows for modification of other users nicknames
|
||||
p_manage_roles = 0x00010000000, //!< allows management and editing of roles
|
||||
p_manage_webhooks = 0x00020000000, //!< allows management and editing of webhooks
|
||||
p_manage_emojis_and_stickers = 0x00040000000, //!< allows management and editing of emojis and stickers
|
||||
p_use_application_commands = 0x00080000000, //!< allows members to use application commands, including slash commands and context menus
|
||||
p_request_to_speak = 0x00100000000, //!< allows for requesting to speak in stage channels. (Discord: This permission is under active development and may be changed or removed.)
|
||||
p_manage_events = 0x00200000000, //!< allows for management (creation, updating, deleting, starting) of scheduled events
|
||||
p_manage_threads = 0x00400000000, //!< allows for deleting and archiving threads, and viewing all private threads
|
||||
p_create_public_threads = 0x00800000000, //!< allows for creating public and announcement threads
|
||||
p_create_private_threads = 0x01000000000, //!< allows for creating private threads
|
||||
p_use_external_stickers = 0x02000000000, //!< allows the usage of custom stickers from other servers
|
||||
p_send_messages_in_threads = 0x04000000000, //!< allows for sending messages in threads
|
||||
p_use_embedded_activities = 0x08000000000, //!< allows for using activities (applications with the EMBEDDED flag) in a voice channel
|
||||
p_moderate_members = 0x10000000000, //!< allows for timing out users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents the various discord permissions
|
||||
* @deprecated Use dpp::permissions instead.
|
||||
*/
|
||||
using role_permissions = permissions;
|
||||
|
||||
/**
|
||||
* @brief Represents a permission bitmask (refer to enum dpp::permissions) which are hold in an uint64_t
|
||||
*/
|
||||
class DPP_EXPORT permission {
|
||||
protected:
|
||||
/**
|
||||
* @brief The permission bitmask value
|
||||
*/
|
||||
uint64_t value;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a permission object
|
||||
* @param value A permission bitmask
|
||||
*/
|
||||
permission(const uint64_t& value);
|
||||
|
||||
/**
|
||||
* @brief Construct a permission object
|
||||
*/
|
||||
permission();
|
||||
|
||||
/**
|
||||
* @brief For acting like an integer
|
||||
* @return The permission bitmask value
|
||||
*/
|
||||
operator uint64_t() const;
|
||||
|
||||
/**
|
||||
* @brief For acting like an integer
|
||||
* @return A reference to the permission bitmask value
|
||||
*/
|
||||
operator uint64_t &();
|
||||
|
||||
/**
|
||||
* @brief For building json
|
||||
* @return The permission bitmask value as a string
|
||||
*/
|
||||
operator nlohmann::json() const;
|
||||
|
||||
/**
|
||||
* @brief Check for permission flags set. It uses the Bitwise AND operator
|
||||
* @tparam T one or more uint64_t permission bits
|
||||
* @param values The permissions (from dpp::permissions) to check for
|
||||
*
|
||||
* **Example:**
|
||||
*
|
||||
* ```cpp
|
||||
* bool is_mod = permission.has(dpp::p_kick_members, dpp::p_ban_members);
|
||||
* // Returns true if the permission bitmask contains p_kick_members and p_ban_members
|
||||
* ```
|
||||
*
|
||||
* @return bool True if it has all the given permissions
|
||||
*/
|
||||
template <typename... T>
|
||||
bool has(T... values) const {
|
||||
return (value & (0 | ... | values)) == (0 | ... | values);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Add a permission with the Bitwise OR operation
|
||||
* @tparam T one or more uint64_t permission bits
|
||||
* @param values The permissions (from dpp::permissions) to add
|
||||
*
|
||||
* **Example:**
|
||||
*
|
||||
* ```cpp
|
||||
* permission.add(dpp::p_view_channel, dpp::p_send_messages);
|
||||
* // Adds p_view_channel and p_send_messages to the permission bitmask
|
||||
* ```
|
||||
*
|
||||
* @return permission& reference to self for chaining
|
||||
*/
|
||||
template <typename... T>
|
||||
typename std::enable_if<(std::is_convertible<T, uint64_t>::value && ...), permission&>::type
|
||||
add(T... values) {
|
||||
value |= (0 | ... | values);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assign a permission. This will reset the bitmask to the new value.
|
||||
* @tparam T one or more uint64_t permission bits
|
||||
* @param values The permissions (from dpp::permissions) to set
|
||||
*
|
||||
* **Example:**
|
||||
*
|
||||
* ```cpp
|
||||
* permission.set(dpp::p_view_channel, dpp::p_send_messages);
|
||||
* ```
|
||||
*
|
||||
* @return permission& reference to self for chaining
|
||||
*/
|
||||
template <typename... T>
|
||||
typename std::enable_if<(std::is_convertible<T, uint64_t>::value && ...), permission&>::type
|
||||
set(T... values) {
|
||||
value = (0 | ... | values);
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Remove a permission with the Bitwise NOT operation
|
||||
* @tparam T one or more uint64_t permission bits
|
||||
* @param values The permissions (from dpp::permissions) to remove
|
||||
*
|
||||
* **Example:**
|
||||
*
|
||||
* ```cpp
|
||||
* permission.remove(dpp::p_view_channel, dpp::p_send_messages);
|
||||
* // Removes p_view_channel and p_send_messages permission
|
||||
* ```
|
||||
*
|
||||
* @return permission& reference to self for chaining
|
||||
*/
|
||||
template <typename... T>
|
||||
typename std::enable_if<(std::is_convertible<T, uint64_t>::value && ...), permission&>::type
|
||||
remove(T... values) {
|
||||
value &= ~(0 | ... | values);
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
392
vendor/DPP/include/dpp/presence.h
vendored
Normal file
392
vendor/DPP/include/dpp/presence.h
vendored
Normal file
@ -0,0 +1,392 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/emoji.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <unordered_map>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
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_watching = 3,
|
||||
/// "Emoji..."
|
||||
at_custom = 4,
|
||||
/// "Competing in..."
|
||||
at_competing = 5
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Activity types for rich presence
|
||||
*/
|
||||
enum activity_flags {
|
||||
/// In an instance
|
||||
af_instance = 0b000000001,
|
||||
/// Joining
|
||||
af_join = 0b000000010,
|
||||
/// Spectating
|
||||
af_spectate = 0b000000100,
|
||||
/// Sending join request
|
||||
af_join_request = 0b000001000,
|
||||
/// Synchronising
|
||||
af_sync = 0b000010000,
|
||||
/// Playing
|
||||
af_play = 0b000100000,
|
||||
/// Party privacy friends
|
||||
af_party_privacy_friends = 0b001000000,
|
||||
/// Party privacy voice channel
|
||||
af_party_privacy_voice_channel = 0b010000000,
|
||||
/// Embedded
|
||||
af_embedded = 0b100000000
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief An activity button is a custom button shown in the rich presence. Can be to join a game or whatever
|
||||
*/
|
||||
struct DPP_EXPORT activity_button {
|
||||
public:
|
||||
/** The text shown on the button (1-32 characters)
|
||||
*/
|
||||
std::string label;
|
||||
/** The url opened when clicking the button (1-512 characters). It's may be empty
|
||||
*
|
||||
* @note Bots cannot access the activity button URLs.
|
||||
*/
|
||||
std::string url;
|
||||
|
||||
/** Constructor */
|
||||
activity_button() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief An activity asset are the images and the hover text displayed in the rich presence
|
||||
*/
|
||||
struct DPP_EXPORT activity_assets {
|
||||
public:
|
||||
/** The large asset image which usually contain snowflake ID or prefixed image ID
|
||||
*/
|
||||
std::string large_image;
|
||||
/** Text displayed when hovering over the large image of the activity
|
||||
*/
|
||||
std::string large_text;
|
||||
/** The small asset image which usually contain snowflake ID or prefixed image ID
|
||||
*/
|
||||
std::string small_image;
|
||||
/** Text displayed when hovering over the small image of the activity
|
||||
*/
|
||||
std::string small_text;
|
||||
|
||||
/** Constructor */
|
||||
activity_assets() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Secrets for Rich Presence joining and spectating
|
||||
*/
|
||||
struct DPP_EXPORT activity_secrets {
|
||||
public:
|
||||
/** The secret for joining a party
|
||||
*/
|
||||
std::string join;
|
||||
/** The secret for spectating a game
|
||||
*/
|
||||
std::string spectate;
|
||||
/** The secret for a specific instanced match
|
||||
*/
|
||||
std::string match;
|
||||
|
||||
/** Constructor */
|
||||
activity_secrets() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Information for the current party of the player
|
||||
*/
|
||||
struct DPP_EXPORT activity_party {
|
||||
public:
|
||||
/** The ID of the party
|
||||
*/
|
||||
snowflake id;
|
||||
/** The party's current size. Used to show the party's current size
|
||||
*/
|
||||
int32_t current_size;
|
||||
/** The party's maximum size. Used to show the party's maximum size
|
||||
*/
|
||||
int32_t maximum_size;
|
||||
|
||||
/** Constructor */
|
||||
activity_party();
|
||||
};
|
||||
|
||||
/**
|
||||
* @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 DPP_EXPORT activity {
|
||||
public:
|
||||
/** Name of activity
|
||||
* e.g. "Fortnite"
|
||||
*/
|
||||
std::string name;
|
||||
/** State of activity or the custom user status.
|
||||
* e.g. "Waiting in lobby"
|
||||
*/
|
||||
std::string state;
|
||||
/** What the player is currently doing
|
||||
*/
|
||||
std::string details;
|
||||
/** Images for the presence and their hover texts
|
||||
*/
|
||||
activity_assets assets;
|
||||
/** URL.
|
||||
* Only applicable for certain sites such a YouTube
|
||||
* Alias: details
|
||||
*/
|
||||
std::string url;
|
||||
/** The custom buttons shown in the Rich Presence (max 2)
|
||||
*/
|
||||
std::vector<activity_button> buttons;
|
||||
/** The emoji used for the custom status
|
||||
*/
|
||||
dpp::emoji emoji;
|
||||
/** Information of the current party if there is one
|
||||
*/
|
||||
activity_party party;
|
||||
/** Secrets for rich presence joining and spectating
|
||||
*/
|
||||
activity_secrets secrets;
|
||||
/** 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 dpp::activity_flags
|
||||
*/
|
||||
uint8_t flags;
|
||||
/** Whether or not the activity is an instanced game session
|
||||
*/
|
||||
bool is_instance;
|
||||
|
||||
/**
|
||||
* @brief Get the assets large image url if they have one, otherwise returns an empty string. In case of prefixed image IDs (mp:{image_id}) it returns an empty string.
|
||||
*
|
||||
* @see https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-asset-image
|
||||
*
|
||||
* @param size The size of the image in pixels. It can be any power of two between 16 and 4096,
|
||||
* otherwise the default sized image is returned.
|
||||
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg` or `i_png`.
|
||||
* @return std::string image url or an empty string, if required attributes are missing or an invalid format was passed
|
||||
*/
|
||||
std::string get_large_asset_url(uint16_t size = 0, const image_type format = i_png) const;
|
||||
|
||||
/**
|
||||
* @brief Get the assets small image url if they have one, otherwise returns an empty string. In case of prefixed image IDs (mp:{image_id}) it returns an empty string.
|
||||
*
|
||||
* @see https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-asset-image
|
||||
*
|
||||
* @param size The size of the image in pixels. It can be any power of two between 16 and 4096,
|
||||
* otherwise the default sized image is returned.
|
||||
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg` or `i_png`.
|
||||
* @return std::string image url or an empty string, if required attributes are missing or an invalid format was passed
|
||||
*/
|
||||
std::string get_small_asset_url(uint16_t size = 0, const image_type format = i_png) const;
|
||||
|
||||
activity();
|
||||
|
||||
/**
|
||||
* @brief Construct a new activity
|
||||
*
|
||||
* @param typ activity type
|
||||
* @param nam Name of the activity
|
||||
* @param stat State of the activity
|
||||
* @param url_ url of the activity, only works for certain sites, such as YouTube
|
||||
*/
|
||||
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 DPP_EXPORT presence : public json_interface<presence> {
|
||||
public:
|
||||
/** The user the presence applies to */
|
||||
snowflake user_id;
|
||||
|
||||
/** Guild ID. Apparently, Discord supports this internally but the client doesn't... */
|
||||
snowflake guild_id;
|
||||
|
||||
/** Flags bitmask containing dpp::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 Status of the activity
|
||||
* @param type Type of activity
|
||||
* @param activity_description Description of the activity
|
||||
*/
|
||||
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 Status of the activity
|
||||
* @param a Activity itself
|
||||
*/
|
||||
presence(presence_status status, const 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.
|
||||
*
|
||||
* Note: This excludes any part of the presence object that are not valid for websockets and bots,
|
||||
* and includes websocket opcode 3. You will not get what you expect if you call this on a user's
|
||||
* presence received from on_presence_update or on_guild_create!
|
||||
*
|
||||
* @param with_id Add ID to output
|
||||
* @return The JSON text of the presence
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) 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<snowflake, presence> presence_map;
|
||||
|
||||
};
|
63
vendor/DPP/include/dpp/prune.h
vendored
Normal file
63
vendor/DPP/include/dpp/prune.h
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Defines a request to count prunable users, or start a prune operation
|
||||
*/
|
||||
struct DPP_EXPORT prune : public json_interface<prune> {
|
||||
/**
|
||||
* Destroy this prune object
|
||||
*/
|
||||
virtual ~prune() = default;
|
||||
|
||||
/** 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
|
||||
*/
|
||||
virtual std::string build_json(bool with_prune_count = false) const;
|
||||
|
||||
};
|
||||
|
||||
};
|
457
vendor/DPP/include/dpp/queues.h
vendored
Normal file
457
vendor/DPP/include/dpp/queues.h
vendored
Normal file
@ -0,0 +1,457 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <shared_mutex>
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <condition_variable>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Error values. Most of these are currently unused in https_client.
|
||||
*/
|
||||
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 DPP_EXPORT http_request_completion_t {
|
||||
/** @brief HTTP headers of response */
|
||||
std::map<std::string, std::string> headers;
|
||||
/** @brief HTTP status, e.g. 200 = OK, 404 = Not found, 429 = Rate limited */
|
||||
uint16_t status = 0;
|
||||
/** @brief Error status (e.g. if the request could not connect at all) */
|
||||
http_error error = h_success;
|
||||
/** @brief Ratelimit bucket */
|
||||
std::string ratelimit_bucket;
|
||||
/** @brief Ratelimit limit of requests */
|
||||
uint64_t ratelimit_limit = 0;
|
||||
/** @brief Ratelimit remaining requests */
|
||||
uint64_t ratelimit_remaining = 0;
|
||||
/** @brief Ratelimit reset after (seconds) */
|
||||
uint64_t ratelimit_reset_after = 0;
|
||||
/** @brief Ratelimit retry after (seconds) */
|
||||
uint64_t ratelimit_retry_after = 0;
|
||||
/** @brief True if this request has caused us to be globally rate limited */
|
||||
bool ratelimit_global = false;
|
||||
/** @brief Reply body */
|
||||
std::string body;
|
||||
/** @brief Ping latency */
|
||||
double latency;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Results of HTTP requests are called back to these std::function types.
|
||||
* @note Returned http_completion_events are called ASYNCHRONOUSLY 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;
|
||||
|
||||
/**
|
||||
* @brief 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 DPP_EXPORT http_request {
|
||||
/** @brief Completion callback */
|
||||
http_completion_event complete_handler;
|
||||
/** @brief True if request has been made */
|
||||
bool completed;
|
||||
/** @brief True for requests that are not going to discord (rate limits code skipped) */
|
||||
bool non_discord;
|
||||
public:
|
||||
/** @brief Endpoint name e.g. /api/users */
|
||||
std::string endpoint;
|
||||
/** @brief Major and minor parameters */
|
||||
std::string parameters;
|
||||
/** @brief Postdata for POST and PUT */
|
||||
std::string postdata;
|
||||
/** @brief HTTP method for request */
|
||||
http_method method;
|
||||
/** @brief Audit log reason for Discord requests, if non-empty */
|
||||
std::string reason;
|
||||
/** @brief Upload file name (server side) */
|
||||
std::vector<std::string> file_name;
|
||||
/** @brief Upload file contents (binary) */
|
||||
std::vector<std::string> file_content;
|
||||
/** @brief Request mime type */
|
||||
std::string mimetype;
|
||||
/** @brief Request headers (non-discord requests only) */
|
||||
std::multimap<std::string, std::string> req_headers;
|
||||
/** @brief Waiting for rate limit to expire */
|
||||
bool waiting;
|
||||
|
||||
/**
|
||||
* @brief 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 audit_reason Audit log reason to send, empty to send none
|
||||
* @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 &audit_reason = "", const std::string &filename = "", const std::string &filecontent = "");
|
||||
|
||||
/**
|
||||
* @brief 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 audit_reason Audit log reason to send, empty to send none
|
||||
* @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 &audit_reason = "", const std::vector<std::string> &filename = {}, const std::vector<std::string> &filecontent = {});
|
||||
|
||||
/**
|
||||
* @brief Constructor. When constructing one of these objects it should be passed to request_queue::post_request().
|
||||
* @param _url Raw HTTP url
|
||||
* @param completion completion event to call when done
|
||||
* @param method The HTTP method to use from dpp::http_method
|
||||
* @param _postdata Data to send in POST and PUT requests
|
||||
* @param _mimetype POST data mime type
|
||||
* @param _headers HTTP headers to send
|
||||
*/
|
||||
http_request(const std::string &_url, http_completion_event completion, http_method method = m_get, const std::string &_postdata = "", const std::string &_mimetype = "text/plain", const std::multimap<std::string, std::string> &_headers = {});
|
||||
|
||||
/**
|
||||
* @brief Destroy the http request object
|
||||
*/
|
||||
~http_request();
|
||||
|
||||
/**
|
||||
* @brief Call the completion callback, if the request is complete.
|
||||
* @param c callback to call
|
||||
*/
|
||||
void complete(const http_request_completion_t &c);
|
||||
|
||||
/**
|
||||
* @brief Execute the HTTP request and mark the request complete.
|
||||
* @param owner creating cluster
|
||||
*/
|
||||
http_request_completion_t run(class cluster* owner);
|
||||
|
||||
/** @brief Returns true if the request is complete */
|
||||
bool is_completed();
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A rate limit bucket. The library builds one of these for
|
||||
* each endpoint.
|
||||
*/
|
||||
struct DPP_EXPORT bucket_t {
|
||||
/** @brief Request limit */
|
||||
uint64_t limit;
|
||||
/** @brief Requests remaining */
|
||||
uint64_t remaining;
|
||||
/** @brief Ratelimit of this bucket resets after this many seconds */
|
||||
uint64_t reset_after;
|
||||
/** @brief Ratelimit of this bucket can be retried after this many seconds */
|
||||
uint64_t retry_after;
|
||||
/** @brief Timestamp this buckets counters were updated */
|
||||
time_t timestamp;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Represents a thread in the thread pool handling requests to HTTP(S) servers.
|
||||
* There are several of these, the total defined by a constant in queues.cpp, and each
|
||||
* one will always receive requests for the same rate limit bucket based on its endpoint
|
||||
* portion of the url. This makes rate limit handling reliable and easy to manage.
|
||||
* Each of these also has its own mutex, so that requests are less likely to block while
|
||||
* waiting for internal containers to be usable.
|
||||
*/
|
||||
class DPP_EXPORT in_thread {
|
||||
private:
|
||||
/**
|
||||
* @brief True if ending
|
||||
*/
|
||||
bool terminating;
|
||||
|
||||
/**
|
||||
* @brief Request queue that owns this in_thread
|
||||
*/
|
||||
class request_queue* requests;
|
||||
|
||||
/**
|
||||
* @brief The cluster that owns this in_thread
|
||||
*/
|
||||
class cluster* creator;
|
||||
|
||||
/**
|
||||
* @brief Inbound queue mutex thread safety
|
||||
*/
|
||||
std::shared_mutex in_mutex;
|
||||
|
||||
/**
|
||||
* @brief Inbound queue thread
|
||||
*/
|
||||
std::thread* in_thr;
|
||||
|
||||
/**
|
||||
* @brief Inbound queue condition, signalled when there are requests to fulfill
|
||||
*/
|
||||
std::condition_variable in_ready;
|
||||
|
||||
/**
|
||||
* @brief Ratelimit bucket counters
|
||||
*/
|
||||
std::map<std::string, bucket_t> buckets;
|
||||
|
||||
/**
|
||||
* @brief Queue of requests to be made
|
||||
*/
|
||||
std::map<std::string, std::vector<http_request*>> requests_in;
|
||||
|
||||
/**
|
||||
* @brief Inbound queue thread loop
|
||||
* @param index Thread index
|
||||
*/
|
||||
void in_loop(uint32_t index);
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new in thread object
|
||||
*
|
||||
* @param owner Owning cluster
|
||||
* @param req_q Owning request queue
|
||||
* @param index Thread index number
|
||||
*/
|
||||
in_thread(class cluster* owner, class request_queue* req_q, uint32_t index);
|
||||
|
||||
/**
|
||||
* @brief Destroy the in thread object
|
||||
* This will end the thread that is owned by this object by joining it.
|
||||
*/
|
||||
~in_thread();
|
||||
|
||||
/**
|
||||
* @brief Post a http_request to this thread.
|
||||
*
|
||||
* @param req http_request to post. The pointer will be freed when it has
|
||||
* been executed.
|
||||
*/
|
||||
void post_request(http_request* req);
|
||||
};
|
||||
|
||||
/**
|
||||
* @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 are usually two request_queue objects in each dpp::cluster, one of which is used
|
||||
* internally for the various REST methods to Discord such as sending messages, and the other
|
||||
* used to support user REST calls via dpp::cluster::request().
|
||||
*/
|
||||
class DPP_EXPORT request_queue {
|
||||
protected:
|
||||
/**
|
||||
* @brief Required so in_thread can access these member variables
|
||||
*/
|
||||
friend class in_thread;
|
||||
|
||||
/**
|
||||
* @brief The cluster that owns this request_queue
|
||||
*/
|
||||
class cluster* creator;
|
||||
|
||||
/**
|
||||
* @brief Outbound queue mutex thread safety
|
||||
*/
|
||||
std::shared_mutex out_mutex;
|
||||
|
||||
/**
|
||||
* @brief Outbound queue thread
|
||||
* Note that although there are many 'in queues', which handle the HTTP requests,
|
||||
* there is only ever one 'out queue' which dispatches the results to the caller.
|
||||
* This is to simplify thread management in bots that use the library, as less mutexing
|
||||
* and thread safety boilerplate is required.
|
||||
*/
|
||||
std::thread* out_thread;
|
||||
|
||||
/**
|
||||
* @brief Outbound queue condition, signalled when there are requests completed to call callbacks for
|
||||
*/
|
||||
std::condition_variable out_ready;
|
||||
|
||||
/**
|
||||
* @brief Completed requests queue
|
||||
*/
|
||||
std::queue<std::pair<http_request_completion_t*, http_request*>> responses_out;
|
||||
|
||||
/**
|
||||
* @brief A vector of inbound request threads forming a pool.
|
||||
* There are a set number of these defined by a constant in queues.cpp. A request is always placed
|
||||
* on the same element in this vector, based upon its url, so that two conditions are satisfied:
|
||||
* 1) Any requests for the same ratelimit bucket are handled by the same thread in the pool so that
|
||||
* they do not create unnecessary 429 errors,
|
||||
* 2) Requests for different endpoints go into different buckets, so that they may be requested in parallel
|
||||
* A global ratelimit event pauses all threads in the pool. These are few and far between.
|
||||
*/
|
||||
std::vector<in_thread*> requests_in;
|
||||
|
||||
/**
|
||||
* @brief Completed requests to delete
|
||||
*/
|
||||
std::multimap<time_t, std::pair<http_request_completion_t*, http_request*>> responses_to_delete;
|
||||
|
||||
/**
|
||||
* @brief Set to true if the threads should terminate
|
||||
*/
|
||||
bool terminating;
|
||||
|
||||
/**
|
||||
* @brief True if globally rate limited - makes the entire request thread wait
|
||||
*/
|
||||
bool globally_ratelimited;
|
||||
|
||||
/**
|
||||
* @brief How many seconds we are globally rate limited for, if globally_ratelimited is true
|
||||
*/
|
||||
uint64_t globally_limited_for;
|
||||
|
||||
/**
|
||||
* @brief Number of request threads in the thread pool
|
||||
*/
|
||||
uint32_t in_thread_pool_size;
|
||||
|
||||
/**
|
||||
* @brief Outbound queue thread loop
|
||||
*/
|
||||
void out_loop();
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief constructor
|
||||
* @param owner The creating cluster.
|
||||
* @param request_threads The number of http request threads to allocate to the threadpool.
|
||||
* By default eight threads are allocated.
|
||||
* Side effects: Creates threads for the queue
|
||||
*/
|
||||
request_queue(class cluster* owner, uint32_t request_threads = 8);
|
||||
|
||||
/**
|
||||
* @brief Add more request threads to the library at runtime.
|
||||
* @note You should do this at a quiet time when there are few requests happening.
|
||||
* This will reorganise the hashing used to place requests into the thread pool so if you do
|
||||
* this while the bot is busy there is a small chance of receiving "429 rate limited" errors.
|
||||
* @param request_threads Number of threads to add. It is not possible to scale down at runtime.
|
||||
* @return reference to self
|
||||
*/
|
||||
request_queue& add_request_threads(uint32_t request_threads);
|
||||
|
||||
/**
|
||||
* @brief Get the request thread count
|
||||
* @return uint32_t number of request threads that are active
|
||||
*/
|
||||
uint32_t get_request_thread_count() const;
|
||||
|
||||
/**
|
||||
* @brief Destroy the request queue object.
|
||||
* Side effects: Joins and deletes queue threads
|
||||
*/
|
||||
~request_queue();
|
||||
|
||||
/**
|
||||
* @brief 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!
|
||||
* @note Will use a simple hash function to determine which of the 'in queues' to place
|
||||
* this request onto.
|
||||
* @param req request to add
|
||||
* @return reference to self
|
||||
*/
|
||||
request_queue& post_request(http_request *req);
|
||||
|
||||
/**
|
||||
* @brief Returns true if the bot is currently globally rate limited
|
||||
* @return true if globally rate limited
|
||||
*/
|
||||
bool is_globally_ratelimited() const;
|
||||
};
|
||||
|
||||
};
|
205
vendor/DPP/include/dpp/restrequest.h
vendored
Normal file
205
vendor/DPP/include/dpp/restrequest.h
vendored
Normal file
@ -0,0 +1,205 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2022 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/snowflake.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/invite.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Templated REST request helper to save on typing
|
||||
*
|
||||
* @tparam T type to return in lambda callback
|
||||
* @param c calling cluster
|
||||
* @param basepath base path for API call
|
||||
* @param major major API function
|
||||
* @param minor minor API function
|
||||
* @param method HTTP method
|
||||
* @param postdata Post data or empty string
|
||||
* @param callback Callback lambda
|
||||
*/
|
||||
template<class T> inline void rest_request(dpp::cluster* c, const char* basepath, const std::string &major, const std::string &minor, http_method method, const std::string& postdata, command_completion_event_t callback) {
|
||||
c->post_rest(basepath, major, minor, method, postdata, [c, callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(c, T().fill_from_json(&j), http));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Templated REST request helper to save on typing (specialised for message)
|
||||
*
|
||||
* @tparam T type to return in lambda callback
|
||||
* @param c calling cluster
|
||||
* @param basepath base path for API call
|
||||
* @param major major API function
|
||||
* @param minor minor API function
|
||||
* @param method HTTP method
|
||||
* @param postdata Post data or empty string
|
||||
* @param callback Callback lambda
|
||||
*/
|
||||
template<> inline void rest_request<message>(dpp::cluster* c, const char* basepath, const std::string &major, const std::string &minor, http_method method, const std::string& postdata, command_completion_event_t callback) {
|
||||
c->post_rest(basepath, major, minor, method, postdata, [c, callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(c, message(c).fill_from_json(&j), http));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Templated REST request helper to save on typing (specialised for confirmation)
|
||||
*
|
||||
* @tparam T type to return in lambda callback
|
||||
* @param c calling cluster
|
||||
* @param basepath base path for API call
|
||||
* @param major major API function
|
||||
* @param minor minor API function
|
||||
* @param method HTTP method
|
||||
* @param postdata Post data or empty string
|
||||
* @param callback Callback lambda
|
||||
*/
|
||||
template<> inline void rest_request<confirmation>(dpp::cluster* c, const char* basepath, const std::string &major, const std::string &minor, http_method method, const std::string& postdata, command_completion_event_t callback) {
|
||||
c->post_rest(basepath, major, minor, method, postdata, [c, callback](json &j, const http_request_completion_t& http) {
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(c, confirmation(), http));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Templated REST request helper to save on typing (for returned lists)
|
||||
*
|
||||
* @tparam T singular type to return in lambda callback
|
||||
* @tparam T map type to return in lambda callback
|
||||
* @param c calling cluster
|
||||
* @param basepath base path for API call
|
||||
* @param major major API function
|
||||
* @param minor minor API function
|
||||
* @param method HTTP method
|
||||
* @param postdata Post data or empty string
|
||||
* @param key Key name of elements in the json list
|
||||
* @param callback Callback lambda
|
||||
*/
|
||||
template<class T> inline void rest_request_list(dpp::cluster* c, const char* basepath, const std::string &major, const std::string &minor, http_method method, const std::string& postdata, command_completion_event_t callback, const std::string& key = "id") {
|
||||
c->post_rest(basepath, major, minor, method, postdata, [c, key, callback](json &j, const http_request_completion_t& http) {
|
||||
std::unordered_map<snowflake, T> list;
|
||||
confirmation_callback_t e(c, confirmation(), http);
|
||||
if (!e.is_error()) {
|
||||
for (auto & curr_item : j) {
|
||||
list[snowflake_not_null(&curr_item, key.c_str())] = T().fill_from_json(&curr_item);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(c, list, http));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Templated REST request helper to save on typing (for returned lists, specialised for invites)
|
||||
*
|
||||
* @tparam T singular type to return in lambda callback
|
||||
* @tparam T map type to return in lambda callback
|
||||
* @param c calling cluster
|
||||
* @param basepath base path for API call
|
||||
* @param major major API function
|
||||
* @param minor minor API function
|
||||
* @param method HTTP method
|
||||
* @param postdata Post data or empty string
|
||||
* @param key Key name of elements in the json list
|
||||
* @param callback Callback lambda
|
||||
*/
|
||||
template<> inline void rest_request_list<invite>(dpp::cluster* c, const char* basepath, const std::string &major, const std::string &minor, http_method method, const std::string& postdata, command_completion_event_t callback, const std::string& key) {
|
||||
c->post_rest(basepath, major, minor, method, postdata, [c, callback](json &j, const http_request_completion_t& http) {
|
||||
std::unordered_map<std::string, invite> list;
|
||||
confirmation_callback_t e(c, confirmation(), http);
|
||||
if (!e.is_error()) {
|
||||
for (auto & curr_item : j) {
|
||||
list[string_not_null(&curr_item, "code")] = invite().fill_from_json(&curr_item);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(c, list, http));
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @brief Templated REST request helper to save on typing (for returned lists, specialised for voiceregions)
|
||||
*
|
||||
* @tparam T singular type to return in lambda callback
|
||||
* @tparam T map type to return in lambda callback
|
||||
* @param c calling cluster
|
||||
* @param basepath base path for API call
|
||||
* @param major major API function
|
||||
* @param minor minor API function
|
||||
* @param method HTTP method
|
||||
* @param postdata Post data or empty string
|
||||
* @param key Key name of elements in the json list
|
||||
* @param callback Callback lambda
|
||||
*/
|
||||
template<> inline void rest_request_list<voiceregion>(dpp::cluster* c, const char* basepath, const std::string &major, const std::string &minor, http_method method, const std::string& postdata, command_completion_event_t callback, const std::string& key) {
|
||||
c->post_rest(basepath, major, minor, method, postdata, [c, callback](json &j, const http_request_completion_t& http) {
|
||||
std::unordered_map<std::string, voiceregion> list;
|
||||
confirmation_callback_t e(c, confirmation(), http);
|
||||
if (!e.is_error()) {
|
||||
for (auto & curr_item : j) {
|
||||
list[string_not_null(&curr_item, "id")] = voiceregion().fill_from_json(&curr_item);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(c, list, http));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Templated REST request helper to save on typing (for returned vectors)
|
||||
*
|
||||
* @tparam T singular type to return in lambda callback
|
||||
* @tparam T vector type to return in lambda callback
|
||||
* @param c calling cluster
|
||||
* @param basepath base path for API call
|
||||
* @param major major API function
|
||||
* @param minor minor API function
|
||||
* @param method HTTP method
|
||||
* @param postdata Post data or empty string
|
||||
* @param callback Callback lambda
|
||||
*/
|
||||
template<class T> inline void rest_request_vector(dpp::cluster* c, const char* basepath, const std::string &major, const std::string &minor, http_method method, const std::string& postdata, command_completion_event_t callback) {
|
||||
c->post_rest(basepath, major, minor, method, postdata, [c, callback](json &j, const http_request_completion_t& http) {
|
||||
std::vector<T> list;
|
||||
confirmation_callback_t e(c, confirmation(), http);
|
||||
if (!e.is_error()) {
|
||||
for (auto & curr_item : j) {
|
||||
list.push_back(T().fill_from_json(&curr_item));
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(confirmation_callback_t(c, list, http));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
};
|
316
vendor/DPP/include/dpp/restresults.h
vendored
Normal file
316
vendor/DPP/include/dpp/restresults.h
vendored
Normal file
@ -0,0 +1,316 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <variant>
|
||||
#include <dpp/snowflake.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/misc-enum.h>
|
||||
#include <dpp/timer.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/discordclient.h>
|
||||
#include <dpp/voiceregion.h>
|
||||
#include <dpp/dtemplate.h>
|
||||
#include <dpp/prune.h>
|
||||
#include <dpp/auditlog.h>
|
||||
#include <dpp/queues.h>
|
||||
#include <dpp/cache.h>
|
||||
#include <dpp/intents.h>
|
||||
#include <dpp/sync.h>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <shared_mutex>
|
||||
#include <cstring>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace dpp {
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef _DEBUG
|
||||
extern "C" DPP_EXPORT void you_are_using_a_debug_build_of_dpp_on_a_release_project();
|
||||
#else
|
||||
extern "C" DPP_EXPORT void you_are_using_a_release_build_of_dpp_on_a_debug_project();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
struct DPP_EXPORT version_checker {
|
||||
version_checker() {
|
||||
#ifdef _WIN32
|
||||
#ifdef _DEBUG
|
||||
you_are_using_a_debug_build_of_dpp_on_a_release_project();
|
||||
#else
|
||||
you_are_using_a_release_build_of_dpp_on_a_debug_project();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
static version_checker dpp_vc;
|
||||
|
||||
|
||||
/**
|
||||
* @brief A list of shards
|
||||
*/
|
||||
typedef std::map<uint32_t, class discord_client*> shard_list;
|
||||
|
||||
/**
|
||||
* @brief Represents the various information from the 'get gateway bot' api call
|
||||
*/
|
||||
struct DPP_EXPORT gateway {
|
||||
/// Gateway websocket url
|
||||
std::string url;
|
||||
|
||||
/// Number of suggested shards to start
|
||||
uint32_t shards;
|
||||
|
||||
/// Total number of sessions that can be started
|
||||
uint32_t session_start_total;
|
||||
|
||||
/// How many sessions are left
|
||||
uint32_t session_start_remaining;
|
||||
|
||||
/// How many seconds until the session start quota resets
|
||||
uint32_t session_start_reset_after;
|
||||
|
||||
/// How many sessions can be started at the same time
|
||||
uint32_t session_start_max_concurrency;
|
||||
|
||||
/**
|
||||
* @brief Construct a new gateway object
|
||||
*
|
||||
* @param j JSON data to construct from
|
||||
*/
|
||||
gateway(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Construct a new gateway object
|
||||
*/
|
||||
gateway();
|
||||
|
||||
/**
|
||||
* @brief Fill this object from json
|
||||
*
|
||||
* @param j json to fill from
|
||||
* @return gateway& reference to self
|
||||
*/
|
||||
gateway& fill_from_json(nlohmann::json* j);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Confirmation object represents any true or false simple REST request
|
||||
*
|
||||
*/
|
||||
struct DPP_EXPORT confirmation {
|
||||
bool success;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A container for types that can be returned for a REST API call
|
||||
*
|
||||
*/
|
||||
typedef std::variant<
|
||||
application_role_connection,
|
||||
application_role_connection_metadata_list,
|
||||
confirmation,
|
||||
message,
|
||||
message_map,
|
||||
user,
|
||||
user_identified,
|
||||
user_map,
|
||||
guild_member,
|
||||
guild_member_map,
|
||||
channel,
|
||||
channel_map,
|
||||
thread_member,
|
||||
thread_member_map,
|
||||
guild,
|
||||
guild_map,
|
||||
guild_command_permissions,
|
||||
guild_command_permissions_map,
|
||||
role,
|
||||
role_map,
|
||||
invite,
|
||||
invite_map,
|
||||
dtemplate,
|
||||
dtemplate_map,
|
||||
emoji,
|
||||
emoji_map,
|
||||
ban,
|
||||
ban_map,
|
||||
voiceregion,
|
||||
voiceregion_map,
|
||||
integration,
|
||||
integration_map,
|
||||
webhook,
|
||||
webhook_map,
|
||||
prune,
|
||||
guild_widget,
|
||||
gateway,
|
||||
interaction,
|
||||
interaction_response,
|
||||
auditlog,
|
||||
slashcommand,
|
||||
slashcommand_map,
|
||||
stage_instance,
|
||||
sticker,
|
||||
sticker_map,
|
||||
sticker_pack,
|
||||
sticker_pack_map,
|
||||
application,
|
||||
application_map,
|
||||
connection,
|
||||
connection_map,
|
||||
thread,
|
||||
thread_map,
|
||||
scheduled_event,
|
||||
scheduled_event_map,
|
||||
event_member,
|
||||
event_member_map,
|
||||
automod_rule,
|
||||
automod_rule_map
|
||||
> confirmable_t;
|
||||
|
||||
/**
|
||||
* @brief The details of a field in an error response
|
||||
*/
|
||||
struct DPP_EXPORT error_detail {
|
||||
/**
|
||||
* @brief Object name which is in error
|
||||
*/
|
||||
std::string object;
|
||||
/**
|
||||
* @brief Field name which is in error
|
||||
*/
|
||||
std::string field;
|
||||
/**
|
||||
* @brief Error code
|
||||
*/
|
||||
std::string code;
|
||||
/**
|
||||
* @brief Error reason (full message)
|
||||
*/
|
||||
std::string reason;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The full details of an error from a REST response
|
||||
*/
|
||||
struct DPP_EXPORT error_info {
|
||||
/**
|
||||
* @brief Error code
|
||||
*/
|
||||
uint32_t code = 0;
|
||||
/**
|
||||
* @brief Error message
|
||||
*
|
||||
*/
|
||||
std::string message;
|
||||
/**
|
||||
* @brief Field specific error descriptions
|
||||
*/
|
||||
std::vector<error_detail> errors;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The results of a REST call wrapped in a convenient struct
|
||||
*/
|
||||
struct DPP_EXPORT confirmation_callback_t {
|
||||
/** Information about the HTTP call used to make the request */
|
||||
http_request_completion_t http_info;
|
||||
|
||||
/** Value returned, wrapped in variant */
|
||||
confirmable_t value;
|
||||
|
||||
/** Owner/creator of the callback object */
|
||||
const class cluster* bot;
|
||||
|
||||
/**
|
||||
* @brief Construct a new confirmation callback t object
|
||||
*/
|
||||
confirmation_callback_t() = default;
|
||||
|
||||
/**
|
||||
* @brief Construct a new confirmation callback t object
|
||||
*
|
||||
* @param creator owning cluster object
|
||||
*/
|
||||
confirmation_callback_t(cluster* creator);
|
||||
|
||||
/**
|
||||
* @brief Construct a new confirmation callback object
|
||||
*
|
||||
* @param _http The HTTP metadata from the REST call
|
||||
*/
|
||||
confirmation_callback_t(const http_request_completion_t& _http);
|
||||
|
||||
/**
|
||||
* @brief Construct a new confirmation callback object
|
||||
*
|
||||
* @param creator owning cluster object
|
||||
* @param _value The value to encapsulate in the confirmable_t
|
||||
* @param _http The HTTP metadata from the REST call
|
||||
*/
|
||||
confirmation_callback_t(cluster* creator, const confirmable_t& _value, const http_request_completion_t& _http);
|
||||
|
||||
/**
|
||||
* @brief Returns true if the call resulted in an error rather than a legitimate value in the
|
||||
* confirmation_callback_t::value member.
|
||||
*
|
||||
* @return true There was an error who's details can be obtained by get_error()
|
||||
* @return false There was no error
|
||||
*/
|
||||
bool is_error() const;
|
||||
|
||||
/**
|
||||
* @brief Get the error_info object.
|
||||
* The error_info object contains the details of any REST error, if there is an error
|
||||
* (to find out if there is an error check confirmation_callback_t::is_error())
|
||||
*
|
||||
* @return error_info The details of the error message
|
||||
*/
|
||||
error_info get_error() const;
|
||||
|
||||
/**
|
||||
* @brief Get the stored value via std::get
|
||||
* @tparam T type to get
|
||||
* @return stored value as type T
|
||||
*/
|
||||
template<typename T>
|
||||
T get() const {
|
||||
return std::get<T>(value);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A callback upon command completion
|
||||
*/
|
||||
typedef std::function<void(const confirmation_callback_t&)> command_completion_event_t;
|
||||
|
||||
/**
|
||||
* @brief Automatically JSON encoded HTTP result
|
||||
*/
|
||||
typedef std::function<void(json&, const http_request_completion_t&)> json_encode_t;
|
||||
};
|
650
vendor/DPP/include/dpp/role.h
vendored
Normal file
650
vendor/DPP/include/dpp/role.h
vendored
Normal file
@ -0,0 +1,650 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <variant>
|
||||
#include <dpp/export.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/permissions.h>
|
||||
#include <dpp/guild.h>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/** Various flags related to dpp::role */
|
||||
enum role_flags : uint8_t {
|
||||
r_hoist = 0b00000001, //!< Hoisted role
|
||||
r_managed = 0b00000010, //!< Managed role (introduced by a bot or application)
|
||||
r_mentionable = 0b00000100, //!< Mentionable with a ping
|
||||
r_premium_subscriber = 0b00001000, //!< This is set for the role given to nitro
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a role within a dpp::guild.
|
||||
* Roles are combined via logical OR of the permission bitmasks, then channel-specific overrides
|
||||
* can be applied on top, deny types apply a logic NOT to the bit mask, and allows apply a logical OR.
|
||||
* @note Every guild has at least one role, called the 'everyone' role, which always has the same role
|
||||
* ID as the guild's ID. This is the base permission set applied to all users where no other role or override
|
||||
* applies, and is the starting value of the bit mask looped through to calculate channel permissions.
|
||||
*/
|
||||
class DPP_EXPORT role : public managed, public json_interface<role> {
|
||||
public:
|
||||
/**
|
||||
* @brief Role name
|
||||
* Between 1 and 100 characters.
|
||||
*/
|
||||
std::string name;
|
||||
/**
|
||||
* @brief Guild ID
|
||||
*/
|
||||
snowflake guild_id;
|
||||
/**
|
||||
* @brief Role colour.
|
||||
* A colour of 0 means no colour. If you want a black role,
|
||||
* you must use the value 0x000001.
|
||||
*/
|
||||
uint32_t colour;
|
||||
/** Role position */
|
||||
uint8_t position;
|
||||
/** Role permissions bitmask values from dpp::permissions */
|
||||
permission 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;
|
||||
/** The unicode emoji used for the role's icon, can be an empty string */
|
||||
std::string unicode_emoji;
|
||||
/** The role icon hash, can be an empty string */
|
||||
utility::iconhash icon;
|
||||
/** Image data for the role icon (if any) */
|
||||
std::string* image_data;
|
||||
|
||||
/**
|
||||
* @brief Construct a new role object
|
||||
*/
|
||||
role();
|
||||
|
||||
/**
|
||||
* @brief Destroy the role object
|
||||
*/
|
||||
virtual ~role();
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable role.
|
||||
* @param id The ID of the role.
|
||||
* @return std::string The formatted mention of the role.
|
||||
*/
|
||||
static std::string get_mention(const snowflake& id);
|
||||
|
||||
/**
|
||||
* @brief Set the name of the role
|
||||
* Maximum length: 100
|
||||
* Minimum length: 1
|
||||
* @param n Name to set
|
||||
* @return role& reference to self
|
||||
* @throw dpp::exception thrown if role length is less than 1 character
|
||||
*/
|
||||
role& set_name(const std::string& n);
|
||||
|
||||
/**
|
||||
* @brief Set the colour
|
||||
*
|
||||
* @param c Colour to set
|
||||
* @note There is an americanised version of this method, role::set_color().
|
||||
* @return role& reference to self
|
||||
*/
|
||||
role& set_colour(uint32_t c);
|
||||
|
||||
/**
|
||||
* @brief Set the color
|
||||
*
|
||||
* @param c Colour to set
|
||||
* @note This is an alias of role::set_colour for American spelling.
|
||||
* @return role& reference to self
|
||||
*/
|
||||
role& set_color(uint32_t c);
|
||||
|
||||
/**
|
||||
* @brief Set the flags
|
||||
*
|
||||
* @param f Flags to set from dpp::role_flags
|
||||
* @return role& reference to self
|
||||
*/
|
||||
role& set_flags(uint8_t f);
|
||||
|
||||
/**
|
||||
* @brief Set the integration id
|
||||
*
|
||||
* @param i Integration ID to set
|
||||
* @return role& reference to self
|
||||
*/
|
||||
role& set_integration_id(snowflake i);
|
||||
|
||||
/**
|
||||
* @brief Set the bot id
|
||||
*
|
||||
* @param b Bot ID to set
|
||||
* @return role& reference to self
|
||||
*/
|
||||
role& set_bot_id(snowflake b);
|
||||
|
||||
/**
|
||||
* @brief Set the guild id
|
||||
*
|
||||
* @param gid Guild ID to set
|
||||
* @return role& reference to self
|
||||
*/
|
||||
role& set_guild_id(snowflake gid);
|
||||
|
||||
/**
|
||||
* @brief Fill this role from json.
|
||||
*
|
||||
* @param j The json data
|
||||
* @return A reference to self
|
||||
*/
|
||||
role& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief 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);
|
||||
|
||||
/**
|
||||
* @brief 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
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
|
||||
/**
|
||||
* @brief Get the mention/ping for the role
|
||||
*
|
||||
* @return std::string mention
|
||||
*/
|
||||
std::string get_mention() const;
|
||||
|
||||
/**
|
||||
* @brief Returns the role's icon url if they have one, otherwise returns an empty string
|
||||
*
|
||||
* @param size The size of the icon in pixels. It can be any power of two between 16 and 4096,
|
||||
* otherwise the default sized icon is returned.
|
||||
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg` or `i_png`.
|
||||
* @return std::string icon url or an empty string, if required attributes are missing or an invalid format was passed
|
||||
*/
|
||||
std::string get_icon_url(uint16_t size = 0, const image_type format = i_png) const;
|
||||
|
||||
/**
|
||||
* @brief Load an image into the object as base64
|
||||
*
|
||||
* @param image_blob Image binary data
|
||||
* @param type Type of image. It can be one of `i_gif`, `i_jpg` or `i_png`.
|
||||
* @return emoji& Reference to self
|
||||
*/
|
||||
role& load_image(const std::string &image_blob, const image_type type);
|
||||
|
||||
/**
|
||||
* @brief Operator less than, used for checking if a role is below another.
|
||||
*
|
||||
* @param lhs first role to compare
|
||||
* @param rhs second role to compare
|
||||
* @return true if lhs is less than rhs
|
||||
*/
|
||||
friend inline bool operator< (const role& lhs, const role& rhs)
|
||||
{
|
||||
return lhs.position < rhs.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Operator greater than, used for checking if a role is above another.
|
||||
*
|
||||
* @param lhs first role to compare
|
||||
* @param rhs second role to compare
|
||||
* @return true if lhs is greater than rhs
|
||||
*/
|
||||
friend inline bool operator> (const role& lhs, const role& rhs)
|
||||
{
|
||||
return lhs.position > rhs.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Operator equals, used for checking if a role is ranked equal to another.
|
||||
*
|
||||
* @param other role to compare
|
||||
* @return true if is equal to other
|
||||
*/
|
||||
inline bool operator== (const role& other) const
|
||||
{
|
||||
return this->position == other.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Operator not equals, used for checking if a role is ranked equal to another.
|
||||
*
|
||||
* @param other role to compare
|
||||
* @return true if is not equal to other
|
||||
*/
|
||||
inline bool operator!= (const role& other) const
|
||||
{
|
||||
return this->position != other.position;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief True if the role is hoisted
|
||||
* @return bool Role appears separated from others in the member list
|
||||
*/
|
||||
bool is_hoisted() const;
|
||||
/**
|
||||
* @brief True if the role is mentionable
|
||||
* @return bool Role is mentionable
|
||||
*/
|
||||
bool is_mentionable() const;
|
||||
/**
|
||||
* @brief True if the role is managed (belongs to a bot or application)
|
||||
* @return bool True if the role is managed (introduced for a bot or other application by Discord)
|
||||
*/
|
||||
bool is_managed() const;
|
||||
/**
|
||||
* @brief True if has create instant invite permission
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the instant invite permission or is administrator.
|
||||
*/
|
||||
bool has_create_instant_invite() const;
|
||||
/**
|
||||
* @brief True if has the kick members permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the kick members permission or is administrator.
|
||||
*/
|
||||
bool has_kick_members() const;
|
||||
/**
|
||||
* @brief True if has the ban members permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the ban members permission or is administrator.
|
||||
*/
|
||||
bool has_ban_members() const;
|
||||
/**
|
||||
* @brief True if has the administrator permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the administrator permission or is administrator.
|
||||
*/
|
||||
bool has_administrator() const;
|
||||
/**
|
||||
* @brief True if has the manage channels permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the manage channels permission or is administrator.
|
||||
*/
|
||||
bool has_manage_channels() const;
|
||||
/**
|
||||
* @brief True if has the manage guild permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the manage guild permission or is administrator.
|
||||
*/
|
||||
bool has_manage_guild() const;
|
||||
/**
|
||||
* @brief True if has the add reactions permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the add reactions permission or is administrator.
|
||||
*/
|
||||
bool has_add_reactions() const;
|
||||
/**
|
||||
* @brief True if has the view audit log permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the view audit log permission or is administrator.
|
||||
*/
|
||||
bool has_view_audit_log() const;
|
||||
/**
|
||||
* @brief True if has the priority speaker permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the priority speaker permission or is administrator.
|
||||
*/
|
||||
bool has_priority_speaker() const;
|
||||
/**
|
||||
* @brief True if has the stream permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the stream permission or is administrator.
|
||||
*/
|
||||
bool has_stream() const;
|
||||
/**
|
||||
* @brief True if has the view channel permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the view channel permission or is administrator.
|
||||
*/
|
||||
bool has_view_channel() const;
|
||||
/**
|
||||
* @brief True if has the send messages permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the send messages permission or is administrator.
|
||||
*/
|
||||
bool has_send_messages() const;
|
||||
/**
|
||||
* @brief True if has the send TTS messages permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the send TTS messages permission or is administrator.
|
||||
*/
|
||||
bool has_send_tts_messages() const;
|
||||
/**
|
||||
* @brief True if has the manage messages permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the manage messages permission or is administrator.
|
||||
*/
|
||||
bool has_manage_messages() const;
|
||||
/**
|
||||
* @brief True if has the embed links permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the embed links permission or is administrator.
|
||||
*/
|
||||
bool has_embed_links() const;
|
||||
/**
|
||||
* @brief True if has the attach files permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the attach files permission or is administrator.
|
||||
*/
|
||||
bool has_attach_files() const;
|
||||
/**
|
||||
* @brief True if has the read message history permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the read message history permission or is administrator.
|
||||
*/
|
||||
bool has_read_message_history() const;
|
||||
/**
|
||||
* @brief True if has the mention \@everyone and \@here permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the mention \@everyone and \@here permission or is administrator.
|
||||
*/
|
||||
bool has_mention_everyone() const;
|
||||
/**
|
||||
* @brief True if has the use external emojis permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the use external emojis permission or is administrator.
|
||||
*/
|
||||
bool has_use_external_emojis() const;
|
||||
/**
|
||||
* @brief True if has the view guild insights permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the view guild insights permission or is administrator.
|
||||
*/
|
||||
bool has_view_guild_insights() const;
|
||||
/**
|
||||
* @brief True if has the connect voice permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the connect voice permission or is administrator.
|
||||
*/
|
||||
bool has_connect() const;
|
||||
/**
|
||||
* @brief True if has the speak permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the speak permission or is administrator.
|
||||
*/
|
||||
bool has_speak() const;
|
||||
/**
|
||||
* @brief True if has the mute members permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the mute members permission or is administrator.
|
||||
*/
|
||||
bool has_mute_members() const;
|
||||
/**
|
||||
* @brief True if has the deafen members permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the deafen members permission or is administrator.
|
||||
*/
|
||||
bool has_deafen_members() const;
|
||||
/**
|
||||
* @brief True if has the move members permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the move members permission or is administrator.
|
||||
*/
|
||||
bool has_move_members() const;
|
||||
/** True if has use voice activity detection permission */
|
||||
bool has_use_vad() const;
|
||||
/**
|
||||
* @brief True if has the change nickname permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the change nickname permission or is administrator.
|
||||
*/
|
||||
bool has_change_nickname() const;
|
||||
/**
|
||||
* @brief True if has the manage nicknames permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the manage nicknames permission or is administrator.
|
||||
*/
|
||||
bool has_manage_nicknames() const;
|
||||
/**
|
||||
* @brief True if has the manage roles permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the manage roles permission or is administrator.
|
||||
*/
|
||||
bool has_manage_roles() const;
|
||||
/**
|
||||
* @brief True if has the manage webhooks permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the manage webhooks permission or is administrator.
|
||||
*/
|
||||
bool has_manage_webhooks() const;
|
||||
/**
|
||||
* @brief True if has the manage emojis and stickers permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the manage emojis and stickers permission or is administrator.
|
||||
*/
|
||||
bool has_manage_emojis_and_stickers() const;
|
||||
/**
|
||||
* @brief True if has the use application commands permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the use application commands permission or is administrator.
|
||||
*/
|
||||
bool has_use_application_commands() const;
|
||||
/**
|
||||
* @brief True if has the request to speak permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the request to speak permission or is administrator.
|
||||
*/
|
||||
bool has_request_to_speak() const;
|
||||
/**
|
||||
* @brief True if has the manage threads permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the manage threads permission or is administrator.
|
||||
*/
|
||||
bool has_manage_threads() const;
|
||||
/**
|
||||
* @brief True if has the create public threads permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the create public threads permission or is administrator.
|
||||
*/
|
||||
bool has_create_public_threads() const;
|
||||
/**
|
||||
* @brief True if has the create private threads permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the create private threads permission or is administrator.
|
||||
*/
|
||||
bool has_create_private_threads() const;
|
||||
/**
|
||||
* @brief True if has the use external stickers permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the use external stickers permission or is administrator.
|
||||
*/
|
||||
bool has_use_external_stickers() const;
|
||||
/**
|
||||
* @brief True if has the send messages in threads permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the send messages in threads permission or is administrator.
|
||||
*/
|
||||
bool has_send_messages_in_threads() const;
|
||||
/**
|
||||
* @brief True if has the start embedded activities permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the start embedded activities permission or is administrator.
|
||||
*/
|
||||
bool has_use_embedded_activities() const;
|
||||
/**
|
||||
* @brief True if has the manage events permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the manage events permission or is administrator.
|
||||
*/
|
||||
bool has_manage_events() const;
|
||||
/**
|
||||
* @brief True if has the moderate users permission.
|
||||
* @note Having the administrator permission causes this method to always return true
|
||||
* Channel specific overrides may apply to permissions.
|
||||
* @return bool True if user has the moderate users permission or is administrator.
|
||||
*/
|
||||
bool has_moderate_members() const;
|
||||
|
||||
/**
|
||||
* @brief Get guild members who have this role
|
||||
* @note This method requires user/members cache to be active
|
||||
* @return members_container List of members who have this role
|
||||
*/
|
||||
members_container get_members() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Application Role Connection Metadata Type
|
||||
*
|
||||
* @note Each metadata type offers a comparison operation that allows guilds to configure role requirements based on metadata values stored by the bot. Bots specify a `metadata value` for each user and guilds specify the required `guild's configured value` within the guild role settings.
|
||||
*/
|
||||
enum application_role_connection_metadata_type : uint8_t {
|
||||
rc_integer_less_than_or_equal = 1, //!< The metadata value (integer) is less than or equal to the guild's configured value (integer)
|
||||
rc_integer_greater_than_or_equal = 2, //!< The metadata value (integer) is greater than or equal to the guild's configured value (integer)
|
||||
rc_integer_equal = 3, //!< The metadata value (integer) is equal to the guild's configured value (integer)
|
||||
rc_integer_not_equal = 4, //!< The metadata value (integer) is not equal to the guild's configured value (integer)
|
||||
rc_datetime_less_than_or_equal = 5, //!< The metadata value (ISO8601 string) is less than or equal to the guild's configured value (integer; days before current date)
|
||||
rc_datetime_greater_than_or_equal = 6, //!< The metadata value (ISO8601 string) is greater than or equal to the guild's configured value (integer; days before current date)
|
||||
rc_boolean_equal = 7, //!< The metadata value (integer) is equal to the guild's configured value (integer; 1)
|
||||
rc_boolean_not_equal = 8, //!< The metadata value (integer) is not equal to the guild's configured value (integer; 1)
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Application Role Connection Metadata. Represents a role connection metadata for an dpp::application
|
||||
*/
|
||||
class DPP_EXPORT application_role_connection_metadata : public json_interface<application_role_connection_metadata> {
|
||||
public:
|
||||
application_role_connection_metadata_type type; //!< Type of metadata value
|
||||
std::string key; //!< Dictionary key for the metadata field (must be `a-z`, `0-9`, or `_` characters; 1-50 characters)
|
||||
std::string name; //!< Name of the metadata field (1-100 characters)
|
||||
std::map<std::string, std::string> name_localizations; //!< Translations of the name
|
||||
std::string description; //!< Description of the metadata field (1-200 characters)
|
||||
std::map<std::string, std::string> description_localizations; //!< Translations of the description
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
application_role_connection_metadata();
|
||||
|
||||
virtual ~application_role_connection_metadata() = default;
|
||||
|
||||
/** Fill this record from json.
|
||||
* @param j The json to fill this record from
|
||||
* @return Reference to self
|
||||
*/
|
||||
application_role_connection_metadata& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Convert to JSON string
|
||||
*
|
||||
* @param with_id include ID in output
|
||||
* @return std::string JSON output
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The application role connection that an application has attached to a user.
|
||||
*/
|
||||
class DPP_EXPORT application_role_connection : public json_interface<application_role_connection> {
|
||||
public:
|
||||
std::string platform_name; //!< Optional: The vanity name of the platform a bot has connected (max 50 characters)
|
||||
std::string platform_username; //!< Optional: The username on the platform a bot has connected (max 100 characters)
|
||||
std::variant<std::monostate, application_role_connection_metadata> metadata; //!< Optional: Object mapping application role connection metadata keys to their stringified value (max 100 characters) for the user on the platform a bot has connected
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
application_role_connection();
|
||||
|
||||
virtual ~application_role_connection() = default;
|
||||
|
||||
/** Fill this record from json.
|
||||
* @param j The json to fill this record from
|
||||
* @return Reference to self
|
||||
*/
|
||||
application_role_connection& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Convert to JSON string
|
||||
*
|
||||
* @param with_id include ID in output
|
||||
* @return std::string JSON output
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
};
|
||||
|
||||
/** A group of roles */
|
||||
typedef std::unordered_map<snowflake, role> role_map;
|
||||
|
||||
/** A group of application_role_connection_metadata objects */
|
||||
typedef std::vector<application_role_connection_metadata> application_role_connection_metadata_list;
|
||||
|
||||
};
|
||||
|
224
vendor/DPP/include/dpp/scheduled_event.h
vendored
Normal file
224
vendor/DPP/include/dpp/scheduled_event.h
vendored
Normal file
@ -0,0 +1,224 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/user.h>
|
||||
#include <dpp/guild.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents the privacy of an event
|
||||
*/
|
||||
enum event_privacy_level : uint8_t {
|
||||
/// The event is visible to only guild members.
|
||||
ep_guild_only = 2
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Event entity types
|
||||
*/
|
||||
enum event_entity_type : uint8_t {
|
||||
/// A stage instance
|
||||
eet_stage_instance = 1,
|
||||
/// A voice channel
|
||||
eet_voice = 2,
|
||||
/// External to discord, or a text channel etc
|
||||
eet_external = 3
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Event status types
|
||||
*/
|
||||
enum event_status : uint8_t {
|
||||
/// Scheduled
|
||||
es_scheduled = 1,
|
||||
/// Active now
|
||||
es_active = 2,
|
||||
/// Completed
|
||||
es_completed = 3,
|
||||
/// Cancelled
|
||||
es_cancelled = 4
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Entities for the event
|
||||
*/
|
||||
struct DPP_EXPORT event_entities {
|
||||
/// location of the event
|
||||
std::string location;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a guild member/user who has registered interest in an event
|
||||
*
|
||||
*/
|
||||
struct DPP_EXPORT event_member {
|
||||
/**
|
||||
* @brief Event ID associated with
|
||||
*/
|
||||
snowflake guild_scheduled_event_id;
|
||||
/**
|
||||
* @brief User details of associated user
|
||||
*
|
||||
*/
|
||||
dpp::user user;
|
||||
/**
|
||||
* @brief Member details of user on the associated guild
|
||||
*/
|
||||
dpp::guild_member member;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A scheduled event
|
||||
*/
|
||||
struct DPP_EXPORT scheduled_event : public managed, public json_interface<scheduled_event> {
|
||||
snowflake guild_id; //!< the guild id which the scheduled event belongs to
|
||||
snowflake channel_id; //!< the channel id in which the scheduled event will be hosted, or null if scheduled entity type is EXTERNAL (may be empty)
|
||||
snowflake creator_id; //!< Optional: the id of the user that created the scheduled event
|
||||
std::string name; //!< the name of the scheduled event
|
||||
std::string description; //!< Optional: the description of the scheduled event (1-1000 characters)
|
||||
std::string image; //!< the image of the scheduled event (may be empty)
|
||||
time_t scheduled_start_time; //!< the time the scheduled event will start
|
||||
time_t scheduled_end_time; //!< the time the scheduled event will end, or null if the event does not have a scheduled time to end (may be empty)
|
||||
event_privacy_level privacy_level; //!< the privacy level of the scheduled event
|
||||
event_status status; //!< the status of the scheduled event
|
||||
event_entity_type entity_type; //!< the type of hosting entity associated with a scheduled event, e.g. voice channel or stage channel
|
||||
snowflake entity_id; //!< any additional id of the hosting entity associated with event, e.g. stage instance id) (may be empty)
|
||||
event_entities entity_metadata; //!< the entity metadata for the scheduled event (may be empty)
|
||||
user creator; //!< Optional: the creator of the scheduled event
|
||||
uint32_t user_count; //!< Optional: the number of users subscribed to the scheduled event
|
||||
|
||||
/**
|
||||
* @brief Create a scheduled_event object
|
||||
*/
|
||||
scheduled_event();
|
||||
|
||||
/**
|
||||
* @brief Destroy the scheduled_event object
|
||||
*/
|
||||
~scheduled_event() = default;
|
||||
|
||||
/**
|
||||
* @brief Set the name of the event
|
||||
* Minimum length: 1, Maximum length: 100
|
||||
* @param n event name
|
||||
* @return scheduled_event& reference to self
|
||||
* @throw dpp::length_error if length < 1
|
||||
*/
|
||||
scheduled_event& set_name(const std::string& n);
|
||||
|
||||
/**
|
||||
* @brief Set the description of the event
|
||||
* Minimum length: 1 (if set), Maximum length: 100
|
||||
* @param d event description
|
||||
* @return scheduled_event& reference to self
|
||||
* @throw dpp::length_error if length < 1
|
||||
*/
|
||||
scheduled_event& set_description(const std::string& d);
|
||||
|
||||
/**
|
||||
* @brief Clear the description of the event
|
||||
* @return scheduled_event& reference to self
|
||||
*/
|
||||
scheduled_event& clear_description();
|
||||
|
||||
/**
|
||||
* @brief Set the location of the event.
|
||||
* Minimum length: 1, Maximum length: 1000
|
||||
* @note Clears channel_id
|
||||
* @param l event location
|
||||
* @return scheduled_event& reference to self
|
||||
* @throw dpp::length_error if length < 1
|
||||
*/
|
||||
scheduled_event& set_location(const std::string& l);
|
||||
|
||||
/**
|
||||
* @brief Set the voice channel id of the event
|
||||
* @note clears location
|
||||
* @param c channel ID
|
||||
* @return scheduled_event& reference to self
|
||||
*/
|
||||
scheduled_event& set_channel_id(snowflake c);
|
||||
|
||||
/**
|
||||
* @brief Set the creator id of the event
|
||||
* @param c creator user ID
|
||||
* @return scheduled_event& reference to self
|
||||
*/
|
||||
scheduled_event& set_creator_id(snowflake c);
|
||||
|
||||
/**
|
||||
* @brief Set the status of the event
|
||||
* @param s status to set
|
||||
* @return scheduled_event& reference to self
|
||||
* @throw dpp::logic_exception if status change is not valid
|
||||
*/
|
||||
scheduled_event& set_status(event_status s);
|
||||
|
||||
/**
|
||||
* @brief Set the start time of the event
|
||||
* @param t starting time
|
||||
* @return scheduled_event& reference to self
|
||||
* @throw dpp::length_error if time is before now
|
||||
*/
|
||||
scheduled_event& set_start_time(time_t t);
|
||||
|
||||
/**
|
||||
* @brief Set the end time of the event
|
||||
* @param t ending time
|
||||
* @return scheduled_event& reference to self
|
||||
* @throw dpp::length_error if time is before now
|
||||
*/
|
||||
scheduled_event& set_end_time(time_t t);
|
||||
|
||||
/**
|
||||
* @brief Serialise a scheduled_event object from json
|
||||
*
|
||||
* @return scheduled_event& a reference to self
|
||||
*/
|
||||
scheduled_event& fill_from_json(const nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build json for this object
|
||||
* @param with_id Include id field in json
|
||||
*
|
||||
* @return std::string Dumped json of this object
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A group of scheduled events
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, scheduled_event> scheduled_event_map;
|
||||
|
||||
/**
|
||||
* @brief A group of scheduled event members
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, event_member> event_member_map;
|
||||
|
||||
|
||||
};
|
196
vendor/DPP/include/dpp/snowflake.h
vendored
Normal file
196
vendor/DPP/include/dpp/snowflake.h
vendored
Normal file
@ -0,0 +1,196 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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.h>
|
||||
#include <stdint.h>
|
||||
#include <functional>
|
||||
|
||||
/**
|
||||
* @brief The main namespace for D++ functions. classes and types
|
||||
*/
|
||||
namespace dpp {
|
||||
|
||||
/** @brief A container for a 64 bit unsigned value representing many things on discord.
|
||||
* This value is known in distributed computing as a snowflake value.
|
||||
*
|
||||
* Snowflakes are:
|
||||
*
|
||||
* - Performant (very fast to generate at source and to compare in code)
|
||||
* - Uncoordinated (allowing high availability across clusters, data centres etc)
|
||||
* - Time ordered (newer snowflakes have higher IDs)
|
||||
* - Directly Sortable (due to time ordering)
|
||||
* - Compact (64 bit numbers, not 128 bit, or string)
|
||||
*
|
||||
* An identical format of snowflake is used by Twitter, Instagram and several other platforms.
|
||||
*
|
||||
* @see https://en.wikipedia.org/wiki/Snowflake_ID
|
||||
* @see https://github.com/twitter-archive/snowflake/tree/b3f6a3c6ca8e1b6847baa6ff42bf72201e2c2231
|
||||
*/
|
||||
class DPP_EXPORT snowflake final {
|
||||
friend struct std::hash<dpp::snowflake>;
|
||||
protected:
|
||||
/**
|
||||
* @brief The snowflake value
|
||||
*/
|
||||
uint64_t value;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a snowflake object
|
||||
* @param value A snowflake value
|
||||
*/
|
||||
snowflake(const uint64_t& value);
|
||||
|
||||
/**
|
||||
* @brief Construct a snowflake object
|
||||
* @param value A snowflake value
|
||||
*/
|
||||
snowflake(const std::string& string_value);
|
||||
|
||||
/**
|
||||
* @brief Construct a snowflake object
|
||||
*/
|
||||
snowflake();
|
||||
|
||||
/**
|
||||
* @brief Destroy the snowflake object
|
||||
*/
|
||||
~snowflake() = default;
|
||||
|
||||
/**
|
||||
* @brief For acting like an integer
|
||||
* @return The snowflake value
|
||||
*/
|
||||
operator uint64_t() const;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the snowflake holds an empty value (is 0)
|
||||
*
|
||||
* @return true if empty (zero)
|
||||
*/
|
||||
inline bool empty() const
|
||||
{
|
||||
return value == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Operator less than, used for maps/unordered maps
|
||||
* when the snowflake is a key value.
|
||||
*
|
||||
* @param lhs fist snowflake to compare
|
||||
* @param rhs second snowflake to compare
|
||||
* @return true if lhs is less than rhs
|
||||
*/
|
||||
friend inline bool operator< (const snowflake& lhs, const snowflake& rhs)
|
||||
{
|
||||
return lhs.value < rhs.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Assign from std::string
|
||||
*
|
||||
* @param snowflake_val string to assign from.
|
||||
*/
|
||||
snowflake& operator=(const std::string &snowflake_val);
|
||||
|
||||
/**
|
||||
* @brief Assign from std::string
|
||||
*
|
||||
* @param snowflake_val value to assign from.
|
||||
*/
|
||||
snowflake& operator=(const uint64_t &snowflake_val);
|
||||
|
||||
/**
|
||||
* @brief Check if one snowflake value is equal to another
|
||||
*
|
||||
* @param other other snowflake to compare
|
||||
* @return True if the snowflake objects match
|
||||
*/
|
||||
bool operator==(const snowflake& other) const;
|
||||
|
||||
/**
|
||||
* @brief Check if one snowflake value is equal to a uint64_t
|
||||
*
|
||||
* @param other other snowflake to compare
|
||||
* @return True if the snowflake objects match
|
||||
*/
|
||||
bool operator==(const uint64_t& other) const;
|
||||
|
||||
/**
|
||||
* @brief For acting like an integer
|
||||
* @return A reference to the snowflake value
|
||||
*/
|
||||
operator uint64_t &();
|
||||
|
||||
/**
|
||||
* @brief For building json
|
||||
* @return The snowflake value as a string
|
||||
*/
|
||||
operator nlohmann::json() const;
|
||||
|
||||
/**
|
||||
* @brief Get the creation time of this snowflake according to Discord.
|
||||
*
|
||||
* @return double creation time inferred from the snowflake ID.
|
||||
* The minimum possible value is the first second of 2015.
|
||||
*/
|
||||
double get_creation_time() const;
|
||||
|
||||
/**
|
||||
* @brief Get the worker id that produced this snowflake value
|
||||
*
|
||||
* @return uint8_t worker id
|
||||
*/
|
||||
uint8_t get_worker_id() const;
|
||||
|
||||
/**
|
||||
* @brief Get the process id that produced this snowflake value
|
||||
*
|
||||
* @return uint8_t process id
|
||||
*/
|
||||
uint8_t get_process_id() const;
|
||||
|
||||
/**
|
||||
* @brief Get the increment, which is incremented for every snowflake
|
||||
* created over the one millisecond resolution in the timestamp.
|
||||
*
|
||||
* @return uint64_t millisecond increment
|
||||
*/
|
||||
uint16_t get_increment() const;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
template<>
|
||||
struct std::hash<dpp::snowflake>
|
||||
{
|
||||
/**
|
||||
* @brief Hashing function for dpp::slowflake
|
||||
* Used by std::unordered_map. This just calls std::hash<uint64_t>.
|
||||
*
|
||||
* @param s Snowflake value to hash
|
||||
* @return std::size_t hash value
|
||||
*/
|
||||
std::size_t operator()(dpp::snowflake const& s) const noexcept {
|
||||
return std::hash<uint64_t>{}(s.value);
|
||||
}
|
||||
};
|
30
vendor/DPP/include/dpp/socket.h
vendored
Normal file
30
vendor/DPP/include/dpp/socket.h
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef _WIN32
|
||||
#ifndef SOCKET
|
||||
#define SOCKET int
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace dpp
|
||||
{
|
||||
/**
|
||||
* @brief Represents a socket file descriptor.
|
||||
* This is used to ensure parity between windows and unix-like systems.
|
||||
*/
|
||||
typedef SOCKET socket;
|
||||
}
|
||||
|
||||
#ifndef SOCKET_ERROR
|
||||
/**
|
||||
* @brief Represents a socket in error state
|
||||
*/
|
||||
#define SOCKET_ERROR -1
|
||||
#endif
|
||||
|
||||
#ifndef INVALID_SOCKET
|
||||
/**
|
||||
* @brief Represents a socket which is not yet assigned
|
||||
*/
|
||||
#define INVALID_SOCKET ~0
|
||||
#endif
|
257
vendor/DPP/include/dpp/sslclient.h
vendored
Normal file
257
vendor/DPP/include/dpp/sslclient.h
vendored
Normal file
@ -0,0 +1,257 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/misc-enum.h>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <dpp/socket.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief This is an opaque class containing openssl library specific structures.
|
||||
* We define it this way so that the public facing D++ library doesn't require
|
||||
* the openssl headers be available to build against it.
|
||||
*/
|
||||
class openssl_connection;
|
||||
|
||||
/**
|
||||
* @brief A callback for socket status
|
||||
*/
|
||||
typedef std::function<dpp::socket()> socket_callback_t;
|
||||
|
||||
/**
|
||||
* @brief A socket notification callback
|
||||
*/
|
||||
typedef std::function<void()> socket_notification_t;
|
||||
|
||||
/**
|
||||
* @brief Close a socket
|
||||
*
|
||||
* @param sfd Socket to close
|
||||
* @return false on error, true on success
|
||||
*/
|
||||
bool close_socket(dpp::socket sfd);
|
||||
|
||||
/**
|
||||
* @brief Set a socket to blocking or non-blocking IO
|
||||
*
|
||||
* @param sockfd socket to act upon
|
||||
* @return false on error, true on success
|
||||
*/
|
||||
bool set_nonblocking(dpp::socket sockfd, bool non_blocking);
|
||||
|
||||
/**
|
||||
* @brief Implements a simple non-blocking SSL stream client.
|
||||
*
|
||||
* @note 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 DPP_EXPORT ssl_client
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* @brief Clean up resources
|
||||
*/
|
||||
void cleanup();
|
||||
protected:
|
||||
/**
|
||||
* @brief Input buffer received from socket
|
||||
*/
|
||||
std::string buffer;
|
||||
|
||||
/**
|
||||
* @brief Output buffer for sending to socket
|
||||
*/
|
||||
std::string obuffer;
|
||||
|
||||
/**
|
||||
* @brief True if in nonblocking mode. The socket switches to nonblocking mode
|
||||
* once ReadLoop is called.
|
||||
*/
|
||||
bool nonblocking;
|
||||
|
||||
/**
|
||||
* @brief Raw file descriptor of connection
|
||||
*/
|
||||
dpp::socket sfd;
|
||||
|
||||
/**
|
||||
* @brief Openssl opaque contexts
|
||||
*/
|
||||
openssl_connection* ssl;
|
||||
|
||||
/**
|
||||
* @brief SSL cipher in use
|
||||
*/
|
||||
std::string cipher;
|
||||
|
||||
/**
|
||||
* @brief For timers
|
||||
*/
|
||||
time_t last_tick;
|
||||
|
||||
/**
|
||||
* @brief Hostname connected to
|
||||
*/
|
||||
std::string hostname;
|
||||
|
||||
/**
|
||||
* @brief Port connected to
|
||||
*/
|
||||
std::string port;
|
||||
|
||||
/**
|
||||
* @brief Bytes out
|
||||
*/
|
||||
uint64_t bytes_out;
|
||||
|
||||
/**
|
||||
* @brief Bytes in
|
||||
*/
|
||||
uint64_t bytes_in;
|
||||
|
||||
/**
|
||||
* @brief True for a plain text connection
|
||||
*/
|
||||
bool plaintext;
|
||||
|
||||
/**
|
||||
* @brief True if we are establishing a new connection, false if otherwise.
|
||||
*/
|
||||
bool make_new;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Called every second
|
||||
*/
|
||||
virtual void one_second_timer();
|
||||
|
||||
/**
|
||||
* @brief Start SSL connection and connect to TCP endpoint
|
||||
* @throw dpp::exception Failed to initialise connection
|
||||
*/
|
||||
virtual void connect();
|
||||
public:
|
||||
/**
|
||||
* @brief Get the bytes out objectGet total bytes sent
|
||||
* @return uint64_t bytes sent
|
||||
*/
|
||||
uint64_t get_bytes_out();
|
||||
|
||||
/**
|
||||
* @brief Get total bytes received
|
||||
* @return uint64_t bytes received
|
||||
*/
|
||||
uint64_t get_bytes_in();
|
||||
|
||||
/**
|
||||
* @brief Get SSL cipher name
|
||||
* @return std::string 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.
|
||||
*/
|
||||
socket_callback_t 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).
|
||||
*/
|
||||
socket_callback_t custom_writeable_fd;
|
||||
|
||||
/**
|
||||
* @brief This event will be called when you can read from the custom fd
|
||||
*/
|
||||
socket_notification_t custom_readable_ready;
|
||||
|
||||
/**
|
||||
* @brief This event will be called when you can write to a custom fd
|
||||
*/
|
||||
socket_notification_t custom_writeable_ready;
|
||||
|
||||
/**
|
||||
* @brief True if we are keeping the connection alive after it has finished
|
||||
*/
|
||||
bool keepalive;
|
||||
|
||||
/**
|
||||
* @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
|
||||
* @param plaintext_downgrade Set to true to connect using plaintext only, without initialising SSL.
|
||||
* @param reuse Attempt to reuse previous connections for this hostname and port, if available
|
||||
* Note that no Discord endpoints will function when downgraded. This option is provided only for
|
||||
* connection to non-Discord addresses such as within dpp::cluster::request().
|
||||
* @throw dpp::exception Failed to initialise connection
|
||||
*/
|
||||
ssl_client(const std::string &_hostname, const std::string &_port = "443", bool plaintext_downgrade = false, bool reuse = false);
|
||||
|
||||
/**
|
||||
* @brief Nonblocking I/O loop
|
||||
* @throw std::exception Any std::exception (or derivative) thrown from read_loop() causes reconnection of the shard
|
||||
*/
|
||||
void read_loop();
|
||||
|
||||
/**
|
||||
* @brief Destroy the ssl_client object
|
||||
*/
|
||||
virtual ~ssl_client();
|
||||
|
||||
/**
|
||||
* @brief Handle input from the input buffer. This function will be called until
|
||||
* all data in the buffer has been processed and the buffer is empty.
|
||||
* @param buffer the buffer content. Will be modified removing any processed front elements
|
||||
* @return bool True if the socket should remain connected
|
||||
*/
|
||||
virtual bool handle_buffer(std::string &buffer);
|
||||
|
||||
/**
|
||||
* @brief Write to the output buffer.
|
||||
* @param data Data to be written to the buffer
|
||||
* @note The data may not be written immediately and may be written at a later time to the socket.
|
||||
*/
|
||||
virtual void write(const std::string &data);
|
||||
|
||||
/**
|
||||
* @brief Close socket 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;
|
||||
};
|
||||
|
||||
};
|
86
vendor/DPP/include/dpp/stage_instance.h
vendored
Normal file
86
vendor/DPP/include/dpp/stage_instance.h
vendored
Normal file
@ -0,0 +1,86 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <unordered_map>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents the privacy of a stage instance
|
||||
*/
|
||||
enum stage_privacy_level : uint8_t {
|
||||
/// The Stage instance is visible publicly, such as on Stage Discovery.
|
||||
sp_public = 1,
|
||||
/// The Stage instance is visible to only guild members.
|
||||
sp_guild_only = 2
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A stage instance.
|
||||
* Stage instances are like a conference facility, with moderators/speakers and listeners.
|
||||
*/
|
||||
struct DPP_EXPORT stage_instance : public managed, public json_interface<stage_instance> {
|
||||
/// The guild id of the associated Stage channel
|
||||
snowflake guild_id;
|
||||
/// The id of the associated Stage channel
|
||||
snowflake channel_id;
|
||||
/// The topic of the Stage instance (1-120 characters)
|
||||
std::string topic;
|
||||
/// The privacy level of the Stage instance
|
||||
stage_privacy_level privacy_level;
|
||||
/// Whether or not Stage Discovery is disabled
|
||||
bool discoverable_disabled;
|
||||
|
||||
/**
|
||||
* @brief Create a stage_instance object
|
||||
*/
|
||||
stage_instance();
|
||||
|
||||
/**
|
||||
* @brief Destroy the stage_instance object
|
||||
*/
|
||||
~stage_instance() = default;
|
||||
|
||||
/**
|
||||
* @brief Serialise a stage_instance object rom json
|
||||
*
|
||||
* @return stage_instance& a reference to self
|
||||
*/
|
||||
stage_instance& fill_from_json(const nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Build json for this object
|
||||
*
|
||||
* @param with_id include ID
|
||||
* @return std::string Dumped json of this object
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
};
|
||||
|
||||
/** A group of stage instances */
|
||||
typedef std::unordered_map<snowflake, stage_instance> stage_instance_map;
|
||||
|
||||
};
|
212
vendor/DPP/include/dpp/stringops.h
vendored
Normal file
212
vendor/DPP/include/dpp/stringops.h
vendored
Normal file
@ -0,0 +1,212 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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>
|
||||
|
||||
namespace dpp {
|
||||
/**
|
||||
* @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 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 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert any value from a string to another type using stringstream.
|
||||
*
|
||||
* @tparam T Type to convert to
|
||||
* @param s String to convert from
|
||||
* @return T Returned numeric value
|
||||
*
|
||||
* @note Base 10 for numeric conversions.
|
||||
*/
|
||||
template <typename T> T from_string(const std::string &s)
|
||||
{
|
||||
T t;
|
||||
std::istringstream iss(s);
|
||||
iss >> t;
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Specialised conversion of uint64_t from string
|
||||
*
|
||||
* @tparam int64_t
|
||||
* @param s string to convert
|
||||
* @return uint64_t return value
|
||||
*/
|
||||
template <uint64_t> uint64_t from_string(const std::string &s)
|
||||
{
|
||||
return std::stoull(s, 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Specialised conversion of uint32_t from string
|
||||
*
|
||||
* @tparam uint32_t
|
||||
* @param s string to convert
|
||||
* @return uint32_t return value
|
||||
*/
|
||||
template <uint32_t> uint32_t from_string(const std::string &s)
|
||||
{
|
||||
return std::stoul(s, 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Specialised conversion of int from string
|
||||
*
|
||||
* @tparam int
|
||||
* @param s string to convert
|
||||
* @return int return value
|
||||
*/
|
||||
template <int> int from_string(const std::string &s)
|
||||
{
|
||||
return std::stoi(s, 0, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert a numeric value to hex
|
||||
*
|
||||
* @tparam T numeric type
|
||||
* @param i numeric value
|
||||
* @return std::string value in hex, the length will be 2* the raw size of the type
|
||||
*/
|
||||
template <typename T> std::string to_hex(T i)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << std::setfill('0') << std::setw(sizeof(T)*2) << std::hex << i;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Format a numeric type as a string with leading zeroes
|
||||
*
|
||||
* @tparam T numeric type
|
||||
* @param i numeric value
|
||||
* @param width width of type including the leading zeroes
|
||||
* @return std::string resultant string with leading zeroes
|
||||
*/
|
||||
template <typename T> std::string leading_zeroes(T i, size_t width)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << std::setfill('0') << std::setw(width) << std::dec << i;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
};
|
80
vendor/DPP/include/dpp/sync.h
vendored
Normal file
80
vendor/DPP/include/dpp/sync.h
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* D++, A Lightweight C++ library for Discord
|
||||
*
|
||||
* Copyright 2022 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/snowflake.h>
|
||||
#include <future>
|
||||
#include <utility>
|
||||
#include <dpp/exception.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Call a D++ REST function synchronously.
|
||||
*
|
||||
* Synchronously calling a REST function means *IT WILL BLOCK* - This is a Bad Thing™ and strongly discouraged.
|
||||
* There are very few circumstances you actually need this. If you do need to use this, you'll know it.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```cpp
|
||||
* dpp::message m = dpp::sync<dpp::message>(&bot, &dpp::cluster::message_create, dpp::message(channel_id, "moo."));
|
||||
* ```
|
||||
*
|
||||
* @warning As previously mentioned, this template will block. It is ill-advised to call this outside of
|
||||
* a separate thread and this should never be directly used in any event such as dpp::cluster::on_interaction_create!
|
||||
* @tparam T type of expected return value, should match up with the method called
|
||||
* @tparam F Type of class method in dpp::cluster to call.
|
||||
* @tparam Ts Function parameters in method call
|
||||
* @param c A pointer to dpp::cluster object
|
||||
* @param func pointer to class method in dpp::cluster to call. This can call any
|
||||
* dpp::cluster member function who's last parameter is a dpp::command_completion_event_t callback type.
|
||||
* @param args Zero or more arguments for the method call
|
||||
* @return An instantiated object of type T
|
||||
* @throw dpp::rest_exception On failure of the method call, an exception is thrown
|
||||
*/
|
||||
template<typename T, class F, class... Ts> T sync(class cluster* c, F func, Ts&&... args) {
|
||||
std::promise<T> _p;
|
||||
std::future<T> _f = _p.get_future();
|
||||
/* (obj ->* func) is the obscure syntax for calling a method pointer on an object instance */
|
||||
(c ->* func)(std::forward<Ts>(args)..., [&_p](const auto& cc) {
|
||||
try {
|
||||
if (cc.is_error()) {
|
||||
throw dpp::rest_exception(cc.get_error().message);
|
||||
} else {
|
||||
try {
|
||||
_p.set_value(std::get<T>(cc.value));
|
||||
} catch (const std::exception& e) {
|
||||
throw dpp::rest_exception(e.what());
|
||||
}
|
||||
}
|
||||
} catch (const dpp::rest_exception&) {
|
||||
_p.set_exception(std::current_exception());
|
||||
}
|
||||
});
|
||||
|
||||
/* Blocking calling thread until rest request is completed.
|
||||
* Exceptions encountered on the other thread are re-thrown.
|
||||
*/
|
||||
return _f.get();
|
||||
}
|
||||
|
||||
};
|
120
vendor/DPP/include/dpp/sysdep.h
vendored
Normal file
120
vendor/DPP/include/dpp/sysdep.h
vendored
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Discord erlpack - tidied up for D++, Craig Edwards 2021.
|
||||
*
|
||||
* MessagePack system dependencies modified for erlpack.
|
||||
*
|
||||
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
*
|
||||
* 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 <stdlib.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#if defined(__linux__)
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* numeric_limits<T>::min,max */
|
||||
#ifdef max
|
||||
#undef max
|
||||
#endif
|
||||
#ifdef min
|
||||
#undef min
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
#include <arpa/inet.h> /* __BYTE_ORDER */
|
||||
#endif
|
||||
|
||||
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define __LITTLE_ENDIAN__
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define __BIG_ENDIAN__
|
||||
#elif _WIN32
|
||||
#define __LITTLE_ENDIAN__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
|
||||
#ifdef _WIN32
|
||||
# if defined(ntohs)
|
||||
# define etf_byte_order_16(x) ntohs(x)
|
||||
# elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
||||
# define etf_byte_order_16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
|
||||
# else
|
||||
# define etf_byte_order_16(x) ( \
|
||||
((((uint16_t)x) << 8) ) | \
|
||||
((((uint16_t)x) >> 8) ) )
|
||||
# endif
|
||||
#else
|
||||
# define etf_byte_order_16(x) ntohs(x)
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
# if defined(ntohl)
|
||||
# define etf_byte_order_32(x) ntohl(x)
|
||||
# elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
||||
# define etf_byte_order_32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
|
||||
# else
|
||||
# define etf_byte_order_32(x) \
|
||||
( ((((uint32_t)x) << 24) ) | \
|
||||
((((uint32_t)x) << 8) & 0x00ff0000U ) | \
|
||||
((((uint32_t)x) >> 8) & 0x0000ff00U ) | \
|
||||
((((uint32_t)x) >> 24) ) )
|
||||
# endif
|
||||
#else
|
||||
# define etf_byte_order_32(x) ntohl(x)
|
||||
#endif
|
||||
|
||||
#if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
||||
# define etf_byte_order_64(x) (_byteswap_uint64(x))
|
||||
#elif defined(bswap_64)
|
||||
# define etf_byte_order_64(x) bswap_64(x)
|
||||
#elif defined(__DARWIN_OSSwapInt64)
|
||||
# define etf_byte_order_64(x) __DARWIN_OSSwapInt64(x)
|
||||
#elif defined(__linux__)
|
||||
# define etf_byte_order_64(x) be64toh(x)
|
||||
#else
|
||||
# define etf_byte_order_64(x) \
|
||||
( ((((uint64_t)x) << 56) ) | \
|
||||
((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \
|
||||
((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \
|
||||
((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \
|
||||
((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \
|
||||
((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \
|
||||
((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \
|
||||
((((uint64_t)x) >> 56) ) )
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define etf_byte_order_16(x) (x)
|
||||
#define etf_byte_order_32(x) (x)
|
||||
#define etf_byte_order_64(x) (x)
|
||||
#endif
|
||||
|
||||
#define store_16_bits(to, num) \
|
||||
do { uint16_t val = etf_byte_order_16(num); memcpy(to, &val, 2); } while(0)
|
||||
#define store_32_bits(to, num) \
|
||||
do { uint32_t val = etf_byte_order_32(num); memcpy(to, &val, 4); } while(0)
|
||||
#define store_64_bits(to, num) \
|
||||
do { uint64_t val = etf_byte_order_64(num); memcpy(to, &val, 8); } while(0)
|
95
vendor/DPP/include/dpp/timed_listener.h
vendored
Normal file
95
vendor/DPP/include/dpp/timed_listener.h
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/cluster.h>
|
||||
#include <time.h>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief A timed_listener is a way to temporarily attach to an event for a specific timeframe, then detach when complete.
|
||||
* A lambda may also be optionally called when the timeout is reached. Destructing the timed_listener detaches any attached
|
||||
* event listeners, and cancels any created timers, but does not call any timeout lambda.
|
||||
*
|
||||
* @tparam attached_event Event within cluster to attach to within the cluster::dispatch member (dpp::dispatcher object)
|
||||
* @tparam listening_function Definition of lambda function that matches up with the attached_event.
|
||||
*/
|
||||
template <typename attached_event, class listening_function> class timed_listener
|
||||
{
|
||||
private:
|
||||
/// Owning cluster
|
||||
cluster* owner;
|
||||
|
||||
/// Duration of listen
|
||||
time_t duration;
|
||||
|
||||
/// Reference to attached event in cluster
|
||||
//event_router_t<thread_member_update_t> on_thread_member_update;
|
||||
attached_event& ev;
|
||||
|
||||
/// Timer handle
|
||||
timer th;
|
||||
|
||||
/// Event handle
|
||||
event_handle listener_handle;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new timed listener object
|
||||
*
|
||||
* @param cl Owning cluster
|
||||
* @param _duration Duration of timed event in seconds
|
||||
* @param event Event to hook, e.g. cluster.on_message_create
|
||||
* @param on_end An optional void() lambda to trigger when the timed_listener times out.
|
||||
* Calling the destructor before the timeout is reached does not call this lambda.
|
||||
* @param listener Lambda to receive events. Type must match up properly with that passed into the 'event' parameter.
|
||||
*/
|
||||
timed_listener(cluster* cl, uint64_t _duration, attached_event& event, listening_function listener, timer_callback_t on_end = {})
|
||||
: owner(cl), duration(_duration), ev(event)
|
||||
{
|
||||
/* Attach event */
|
||||
listener_handle = ev(listener);
|
||||
/* Create timer */
|
||||
th = cl->start_timer([this](dpp::timer timer_handle) {
|
||||
/* Timer has finished, detach it from event.
|
||||
* Only allowed to tick once.
|
||||
*/
|
||||
ev.detach(listener_handle);
|
||||
owner->stop_timer(th);
|
||||
}, duration, on_end);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Destroy the timed listener object
|
||||
*/
|
||||
~timed_listener() {
|
||||
/* Stop timer and detach event, but do not call on_end */
|
||||
ev.detach(listener_handle);
|
||||
owner->stop_timer(th);
|
||||
}
|
||||
};
|
||||
|
||||
};
|
124
vendor/DPP/include/dpp/timer.h
vendored
Normal file
124
vendor/DPP/include/dpp/timer.h
vendored
Normal file
@ -0,0 +1,124 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <stdint.h>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <stddef.h>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Represents a timer handle.
|
||||
* Returned from cluster::start_timer and used by cluster::stop_timer.
|
||||
* This is obtained from a simple incrementing value, internally.
|
||||
*/
|
||||
typedef size_t timer;
|
||||
|
||||
/**
|
||||
* @brief The type for a timer callback
|
||||
*/
|
||||
typedef std::function<void(timer)> timer_callback_t;
|
||||
|
||||
/**
|
||||
* @brief Used internally to store state of active timers
|
||||
*/
|
||||
struct DPP_EXPORT timer_t {
|
||||
/**
|
||||
* @brief Timer handle
|
||||
*/
|
||||
timer handle;
|
||||
/**
|
||||
* @brief Next timer tick as unix epoch
|
||||
*/
|
||||
time_t next_tick;
|
||||
/**
|
||||
* @brief Frequency between ticks
|
||||
*/
|
||||
uint64_t frequency;
|
||||
/**
|
||||
* @brief Lambda to call on tick
|
||||
*/
|
||||
timer_callback_t on_tick;
|
||||
/**
|
||||
* @brief Lambda to call on stop (optional)
|
||||
*/
|
||||
timer_callback_t on_stop;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A map of timers, ordered by earliest first so that map::begin() is always the
|
||||
* soonest to be due.
|
||||
*/
|
||||
typedef std::multimap<time_t, timer_t*> timer_next_t;
|
||||
|
||||
/**
|
||||
* @brief A map of timers stored by handle
|
||||
*/
|
||||
typedef std::unordered_map<timer, timer_t*> timer_reg_t;
|
||||
|
||||
/**
|
||||
* @brief Trigger a timed event once.
|
||||
* The provided callback is called only once.
|
||||
*/
|
||||
class DPP_EXPORT oneshot_timer
|
||||
{
|
||||
private:
|
||||
/// Owning cluster
|
||||
class cluster* owner;
|
||||
/// Timer handle
|
||||
timer th;
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new oneshot timer object
|
||||
*
|
||||
* @param cl cluster owner
|
||||
* @param duration duration before firing
|
||||
* @param callback callback to call on firing
|
||||
*/
|
||||
oneshot_timer(class cluster* cl, uint64_t duration, timer_callback_t callback);
|
||||
|
||||
/**
|
||||
* @brief Get the handle for the created one-shot timer
|
||||
*
|
||||
* @return timer handle for use with stop_timer
|
||||
*/
|
||||
timer get_handle();
|
||||
|
||||
/**
|
||||
* @brief Cancel the one shot timer immediately.
|
||||
* Callback function is not called.
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* @brief Destroy the oneshot timer object
|
||||
*/
|
||||
~oneshot_timer();
|
||||
};
|
||||
|
||||
|
||||
|
||||
};
|
406
vendor/DPP/include/dpp/user.h
vendored
Normal file
406
vendor/DPP/include/dpp/user.h
vendored
Normal file
@ -0,0 +1,406 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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.h>
|
||||
#include <dpp/snowflake.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/utility.h>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Various bitmask flags used to represent information about a dpp::user
|
||||
*/
|
||||
enum user_flags : uint32_t {
|
||||
/// User is a bot
|
||||
u_bot = 0b00000000000000000000000000000001,
|
||||
/// User is a system user (Clyde!)
|
||||
u_system = 0b00000000000000000000000000000010,
|
||||
/// User has multi-factor authentication enabled
|
||||
u_mfa_enabled = 0b00000000000000000000000000000100,
|
||||
/// User is verified (verified email address)
|
||||
u_verified = 0b00000000000000000000000000001000,
|
||||
/// User has full nitro
|
||||
u_nitro_full = 0b00000000000000000000000000010000,
|
||||
/// User has nitro classic
|
||||
u_nitro_classic = 0b00000000000000000000000000100000,
|
||||
/// User is discord staff
|
||||
u_discord_employee = 0b00000000000000000000000001000000,
|
||||
/// User owns a partnered server
|
||||
u_partnered_owner = 0b00000000000000000000000010000000,
|
||||
/// User is a member of hypesquad events
|
||||
u_hypesquad_events = 0b00000000000000000000000100000000,
|
||||
/// User has BugHunter level 1
|
||||
u_bughunter_1 = 0b00000000000000000000001000000000,
|
||||
/// User is a member of House Bravery
|
||||
u_house_bravery = 0b00000000000000000000010000000000,
|
||||
/// User is a member of House Brilliance
|
||||
u_house_brilliance = 0b00000000000000000000100000000000,
|
||||
/// User is a member of House Balance
|
||||
u_house_balance = 0b00000000000000000001000000000000,
|
||||
/// User is an early supporter
|
||||
u_early_supporter = 0b00000000000000000010000000000000,
|
||||
/// User is a team user
|
||||
u_team_user = 0b00000000000000000100000000000000,
|
||||
/// User is has Bug Hunter level 2
|
||||
u_bughunter_2 = 0b00000000000000001000000000000000,
|
||||
/// User is a verified bot
|
||||
u_verified_bot = 0b00000000000000010000000000000000,
|
||||
/// User has the Early Verified Bot Developer badge
|
||||
u_verified_bot_dev = 0b00000000000000100000000000000000,
|
||||
/// User's icon is animated
|
||||
u_animated_icon = 0b00000000000001000000000000000000,
|
||||
/// User is a certified moderator
|
||||
u_certified_moderator = 0b00000000000010000000000000000000,
|
||||
/// User is a bot using HTTP interactions (shows online even when not connected to a websocket)
|
||||
u_bot_http_interactions = 0b00000000000100000000000000000000,
|
||||
/// User has nitro basic
|
||||
u_nitro_basic = 0b00000000001000000000000000000000,
|
||||
/// User has the active developer badge
|
||||
u_active_developer = 0b00000000010000000000000000000000,
|
||||
/// User's banner is animated
|
||||
u_animated_banner = 0b00000000100000000000000000000000,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Represents a user on discord. May or may not be a member of a dpp::guild.
|
||||
*/
|
||||
class DPP_EXPORT user : public managed, public json_interface<user> {
|
||||
public:
|
||||
/** Discord username */
|
||||
std::string username;
|
||||
/** Avatar hash */
|
||||
utility::iconhash avatar;
|
||||
/** Flags built from a bitmask of values in dpp::user_flags */
|
||||
uint32_t flags;
|
||||
/** Discriminator (aka tag), 4 digits usually displayed with leading zeroes.
|
||||
*
|
||||
* @note To print the discriminator with leading zeroes, use format_username()
|
||||
*/
|
||||
uint16_t discriminator;
|
||||
/** 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();
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable user.
|
||||
* @param id The ID of the user.
|
||||
* @return std::string The formatted mention of the user.
|
||||
*/
|
||||
static std::string get_mention(const snowflake& id);
|
||||
|
||||
/** 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 Convert to JSON string
|
||||
*
|
||||
* @param with_id include ID in output
|
||||
* @return std::string JSON output
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = true) const;
|
||||
|
||||
/**
|
||||
* @brief Get the avatar url of the user
|
||||
*
|
||||
* @note If the user doesn't have an avatar, the default user avatar url is returned which is always in `png` format!
|
||||
*
|
||||
* @param size The size of the avatar in pixels. It can be any power of two between 16 and 4096,
|
||||
* otherwise the default sized avatar is returned.
|
||||
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg`, `i_png` or `i_gif`.
|
||||
* Passing `i_gif` might result in an invalid url for non-animated images. Consider using the `prefer_animated` parameter instead.
|
||||
* @param prefer_animated Whether you prefer gif format.
|
||||
* If true, it'll return gif format whenever the image is available as animated.
|
||||
* @return std::string avatar url or an empty string, if required attributes are missing or an invalid format was passed
|
||||
*/
|
||||
std::string get_avatar_url(uint16_t size = 0, const image_type format = i_png, bool prefer_animated = true) const;
|
||||
|
||||
/**
|
||||
* @brief Get the default avatar url of the user. This is calculated by the discriminator.
|
||||
*
|
||||
* @return std::string avatar url or an empty string, if the discriminator is empty
|
||||
*/
|
||||
std::string get_default_avatar_url() const;
|
||||
|
||||
/**
|
||||
* @brief Return a ping/mention for the user
|
||||
*
|
||||
* @return std::string mention
|
||||
*/
|
||||
std::string get_mention() const;
|
||||
|
||||
/**
|
||||
* @brief Return true if user has the active Developer badge
|
||||
*
|
||||
* @return true if has active developer
|
||||
*/
|
||||
bool is_active_developer() 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 has nitro basic.
|
||||
* This is mutually exclusive with nitro basic.
|
||||
*
|
||||
* @return true if user has nitro basic
|
||||
*/
|
||||
bool has_nitro_basic() 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_balance() 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 is a bot which exclusively uses HTTP interactions.
|
||||
* Bots using HTTP interactions are always considered online even when not connected to a websocket.
|
||||
*
|
||||
* @return true if is a http interactions only bot
|
||||
*/
|
||||
bool is_bot_http_interactions() const;
|
||||
/**
|
||||
* @brief Return true if user has an animated icon
|
||||
*
|
||||
* @return true if icon is animated (gif)
|
||||
*/
|
||||
bool has_animated_icon() const;
|
||||
|
||||
/**
|
||||
* @brief Format a username into user#discriminator
|
||||
*
|
||||
* For example Brain#0001
|
||||
*
|
||||
* @return Formatted username and discriminator
|
||||
*/
|
||||
std::string format_username() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A user with additional fields only available via the oauth2 identify scope.
|
||||
* These are not included in dpp::user as additional scopes are needed to fetch them
|
||||
* which bots do not normally have.
|
||||
*/
|
||||
class DPP_EXPORT user_identified : public user, public json_interface<user_identified> {
|
||||
public:
|
||||
std::string locale; //!< Optional: the user's chosen language option identify
|
||||
std::string email; //!< Optional: the user's email email (may be empty)
|
||||
utility::iconhash banner; //!< Optional: the user's banner hash identify (may be empty)
|
||||
uint32_t accent_color; //!< Optional: the user's banner color encoded as an integer representation of hexadecimal color code identify (may be empty)
|
||||
bool verified; //!< Optional: whether the email on this account has been verified email
|
||||
|
||||
/** Fill this record from json.
|
||||
* @param j The json to fill this record from
|
||||
* @return Reference to self
|
||||
*/
|
||||
user_identified& fill_from_json(nlohmann::json* j);
|
||||
|
||||
/**
|
||||
* @brief Convert to JSON string
|
||||
*
|
||||
* @param with_id include ID in output
|
||||
* @return std::string JSON output
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = true) const;
|
||||
|
||||
/**
|
||||
* @brief Construct a new user identified object
|
||||
*/
|
||||
user_identified();
|
||||
|
||||
/**
|
||||
* @brief Construct a new user identified object from a user object
|
||||
*
|
||||
* @param u user object
|
||||
*/
|
||||
user_identified(const user& u);
|
||||
|
||||
/**
|
||||
* @brief Destroy the user identified object
|
||||
*/
|
||||
virtual ~user_identified();
|
||||
|
||||
/**
|
||||
* @brief Return true if user has an animated banner
|
||||
*
|
||||
* @return true if banner is animated (gif)
|
||||
*/
|
||||
bool has_animated_banner() const;
|
||||
|
||||
/**
|
||||
* @brief Get the user identified's banner url if they have one, otherwise returns an empty string
|
||||
*
|
||||
* @param size The size of the banner in pixels. It can be any power of two between 16 and 4096,
|
||||
* otherwise the default sized banner is returned.
|
||||
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg`, `i_png` or `i_gif`.
|
||||
* Passing `i_gif` might result in an invalid url for non-animated images. Consider using the `prefer_animated` parameter instead.
|
||||
* @param prefer_animated Whether you prefer gif format.
|
||||
* If true, it'll return gif format whenever the image is available as animated.
|
||||
* @return std::string banner url or an empty string, if required attributes are missing or an invalid format was passed
|
||||
*/
|
||||
std::string get_banner_url(uint16_t size = 0, const image_type format = i_png, bool prefer_animated = true) 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);
|
||||
|
||||
/**
|
||||
* @brief helper function to deserialize a user_identified 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_identified& u);
|
||||
|
||||
/** A group of users */
|
||||
typedef std::unordered_map<snowflake, user> user_map;
|
||||
|
||||
};
|
494
vendor/DPP/include/dpp/utility.h
vendored
Normal file
494
vendor/DPP/include/dpp/utility.h
vendored
Normal file
@ -0,0 +1,494 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/misc-enum.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
#ifndef MAX_CND_IMAGE_SIZE
|
||||
#define MAX_CDN_IMAGE_SIZE 4096
|
||||
#endif
|
||||
#ifndef MIN_CDN_IMAGE_SIZE
|
||||
#define MIN_CDN_IMAGE_SIZE 16
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief The main namespace for D++ functions, classes and types
|
||||
*/
|
||||
namespace dpp {
|
||||
/**
|
||||
* @brief Utility helper functions, generally for logging, running programs, time/date manipulation, etc
|
||||
*/
|
||||
namespace utility {
|
||||
|
||||
/**
|
||||
* @brief Timestamp formats for dpp::utility::timestamp()
|
||||
*
|
||||
* @note These values are the actual character values specified by the Discord API
|
||||
* and should not be changed unless the Discord API changes the specification!
|
||||
* They have been sorted into numerical order of their ASCII value to keep C++ happy.
|
||||
*/
|
||||
enum time_format : uint8_t {
|
||||
/// "20 April 2021" - Long Date
|
||||
tf_long_date = 'D',
|
||||
/// "Tuesday, 20 April 2021 16:20" - Long Date/Time
|
||||
tf_long_datetime = 'F',
|
||||
/// "2 months ago" - Relative Time
|
||||
tf_relative_time = 'R',
|
||||
/// "16:20:30" - Long Time
|
||||
tf_long_time = 'T',
|
||||
/// "20/04/2021" - Short Date
|
||||
tf_short_date = 'd',
|
||||
/// "20 April 2021 16:20" - Short Date/Time
|
||||
tf_short_datetime = 'f',
|
||||
/// "16:20" - Short Time
|
||||
tf_short_time = 't',
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The base URL for CDN content such as profile pictures and guild icons.
|
||||
*/
|
||||
const std::string cdn_host = "https://cdn.discordapp.com";
|
||||
|
||||
/**
|
||||
* @brief Callback for the results of a command executed via dpp::utility::exec
|
||||
*/
|
||||
typedef std::function<void(const std::string& output)> cmd_result_t;
|
||||
|
||||
/**
|
||||
* @brief Run a commandline program asynchronously. 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 parameter. For example
|
||||
* ```
|
||||
* dpp::utility::exec("/bin/ls", {"-al"}, [](const std::string& output) {
|
||||
* std::cout << "Output of 'ls -al': " << 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 DPP_EXPORT exec(const std::string& cmd, std::vector<std::string> parameters = {}, cmd_result_t callback = {});
|
||||
|
||||
/**
|
||||
* @brief Return a mentionable timestamp (used in a message). These timestamps will display the given timestamp in the user's timezone and locale.
|
||||
*
|
||||
* @param ts Time stamp to convert
|
||||
* @param tf Format of timestamp using dpp::utility::time_format
|
||||
* @return std::string The formatted timestamp
|
||||
*/
|
||||
std::string DPP_EXPORT timestamp(time_t ts, time_format tf = tf_short_datetime);
|
||||
|
||||
/**
|
||||
* @brief Returns current date and time
|
||||
*
|
||||
* @return std::string Current date and time in "Y-m-d H:M:S" format
|
||||
*/
|
||||
std::string DPP_EXPORT 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 DPP_EXPORT 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 DPP_EXPORT iconhash {
|
||||
|
||||
uint64_t first; //!< High 64 bits
|
||||
uint64_t second; //!< Low 64 bits
|
||||
|
||||
/**
|
||||
* @brief Construct a new iconhash object
|
||||
* @param _first Leftmost portion of the hash value
|
||||
* @param _second Rightmost portion of the hash value
|
||||
*/
|
||||
iconhash(uint64_t _first = 0, uint64_t _second = 0);
|
||||
|
||||
/**
|
||||
* @brief Construct a new iconhash object
|
||||
*/
|
||||
iconhash(const iconhash&);
|
||||
|
||||
/**
|
||||
* @brief Destroy the iconhash 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 Check if one iconhash is equal to another
|
||||
*
|
||||
* @param other other iconhash to compare
|
||||
* @return True if the iconhash objects match
|
||||
*/
|
||||
bool operator==(const iconhash& other) const;
|
||||
|
||||
/**
|
||||
* @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 DPP_EXPORT time_f();
|
||||
|
||||
/**
|
||||
* @brief Returns true if D++ was built with voice support
|
||||
*
|
||||
* @return bool True if voice support is compiled in (libsodium/libopus)
|
||||
*/
|
||||
bool DPP_EXPORT has_voice();
|
||||
|
||||
/**
|
||||
* @brief Convert a byte count to display value
|
||||
*
|
||||
* @param c number of bytes
|
||||
* @return std::string display value suffixed with M, G, T where necessary
|
||||
*/
|
||||
std::string DPP_EXPORT 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 DPP_EXPORT 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 Construct a new uptime object
|
||||
*
|
||||
* @param diff A time_t to initialise the object from
|
||||
*/
|
||||
uptime(double diff);
|
||||
|
||||
/**
|
||||
* @brief Get uptime as string
|
||||
*
|
||||
* @return std::string Uptime as string
|
||||
*/
|
||||
std::string to_string() const;
|
||||
|
||||
/**
|
||||
* @brief Get uptime as seconds
|
||||
*
|
||||
* @return uint64_t Uptime as seconds
|
||||
*/
|
||||
uint64_t to_secs() const;
|
||||
|
||||
/**
|
||||
* @brief Get uptime as milliseconds
|
||||
*
|
||||
* @return uint64_t Uptime as milliseconds
|
||||
*/
|
||||
uint64_t to_msecs() const;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Convert doubles to RGB for sending in embeds
|
||||
*
|
||||
* @param red red value, between 0 and 1 inclusive
|
||||
* @param green green value, between 0 and 1 inclusive
|
||||
* @param blue blue value, between 0 and 1 inclusive
|
||||
* @return uint32_t returned integer colour value
|
||||
*/
|
||||
uint32_t DPP_EXPORT rgb(double red, double green, double blue);
|
||||
|
||||
/**
|
||||
* @brief Convert ints to RGB for sending in embeds
|
||||
*
|
||||
* @param red red value, between 0 and 255 inclusive
|
||||
* @param green green value, between 0 and 255 inclusive
|
||||
* @param blue blue value, between 0 and 255 inclusive
|
||||
* @return uint32_t returned integer colour value
|
||||
*/
|
||||
uint32_t DPP_EXPORT rgb(int red, int green, int blue);
|
||||
|
||||
/**
|
||||
* @brief Convert doubles to CMYK for sending in embeds
|
||||
*
|
||||
* @param c cyan value, between 0 and 1 inclusive
|
||||
* @param m magenta value, between 0 and 1 inclusive
|
||||
* @param y yellow value, between 0 and 1 inclusive
|
||||
* @param k key (black) value, between 0 and 1 inclusive
|
||||
* @return uint32_t returned integer colour value
|
||||
*/
|
||||
uint32_t DPP_EXPORT cmyk(double c, double m, double y, double k);
|
||||
|
||||
/**
|
||||
* @brief Convert ints to CMYK for sending in embeds
|
||||
*
|
||||
* @param c cyan value, between 0 and 255 inclusive
|
||||
* @param m magenta value, between 0 and 255 inclusive
|
||||
* @param y yellow value, between 0 and 255 inclusive
|
||||
* @param k key (black) value, between 0 and 255 inclusive
|
||||
* @return uint32_t returned integer colour value
|
||||
*/
|
||||
uint32_t DPP_EXPORT cmyk(int c, int m, int y, int k);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
std::string DPP_EXPORT 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 DPP_EXPORT utf8len(const std::string &str);
|
||||
|
||||
/**
|
||||
* @brief Return substring of a UTF-8 encoded string in codepoints
|
||||
*
|
||||
* @param str string to return substring from
|
||||
* @param start start codepoint offset
|
||||
* @param length length in codepoints
|
||||
* @return std::string Substring in UTF-8 or empty string if invalid UTF-8 passed in
|
||||
*/
|
||||
std::string DPP_EXPORT utf8substr(const std::string& str, std::string::size_type start, std::string::size_type length);
|
||||
|
||||
/**
|
||||
* @brief Read a whole file into a std::string.
|
||||
* Be sure you have enough memory to read the file, if you are reading a large file.
|
||||
* @note Be aware this function can block! If you are regularly reading large files, consider caching them.
|
||||
* @param filename The path to the file to read
|
||||
* @return std::string The file contents
|
||||
* @throw dpp::exception on failure to read the entire file
|
||||
*/
|
||||
std::string DPP_EXPORT read_file(const std::string& filename);
|
||||
|
||||
/**
|
||||
* @brief Validate a string value
|
||||
* In the event the length of the string is less than _min, then an exception of type dpp:length_exception
|
||||
* will be thrown. If the string is longer than _max UTF8 codepoints it will be truncated to fit.
|
||||
*
|
||||
* @param value The value to validate
|
||||
* @param _min Minimum length
|
||||
* @param _max Maximum length
|
||||
* @param exception_message Exception message to throw if value length < _min
|
||||
* @return std::string Validated string, truncated if necessary.
|
||||
* @throw dpp::length_exception if value UTF8 length < _min
|
||||
*/
|
||||
std::string DPP_EXPORT validate(const std::string& value, size_t _min, size_t _max, const std::string& exception_message);
|
||||
|
||||
/**
|
||||
* @brief Get the url query parameter for the cdn endpoint. Internally used to build url getters.
|
||||
*
|
||||
* @param size size to generate url parameter for. Must be any power of two between 16 and 4096 (inclusive) or it'll return an empty string.
|
||||
* @return std::string url query parameter e.g. `?size=128`, or an empty string
|
||||
*/
|
||||
std::string DPP_EXPORT avatar_size(uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Split (tokenize) a string into a vector, using the given separators
|
||||
*
|
||||
* @param in Input string
|
||||
* @param sep Separator characters
|
||||
* @return std::vector<std::string> Tokenized strings
|
||||
*/
|
||||
std::vector<std::string> DPP_EXPORT tokenize(std::string const &in, const char* sep = "\r\n");
|
||||
|
||||
/**
|
||||
* @brief Create a bot invite
|
||||
*
|
||||
* @param bot_id Bot ID
|
||||
* @param permissions Permission bitmask of the bot to invite
|
||||
* @param scopes Scopes to use
|
||||
* @return Invite URL
|
||||
*/
|
||||
std::string DPP_EXPORT bot_invite_url(const snowflake bot_id, const uint64_t permissions = 0, const std::vector<std::string>& scopes = {"bot", "applications.commands"});
|
||||
|
||||
/**
|
||||
* @brief Escapes Discord's markdown sequences in a string
|
||||
*
|
||||
* @param text Text to escape
|
||||
* @param escape_code_blocks If set to false, then code blocks are not escaped.
|
||||
* This means that you can still use a code block, and the text within will be left as-is.
|
||||
* If set to true, code blocks will also be escaped so that ` symbol may be used as a normal
|
||||
* character.
|
||||
* @return std::string The text with the markdown special characters escaped with a backslash
|
||||
*/
|
||||
std::string DPP_EXPORT markdown_escape(const std::string& text, bool escape_code_blocks = false);
|
||||
|
||||
/**
|
||||
* @brief Encodes a url parameter similar to [php urlencode()](https://www.php.net/manual/en/function.urlencode.php)
|
||||
*
|
||||
* @param value String to encode
|
||||
* @return std::string URL encoded string
|
||||
*/
|
||||
std::string DPP_EXPORT url_encode(const std::string &value);
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable slashcommand (used in a message).
|
||||
* @param command_id The ID of the slashcommand
|
||||
* @param command_name The command name
|
||||
* @param subcommand Optional: The subcommand name (for mentioning a subcommand)
|
||||
* @return std::string The formatted mention
|
||||
*/
|
||||
std::string DPP_EXPORT slashcommand_mention(snowflake command_id, const std::string &command_name, const std::string &subcommand = "");
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable slashcommand (used in a message).
|
||||
* @param command_id The ID of the slashcommand
|
||||
* @param command_name The command name
|
||||
* @param subcommand_group The subcommand group name
|
||||
* @param subcommand The subcommand name
|
||||
* @return std::string The formatted mention of the slashcommand with its subcommand
|
||||
*/
|
||||
std::string DPP_EXPORT slashcommand_mention(snowflake command_id, const std::string &command_name, const std::string &subcommand_group, const std::string &subcommand);
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable user.
|
||||
* @param id The ID of the user.
|
||||
* @return std::string The formatted mention of the user.
|
||||
*/
|
||||
std::string DPP_EXPORT user_mention(const snowflake& id);
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable channel.
|
||||
* @param id The ID of the channel.
|
||||
* @return std::string The formatted mention of the channel.
|
||||
*/
|
||||
std::string DPP_EXPORT channel_mention(const snowflake& id);
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable emoji
|
||||
* @param name The name of the emoji.
|
||||
* @param id The ID of the emoji.
|
||||
* @param is_animated is emoji animated.
|
||||
* @return std::string The formatted mention of the emoji.
|
||||
*/
|
||||
std::string DPP_EXPORT emoji_mention(const std::string& name, const snowflake& id, bool is_animated = false);
|
||||
|
||||
/**
|
||||
* @brief Create a mentionable role.
|
||||
* @param id The ID of the role.
|
||||
* @return std::string The formatted mention of the role.
|
||||
*/
|
||||
std::string DPP_EXPORT role_mention(const snowflake& id);
|
||||
|
||||
/**
|
||||
* @brief Returns the library's version string
|
||||
*
|
||||
* @return std::string version
|
||||
*/
|
||||
std::string DPP_EXPORT version();
|
||||
|
||||
/**
|
||||
* @brief Build a URL parameter string e.g. "?a=b&c=d&e=f" from a map of key/value pairs.
|
||||
* Entries with empty key names or values are omitted.
|
||||
*
|
||||
* @param parameters parameters to create a url query string for
|
||||
* @return std::string A correctly encoded url query string
|
||||
*/
|
||||
std::string DPP_EXPORT make_url_parameters(const std::map<std::string, std::string>& parameters);
|
||||
|
||||
/**
|
||||
* @brief Build a URL parameter string e.g. "?a=b&c=d&e=f" from a map of key/value pairs.
|
||||
* Entries with empty key names or zero values are omitted.
|
||||
*
|
||||
* @param parameters parameters to create a url query string for
|
||||
* @return std::string A correctly encoded url query string
|
||||
*/
|
||||
std::string DPP_EXPORT make_url_parameters(const std::map<std::string, uint64_t>& parameters);
|
||||
|
||||
/**
|
||||
* @brief Set the name of the current thread for debugging and statistical reporting
|
||||
*
|
||||
* @param name New name to set
|
||||
*/
|
||||
void DPP_EXPORT set_thread_name(const std::string& name);
|
||||
|
||||
};
|
||||
};
|
31
vendor/DPP/include/dpp/version.h
vendored
Normal file
31
vendor/DPP/include/dpp/version.h
vendored
Normal 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 0x00100023
|
||||
#define DPP_VERSION_SHORT 100023
|
||||
#define DPP_VERSION_TEXT "D++ 10.0.23 (04-Jan-2023)"
|
||||
|
||||
#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
|
119
vendor/DPP/include/dpp/voiceregion.h
vendored
Normal file
119
vendor/DPP/include/dpp/voiceregion.h
vendored
Normal file
@ -0,0 +1,119 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 <dpp/json_fwd.h>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
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 DPP_EXPORT voiceregion : public json_interface<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
|
||||
*/
|
||||
virtual ~voiceregion() = default;
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* @param with_id Add ID to output
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) 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;
|
||||
|
||||
};
|
110
vendor/DPP/include/dpp/voicestate.h
vendored
Normal file
110
vendor/DPP/include/dpp/voicestate.h
vendored
Normal file
@ -0,0 +1,110 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <unordered_map>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
namespace dpp {
|
||||
|
||||
/**
|
||||
* @brief Bit mask flags relating to voice states
|
||||
*/
|
||||
enum voicestate_flags {
|
||||
vs_deaf = 0b00000001, //!< Deafened by the server
|
||||
vs_mute = 0b00000010, //!< Muted by the server
|
||||
vs_self_mute = 0b00000100, //!< Locally Muted
|
||||
vs_self_deaf = 0b00001000, //!< Locally deafened
|
||||
vs_self_stream = 0b00010000, //!< Whether this user is streaming using "Go Live"
|
||||
vs_self_video = 0b00100000, //!< Whether this user's camera is enabled
|
||||
vs_suppress = 0b01000000 //!< Whether this user's permission to speak is denied
|
||||
};
|
||||
|
||||
/**
|
||||
* @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 DPP_EXPORT voicestate : public json_interface<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 (see dpp::voicestate_flags)
|
||||
time_t request_to_speak; //!< The time at which the user requested to speak, or 0
|
||||
|
||||
/**
|
||||
* @brief Construct a new voicestate object
|
||||
*/
|
||||
voicestate();
|
||||
|
||||
/**
|
||||
* @brief Destroy the voicestate object
|
||||
*/
|
||||
virtual ~voicestate() = default;
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
* @param with_id Add ID to output
|
||||
* @return std::string JSON string
|
||||
*/
|
||||
virtual std::string build_json(bool with_id = false) const;
|
||||
|
||||
/// Return true if the user is deafened by the server
|
||||
bool is_deaf() const;
|
||||
|
||||
/// Return true if the user is muted by the server
|
||||
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 streaming using "Go Live"
|
||||
bool self_stream() const;
|
||||
|
||||
/// Return true if the user's camera is enabled
|
||||
bool self_video() const;
|
||||
|
||||
/// Return true if user is suppressed.
|
||||
/// "HELP HELP I'M BEING SUPPRESSED!"
|
||||
bool is_suppressed() const;
|
||||
};
|
||||
|
||||
/** A container of voicestates */
|
||||
typedef std::unordered_map<std::string, voicestate> voicestate_map;
|
||||
|
||||
};
|
113
vendor/DPP/include/dpp/webhook.h
vendored
Normal file
113
vendor/DPP/include/dpp/webhook.h
vendored
Normal file
@ -0,0 +1,113 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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/snowflake.h>
|
||||
#include <dpp/misc-enum.h>
|
||||
#include <dpp/managed.h>
|
||||
#include <dpp/json_fwd.h>
|
||||
#include <unordered_map>
|
||||
#include <dpp/json_interface.h>
|
||||
|
||||
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 DPP_EXPORT webhook : public managed, public json_interface<webhook> {
|
||||
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 Construct a new webhook object using the Webhook URL provided by Discord
|
||||
*
|
||||
* @param webhook_url a fully qualified web address of an existing webhook
|
||||
*/
|
||||
webhook(const std::string& webhook_url);
|
||||
|
||||
/**
|
||||
* @brief Construct a new webhook object using the webhook ID and the webhook token
|
||||
*
|
||||
* @param webhook_id id taken from a link of an existing webhook
|
||||
* @param webhook_token token taken from a link of an existing webhook
|
||||
*/
|
||||
webhook(const snowflake webhook_id, const std::string& webhook_token);
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
virtual 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. It can be one of `i_gif`, `i_jpg` or `i_png`.
|
||||
* @param is_base64_encoded True if the image data is already base64 encoded
|
||||
* @return webhook& Reference to self
|
||||
* @throw dpp::length_exception Image data is larger than the maximum size of 256 kilobytes
|
||||
*/
|
||||
webhook& load_image(const std::string &image_blob, const image_type type, bool is_base64_encoded = false);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief A group of webhooks
|
||||
*/
|
||||
typedef std::unordered_map<snowflake, webhook> webhook_map;
|
||||
|
||||
};
|
33
vendor/DPP/include/dpp/win32_safe_warnings.h
vendored
Normal file
33
vendor/DPP/include/dpp/win32_safe_warnings.h
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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
|
||||
|
||||
/* This file contains pragmas to disable warnings on win32 builds with msvc only.
|
||||
* It is only included during build of D++ itself, and not when including the headers
|
||||
* into a user's project.
|
||||
*
|
||||
* Before adding a warning here please be ABSOLUTELY SURE it is one we cannot easily fix
|
||||
* and is to be silenced, thrown into the sarlacc pit to be eaten for 1000 years...
|
||||
*/
|
||||
#if !defined(__MINGW__) && !defined(__MINGW32__) && !defined(__MINGW64__)
|
||||
_Pragma("warning( disable : 4251 )"); // 4251 warns when we export classes or structures with stl member variables
|
||||
_Pragma("warning( disable : 5105 )"); // 5105 is to do with macro warnings
|
||||
#endif
|
212
vendor/DPP/include/dpp/wsclient.h
vendored
Normal file
212
vendor/DPP/include/dpp/wsclient.h
vendored
Normal file
@ -0,0 +1,212 @@
|
||||
/************************************************************************************
|
||||
*
|
||||
* 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 protocol types available on Discord
|
||||
*/
|
||||
enum websocket_protocol_t : uint8_t {
|
||||
/**
|
||||
* @brief JSON data, text, UTF-8 character set
|
||||
*/
|
||||
ws_json = 0,
|
||||
/**
|
||||
* @brief Erlang Term Format (ETF) binary protocol
|
||||
*/
|
||||
ws_etf = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Websocket connection status
|
||||
*/
|
||||
enum ws_state : uint8_t {
|
||||
/**
|
||||
* @brief Sending/receiving HTTP headers, acting as a standard HTTP connection.
|
||||
* This is the state prior to receiving "HTTP/1.1 101 Switching Protocols" from the
|
||||
* server side.
|
||||
*/
|
||||
HTTP_HEADERS,
|
||||
|
||||
/**
|
||||
* @brief Connected as a websocket, and "upgraded". Now talking using binary frames.
|
||||
*/
|
||||
CONNECTED
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Low-level websocket opcodes for frames
|
||||
*/
|
||||
enum ws_opcode : uint8_t
|
||||
{
|
||||
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 DPP_EXPORT websocket_client : public ssl_client
|
||||
{
|
||||
/**
|
||||
* @brief Connection key used in the HTTP headers
|
||||
*/
|
||||
std::string key;
|
||||
|
||||
/**
|
||||
* @brief Current websocket state
|
||||
*/
|
||||
ws_state state;
|
||||
|
||||
/**
|
||||
* @brief Path part of URL for websocket
|
||||
*/
|
||||
std::string path;
|
||||
|
||||
/**
|
||||
* @brief Data opcode, represents the type of frames we send
|
||||
*/
|
||||
ws_opcode data_opcode;
|
||||
|
||||
/**
|
||||
* @brief HTTP headers received on connecting/upgrading
|
||||
*/
|
||||
std::map<std::string, std::string> http_headers;
|
||||
|
||||
/**
|
||||
* @brief 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
|
||||
* @return true if a complete header has been received
|
||||
*/
|
||||
bool parseheader(std::string &buffer);
|
||||
|
||||
/**
|
||||
* @brief 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)
|
||||
* @return true if a complete frame has been received
|
||||
*/
|
||||
bool unpack(std::string &buffer, uint32_t offset, bool first = true);
|
||||
|
||||
/**
|
||||
* @brief Fill a header for outbound messages
|
||||
* @param outbuf The raw frame to fill
|
||||
* @param sendlength The size of the data to encapsulate
|
||||
* @param opcode the ws_opcode to send in the header
|
||||
* @return size of filled header
|
||||
*/
|
||||
size_t fill_header(unsigned char* outbuf, size_t sendlength, ws_opcode opcode);
|
||||
|
||||
/**
|
||||
* @brief 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 handle_ping_pong(bool ping, const std::string &payload);
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* @brief (Re)connect
|
||||
*/
|
||||
virtual void connect();
|
||||
|
||||
/**
|
||||
* @brief Get websocket state
|
||||
* @return websocket state
|
||||
*/
|
||||
ws_state get_state();
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @brief 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
|
||||
* @param opcode The encoding type to use, either OP_BINARY or OP_TEXT
|
||||
* @note Voice websockets only support OP_TEXT, and other websockets must be
|
||||
* OP_BINARY if you are going to send ETF.
|
||||
*/
|
||||
websocket_client(const std::string &hostname, const std::string &port = "443", const std::string &urlpath = "", ws_opcode opcode = OP_BINARY);
|
||||
|
||||
/**
|
||||
* @brief Destroy the websocket client object
|
||||
*/
|
||||
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 handle_frame(const std::string &buffer);
|
||||
|
||||
/**
|
||||
* @brief Called upon error frame.
|
||||
*
|
||||
* @param errorcode The error code from the websocket server
|
||||
*/
|
||||
virtual void error(uint32_t errorcode);
|
||||
|
||||
/**
|
||||
* @brief Fires every second from the underlying socket I/O loop, used for sending websocket pings
|
||||
*/
|
||||
virtual void one_second_timer();
|
||||
|
||||
/**
|
||||
* @brief Send OP_CLOSE error code 1000 to the other side of the connection.
|
||||
* This indicates graceful close.
|
||||
*/
|
||||
void send_close_packet();
|
||||
};
|
||||
|
||||
};
|
Reference in New Issue
Block a user