From 42c1fa4fa93636708028f916d17304a178c407d8 Mon Sep 17 00:00:00 2001 From: Archie Jaskowicz Date: Mon, 30 Oct 2023 09:23:04 +0000 Subject: [PATCH] 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 }; /**