From 42c1fa4fa93636708028f916d17304a178c407d8 Mon Sep 17 00:00:00 2001 From: Archie Jaskowicz Date: Mon, 30 Oct 2023 09:23:04 +0000 Subject: [PATCH 1/2] style: refactored comments in several files to follow standard (#975) --- include/dpp/appcommand.h | 319 ++++++++++++++++++++++----- include/dpp/application.h | 404 +++++++++++++++++++++++++++++------ include/dpp/automod.h | 118 +++++----- include/dpp/ban.h | 11 +- include/dpp/cache.h | 5 +- include/dpp/coro/async.h | 54 +++-- include/dpp/coro/coro.h | 16 +- include/dpp/coro/coroutine.h | 7 +- include/dpp/coro/job.h | 23 +- include/dpp/coro/task.h | 29 ++- include/dpp/coro/when_any.h | 105 ++++++--- include/dpp/sku.h | 3 + include/dpp/wsclient.h | 36 +++- 13 files changed, 862 insertions(+), 268 deletions(-) diff --git a/include/dpp/appcommand.h b/include/dpp/appcommand.h index 5ffc850525..8f75001c23 100644 --- a/include/dpp/appcommand.h +++ b/include/dpp/appcommand.h @@ -48,27 +48,59 @@ namespace dpp { * These are the possible parameter value types. */ enum command_option_type : uint8_t { - /** A sub-command */ + /** + * @brief A sub-command. + */ co_sub_command = 1, - /** A sub-command group */ + + /** + * @brief A sub-command group. + */ co_sub_command_group = 2, - /** A string value */ + + /** + * @brief A string value. + */ co_string = 3, - /** An integer value */ + + /** + * @brief An integer value. + */ co_integer = 4, - /** A boolean value */ + + /** + * @brief A boolean value. + */ co_boolean = 5, - /** A user snowflake id */ + + /** + * @brief A user snowflake id. + */ co_user = 6, - /** A channel snowflake id. Includes all channel types and categories */ + + /** + * @brief A channel snowflake id. Includes all channel types and categories. + */ co_channel = 7, - /** A role snowflake id */ + + /** + * @brief A role id (snowflake). + */ co_role = 8, - /** A mentionable. Includes users and roles */ + + /** + * @brief A mentionable (users and roles). + */ co_mentionable = 9, - /** Any double between -2^53 and 2^53 */ + + /** + * @brief Any double between -2^53 and 2^53. + */ co_number = 10, - /** File attachment type */ + + /** + * @brief File attachment type. + */ co_attachment = 11, }; @@ -104,9 +136,20 @@ struct DPP_EXPORT command_option_choice : public json_interface name_localizations; //!< Localisations of command option name + /** + * @brief Option name (1-32 chars). + */ + std::string name; + + /** + * @brief Option value. + */ + command_value value; + + /** + * @brief Localisations of command option name. + */ + std::map name_localizations; /** * @brief Construct a new command option choice object @@ -170,22 +213,79 @@ struct DPP_EXPORT command_option : public json_interface { command_option& fill_from_json_impl(nlohmann::json* j); public: - command_option_type type; //!< Option type (what type of value is accepted) - std::string name; //!< Option name (1-32 chars) - std::string description; //!< Option description (1-100 chars) - bool required; //!< True if this is a mandatory parameter - bool focused; //!< True if the user is typing in this field, when sent via autocomplete - command_value value; //!< Set only by autocomplete went sent as part of an interaction - std::vector choices; //!< List of choices for multiple choice command - bool autocomplete; //!< True if this option supports auto completion - std::vector options; //!< Sub-commands - std::vector channel_types; //!< Allowed channel types for channel snowflake id options + /** + * @brief Option type (what type of value is accepted). + */ + command_option_type type; + + /** + * @brief Option name (1-32 chars). + */ + std::string name; + + /** + * @brief Option description (1-100 chars). + */ + std::string description; + + /** + * @brief Is this a mandatory parameter? + */ + bool required; + + /** + * @brief Is the user is typing in this field? + * + * @note This is sent via autocomplete. + */ + bool focused; + + /** + * @brief Set only by autocomplete when sent as part of an interaction. + */ + command_value value; + + /** + * @brief List of choices for multiple choice command. + */ + std::vector choices; + + /** + * @brief Does this option supports auto completion? + */ + bool autocomplete; + + /** + * @brief An array of sub-commands (options). + */ + std::vector options; + + /** + * @brief Allowed channel types for channel snowflake id options. + */ + std::vector channel_types; + // Combines the `min_length` and `max_length` field by storing its value in the int64_t of the command_option_range - command_option_range min_value; //!< Minimum value/length that can be entered, for dpp::co_number, dpp::co_integer and dpp::co_string types only - command_option_range max_value; //!< Maximum value/length that can be entered, for dpp::co_number, dpp::co_integer and dpp::co_string types only - std::map name_localizations; //!< Localisations of command name - std::map description_localizations; //!< Localisations of command description + /** + * @brief Minimum value/length that can be entered, for dpp::co_number, dpp::co_integer and dpp::co_string types only. + */ + command_option_range min_value; + + /** + * @brief Maximum value/length that can be entered, for dpp::co_number, dpp::co_integer and dpp::co_string types only. + */ + command_option_range max_value; + + /** + * @brief Localisations of command name. + */ + std::map name_localizations; + + /** + * @brief Localisations of command description. + */ + std::map description_localizations; /** * @brief Construct a new command option object @@ -302,10 +402,12 @@ enum interaction_response_type { * @brief Acknowledge a Ping */ ir_pong = 1, + /** * @brief Respond to an interaction with a message. */ ir_channel_message_with_source = 4, + /** * @brief Acknowledge an interaction and edit a response later, the user sees a loading state */ @@ -584,18 +686,37 @@ struct DPP_EXPORT command_resolved { * the command on a channel or in DM. */ struct DPP_EXPORT command_data_option { - std::string name; //!< the name of the parameter - command_option_type type; //!< value of ApplicationCommandOptionType - command_value value; //!< Optional: the value of the pair - std::vector options; //!< Optional: present if this option is a group or subcommand - bool focused; //!< Optional: true if this option is the currently focused option for autocomplete + /** + * @brief The name of the parameter. + */ + std::string name; + + /** + * @brief The type of option (value of ApplicationCommandOptionType). + */ + command_option_type type; + + /** + * @brief Optional: the value of the pair + */ + command_value value; + + /** + * @brief Optional: present if this option is a group or subcommand + */ + std::vector options; + + /** + * @brief Optional: true if this option is the currently focused option for autocomplete + */ + bool focused; /** * @brief Check if the value variant holds std::monostate and options vector is empty (i.e. the option wasn't supplied) * @return bool true, if value variant holds std::monostate and options vector is empty */ bool empty() { - return std::holds_alternative(value) && options.empty(); + return std::holds_alternative(value) && options.empty(); } /** @@ -623,21 +744,55 @@ void from_json(const nlohmann::json& j, command_data_option& cdo); /** Types of interaction in the dpp::interaction class */ enum interaction_type { - it_ping = 1, //!< ping - it_application_command = 2, //!< application command (slash command) - it_component_button = 3, //!< button click or select menu chosen (component interaction) - it_autocomplete = 4, //!< Autocomplete interaction - it_modal_submit = 5, //!< Modal form submission + /** + * @brief A ping interaction. + */ + it_ping = 1, + + /** + * @brief Application command (slash command) interaction. + */ + it_application_command = 2, + + /** + * @brief Button click or select menu chosen (component interaction) + */ + it_component_button = 3, + + /** + * @brief Autocomplete interaction. + */ + it_autocomplete = 4, + + /** + * @brief Modal form submission. + */ + it_modal_submit = 5, }; /** * @brief Right-click context menu types */ enum slashcommand_contextmenu_type { - ctxm_none = 0, //!< Undefined context menu type - ctxm_chat_input = 1, //!< DEFAULT, these are the slash commands you're used to - ctxm_user = 2, //!< Add command to user context menu - ctxm_message = 3 //!< Add command to message context menu + /** + * @brief Undefined context menu type + */ + ctxm_none = 0, + + /** + * @brief DEFAULT: these are the generic slash commands (e.g. /ping, /pong, etc) + */ + ctxm_chat_input = 1, + + /** + * @brief A slashcommand that goes in the user context menu. + */ + ctxm_user = 2, + + /** + * @brief A slashcommand that goes in the message context menu. + */ + ctxm_message = 3 }; /** @@ -646,11 +801,32 @@ enum slashcommand_contextmenu_type { * with the interaction. */ struct DPP_EXPORT command_interaction { - snowflake id; //!< the ID of the invoked command - std::string name; //!< the name of the invoked command - std::vector options; //!< Optional: the params + values from the user - slashcommand_contextmenu_type type; //!< type of the command interaction - dpp::snowflake target_id; //!< Non-zero target ID for context menu actions. e.g. user id or message id whom clicked or tapped with the context menu https://discord.com/developers/docs/interactions/application-commands#user-commands + /** + * @brief The ID of the invoked command. + */ + snowflake id; + + /** + * @brief The name of the invoked command. + */ + std::string name; + + /** + * @brief Optional: the params + values from the user. + */ + std::vector options; + + /** + * @brief The type of command interaction. + */ + slashcommand_contextmenu_type type; + + /** + * @brief Non-zero target ID for context menu actions (e.g. user id or message id whom clicked or tapped with the context menu). + * + * @see https://discord.com/developers/docs/interactions/application-commands#user-commands + */ + dpp::snowflake target_id; /** * @brief Get an option value by index @@ -690,10 +866,12 @@ struct DPP_EXPORT component_interaction { * @brief Component type (dpp::component_type) */ uint8_t component_type; + /** * @brief Custom ID set when created */ std::string custom_id; + /** * @brief Possible values for a drop down list */ @@ -1031,12 +1209,11 @@ void from_json(const nlohmann::json& j, interaction& i); enum command_permission_type { /** * @brief Role permission - * */ cpt_role = 1, + /** * @brief User permission - * */ cpt_user = 2, }; @@ -1058,12 +1235,23 @@ class DPP_EXPORT command_permission : public json_interface command_permission &fill_from_json_impl(nlohmann::json *j); public: - snowflake id; //!< the ID of the role or user - command_permission_type type; //!< the type of permission - bool permission; //!< true to allow, false, to disallow + /** + * @brief The ID of the role/user. + */ + snowflake id; /** - * @brief Construct a new command permission object + * @brief The type of permission. + */ + command_permission_type type; + + /** + * @brief True to allow, false to disallow. + */ + bool permission; + + /** + * @brief Construct a new command permission object. */ command_permission() = default; @@ -1105,10 +1293,25 @@ class DPP_EXPORT guild_command_permissions : public json_interface permissions; //!< the permissions for the command in the guild + /** + * @brief The id of the command. + */ + snowflake id; + + /** + * @brief The id of the application the command belongs to. + */ + snowflake application_id; + + /** + * @brief The id of the guild. + */ + snowflake guild_id; + + /** + * @brief The permissions for the command, in the guild. + */ + std::vector permissions; /** * @brief Construct a new guild command permissions object diff --git a/include/dpp/application.h b/include/dpp/application.h index 33e0ff27f1..eb7e8b32df 100644 --- a/include/dpp/application.h +++ b/include/dpp/application.h @@ -37,9 +37,13 @@ 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 + /** + * @brief User was invited to the team. + */ tms_invited = 1, - /// User has accepted membership onto the team + /** + * @brief User has accepted membership onto the team. + */ tms_accepted = 2 }; @@ -47,25 +51,54 @@ enum team_member_status : uint8_t { * @brief Flags for a bot or application */ enum application_flags : uint32_t { - /// Indicates if an app uses the Auto Moderation API + /** + * @brief Indicates if an app uses the Auto Moderation API + */ apf_application_automod_rule_create_badge = (1 << 6), - /// Has gateway presence intent + + /** + * @brief Has gateway presence intent + */ apf_gateway_presence = (1 << 12), - /// Has gateway presence intent for <100 guilds + + /** + * @brief Has gateway presence intent for <100 guilds + */ apf_gateway_presence_limited = (1 << 13), - /// Has guild members intent + + /** + * @brief Has guild members intent + */ apf_gateway_guild_members = (1 << 14), - /// Has guild members intent for <100 guilds + + /** + * @brief Has guild members intent for <100 guilds + */ apf_gateway_guild_members_limited = (1 << 15), - /// Verification is pending + + /** + * @brief Verification is pending + */ apf_verification_pending_guild_limit = (1 << 16), - /// Embedded + + /** + * @brief Embedded + */ apf_embedded = (1 << 17), - /// Has approval for message content + + /** + * @brief Has approval for message content + */ apf_gateway_message_content = (1 << 18), - /// Has message content, but <100 guilds + + /** + * @brief Has message content, but <100 guilds + */ apf_gateway_message_content_limited = (1 << 19), - /// Indicates if the app has registered global application commands + + /** + * @brief Indicates if the app has registered global application commands + */ apf_application_command_badge = (1 << 23) }; @@ -73,8 +106,17 @@ enum application_flags : uint32_t { * @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 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 A bitmask of dpp::permissions to request for the bot role. + */ + permission permissions; + + /** + * @brief The scopes as strings to add the application to the server with. + * + * @see https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes + */ + std::vector scopes; }; /** @@ -84,10 +126,25 @@ struct DPP_EXPORT application_install_params { * this enum will be extended to support them. */ enum team_member_role_t : uint8_t { - tmr_owner, //!< Team owner - tmr_admin, //!< Team admin - tmr_developer, //!< Developer - tmr_readonly, //!< Read-Only + /** + * @brief Team owner. + */ + tmr_owner, + + /** + * @brief Team admin. + */ + tmr_admin, + + /** + * @brief Developer + */ + tmr_developer, + + /** + * @brief Read-Only + */ + tmr_readonly, }; /** @@ -95,11 +152,30 @@ enum team_member_role_t : uint8_t { */ 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 - team_member_role_t member_role; //!< the role of the user + /** + * @brief The user's membership state on the team. + */ + team_member_status membership_state; + + /** + * @brief Will always be "". + */ + std::string permissions; + + /** + * @brief The id of the parent team of which they are a member. + */ + snowflake team_id; + + /** + * @brief The avatar, discriminator, id, and username, of the user. + */ + user member_user; + + /** + * @brief The role of the user in the team. + */ + team_member_role_t member_role; }; /** @@ -107,11 +183,30 @@ class DPP_EXPORT team_member { */ 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 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 A hash of the image of the team's icon (may be empty). + */ + utility::iconhash icon; + + /** + * @brief The id of the team. + */ + snowflake id; + + /** + * @brief The members of the team. + */ + std::vector members; + + /** + * @brief The name of the team. + */ + std::string name; + + /** + * @brief The user id of the current team owner. + */ + snowflake owner_user_id; }; /** @@ -128,48 +223,213 @@ class DPP_EXPORT application : public managed, public json_interface 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 - user bot; //!< Optional: Partial user object for the bot user associated with the app. - 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 - guild guild_obj; //!< Optional: Partial object of the associated guild - 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 - uint64_t approximate_guild_count; //!< Optional: Approximate count of guilds the app has been added to - std::vector redirect_uris; //!< Optional: Array of redirect URIs for the app - std::string interactions_endpoint_url; //!< Optional: Interactions endpoint URL for the app - 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 - std::vector 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 - - uint8_t discoverability_state; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - uint32_t discovery_eligibility_flags; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - uint8_t explicit_content_filter; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - uint8_t creator_monetization_state; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - bool integration_public; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - bool integration_require_code_grant; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - std::vector interactions_event_types; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - uint8_t interactions_version; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - bool is_monetized; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - uint32_t monetization_eligibility_flags; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - uint8_t monetization_state; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - bool hook; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - uint8_t rpc_application_state; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - uint8_t store_application_state; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. - uint8_t verification_state; //!< @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + /** + * @brief The name of the app. + */ + std::string name; + + /** + * @brief The icon hash of the app (may be empty). + */ + utility::iconhash icon; + + /** + * @brief The description of the app. + */ + std::string description; + + /** + * @brief Optional: an array of rpc origin urls, if rpc is enabled. + */ + std::vector rpc_origins; + + /** + * @brief When false, only app owner add the bot to guilds. + */ + bool bot_public; + + /** + * @brief When true, the app's bot will only join upon completion of the full oauth2 code grant flow + */ + bool bot_require_code_grant; + + /** + * @brief Optional: Partial user object for the bot user associated with the app. + */ + user bot; + + /** + * @brief Optional: the url of the app's terms of service. + */ + std::string terms_of_service_url; + + /** + * @brief Optional: the url of the app's privacy policy. + */ + std::string privacy_policy_url; + + /** + * @brief Optional: partial user object containing info on the owner of the application. + */ + user owner; + + /** + * @brief 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 summary; + + /** + * @brief The hex encoded key for verification in interactions and the GameSDK's GetTicket. + */ + std::string verify_key; + + /** + * @brief If the application belongs to a team, this will be a list of the members of that team (may be empty). + */ + app_team team; + + /** + * @brief Optional: if this application is a game sold on Discord, this field will be the guild to which it has been linked. + */ + snowflake guild_id; + + /** + * @brief Partial object of the associated guild. + */ + guild guild_obj; + + /** + * @brief 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. + */ + snowflake primary_sku_id; + + /** + * @brief Optional: if this application is a game sold on Discord, this field will be the URL slug that links to the store page. + */ + std::string slug; + + /** + * @brief Optional: the application's default rich presence invite cover image hash + */ + utility::iconhash cover_image; + + /** + * @brief Optional: the application's public flags. + */ + uint32_t flags; + + /** + * @brief Optional: Approximate count of guilds the app has been added to. + */ + uint64_t approximate_guild_count; + + /** + * @brief Optional: Array of redirect URIs for the app. + */ + std::vector redirect_uris; + + /** + * @brief Optional: Interactions endpoint URL for the app. + */ + std::string interactions_endpoint_url; + + /** + * @brief 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. + */ + std::string role_connections_verification_url; + + /** + * @brief Up to 5 tags describing the content and functionality of the application. + */ + std::vector tags; + + /** + * @brief Settings for the application's default in-app authorization link, if enabled. + */ + application_install_params install_params; + + /** + * @brief The application's default custom authorization link, if enabled. + */ + std::string custom_install_url; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint8_t discoverability_state; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint32_t discovery_eligibility_flags; + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint8_t explicit_content_filter; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint8_t creator_monetization_state; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + bool integration_public; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + bool integration_require_code_grant; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + std::vector interactions_event_types; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint8_t interactions_version; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + bool is_monetized; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint32_t monetization_eligibility_flags; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint8_t monetization_state; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + bool hook; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint8_t rpc_application_state; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint8_t store_application_state; + + /** + * @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk. + */ + uint8_t verification_state; /** Constructor */ application(); @@ -198,7 +458,9 @@ class DPP_EXPORT application : public managed, public json_interface { * Prefix - word must start with the keyword * * | keyword | matches | - * |----------|-------------------------------------| - * | cat* | catch, Catapult, CAttLE | - * | the mat* | the matrix | - * - * Suffix - word must end with the keyword - * - * | keyword | matches | - * |----------|--------------------------| - * | *cat | wildcat, copyCat | - * | *the mat | breathe mat | - * - * Anywhere - keyword can appear anywhere in the content - * - * | keyword | matches | - * |-----------|-----------------------------| - * | \*cat* | location, eduCation | - * | \*the mat* | breathe matter | - * - * Whole Word - keyword is a full word or phrase and must be surrounded by whitespace at the beginning and end - * - * | keyword | matches | - * |---------|-------------| - * | cat | Cat | - * | the mat | the mat | - * + * |----------|-------------------------------------| + * | cat* | catch, Catapult, CAttLE | + * | the mat* | the matrix | + * + * Suffix - word must end with the keyword + * + * | keyword | matches | + * |----------|--------------------------| + * | *cat | wildcat, copyCat | + * | *the mat | breathe mat | + * + * Anywhere - keyword can appear anywhere in the content + * + * | keyword | matches | + * |-----------|-----------------------------| + * | \*cat* | location, eduCation | + * | \*the mat* | breathe matter | + * + * Whole Word - keyword is a full word or phrase and must be surrounded by whitespace at the beginning and end + * + * | keyword | matches | + * |---------|-------------| + * | cat | Cat | + * | the mat | the mat | + * */ std::vector keywords; @@ -196,31 +204,31 @@ struct DPP_EXPORT automod_metadata : public json_interface { * Prefix - word must start with the keyword * * | keyword | matches | - * |----------|-------------------------------------| - * | cat* | catch, Catapult, CAttLE | - * | the mat* | the matrix | - * - * Suffix - word must end with the keyword - * - * | keyword | matches | - * |----------|--------------------------| - * | *cat | wildcat, copyCat | - * | *the mat | breathe mat | - * - * Anywhere - keyword can appear anywhere in the content - * - * | keyword | matches | - * |-----------|-----------------------------| - * | \*cat* | location, eduCation | - * | \*the mat* | breathe matter | - * - * Whole Word - keyword is a full word or phrase and must be surrounded by whitespace at the beginning and end - * - * | keyword | matches | - * |---------|-------------| - * | cat | Cat | - * | the mat | the mat | - * + * |----------|-------------------------------------| + * | cat* | catch, Catapult, CAttLE | + * | the mat* | the matrix | + * + * Suffix - word must end with the keyword + * + * | keyword | matches | + * |----------|--------------------------| + * | *cat | wildcat, copyCat | + * | *the mat | breathe mat | + * + * Anywhere - keyword can appear anywhere in the content + * + * | keyword | matches | + * |-----------|-----------------------------| + * | \*cat* | location, eduCation | + * | \*the mat* | breathe matter | + * + * Whole Word - keyword is a full word or phrase and must be surrounded by whitespace at the beginning and end + * + * | keyword | matches | + * |---------|-------------| + * | cat | Cat | + * | the mat | the mat | + * */ std::vector allow_list; @@ -326,42 +334,52 @@ class DPP_EXPORT automod_rule : public managed, public json_interface 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 exempt_roles; + /** * @brief the channel ids that should not be affected by the rule (Maximum of 50) */ diff --git a/include/dpp/ban.h b/include/dpp/ban.h index 2a68696660..6a02352ed1 100644 --- a/include/dpp/ban.h +++ b/include/dpp/ban.h @@ -44,9 +44,14 @@ class DPP_EXPORT ban : public json_interface { ban& fill_from_json_impl(nlohmann::json* j); public: - /** The ban reason */ + /** + * @brief The ban reason. + */ std::string reason; - /** User ID the ban applies to */ + + /** + * @brief User ID the ban applies to. + */ snowflake user_id; /** Constructor */ @@ -57,7 +62,7 @@ class DPP_EXPORT ban : public json_interface { }; /** - * A group of bans. The key is the user ID + * @brief A group of bans. The key is the user ID. */ typedef std::unordered_map ban_map; diff --git a/include/dpp/cache.h b/include/dpp/cache.h index 5895af576d..c43242b444 100644 --- a/include/dpp/cache.h +++ b/include/dpp/cache.h @@ -65,7 +65,7 @@ template class cache { /** * @brief Construct a new cache object. * - * Caches must contain classes derived from dpp::managed. + * @note Caches must contain classes derived from dpp::managed. */ cache() { cache_map = new std::unordered_map; @@ -255,7 +255,8 @@ template class cache { }; -/** Run garbage collection across all caches removing deleted items +/** + * Run garbage collection across all caches removing deleted items * that have been deleted over 60 seconds ago. */ void DPP_EXPORT garbage_collection(); diff --git a/include/dpp/coro/async.h b/include/dpp/coro/async.h index bd78369dd9..2c7c9f13e3 100644 --- a/include/dpp/coro/async.h +++ b/include/dpp/coro/async.h @@ -56,39 +56,54 @@ namespace async { * @brief Represents the step an std::async is at. */ enum class state_t { - sent, /* Request was sent but not co_await-ed. handle is nullptr, result_storage is not constructed */ - waiting, /* Request was co_await-ed. handle is valid, result_storage is not constructed */ - done, /* Request was completed. handle is unknown, result_storage is valid */ - dangling /* Request was never co_await-ed. */ + /** + * @brief Request was sent but not co_await-ed. handle is nullptr, result_storage is not constructed. + */ + sent, + + /** + * @brief Request was co_await-ed. handle is valid, result_storage is not constructed. + */ + waiting, + + /** + * @brief Request was completed. handle is unknown, result_storage is valid. + */ + done, + + /** + * @brief Request was never co_await-ed. + */ + dangling }; /** - * @brief State of the async and its callback. - * - * Defined outside of dpp::async because this seems to work better with Intellisense. - */ + * @brief State of the async and its callback. + * + * Defined outside of dpp::async because this seems to work better with Intellisense. + */ template struct async_callback_data { /** - * @brief Number of references to this callback state. - */ + * @brief Number of references to this callback state. + */ std::atomic ref_count{1}; /** - * @brief State of the awaitable and the API callback - */ + * @brief State of the awaitable and the API callback + */ std::atomic state = state_t::sent; /** - * @brief The stored result of the API call, stored as an array of bytes to directly construct in place - */ + * @brief The stored result of the API call, stored as an array of bytes to directly construct in place + */ alignas(R) std::array result_storage; /** - * @brief Handle to the coroutine co_await-ing on this API call - * - * @see std::coroutine_handle - */ + * @brief Handle to the coroutine co_await-ing on this API call + * + * @see std::coroutine_handle + */ std_coroutine::coroutine_handle<> coro_handle = nullptr; /** @@ -374,7 +389,8 @@ class async_base { struct confirmation_callback_t; -/** @class async async.h coro/async.h +/** + * @class async async.h coro/async.h * @brief A co_await-able object handling an API call in parallel with the caller. * * This class is the return type of the dpp::cluster::co_* methods, but it can also be created manually to wrap any async call. diff --git a/include/dpp/coro/coro.h b/include/dpp/coro/coro.h index 2dd0836b94..76f3256ed8 100644 --- a/include/dpp/coro/coro.h +++ b/include/dpp/coro/coro.h @@ -45,17 +45,17 @@ namespace std { namespace dpp { /** - * @brief Implementation details for internal use only. - * - * @attention This is only meant to be used by D++ internally. Support will not be given regarding the facilities in this namespace. - */ + * @brief Implementation details for internal use only. + * + * @attention This is only meant to be used by D++ internally. Support will not be given regarding the facilities in this namespace. + */ namespace detail { #ifdef _DOXYGEN_ /** - * @brief Alias for either std or std::experimental depending on compiler and library. Used by coroutine implementation. - * - * @todo Remove and use std when all supported libraries have coroutines in it - */ + * @brief Alias for either std or std::experimental depending on compiler and library. Used by coroutine implementation. + * + * @todo Remove and use std when all supported libraries have coroutines in it + */ namespace std_coroutine {} #else # ifdef STDCORO_EXPERIMENTAL_NAMESPACE diff --git a/include/dpp/coro/coroutine.h b/include/dpp/coro/coroutine.h index ea656f578e..a03d670b41 100644 --- a/include/dpp/coro/coroutine.h +++ b/include/dpp/coro/coroutine.h @@ -51,8 +51,8 @@ struct promise_t; template /** - * @brief Alias for the handle_t of a coroutine. - */ + * @brief Alias for the handle_t of a coroutine. + */ using handle_t = std_coroutine::coroutine_handle>; /** @@ -188,7 +188,8 @@ class coroutine_base { } // namespace detail -/** @class coroutine coroutine.h coro/coroutine.h +/** + * @class coroutine coroutine.h coro/coroutine.h * @brief Base type for a coroutine, starts on co_await. * * @warning - This feature is EXPERIMENTAL. The API may change at any time and there may be bugs. diff --git a/include/dpp/coro/job.h b/include/dpp/coro/job.h index f7371977d2..ed6ab2518c 100644 --- a/include/dpp/coro/job.h +++ b/include/dpp/coro/job.h @@ -38,7 +38,8 @@ struct job_dummy { namespace dpp { -/** @class job job.h coro/job.h +/** + * @class job job.h coro/job.h * @brief Extremely light coroutine object designed to send off a coroutine to execute on its own. * Can be used in conjunction with coroutine events via @ref dpp::event_router_t::operator()(F&&) "event routers", or on its own. * @@ -78,20 +79,20 @@ struct promise { } #endif - /* - * @brief Function called when the job is done. - * - * @return std::suspend_never Do not suspend at the end, destroying the handle immediately - */ + /** + * @brief Function called when the job is done. + * + * @return std::suspend_never Do not suspend at the end, destroying the handle immediately + */ std_coroutine::suspend_never final_suspend() const noexcept { return {}; } - /* - * @brief Function called when the job is started. - * - * @return std::suspend_never Do not suspend at the start, starting the job immediately - */ + /** + * @brief Function called when the job is started. + * + * @return std::suspend_never Do not suspend at the start, starting the job immediately + */ std_coroutine::suspend_never initial_suspend() const noexcept { return {}; } diff --git a/include/dpp/coro/task.h b/include/dpp/coro/task.h index c208440de5..5cdf4577d1 100644 --- a/include/dpp/coro/task.h +++ b/include/dpp/coro/task.h @@ -51,15 +51,25 @@ namespace detail { /* Internal cogwheels for dpp::task */ namespace task { -/** @brief State of a task */ +/** + * @brief State of a task + */ enum class state_t { - /** @brief Task was started but never co_await-ed */ + /** + * @brief Task was started but never co_await-ed + */ started, - /** @brief Task was co_await-ed and is pending completion */ + /** + * @brief Task was co_await-ed and is pending completion + */ awaited, - /** @brief Task is completed */ + /** + * @brief Task is completed + */ done, - /** @brief Task is still running but the actual dpp::task object is destroyed */ + /** + * @brief Task is still running but the actual dpp::task object is destroyed + */ dangling }; @@ -261,7 +271,8 @@ class task_base { } // namespace detail -/** @class task task.h coro/task.h +/** + * @class task task.h coro/task.h * @brief A coroutine task. It starts immediately on construction and can be co_await-ed, making it perfect for parallel coroutines returning a value. * * @warning - This feature is EXPERIMENTAL. The API may change at any time and there may be bugs. @@ -487,7 +498,7 @@ class task : private detail::task::task_base { #endif /* _DOXYGEN_ */ namespace detail::task { - /** +/** * @brief Awaitable returned from task::promise_t's final_suspend. Resumes the parent and cleans up its handle if needed */ template @@ -499,7 +510,7 @@ struct final_awaiter { return (false); } - /* + /** * @brief The suspension logic of the coroutine when it finishes. Always suspend the caller, meaning cleaning up the handle is on us * * @param handle The handle of this coroutine @@ -507,7 +518,7 @@ struct final_awaiter { */ [[nodiscard]] std_coroutine::coroutine_handle<> await_suspend(handle_t handle) const noexcept; - /* + /** * @brief Function called when this object is co_awaited by the standard library at the end of final_suspend. Do nothing, return nothing */ void await_resume() const noexcept {} diff --git a/include/dpp/coro/when_any.h b/include/dpp/coro/when_any.h index 96952c17e7..1e3fd5a359 100644 --- a/include/dpp/coro/when_any.h +++ b/include/dpp/coro/when_any.h @@ -45,18 +45,30 @@ class awaitable; } -/** @brief Internal cogwheels for dpp::when_any */ +/** + * @brief Internal cogwheels for dpp::when_any + */ namespace when_any { -/** @brief Current state of a when_any object */ +/** + * @brief Current state of a when_any object + */ enum class await_state { - /** @brief Object was started but not awaited */ + /** + * @brief Object was started but not awaited + */ started, - /** @brief Object is being awaited */ + /** + * @brief Object is being awaited + */ waiting, - /** @brief Object was resumed*/ + /** + * @brief Object was resumed + */ done, - /** @brief Object was destroyed */ + /** + * @brief Object was destroyed + */ dangling }; @@ -102,14 +114,20 @@ using awaitable_type = typename arg_helper_s::type; template using arg_helper = arg_helper_s>; -/** @brief Empty result from void-returning awaitable */ +/** + * @brief Empty result from void-returning awaitable + */ struct empty{}; -/** @brief Actual type a result will be stores as in when_any */ +/** + * @brief Actual type a result will be stores as in when_any + */ template using storage_type = std::conditional_t, empty, T>; -/** @brief Concept satisfied if a stored result is void */ +/** + * @brief Concept satisfied if a stored result is void + */ template concept void_result = std::same_as; @@ -117,7 +135,8 @@ concept void_result = std::same_as; } // namespace detail -/** @class when_any when_any.h coro/when_any.h +/** + * @class when_any when_any.h coro/when_any.h * @brief Experimental class to co_await on a bunch of awaitable objects, resuming when the first one completes. * On completion, returns a @ref result object that contains the index of the awaitable that finished first. * A user can call @ref result::index() and @ref result::get() on the result object to get the result, similar to std::variant. @@ -130,7 +149,9 @@ template requires (sizeof...(Args) >= 1) #endif class when_any { - /** @brief Alias for the type of the result variant */ + /** + * @brief Alias for the type of the result variant + */ using variant_type = std::variant>>...>; /** @@ -193,9 +214,9 @@ class when_any { template static dpp::job make_job(std::shared_ptr shared_state) { /** - * Any exceptions from the awaitable's await_suspend should be thrown to the caller (the coroutine creating the when_any object) - * If the co_await passes, and it is the first one to complete, try construct the result, catch any exceptions to rethrow at resumption, and resume. - */ + * Any exceptions from the awaitable's await_suspend should be thrown to the caller (the coroutine creating the when_any object) + * If the co_await passes, and it is the first one to complete, try construct the result, catch any exceptions to rethrow at resumption, and resume. + */ if constexpr (!std::same_as, detail::when_any::empty>) { decltype(auto) result = co_await std::get(shared_state->awaitables); @@ -236,7 +257,8 @@ class when_any { } /** - * @brief Spawn a dpp::job to handle each awaitable. Each of them will co_await the awaitable and set the result if they are the first to finish + * @brief Spawn a dpp::job to handle each awaitable. + * Each of them will co_await the awaitable and set the result if they are the first to finish */ void make_jobs() { [](when_any *self, std::index_sequence) { @@ -251,26 +273,40 @@ class when_any { class result { friend class when_any; - /** @brief Reference to the shared state to pull the data from */ + /** + * @brief Reference to the shared state to pull the data from + */ std::shared_ptr shared_state; - /** @brief Default construction is deleted */ + /** + * @brief Default construction is deleted + */ result() = delete; - /** @brief Internal constructor taking the shared state */ + /** + * @brief Internal constructor taking the shared state + */ result(std::shared_ptr state) : shared_state{state} {} public: - /** @brief Move constructor */ + /** + * @brief Move constructor + */ result(result&&) = default; - /** @brief This object is not copyable. */ + /** + * @brief This object is not copyable. + */ result(const result &) = delete; - /** @brief Move assignment operator */ + /** + * @brief Move assignment operator + */ result &operator=(result&&) = default; - /** @brief This object is not copyable. */ + /** + * @brief This object is not copyable. + */ result &operator=(const result&) = delete; /** @@ -361,7 +397,9 @@ class when_any { * @see result */ struct awaiter { - /** @brief Pointer to the when_any object */ + /** + * @brief Pointer to the when_any object + */ when_any *self; /** @@ -394,7 +432,10 @@ class when_any { } }; - /** @brief Default constructor. A when_any object created this way holds no state */ + /** + * @brief Default constructor. + * A when_any object created this way holds no state + */ when_any() = default; /** @@ -411,10 +452,14 @@ class when_any { make_jobs(); } - /** @brief This object is not copyable. */ + /** + * @brief This object is not copyable. + */ when_any(const when_any &) = delete; - /** @brief Move constructor. */ + /** + * @brief Move constructor. + */ when_any(when_any &&) noexcept = default; /** @@ -444,10 +489,14 @@ class when_any { }(this, std::index_sequence_for()); } - /** @brief This object is not copyable. */ + /** + * @brief This object is not copyable. + */ when_any &operator=(const when_any &) = delete; - /** @brief Move assignment operator. */ + /** + * @brief Move assignment operator. + */ when_any &operator=(when_any &&) noexcept = default; /** diff --git a/include/dpp/sku.h b/include/dpp/sku.h index 88b07d0728..80db89ff2e 100644 --- a/include/dpp/sku.h +++ b/include/dpp/sku.h @@ -38,6 +38,7 @@ enum sku_type : uint8_t { * @brief Represents a recurring subscription */ SUBSCRIPTION = 5, + /** * @brief System-generated group for each SUBSCRIPTION SKU created * @warning These are automatically created for each subscription SKU and are not used at this time. Please refrain from using these. @@ -53,10 +54,12 @@ enum sku_flags : uint16_t { * @brief SKU is available for purchase */ sku_available = 0b000000000000100, + /** * @brief Recurring SKU that can be purchased by a user and applied to a single server. Grants access to every user in that server. */ sku_guild_subscription = 0b000000010000000, + /** * @brief Recurring SKU purchased by a user for themselves. Grants access to the purchasing user in every server. */ diff --git a/include/dpp/wsclient.h b/include/dpp/wsclient.h index c7cb3b143e..7f047fd6c6 100644 --- a/include/dpp/wsclient.h +++ b/include/dpp/wsclient.h @@ -37,6 +37,7 @@ enum websocket_protocol_t : uint8_t { * @brief JSON data, text, UTF-8 character set */ ws_json = 0, + /** * @brief Erlang Term Format (ETF) binary protocol */ @@ -65,12 +66,35 @@ enum ws_state : uint8_t { */ 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 Continuation. + */ + OP_CONTINUATION = 0x00, + + /** + * @brief Text frame. + */ + OP_TEXT = 0x01, + + /** + * @brief Binary frame. + */ + OP_BINARY = 0x02, + + /** + * @brief Close notification with close code. + */ + OP_CLOSE = 0x08, + + /** + * @brief Low level ping. + */ + OP_PING = 0x09, + + /** + * @brief Low level pong. + */ + OP_PONG = 0x0a }; /** From f3e313ffc189be52ba2e22e7689ea7b473959f8b Mon Sep 17 00:00:00 2001 From: Jaskowicz1 Date: Tue, 31 Oct 2023 08:17:05 +0000 Subject: [PATCH 2/2] style: big chunk of part 3 refactor. --- include/dpp/guild.h | 937 ++++++++++++++++++++++++++--------- include/dpp/httpsclient.h | 9 +- include/dpp/integration.h | 232 +++++++-- include/dpp/intents.h | 116 ++++- include/dpp/invite.h | 110 +++- include/dpp/json_interface.h | 80 +-- include/dpp/managed.h | 150 +++--- 7 files changed, 1195 insertions(+), 439 deletions(-) diff --git a/include/dpp/guild.h b/include/dpp/guild.h index fd6a3d8a98..755b53befe 100644 --- a/include/dpp/guild.h +++ b/include/dpp/guild.h @@ -35,125 +35,302 @@ namespace dpp { class channel; +/* Note from Archie: I'd like to move this soon (dpp::guild::region) and allow users to use a region enum. + * This would make it easier for people to be able to alter a channel region without having to get the text right. + */ + /** * @brief Represents voice regions for guilds and channels. * @deprecated Deprecated in favour of per-channel regions. - * Please use channel::rtc_region instead. + * Please use dpp::channel::rtc_region instead. */ enum region : uint8_t { - r_brazil, //!< Brazil - r_central_europe, //!< Central Europe - r_hong_kong, //!< Hong Kong - r_india, //!< India - r_japan, //!< Japan - r_russia, //!< Russia - r_singapore, //!< Singapore - r_south_africa, //!< South Africa - r_sydney, //!< Sydney - r_us_central, //!< US Central - r_us_east, //!< US East Coast - r_us_south, //!< US South - r_us_west, //!< US West Coast - r_western_europe //!< Western Europe + /** + * @brief Brazil + */ + r_brazil, + + /** + * @brief Central Europe + */ + r_central_europe, + + /** + * @brief Hong Kong + */ + r_hong_kong, + + /** + * @brief India + */ + r_india, + + /** + * @brief Japan + */ + r_japan, + + /** + * @brief Russia + */ + r_russia, + + /** + * @brief Singapore + */ + r_singapore, + + /** + * @brief South Africa + */ + r_south_africa, + + /** + * @brief Sydney + */ + r_sydney, + + /** + * @brief US Central + */ + r_us_central, + + /** + * @brief US East Coast + */ + r_us_east, + + /** + * @brief US South + */ + r_us_south, + + /** + * @brief US West Coast + */ + r_us_west, + + /** + * @brief Western Europe + */ + r_western_europe }; /** * @brief The various flags that represent the status of a dpp::guild object */ enum guild_flags : uint32_t { - /** Large guild */ - g_large = 0b00000000000000000000000000000001, - /** Unavailable guild (inaccessible due to an outage) */ - g_unavailable = 0b00000000000000000000000000000010, - /** Guild has widget enabled */ - g_widget_enabled = 0b00000000000000000000000000000100, - /** Guild can have an invite splash image */ - g_invite_splash = 0b00000000000000000000000000001000, - /** Guild can have VIP regions */ - g_vip_regions = 0b00000000000000000000000000010000, - /** Guild can have a vanity url */ - g_vanity_url = 0b00000000000000000000000000100000, - /** Guild is verified */ - g_verified = 0b00000000000000000000000001000000, - /** Guild is partnered */ - g_partnered = 0b00000000000000000000000010000000, - /** Community features enabled */ - g_community = 0b00000000000000000000000100000000, - /** Guild has enabled role subscriptions */ - g_role_subscription_enabled = 0b00000000000000000000001000000000, - /** Guild has access to create announcement channels */ - g_news = 0b00000000000000000000010000000000, - /** Guild is discoverable in discovery */ - g_discoverable = 0b00000000000000000000100000000000, - /** Guild is featureable */ - g_featureable = 0b00000000000000000001000000000000, - /** Guild can have an animated icon (doesn't mean it actually has one though) */ - g_animated_icon = 0b00000000000000000010000000000000, - /** Guild can have a banner image */ - g_banner = 0b00000000000000000100000000000000, - /** Guild has a welcome screen */ - g_welcome_screen_enabled = 0b00000000000000001000000000000000, - /** Guild has a member verification gate */ - g_member_verification_gate = 0b00000000000000010000000000000000, - /** Guild has a preview */ - g_preview_enabled = 0b00000000000000100000000000000000, - /** Guild join notifications are off */ - g_no_join_notifications = 0b00000000000001000000000000000000, - /** Guild boost notifications are off */ - g_no_boost_notifications = 0b00000000000010000000000000000000, - /** Guild has an actual animated icon (set by the icon hash starting with 'a_') */ - g_has_animated_icon = 0b00000000000100000000000000000000, - /** Guild has an actual animated banner (set by the icon hash starting with 'a_') */ - g_has_animated_banner = 0b00000000001000000000000000000000, - /** Guild setup tips are off */ - g_no_setup_tips = 0b00000000010000000000000000000000, - /** "Wave to say hi" sticker prompt buttons are off */ - g_no_sticker_greeting = 0b00000000100000000000000000000000, - /** guild has enabled monetization */ - g_monetization_enabled = 0b00000001000000000000000000000000, - /** guild has increased custom sticker slots */ - g_more_stickers = 0b00000010000000000000000000000000, - /** Guild has enabled the role subscription promo page */ - g_creator_store_page_enabled = 0b00000100000000000000000000000000, - /** guild is able to set role icons */ - g_role_icons = 0b00001000000000000000000000000000, - /** guild has access to the seven day archive time for threads + /** + * @brief Large guild + */ + g_large = 0b00000000000000000000000000000001, + + /** + * @brief Unavailable guild (inaccessible due to an outage) + */ + g_unavailable = 0b00000000000000000000000000000010, + + /** + * @brief Guild has widget enabled + */ + g_widget_enabled = 0b00000000000000000000000000000100, + + /** + * @brief Guild can have an invite splash image + */ + g_invite_splash = 0b00000000000000000000000000001000, + + /** + * @brief Guild can have VIP regions + */ + g_vip_regions = 0b00000000000000000000000000010000, + + /** + * @brief Guild can have a vanity url + */ + g_vanity_url = 0b00000000000000000000000000100000, + + /** + * @brief Guild is verified + */ + g_verified = 0b00000000000000000000000001000000, + + /** + * @brief Guild is partnered + */ + g_partnered = 0b00000000000000000000000010000000, + + /** + * @brief Community features enabled + */ + g_community = 0b00000000000000000000000100000000, + + /** + * @brief Guild has enabled role subscriptions + */ + g_role_subscription_enabled = 0b00000000000000000000001000000000, + + /** + * @brief Guild has access to create announcement channels + */ + g_news = 0b00000000000000000000010000000000, + + /** + * @brief Guild is discoverable in discovery + */ + g_discoverable = 0b00000000000000000000100000000000, + + /** + * @brief Guild is featureable + */ + g_featureable = 0b00000000000000000001000000000000, + + /** + * @brief Guild can have an animated icon (doesn't mean it actually has one though) + */ + g_animated_icon = 0b00000000000000000010000000000000, + + /** + * @brief Guild can have a banner image + */ + g_banner = 0b00000000000000000100000000000000, + + /** + * @brief Guild has a welcome screen + */ + g_welcome_screen_enabled = 0b00000000000000001000000000000000, + + /** + * @brief Guild has a member verification gate + */ + g_member_verification_gate = 0b00000000000000010000000000000000, + + /** + * @brief Guild has a preview + */ + g_preview_enabled = 0b00000000000000100000000000000000, + + /** + * @brief Guild join notifications are off + */ + g_no_join_notifications = 0b00000000000001000000000000000000, + + /** + * @brief Guild boost notifications are off + */ + g_no_boost_notifications = 0b00000000000010000000000000000000, + + /** + * @brief Guild has an actual animated icon (set by the icon hash starting with 'a_') + */ + g_has_animated_icon = 0b00000000000100000000000000000000, + + /** + * @brief Guild has an actual animated banner (set by the icon hash starting with 'a_') + */ + g_has_animated_banner = 0b00000000001000000000000000000000, + + /** + * @brief Guild setup tips are off + */ + g_no_setup_tips = 0b00000000010000000000000000000000, + + /** + * @brief "Wave to say hi" sticker prompt buttons are off + */ + g_no_sticker_greeting = 0b00000000100000000000000000000000, + + /** + * @brief Guild has enabled monetization + */ + g_monetization_enabled = 0b00000001000000000000000000000000, + + /** + * @brief Guild has increased custom sticker slots + */ + g_more_stickers = 0b00000010000000000000000000000000, + + /** + * @brief Guild has enabled the role subscription promo page + */ + g_creator_store_page_enabled = 0b00000100000000000000000000000000, + + /** + * @brief Guild is able to set role icons + */ + g_role_icons = 0b00001000000000000000000000000000, + + /** + * @brief Guild has access to the seven day archive time for threads * @deprecated Removed by Discord */ - g_seven_day_thread_archive = 0b00010000000000000000000000000000, - /** guild has access to the three day archive time for threads + g_seven_day_thread_archive = 0b00010000000000000000000000000000, + + /** + * @brief Guild has access to the three day archive time for threads * @deprecated Removed by Discord */ - g_three_day_thread_archive = 0b00100000000000000000000000000000, - /** guild has enabled ticketed events */ - g_ticketed_events = 0b01000000000000000000000000000000, - /** guild can have channel banners + g_three_day_thread_archive = 0b00100000000000000000000000000000, + + /** + * @brief Guild has enabled ticketed events + */ + g_ticketed_events = 0b01000000000000000000000000000000, + + /** + * @brief Guild can have channel banners * @deprecated Removed by Discord */ - g_channel_banners = 0b10000000000000000000000000000000, + g_channel_banners = 0b10000000000000000000000000000000, }; /** * @brief Additional boolean flag values for guild, as guild_flags is full */ enum guild_flags_extra : uint16_t { - /** Guild has premium progress bar enabled */ - g_premium_progress_bar_enabled = 0b0000000000000001, - /** Guild can have an animated banner (doesn't mean it actually has one though) */ - g_animated_banner = 0b0000000000000010, - /** Guild has auto moderation */ - g_auto_moderation = 0b0000000000000100, - /** Guild has paused invites, preventing new users from joining */ - g_invites_disabled = 0b0000000000001000, - /** Guild has been set as support server of an app in the App Directory */ - g_developer_support_server = 0b0000000000010000, - /** Guild role subscription purchase and renewal notifications are off */ + /** + * @brief Guild has premium progress bar enabled + */ + g_premium_progress_bar_enabled = 0b0000000000000001, + + /** + * @brief Guild can have an animated banner (doesn't mean it actually has one though) + */ + g_animated_banner = 0b0000000000000010, + + /** + * @brief Guild has auto moderation + */ + g_auto_moderation = 0b0000000000000100, + + /** + * @brief Guild has paused invites, preventing new users from joining + */ + g_invites_disabled = 0b0000000000001000, + + /** + * @brief Guild has been set as support server of an app in the App Directory + */ + g_developer_support_server = 0b0000000000010000, + + /** + * @brief Guild role subscription purchase and renewal notifications are off + */ g_no_role_subscription_notifications = 0b0000000000100000, - /** Guild role subscription sticker reply buttons are off */ + + /** + * @brief Guild role subscription sticker reply buttons are off + */ g_no_role_subscription_notification_replies = 0b0000000001000000, - /** Guild has role subscriptions that can be purchased */ + + /** + * @brief Guild has role subscriptions that can be purchased + */ g_role_subscriptions_available_for_purchase = 0b0000000010000000, - /** Guild has disabled alerts for join raids in the configured safety alerts channel */ + + /** + * @brief Guild has disabled alerts for join raids in the configured safety alerts channel + */ g_raid_alerts_disabled = 0b0000000100000000, }; @@ -162,25 +339,63 @@ enum guild_flags_extra : uint16_t { * @note Use the setter functions in dpp::guild_member and do not toggle the bits yourself. */ enum guild_member_flags : uint16_t { - /** Member deafened in voice channels */ - gm_deaf = 0b0000000000000001, - /** Member muted in voice channels */ - gm_mute = 0b0000000000000010, - /** Member pending verification by membership screening */ - gm_pending = 0b0000000000000100, - /** Member has animated guild-specific avatar */ - gm_animated_avatar = 0b0000000000001000, - /** gm_deaf or gm_mute has been toggled */ - gm_voice_action = 0b0000000000010000, - /** Member has left and rejoined the guild */ + /** + * @brief Member deafened in voice channel + */ + gm_deaf = 0b0000000000000001, + + /** + * @brief Member muted in voice channels + */ + gm_mute = 0b0000000000000010, + + /** + * @brief Member pending verification by membership screening + */ + gm_pending = 0b0000000000000100, + + /** + * @brief Member has animated guild-specific avatar + */ + gm_animated_avatar = 0b0000000000001000, + + /** + * @brief gm_deaf or gm_mute has been toggled + */ + gm_voice_action = 0b0000000000010000, + + /** + * @brief Member has left and rejoined the guild + */ gm_did_rejoin = 0b0000000000100000, - /** Member has completed onboarding */ + + /** + * @brief Member has completed onboarding + */ gm_completed_onboarding = 0b0000000001000000, - /** Member is exempt from guild verification requirements */ + + /** + * @brief Member is exempt from guild verification requirements + */ gm_bypasses_verification = 0b0000000010000000, - /** Member has started onboarding */ + + /** + * @brief Member has started onboarding + */ gm_started_onboarding = 0b0000000100000000, - gm_roles_action = 0b0000001000000000, + + /** + * @brief Should change roles on next call to edit guild_member? + * @warning This is set by dpp::guild_member::add_role, dpp::guild_member::remove_role, and dpp::guild_member::set_roles. + * You should only ever use this value if you know what you're doing, otherwise stick to the three functions listed. + */ + gm_roles_action = 0b0000001000000000, + + /** + * @brief Should nicknames on next call to edit guild_member? + * @warning This is set by dpp::guild_member::set_nickname. + * You should only ever use this value if you know what you're doing, otherwise stick to the function listed. + */ gm_nickname_action = 0b0000010000000000, }; @@ -201,33 +416,58 @@ class DPP_EXPORT guild_member : public json_interface { json to_json_impl(bool with_id = false) const; protected: - /** Nickname, or empty string if they don't have a nickname on this guild */ + /** + * @brief Nickname, or empty string if they don't have a nickname on this guild + */ std::string nickname; - /** List of roles this user has on this guild */ + + /** + * @brief List of roles this user has on this guild + */ std::vector roles; - /** A set of flags built from the bitmask defined by dpp::guild_member_flags */ + + /** + * @brief A set of flags built from the bitmask defined by dpp::guild_member_flags + */ uint16_t flags; friend void from_json(const nlohmann::json& j, guild_member& gm); public: - /** Guild id */ + /** + * @brief Guild id + */ snowflake guild_id; - /** User id */ + + /** + * @brief User id + */ snowflake user_id; - /** User avatar (per-server avatar is a nitro only feature) */ + + /** + * @brief User avatar (per-server avatar is a nitro only feature) + */ utility::iconhash avatar; - /** timestamp of when the time out will be removed; until then, they cannot interact with the guild */ + /** + * @brief Timestamp of when the time out will be removed; until then, they cannot interact with the guild + */ time_t communication_disabled_until; - /** Date and time the user joined the guild */ + + /** + * @brief Date and time the user joined the guild. + */ time_t joined_at; - /** Boosting since */ + + /** + * @brief The Date and time the user started boosting. + */ time_t premium_since; /** Default constructor */ guild_member(); - /** Fill this object from a json object. + /** + * @brief Fill this object from a json object. * @param j The json object to get data from * @param g_id The guild id to associate the member with * @param u_id The user id to associate the member with @@ -440,7 +680,7 @@ class DPP_EXPORT guild_member : public json_interface { /** * @brief Defines a channel on a server's welcome screen */ -struct DPP_EXPORT welcome_channel: public json_interface { +struct DPP_EXPORT welcome_channel : public json_interface { protected: friend struct json_interface; @@ -461,13 +701,24 @@ struct DPP_EXPORT welcome_channel: public json_interface { json to_json_impl(bool with_id = false) const; public: - /// The description shown for the channel + /** + * @brief The description shown for the channel. + */ std::string description; - /// The emoji name if custom, the unicode character if standard, or null if no emoji is set + + /** + * @brief The emoji name if custom, the unicode character if standard, or null if no emoji is set. + */ std::string emoji_name; - /// The channel's id + + /** + * @brief The channel's id. + */ snowflake channel_id; - /// The emoji id, if the emoji is custom + + /** + * @brief The emoji id, if the emoji is custom. + */ snowflake emoji_id; /** @@ -501,7 +752,7 @@ struct DPP_EXPORT welcome_channel: public json_interface { /** * @brief Defines a server's welcome screen */ -struct DPP_EXPORT welcome_screen: public json_interface { +struct DPP_EXPORT welcome_screen : public json_interface { protected: friend struct json_interface; @@ -522,9 +773,14 @@ struct DPP_EXPORT welcome_screen: public json_interface { json to_json_impl(bool with_id = false) const; public: - /// The server description shown in the welcome screen + /** + * @brief The server description shown in the welcome screen + */ std::string description; - /// The channels shown in the welcome screen (max 5) + + /** + * @brief The channels shown in the welcome screen (max 5) + */ std::vector welcome_channels; /** @@ -552,14 +808,25 @@ struct DPP_EXPORT welcome_screen: public json_interface { * @note This is set by Discord, and cannot be set by any bot or user on the guild. */ enum guild_nsfw_level_t : uint8_t { - /// Default setting, not configured - nsfw_default = 0, - /// Explicit content may be in this guild - nsfw_explicit = 1, - /// Safe for work content only - nsfw_safe = 2, - /// Age restricted, 18+ - nsfw_age_restricted = 3 + /** + * @brief Default setting, not configured + */ + nsfw_default = 0, + + /** + * @brief Explicit content may be in this guild + */ + nsfw_explicit = 1, + + /** + * @brief Safe for work content only + */ + nsfw_safe = 2, + + /** + * @brief Age restricted, 18+ + */ + nsfw_age_restricted = 3 }; /** @@ -568,12 +835,20 @@ enum guild_nsfw_level_t : uint8_t { * partnered, official etc. */ enum guild_explicit_content_t : uint8_t { - /// media content will not be scanned - expl_disabled = 0, - /// media content sent by members without roles will be scanned - expl_members_without_roles = 1, - /// media content sent by all members will be scanned - expl_all_members = 2 + /** + * @brief Media content will not be scanned. + */ + expl_disabled = 0, + + /** + * @brief Media content sent by members without roles will be scanned. + */ + expl_members_without_roles = 1, + + /** + * @brief Media content sent by all members will be scanned. + */ + expl_all_members = 2 }; /** @@ -581,9 +856,14 @@ enum guild_explicit_content_t : uint8_t { * actions such as kick or ban. */ enum mfa_level_t : uint8_t { - /// MFA not elevated + /** + * @brief MFA not elevated + */ mfa_none = 0, - /// MFA elevated + + /** + * @brief MFA elevated. + */ mfa_elevated = 1 }; @@ -591,61 +871,109 @@ enum mfa_level_t : uint8_t { * @brief Guild verification level */ enum verification_level_t : uint8_t { - /// unrestricted - ver_none = 0, - /// must have verified email on account - ver_low = 1, - /// must be registered on Discord for longer than 5 minutes - ver_medium = 2, - /// must be a member of the server for longer than 10 minutes - ver_high = 3, - /// must have a verified phone number + /** + * @brief Unrestricted. + */ + ver_none = 0, + + /** + * @brief Must have verified email on account. + */ + ver_low = 1, + + /** + * @brief Must be registered on Discord for longer than 5 minutes. + */ + ver_medium = 2, + + /** + * @brief Must be a member of the server for longer than 10 minutes. + */ + ver_high = 3, + + /** + * @brief Must have a verified phone number. + */ ver_very_high = 4, }; /** * @brief Default message notification level */ -enum default_message_notification_t: uint8_t { - /// members will receive notifications for all messages by default +enum default_message_notification_t : uint8_t { + /** + * @brief Members will receive notifications for all messages by default. + */ dmn_all = 0, - /// members will receive notifications only for messages that \@mention them by default + + /** + * @brief Members will receive notifications only for messages that \@mention them by default. + */ dmn_only_mentions = 1, }; /** - * @brief Premium tier + * @brief The guild's premium tier. */ -enum guild_premium_tier_t: uint8_t { - /// guild has not unlocked any Server Boost perks +enum guild_premium_tier_t : uint8_t { + /** + * @brief Guild has not unlocked any Server Boost perks. + */ tier_none = 0, - /// guild has unlocked Server Boost level 1 perks + + /** + * @brief Guild has unlocked Server Boost level 1 perks. + */ tier_1 = 1, - /// guild has unlocked Server Boost level 2 perks + + /** + * @brief Guild has unlocked Server Boost level 2 perks. + */ tier_2 = 2, - /// guild has unlocked Server Boost level 3 perks + + /** + * @brief Guild has unlocked Server Boost level 3 perks. + */ tier_3 = 3, }; /** * @brief Voice AFK timeout values for guild::afk_timeout */ -enum guild_afk_timeout_t: uint8_t { - /// AFK timeout disabled +enum guild_afk_timeout_t : uint8_t { + /** + * @brief AFK timeout disabled + */ afk_off, - /// AFK timeout of 1 Minute + + /** + * @brief AFK timeout of 1 Minute + */ afk_60, - /// AFK timeout of 5 Minutes + + /** + * @brief AFK timeout of 5 Minutes + */ afk_300, - /// AFK timeout of 15 Minutes + + /** + * @brief AFK timeout of 15 Minutes + */ afk_900, - /// AFK timeout of 30 Minutes + + /** + * @brief AFK timeout of 30 Minutes + */ afk_1800, - /// AFK timeout of 1 Hour + + /** + * @brief AFK timeout of 1 Hour + */ afk_3600, }; -/** @brief Guild members container +/** + * @brief Guild members container */ typedef std::unordered_map members_container; @@ -671,10 +999,14 @@ class DPP_EXPORT guild : public managed, public json_interface { public: using json_interface::fill_from_json; - /** Guild name */ + /** + * @brief Guild name + */ std::string name; - /** Server description */ + /** + * @brief Server description + */ std::string description; /** @@ -685,74 +1017,114 @@ class DPP_EXPORT guild : public managed, public json_interface { */ std::string vanity_url_code; - /** Roles defined on this server */ + /** + * @brief Roles defined on this server + */ std::vector roles; - /** List of channels on this server */ + /** + * @brief List of channels on this server + */ std::vector channels; - /** List of threads on this server */ + /** + * @brief List of threads on this server + */ std::vector threads; - /** List of emojis - */ + /** + * @brief List of emojis + */ std::vector emojis; - /** List of members in voice channels in the guild. + /** + * @brief List of members in voice channels in the guild. */ std::map voice_members; - /** List of guild members. Note that when you first receive the - * guild create event, this may be empty or near empty. - * This depends upon your dpp::intents and the size of your bot. + /** + * @brief List of guild members. + * + * @note When you first receive the guild create event, + * this may be empty or near empty. This depends upon your + * dpp::intents and the size of your bot. * It will be filled by guild member chunk requests. */ members_container members; - /** Welcome screen + /** + * @brief Welcome screen */ dpp::welcome_screen welcome_screen; - /** Guild icon */ + /** + * @brief Guild icon + */ utility::icon icon; - /** Guild splash */ + /** + * @brief Guild splash + */ utility::icon splash; - /** Guild discovery splash */ + /** + * @brief Guild discovery splash + */ utility::icon discovery_splash; - /** Server banner */ + /** + * @brief Server banner + */ utility::icon banner; - /** Snowflake id of guild owner */ + /** + * @brief Snowflake id of guild owner + */ snowflake owner_id; - /** Snowflake ID of AFK voice channel or 0 */ + /** + * @brief Snowflake ID of AFK voice channel or 0 + */ snowflake afk_channel_id; - /** ID of creating application, if any, or 0 */ + /** + * @brief ID of creating application, if any, or 0 + */ snowflake application_id; - /** ID of system channel where discord update messages are sent */ + /** + * @brief ID of system channel where discord update messages are sent + */ snowflake system_channel_id; - /** ID of rules channel for communities */ + /** + * @brief ID of rules channel for communities + */ snowflake rules_channel_id; - /** Public updates channel id or 0 */ + /** + * @brief Public updates channel id or 0 + */ snowflake public_updates_channel_id; - /** Snowflake ID of widget channel, or 0 */ + /** + * @brief Snowflake ID of widget channel, or 0 + */ snowflake widget_channel_id; - /** The id of the channel where admins and moderators of Community guilds receive safety alerts from Discord */ + /** + * @brief The id of the channel where admins and moderators of Community guilds receive safety alerts from Discord + */ snowflake safety_alerts_channel_id; - /** Approximate member count. May be sent as zero */ + /** + * @brief Approximate member count. May be sent as zero + */ uint32_t member_count; - /** Flags bitmask as defined by values within dpp::guild_flags */ + /** + * @brief Flags bitmask as defined by values within dpp::guild_flags + */ uint32_t flags; /** @@ -771,31 +1143,49 @@ class DPP_EXPORT guild : public managed, public json_interface { */ uint16_t flags_extra; - /** Shard ID of the guild */ + /** + * @brief Shard ID of the guild + */ uint16_t shard_id; - /** Number of boosters */ + /** + * @brief Number of boosters + */ uint16_t premium_subscription_count; - /** Voice AFK timeout before moving users to AFK channel */ + /** + * @brief Voice AFK timeout before moving users to AFK channel + */ guild_afk_timeout_t afk_timeout; - /** Maximum users in a video channel, or 0 */ + /** + * @brief Maximum users in a video channel, or 0 + */ uint8_t max_video_channel_users; - /** Setting for how notifications are to be delivered to users */ + /** + * @brief Setting for how notifications are to be delivered to users + */ default_message_notification_t default_message_notifications; - /** Boost level */ + /** + * @brief Boost level + */ guild_premium_tier_t premium_tier; - /** Verification level of server */ + /** + * @brief Verification level of server + */ verification_level_t verification_level; - /** Whether or not explicit content filtering is enable and what setting it is */ + /** + * @brief Whether or not explicit content filtering is enable and what setting it is + */ guild_explicit_content_t explicit_content_filter; - /** If multi factor authentication is required for moderators or not */ + /** + * @brief If multi factor authentication is required for moderators or not + */ mfa_level_t mfa_level; /** @@ -1262,7 +1652,9 @@ class DPP_EXPORT guild : public managed, public json_interface { bool has_invites_disabled() const; }; -/** A container of guilds */ +/** + * @brief A container of guilds + */ typedef std::unordered_map guild_map; /** @@ -1308,32 +1700,58 @@ class DPP_EXPORT guild_widget : public json_interface { /** * @brief The onboarding mode for the dpp::onboarding object. Defines the criteria used to satisfy Onboarding constraints that are required for enabling. */ -enum onboarding_mode: uint8_t { - gom_default = 0, //!< Counts only Default Channels towards constraints - gom_advanced = 1, //!< Counts Default Channels and Questions towards constraints +enum onboarding_mode : uint8_t { + /** + * @brief Counts only Default Channels towards constraints. + */ + gom_default = 0, + + /** + * @brief Counts Default Channels and Questions towards constraints. + */ + gom_advanced = 1, }; /** * @brief The various types of dpp::onboarding_prompt */ -enum onboarding_prompt_type: uint8_t { - opt_multiple_choice = 0, //!< Multiple choice - opt_dropdown = 1, //!< Dropdown +enum onboarding_prompt_type : uint8_t { + /** + * @brief Multiple choice. + */ + opt_multiple_choice = 0, + + /** + * @brief Dropdown. + */ + opt_dropdown = 1, }; /** * @brief Various flags for dpp::onboarding_prompt */ -enum onboarding_prompt_flags: uint8_t { - opf_single_select = 1 << 0, //!< Indicates whether users are limited to selecting one option for the prompt - opf_required = 1 << 1, //!< Indicates whether the prompt is required before a user completes the onboarding flow - opf_in_onboarding = 1 << 2, //!< Indicates whether the prompt is present in the onboarding flow. If set, the prompt will only appear in the Channels & Roles tab +enum onboarding_prompt_flags : uint8_t { + /** + * @brief Indicates whether users are limited to selecting one option for the prompt. + */ + opf_single_select = 1 << 0, + + /** + * @brief Indicates whether the prompt is required before a user completes the onboarding flow. + */ + opf_required = 1 << 1, + + /** + * @brief Indicates whether the prompt is present in the onboarding flow. + * If set, the prompt will only appear in the Channels & Roles tab + */ + opf_in_onboarding = 1 << 2, }; /** * @brief Represents an onboarding prompt option */ -struct DPP_EXPORT onboarding_prompt_option: public managed, public json_interface { +struct DPP_EXPORT onboarding_prompt_option : public managed, public json_interface { protected: friend struct json_interface; @@ -1354,11 +1772,30 @@ struct DPP_EXPORT onboarding_prompt_option: public managed, public json_interfac json to_json_impl(bool with_id = false) const; public: - std::vector channel_ids; //!< IDs for channels a member is added to when the option is selected - std::vector role_ids; //!< IDs for roles assigned to a member when the option is selected - dpp::emoji emoji; //!< Emoji of the option - std::string title; //!< Title of the option - std::string description; //!< Description of the option + /** + * @brief IDs for channels a member is added to when the option is selected. + */ + std::vector channel_ids; + + /** + * @brief IDs for roles assigned to a member when the option is selected + */ + std::vector role_ids; + + /** + * @brief Emoji of the option + */ + dpp::emoji emoji; + + /** + * @brief Title of the option + */ + std::string title; + + /** + * @brief Description of the option + */ + std::string description; /** * @brief Construct a new onboarding prompt option object @@ -1398,7 +1835,7 @@ struct DPP_EXPORT onboarding_prompt_option: public managed, public json_interfac /** * @brief Represents an onboarding prompt */ -struct DPP_EXPORT onboarding_prompt: public managed, public json_interface { +struct DPP_EXPORT onboarding_prompt : public managed, public json_interface { protected: friend struct json_interface; @@ -1419,10 +1856,25 @@ struct DPP_EXPORT onboarding_prompt: public managed, public json_interface options; //!< Options available within the prompt - std::string title; //!< Title of the prompt - uint8_t flags; //!< A set of flags built from the bitmask defined by dpp::onboarding_prompt_flags + /** + * @brief Type of prompt (defaults to dpp::opt_multiple_choice). + */ + onboarding_prompt_type type; + + /** + * @brief Options available within the prompt + */ + std::vector options; + + /** + * @brief Title of the prompt. + */ + std::string title; + + /** + * @brief A set of flags built from the bitmask defined by dpp::onboarding_prompt_flags + */ + uint8_t flags; /** * @brief Construct a new onboarding prompt object @@ -1472,7 +1924,7 @@ struct DPP_EXPORT onboarding_prompt: public managed, public json_interface { +struct DPP_EXPORT onboarding : public json_interface { protected: friend struct json_interface; @@ -1493,11 +1945,30 @@ struct DPP_EXPORT onboarding: public json_interface { json to_json_impl(bool with_id = false) const; public: - snowflake guild_id; //!< ID of the guild this onboarding is part of - std::vector prompts; //!< Prompts shown during onboarding and in customize community - std::vector default_channel_ids; //!< Channel IDs that members get opted into automatically - onboarding_mode mode; //!< Current mode of onboarding (defaults to dpp::gom_default) - bool enabled; //!< Whether onboarding is enabled in the guild + /** + * @brief ID of the guild this onboarding is part of. + */ + snowflake guild_id; + + /** + * @brief Prompts shown during onboarding and in customize community. + */ + std::vector prompts; + + /** + * @brief Channel IDs that members get opted into automatically + */ + std::vector default_channel_ids; + + /** + * @brief Current mode of onboarding (defaults to dpp::gom_default) + */ + onboarding_mode mode; + + /** + * @brief Whether onboarding is enabled in the guild + */ + bool enabled; /** * @brief Construct a new onboarding object @@ -1544,7 +2015,9 @@ struct DPP_EXPORT onboarding: public json_interface { */ void from_json(const nlohmann::json& j, guild_member& gm); -/** A container of guild members */ +/** + * @brief A container of guild members + */ typedef std::unordered_map guild_member_map; /** diff --git a/include/dpp/httpsclient.h b/include/dpp/httpsclient.h index d9ca9e582a..f043d533f7 100644 --- a/include/dpp/httpsclient.h +++ b/include/dpp/httpsclient.h @@ -96,6 +96,7 @@ struct multipart_content { * @brief Multipart body */ std::string body; + /** * @brief MIME type */ @@ -111,14 +112,17 @@ 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 @@ -130,8 +134,7 @@ struct http_connect_info { * @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 -{ +class DPP_EXPORT https_client : public ssl_client { /** * @brief Current connection state */ @@ -215,7 +218,6 @@ class DPP_EXPORT https_client : public ssl_client bool do_buffer(std::string& buffer); protected: - /** * @brief Start the connection */ @@ -228,7 +230,6 @@ class DPP_EXPORT https_client : public ssl_client http_state get_state(); public: - /** * @brief Connect to a specific HTTP(S) server and complete a request. * diff --git a/include/dpp/integration.h b/include/dpp/integration.h index 98d5cb507d..1e48c7be65 100644 --- a/include/dpp/integration.h +++ b/include/dpp/integration.h @@ -34,13 +34,24 @@ namespace dpp { * @brief Integration types */ enum integration_type { - /// Twitch integration + /** + * @brief Twitch integration + */ i_twitch, - /// YouTube integration + + /** + * @brief YouTube integration + */ i_youtube, - /// Discord integration + + /** + * @brief Discord integration + */ i_discord, - /// Subscription + + /** + * @brief Subscription + */ i_guild_subscription, }; @@ -48,30 +59,79 @@ enum integration_type { * @brief Integration flags */ enum integration_flags { - if_enabled = 0b00000001, //!< is this integration enabled - if_syncing = 0b00000010, //!< is this integration syncing @warning This is not provided for discord bot integrations. - if_emoticons = 0b00000100, //!< whether emoticons should be synced for this integration (twitch only currently) @warning This is not provided for discord bot integrations. - if_revoked = 0b00001000, //!< has this integration been revoked @warning This is not provided for discord bot integrations. - if_expire_kick = 0b00010000, //!< kick user when their subscription expires, otherwise only remove the role that is specified by `role_id`. @warning This is not provided for discord bot integrations. + /** + * @brief Is this integration enabled? + */ + if_enabled = 0b00000001, + + /** + * @brief Is this integration syncing? + * @warning This is not provided for discord bot integrations. + */ + if_syncing = 0b00000010, + + /** + * @brief Whether emoticons should be synced for this integration (twitch only currently). + * @warning This is not provided for discord bot integrations. + */ + if_emoticons = 0b00000100, + + /** + * @brief Has this integration been revoked? + * @warning This is not provided for discord bot integrations. + */ + if_revoked = 0b00001000, + + /** + * @brief Kick user when their subscription expires, otherwise only remove the role that is specified by `role_id`. + * @warning This is not provided for discord bot integrations. + */ + if_expire_kick = 0b00010000, }; /** * @brief An application that has been integrated */ struct DPP_EXPORT integration_app { - snowflake id; //!< the id of the app - std::string name; //!< the name of the app - utility::iconhash icon; //!< the icon hash of the app - std::string description; //!< the description of the app - class user* bot; //!< the bot associated with this application + /** + * @brief The id of the app. + */ + snowflake id; + + /** + * @brief The name of the app. + */ + std::string name; + + /** + * @brief The icon hash of the app. + */ + utility::iconhash icon; + + /** + * @brief The description of the app + */ + std::string description; + + /** + * @brief The bot associated with this application. + */ + class user* bot; }; /** * @brief The account information for an integration. */ struct DPP_EXPORT integration_account { - snowflake id; //!< id of the account - std::string name; //!< name of the account + /** + * @brief ID of the account + */ + snowflake id; + + /** + * @brief Name of the account. + */ + std::string name; }; /** @@ -94,17 +154,68 @@ class DPP_EXPORT integration : public managed, public json_interface scopes; //!< the scopes the application has been authorized for + /** + * @brief Integration name. + */ + std::string name; + + /** + * @brief Integration type (twitch, youtube, discord, or guild_subscription). + */ + integration_type type; + + /** + * @brief Integration flags from dpp::integration_flags + */ + uint8_t flags; + + /** + * @brief ID that this integration uses for "subscribers". + * + * @warning This is not provided for discord bot integrations. + */ + snowflake role_id; + + /** + * @brief The grace period (in days) before expiring subscribers. + * + * @warning This is not provided for discord bot integrations. + */ + uint32_t expire_grace_period; + + /** + * @brief User for this integration + */ + user user_obj; + + /** + * @brief Integration account information + */ + integration_account account; + + /** + * @brief When this integration was last synced. + * + * @warning This is not provided for discord bot integrations. + */ + time_t synced_at; + + /** + * @brief How many subscribers this integration has. + * + * @warning This is not provided for discord bot integrations. + */ + uint32_t subscriber_count; + + /** + * @brief The bot/OAuth2 application for discord integrations. + */ + integration_app app; + + /** + * @brief The scopes the application has been authorized for. + */ + std::vector scopes; /** Default constructor */ integration(); @@ -158,16 +269,55 @@ class DPP_EXPORT connection : public json_interface { connection& fill_from_json_impl(nlohmann::json* j); 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 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 ID of the connection account. + */ + std::string id; + + /** + * @brief the username of the connection account. + */ + std::string name; + + /** + * @brief the service of the connection (twitch, youtube, discord, or guild_subscription). + */ + std::string type; + + /** + * @brief Optional: whether the connection is revoked. + */ + bool revoked; + + /** + * @brief Optional: an array of partial server integrations. + */ + std::vector integrations; + + /** + * @brief Whether the connection is verified. + */ + bool verified; + + /** + * @brief Whether friend sync is enabled for this connection. + */ + bool friend_sync; + + /** + * @brief Whether activities related to this connection will be shown in presence updates. + */ + bool show_activity; + + /** + * @brief Whether this connection has a corresponding third party OAuth2 token. + */ + bool two_way_link; + + /** + * @brief Visibility of this connection. + */ + bool visible; /** * @brief Construct a new connection object @@ -175,10 +325,14 @@ class DPP_EXPORT connection : public json_interface { connection(); }; -/** A group of integrations */ +/** + * @brief A group of integrations + */ typedef std::unordered_map integration_map; -/** A group of connections */ +/** + * @brief A group of connections + */ typedef std::unordered_map connection_map; } // namespace dpp diff --git a/include/dpp/intents.h b/include/dpp/intents.h index 80bc94bba2..d225a9d5e1 100644 --- a/include/dpp/intents.h +++ b/include/dpp/intents.h @@ -31,56 +31,124 @@ namespace dpp { * your real life ID. */ enum intents { - /// Intent for receipt of guild information + /** + * @brief Intent for receipt of guild information. + */ i_guilds = (1 << 0), - /// Intent for receipt of guild members + + /** + * @brief Intent for receipt of guild members. + */ i_guild_members = (1 << 1), - /// Intent for receipt of guild bans + + /** + * @brief Intent for receipt of guild bans. + */ i_guild_bans = (1 << 2), - /// Intent for receipt of guild emojis + + /** + * @brief Intent for receipt of guild emojis. + */ i_guild_emojis = (1 << 3), - /// Intent for receipt of guild integrations + + /** + * @brief Intent for receipt of guild integrations. + */ i_guild_integrations = (1 << 4), - /// Intent for receipt of guild webhooks + + /** + * @brief Intent for receipt of guild webhooks. + */ i_guild_webhooks = (1 << 5), - /// Intent for receipt of guild invites + + /** + * @brief Intent for receipt of guild invites. + */ i_guild_invites = (1 << 6), - /// Intent for receipt of guild voice states + + /** + * @brief Intent for receipt of guild voice states. + */ i_guild_voice_states = (1 << 7), - /// Intent for receipt of guild presences + + /** + * @brief Intent for receipt of guild presences. + */ i_guild_presences = (1 << 8), - /// Intent for receipt of guild messages + + /** + * @brief Intent for receipt of guild messages. + */ i_guild_messages = (1 << 9), - /// Intent for receipt of guild message reactions + + /** + * @brief Intent for receipt of guild message reactions. + */ i_guild_message_reactions = (1 << 10), - /// Intent for receipt of guild message typing notifications + + /** + * @brief Intent for receipt of guild message typing notifications. + */ i_guild_message_typing = (1 << 11), - /// Intent for receipt of direct messages (DMs) + + /** + * @brief Intent for receipt of direct messages (DMs). + */ i_direct_messages = (1 << 12), - /// Intent for receipt of direct message reactions + + /** + * @brief Intent for receipt of direct message reactions. + */ i_direct_message_reactions = (1 << 13), - /// Intent for receipt of direct message typing notifications + + /** + * @brief Intent for receipt of direct message typing notifications. + */ i_direct_message_typing = (1 << 14), - /// Intent for receipt of message content + + /** + * @brief Intent for receipt of message content. + */ i_message_content = (1 << 15), - /// Scheduled events + + /** + * @brief Scheduled events. + */ i_guild_scheduled_events = (1 << 16), - /// Auto moderation configuration + + /** + * @brief Auto moderation configuration. + */ i_auto_moderation_configuration = (1 << 20), - /// Auto moderation configuration + + /** + * @brief Auto moderation configuration. + */ i_auto_moderation_execution = (1 << 21), - /// Default D++ intents (all non-privileged intents) + + /** + * @brief 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 + dpp::i_auto_moderation_execution, + + /** + * @brief Privileged intents requiring ID. + */ i_privileged_intents = dpp::i_guild_members | dpp::i_guild_presences | dpp::i_message_content, - /// Every single intent + + /** + * @brief Every single intent (dpp::i_default_intents and dpp::i_privileged_intents). + */ i_all_intents = dpp::i_default_intents | dpp::i_privileged_intents, - /// Unverified bots default intents + + /** + * @brief Unverified bots default intents. + */ i_unverified_default_intents = dpp::i_default_intents | dpp::i_message_content }; diff --git a/include/dpp/invite.h b/include/dpp/invite.h index 37798ec410..c20708056a 100644 --- a/include/dpp/invite.h +++ b/include/dpp/invite.h @@ -36,9 +36,20 @@ namespace dpp { * @brief Invite target types for dpp::invite */ enum invite_target_t : uint8_t { - itt_none = 0, //!< Undefined invite target type - itt_stream = 1, //!< Stream target type - itt_embedded_application = 2, //!< Embedded Application target type + /** + * @brief Undefined invite target type. + */ + itt_none = 0, + + /** + * @brief Stream target type. + */ + itt_stream = 1, + + /** + * @brief Embedded Application target type. + */ + itt_embedded_application = 2, }; /** @@ -61,74 +72,119 @@ class DPP_EXPORT invite : public json_interface { virtual json to_json_impl(bool with_id = false) const; public: - /** Invite code + /** + * @brief Invite code. */ std::string code; - /** Readonly expiration timestamp of this invite or 0 if the invite doesn't expire + + /** + * @brief Readonly expiration timestamp of this invite or 0 if the invite doesn't expire. * @note Only returned from cluster::invite_get */ time_t expires_at; - /** Guild ID this invite is for + + /** + * @brief Guild ID this invite is for. */ snowflake guild_id; - /** The partial guild this invite is for. Only filled in retrieved invites + + /** + * @brief The partial guild this invite is for. + * @note Only filled in retrieved invites. */ guild destination_guild; - /** Channel ID this invite is for + + /** + * @brief Channel ID this invite is for. */ snowflake channel_id; - /** The partial channel this invite is for. Only filled in retrieved invites + + /** + * @brief The partial channel this invite is for. + * @note Only filled in retrieved invites. */ channel destination_channel; - /** User ID who created this invite + + /** + * @brief User ID who created this invite. * @deprecated Use the `inviter` field instead */ snowflake inviter_id; - /** User who created this invite + + /** + * @brief User who created this invite. */ user inviter; - /** The user ID whose stream to display for this voice channel stream invite + + /** + * @brief The user ID whose stream to display for this voice channel stream invite. */ snowflake target_user_id; - /** Target type for this voice channel invite + + /** + * @brief Target type for this voice channel invite. */ invite_target_t target_type; - /** Approximate number of online users + + /** + * @brief Approximate number of online users. * @note Only returned from cluster::invite_get */ uint32_t approximate_presence_count; - /** Approximate number of total users online and offline - * @note Only returned from cluster::invite_get + + /** + * @brief Approximate number of total users online and offline. + * @note Only returned from cluster::invite_get. */ uint32_t approximate_member_count; - /** Duration (in seconds) after which the invite expires, or 0 for no expiration. Must be between 0 and 604800 (7 days). Defaults to 86400 (1 day) + + /** + * @brief Duration (in seconds) after which the invite expires, or 0 for no expiration. Defaults to 86400 (1 day). + * + * @note Must be between 0 and 604800 (7 days). */ uint32_t max_age; - /** Maximum number of uses, or 0 for unlimited. Must be between 0 and 100. Defaults to 0 + + /** + * @brief Maximum number of uses, or 0 for unlimited. Defaults to 0. + * + * @note Must be between 0 and 100. */ uint8_t max_uses; - /** Whether this invite only grants temporary membership + + /** + * @brief Whether this invite only grants temporary membership. */ bool temporary; - /** True if this invite should not replace or "attach to" similar invites + + /** + * @brief True if this invite should not replace or "attach to" similar invites. */ bool unique; - /** How many times this invite has been used + + /** + * @brief How many times this invite has been used. */ uint32_t uses; - /** The stage instance data if there is a public stage instance in the stage channel this invite is for + + /** + * @note The stage instance data if there is a public stage instance in the stage channel this invite is for. * @deprecated Deprecated */ stage_instance stage; - /** Timestamp at which the invite was created + + /** + * @brief Timestamp at which the invite was created. */ time_t created_at; - /** Constructor + /** + * @brief Constructor. */ invite(); - /** Destructor + /** + * @brief Destructor. */ virtual ~invite() = default; @@ -181,7 +237,9 @@ class DPP_EXPORT invite : public json_interface { invite& set_unique(const bool is_unique); }; -/** A container of invites */ +/** + * @brief A container of invites + */ typedef std::unordered_map invite_map; } // namespace dpp diff --git a/include/dpp/json_interface.h b/include/dpp/json_interface.h index a5c5fbd3e5..5c3fb69c36 100644 --- a/include/dpp/json_interface.h +++ b/include/dpp/json_interface.h @@ -24,48 +24,50 @@ #include namespace dpp { + +/** + * @brief Represents an interface for an object that can optionally implement functions + * for converting to and from nlohmann::json. The methods are only present if the actual object + * also has those methods. + * + * @tparam T Type of class that implements the interface + */ +template +struct DPP_EXPORT json_interface { /** - * @brief Represents an interface for an object that can optionally implement functions - * for converting to and from nlohmann::json. The methods are only present if the actual object - * also has those methods. + * @brief Convert object from nlohmann::json * - * @tparam T Type of class that implements the interface + * @param j nlohmann::json object + * @return T& Reference to self for fluent calling */ - template - struct DPP_EXPORT json_interface { - /** - * @brief Convert object from nlohmann::json - * - * @param j nlohmann::json object - * @return T& Reference to self for fluent calling - */ - template ().fill_from_json_impl(std::declval()))> - T& fill_from_json(nlohmann::json* j) { - return static_cast(this)->fill_from_json_impl(j); - } + template ().fill_from_json_impl(std::declval()))> + T& fill_from_json(nlohmann::json* j) { + return static_cast(this)->fill_from_json_impl(j); + } - /** - * @brief Convert object to nlohmann::json - * - * @param with_id Whether to include the ID or not - * @note Some fields are conditionally filled, do not rely on all fields being present - * @return json Json built from the structure - */ - template ().to_json_impl(bool{}))> - auto to_json(bool with_id = false) const { - return static_cast(this)->to_json_impl(with_id); - } + /** + * @brief Convert object to nlohmann::json + * + * @param with_id Whether to include the ID or not + * @note Some fields are conditionally filled, do not rely on all fields being present + * @return json Json built from the structure + */ + template ().to_json_impl(bool{}))> + auto to_json(bool with_id = false) const { + return static_cast(this)->to_json_impl(with_id); + } + + /** + * @brief Convert object to json string + * + * @param with_id Whether to include the ID or not + * @note Some fields are conditionally filled, do not rely on all fields being present + * @return std::string Json built from the structure + */ + template ().to_json_impl(bool{}))> + std::string build_json(bool with_id = false) const { + return to_json(with_id).dump(); + } +}; - /** - * @brief Convert object to json string - * - * @param with_id Whether to include the ID or not - * @note Some fields are conditionally filled, do not rely on all fields being present - * @return std::string Json built from the structure - */ - template ().to_json_impl(bool{}))> - std::string build_json(bool with_id = false) const { - return to_json(with_id).dump(); - } - }; } // namespace dpp diff --git a/include/dpp/managed.h b/include/dpp/managed.h index 86188f7da8..4ccd2e5318 100644 --- a/include/dpp/managed.h +++ b/include/dpp/managed.h @@ -26,91 +26,91 @@ 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. +/** @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. */ - 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 = {}; + snowflake id = {}; - /** - * @brief Constructor, initialises id to 0. - */ - managed() = default; + /** + * @brief Constructor, initialises id to 0. + */ + managed() = default; - /** - * @brief Constructor, initialises ID - * @param nid ID to set - */ - managed(const snowflake nid) : id{nid} {} + /** + * @brief Constructor, initialises ID + * @param nid ID to set + */ + managed(const snowflake nid) : id{nid} {} - /** - * @brief Copy constructor - * @param rhs Object to copy - */ - managed(const managed &rhs) = default; + /** + * @brief Copy constructor + * @param rhs Object to copy + */ + managed(const managed &rhs) = default; - /** - * @brief Move constructor - * - * Effectively equivalent to copy constructor - * @param rhs Object to move from - */ - managed(managed &&rhs) = default; + /** + * @brief Move constructor + * + * Effectively equivalent to copy constructor + * @param rhs Object to move from + */ + managed(managed &&rhs) = default; - /** - * @brief Destroy the managed object - */ - virtual ~managed() = default; + /** + * @brief Destroy the managed object + */ + virtual ~managed() = default; - /** - * @brief Copy assignment operator - * @param rhs Object to copy - */ - managed &operator=(const managed& rhs) = default; + /** + * @brief Copy assignment operator + * @param rhs Object to copy + */ + managed &operator=(const managed& rhs) = default; - /** - * @brief Move assignment operator - * @param rhs Object to move from - */ - managed &operator=(managed&& rhs) = default; + /** + * @brief Move assignment operator + * @param rhs Object to move from + */ + managed &operator=(managed&& rhs) = 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. - */ - constexpr double get_creation_time() const noexcept { - return id.get_creation_time(); - }; + /** + * @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. + */ + constexpr double get_creation_time() const noexcept { + return id.get_creation_time(); + }; - /** - * @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 - */ - constexpr bool operator==(const managed& other) const noexcept { - return id == other.id; - } + /** + * @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 + */ + constexpr bool operator==(const managed& other) const noexcept { + return id == other.id; + } - /** - * @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 - */ - constexpr bool operator!=(const managed& other) const noexcept { - return id != other.id; - } - }; + /** + * @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 + */ + constexpr bool operator!=(const managed& other) const noexcept { + return id != other.id; + } +}; } // namespace dpp