diff --git a/include/dpp/misc-enum.h b/include/dpp/misc-enum.h index fd608953c5..feb84b6329 100644 --- a/include/dpp/misc-enum.h +++ b/include/dpp/misc-enum.h @@ -25,32 +25,65 @@ namespace dpp { - /** @brief Supported image types for profile pictures and CDN endpoints */ - enum image_type { - /// image/png - i_png, - /// image/jpeg - i_jpg, - /// image/gif - i_gif, - /// WebP - i_webp, - }; - - /** @brief Log levels */ - enum loglevel { - /// Trace - ll_trace = 0, - /// Debug - ll_debug, - /// Information - ll_info, - /// Warning - ll_warning, - /// Error - ll_error, - /// Critical - ll_critical - }; +/** + * @brief Supported image types for profile pictures and CDN endpoints + */ +enum image_type { + /** + * @brief image/png + */ + i_png, + + /** + * @brief image/jpeg. + */ + i_jpg, + + /** + * @brief image/gif. + */ + i_gif, + + /** + * @brief Webp. + */ + /// WebP + i_webp, +}; + +/** + * @brief Log levels + */ +enum loglevel { + /** + * @brief Trace + */ + ll_trace = 0, + + /** + * @brief Debug + */ + ll_debug, + + /** + * @brief Information + */ + ll_info, + + /** + * @brief Warning + */ + ll_warning, + + /** + * @brief Error + */ + ll_error, + + /** + * @brief Critical + */ + ll_critical +}; } // namespace dpp diff --git a/include/dpp/once.h b/include/dpp/once.h index 4ca494e9af..f81a02cfdb 100644 --- a/include/dpp/once.h +++ b/include/dpp/once.h @@ -24,23 +24,23 @@ namespace dpp { - /** - * @brief Run some code within an if() statement only once. - * - * Use this template like this: - * - * ``` - * if (dpp::run_once()) { - * // Your code here - * } - * ``` - * - * @tparam T any unique 'tag' identifier name - * @return auto a true/false return to say if we should execute or not - */ - template auto run_once() { - static auto called = false; - return !std::exchange(called, true); - }; +/** + * @brief Run some code within an if() statement only once. + * + * Use this template like this: + * + * ``` + * if (dpp::run_once()) { + * // Your code here + * } + * ``` + * + * @tparam T any unique 'tag' identifier name + * @return auto a true/false return to say if we should execute or not + */ +template auto run_once() { + static auto called = false; + return !std::exchange(called, true); +}; } // namespace dpp diff --git a/include/dpp/permissions.h b/include/dpp/permissions.h index 0dd9e9b143..a51702ef4d 100644 --- a/include/dpp/permissions.h +++ b/include/dpp/permissions.h @@ -30,52 +30,240 @@ namespace dpp { * @brief Represents the various discord permissions */ enum permissions : uint64_t { - p_create_instant_invite = 0x00000000001, //!< allows creation of instant invites - p_kick_members = 0x00000000002, //!< allows kicking members - p_ban_members = 0x00000000004, //!< allows banning members - p_administrator = 0x00000000008, //!< allows all permissions and bypasses channel permission overwrites - p_manage_channels = 0x00000000010, //!< allows management and editing of channels - p_manage_guild = 0x00000000020, //!< allows management and editing of the guild - p_add_reactions = 0x00000000040, //!< allows for the addition of reactions to messages - p_view_audit_log = 0x00000000080, //!< allows for viewing of audit logs - p_priority_speaker = 0x00000000100, //!< allows for using priority speaker in a voice channel - p_stream = 0x00000000200, //!< allows the user to go live - p_view_channel = 0x00000000400, //!< allows guild members to view a channel, which includes reading messages in text channels and joining voice channels - p_send_messages = 0x00000000800, //!< allows for sending messages in a channel - p_send_tts_messages = 0x00000001000, //!< allows for sending of /tts messages - p_manage_messages = 0x00000002000, //!< allows for deletion of other users messages - p_embed_links = 0x00000004000, //!< links sent by users with this permission will be auto-embedded - p_attach_files = 0x00000008000, //!< allows for uploading images and files - p_read_message_history = 0x00000010000, //!< allows for reading of message history - p_mention_everyone = 0x00000020000, //!< allows for using the everyone and the here tag to notify users in a channel - p_use_external_emojis = 0x00000040000, //!< allows the usage of custom emojis from other servers - p_view_guild_insights = 0x00000080000, //!< allows for viewing guild insights - p_connect = 0x00000100000, //!< allows for joining of a voice channel - p_speak = 0x00000200000, //!< allows for speaking in a voice channel - p_mute_members = 0x00000400000, //!< allows for muting members in a voice channel - p_deafen_members = 0x00000800000, //!< allows for deafening of members in a voice channel - p_move_members = 0x00001000000, //!< allows for moving of members between voice channels - p_use_vad = 0x00002000000, //!< allows for using voice-activity-detection in a voice channel - p_change_nickname = 0x00004000000, //!< allows for modification of own nickname - p_manage_nicknames = 0x00008000000, //!< allows for modification of other users nicknames - p_manage_roles = 0x00010000000, //!< allows management and editing of roles - p_manage_webhooks = 0x00020000000, //!< allows management and editing of webhooks - p_manage_emojis_and_stickers = 0x00040000000, //!< allows management and editing of emojis and stickers - p_use_application_commands = 0x00080000000, //!< allows members to use application commands, including slash commands and context menus - p_request_to_speak = 0x00100000000, //!< allows for requesting to speak in stage channels. (Discord: This permission is under active development and may be changed or removed.) - p_manage_events = 0x00200000000, //!< allows for management (creation, updating, deleting, starting) of scheduled events - p_manage_threads = 0x00400000000, //!< allows for deleting and archiving threads, and viewing all private threads - p_create_public_threads = 0x00800000000, //!< allows for creating public and announcement threads - p_create_private_threads = 0x01000000000, //!< allows for creating private threads - p_use_external_stickers = 0x02000000000, //!< allows the usage of custom stickers from other servers - p_send_messages_in_threads = 0x04000000000, //!< allows for sending messages in threads - p_use_embedded_activities = 0x08000000000, //!< allows for using activities (applications with the EMBEDDED flag) in a voice channel - p_moderate_members = 0x10000000000, //!< allows for timing out users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels - p_view_creator_monetization_analytics = 0x20000000000, //!< allows for viewing role subscription insights - p_use_soundboard = 0x40000000000, //!< allows for using soundboard in a voice channel - p_use_external_sounds = 0x0000200000000000, //!< allows the usage of custom soundboard sounds from other servers - p_send_voice_messages = 0x0000400000000000, //!< allows sending voice messages - p_use_clyde_ai = 0x0000800000000000, //!< allows use of Clyde AI + /** + * @brief Allows creation of instant invites. + */ + p_create_instant_invite = 0x00000000001, + + /** + * @brief Allows kicking members. + */ + p_kick_members = 0x00000000002, + + /** + * @brief Allows banning members. + */ + p_ban_members = 0x00000000004, + + /** + * @brief Allows all permissions and bypasses channel permission overwrites. + */ + p_administrator = 0x00000000008, + + /** + * @brief Allows management and editing of channels. + */ + p_manage_channels = 0x00000000010, + + /** + * @brief Allows management and editing of the guild. + */ + p_manage_guild = 0x00000000020, + + /** + * @brief Allows for the addition of reactions to messages. + */ + p_add_reactions = 0x00000000040, + + /** + * @brief Allows for viewing of audit logs. + */ + p_view_audit_log = 0x00000000080, + + /** + * @brief Allows for using priority speaker in a voice channel. + */ + p_priority_speaker = 0x00000000100, + + /** + * @brief Allows the user to go live. + */ + p_stream = 0x00000000200, + + /** + * @brief Allows guild members to view a channel, + * which includes reading messages in text channels and joining voice channels. + */ + p_view_channel = 0x00000000400, + + /** + * @brief Allows for sending messages in a channel. + */ + p_send_messages = 0x00000000800, + + /** + * @brief Allows for sending of /tts messages. + */ + p_send_tts_messages = 0x00000001000, + + /** + * @brief Allows for deletion of other users messages. + */ + p_manage_messages = 0x00000002000, + + /** + * @brief Links sent by users with this permission will be auto-embedded. + */ + p_embed_links = 0x00000004000, + + /** + * @brief Allows for uploading images and files. + */ + p_attach_files = 0x00000008000, + + /** + * @brief Allows for reading of message history. + */ + p_read_message_history = 0x00000010000, + + /** + * @brief Allows for using the everyone and the here tag to notify users in a channel. + */ + p_mention_everyone = 0x00000020000, + + /** + * @brief Allows the usage of custom emojis from other servers. + */ + p_use_external_emojis = 0x00000040000, + + /** + * @brief Allows for viewing guild insights. + */ + p_view_guild_insights = 0x00000080000, + + /** + * @brief Allows for joining of a voice channel. + */ + p_connect = 0x00000100000, + + /** + * @brief Allows for speaking in a voice channel. + */ + p_speak = 0x00000200000, + + /** + * @brief Allows for muting members in a voice channel. + */ + p_mute_members = 0x00000400000, + + /** + * @brief Allows for deafening of members in a voice channel. + */ + p_deafen_members = 0x00000800000, + + /** + * @brief Allows for moving of members between voice channels. + */ + p_move_members = 0x00001000000, + + /** + * @brief Allows for using voice-activity-detection in a voice channel. + */ + p_use_vad = 0x00002000000, + + /** + * @brief Allows for modification of own nickname. + */ + p_change_nickname = 0x00004000000, + + /** + * @brief Allows for modification of other users nicknames. + */ + p_manage_nicknames = 0x00008000000, + + /** + * @brief Allows management and editing of roles. + */ + p_manage_roles = 0x00010000000, + + /** + * @brief Allows management and editing of webhooks. + */ + p_manage_webhooks = 0x00020000000, + + /** + * @brief Allows management and editing of emojis and stickers. + */ + p_manage_emojis_and_stickers = 0x00040000000, + + /** + * @brief Allows members to use application commands, + * including slash commands and context menus. + */ + p_use_application_commands = 0x00080000000, + + /** + * @brief Allows for requesting to speak in stage channels. + * + * @warning Discord: This permission is under active development and may be changed or removed. + */ + p_request_to_speak = 0x00100000000, + + /** + * @brief Allows for management (creation, updating, deleting, starting) of scheduled events. + */ + p_manage_events = 0x00200000000, + + /** + * @brief Allows for deleting and archiving threads, and viewing all private threads. + */ + p_manage_threads = 0x00400000000, + + /** + * @brief Allows for creating public and announcement threads. + */ + p_create_public_threads = 0x00800000000, + + /** + * @brief Allows for creating private threads. + */ + p_create_private_threads = 0x01000000000, + + /** + * @brief Allows the usage of custom stickers from other servers. + */ + p_use_external_stickers = 0x02000000000, + + /** + * @brief Allows for sending messages in threads. + */ + p_send_messages_in_threads = 0x04000000000, + + /** + * @brief Allows for using activities (applications with the EMBEDDED flag) in a voice channel. + */ + p_use_embedded_activities = 0x08000000000, + + /** + * @brief Allows for timing out users to prevent them from sending or reacting + * to messages in chat and threads, and from speaking in voice and stage channels. + */ + p_moderate_members = 0x10000000000, + + /** + * @brief Allows for viewing role subscription insights. + */ + p_view_creator_monetization_analytics = 0x20000000000, + + /** + * @brief Allows for using soundboard in a voice channel. + */ + p_use_soundboard = 0x40000000000, + + /** + * @brief Allows the usage of custom soundboard sounds from other servers. + */ + p_use_external_sounds = 0x0000200000000000, + + /** + * @brief Allows sending voice messages. + */ + p_send_voice_messages = 0x0000400000000000, + + /** + * @brief Allows use of Clyde AI. + */ + p_use_clyde_ai = 0x0000800000000000, }; /** diff --git a/include/dpp/presence.h b/include/dpp/presence.h index 1dbc09cbf7..cc507464e4 100644 --- a/include/dpp/presence.h +++ b/include/dpp/presence.h @@ -33,84 +33,174 @@ namespace dpp { * @brief Presence flags bitmask */ enum presence_flags { - /// Desktop: Online - p_desktop_online = 0b00000001, - /// Desktop: DND - p_desktop_dnd = 0b00000010, - /// Desktop: Idle - p_desktop_idle = 0b00000011, - /// Web: Online - p_web_online = 0b00000100, - /// Web: DND - p_web_dnd = 0b00001000, - /// Web: Idle - p_web_idle = 0b00001100, - /// Mobile: Online - p_mobile_online = 0b00010000, - /// Mobile: DND - p_mobile_dnd = 0b00100000, - /// Mobile: Idle - p_mobile_idle = 0b00110000, - /// General: Online - p_status_online = 0b01000000, - /// General: DND - p_status_dnd = 0b10000000, - /// General: Idle - p_status_idle = 0b11000000 + /** + * @brief Desktop: Online. + */ + p_desktop_online = 0b00000001, + + /** + * @brief Desktop: DND. + */ + p_desktop_dnd = 0b00000010, + + /** + * @brief Desktop: Idle. + */ + p_desktop_idle = 0b00000011, + + /** + * @brief Web: Online. + */ + p_web_online = 0b00000100, + + /** + * @brief Web: DND. + */ + p_web_dnd = 0b00001000, + + /** + * @brief Web: Idle. + */ + p_web_idle = 0b00001100, + + /** + * @brief Mobile: Online. + */ + p_mobile_online = 0b00010000, + + /** + * @brief Mobile: DND. + */ + p_mobile_dnd = 0b00100000, + + /** + * @brief Mobile: Idle. + */ + p_mobile_idle = 0b00110000, + + /** + * @brief General: Online. + */ + p_status_online = 0b01000000, + + /** + * @brief General: DND. + */ + p_status_dnd = 0b10000000, + + /** + * @brief General: Idle. + */ + p_status_idle = 0b11000000 }; /** * @brief Online presence status values */ enum presence_status : uint8_t { - /// Offline - ps_offline = 0, - /// Online - ps_online = 1, - /// DND - ps_dnd = 2, - /// Idle - ps_idle = 3, - /// Invisible (show as offline) - ps_invisible = 4, + /** + * @brief Offline. + */ + ps_offline = 0, + + /** + * @brief Online. + */ + ps_online = 1, + + /** + * @brief DND. + */ + ps_dnd = 2, + + /** + * @brief Idle. + */ + ps_idle = 3, + + /** + * @brief Invisible (show as offline). + */ + ps_invisible = 4, }; /** - * @brief Bit shift for desktop status + * @brief Bit shift for desktop status. */ #define PF_SHIFT_DESKTOP 0 -/** Bit shift for web status */ + +/** + * @brief Bit shift for web status. + */ #define PF_SHIFT_WEB 2 -/** Bit shift for mobile status */ + +/** + * @brief Bit shift for mobile status. + */ #define PF_SHIFT_MOBILE 4 -/** Bit shift for main status */ + +/** + * @brief Bit shift for main status. + */ #define PF_SHIFT_MAIN 6 -/** Bit mask for status */ + +/** + * @brief Bit mask for status. + */ #define PF_STATUS_MASK 0b00000011 -/** Bit mask for clearing desktop status */ + +/** + * @brief Bit mask for clearing desktop status. + */ #define PF_CLEAR_DESKTOP 0b11111100 -/** Bit mask for clearing web status */ + +/** + * @brief Bit mask for clearing web status. + */ #define PF_CLEAR_WEB 0b11110011 -/** Bit mask for clearing mobile status */ + +/** + * @brief Bit mask for clearing mobile status. + */ #define PF_CLEAR_MOBILE 0b11001111 -/** Bit mask for clearing main status */ + +/** + * @brief Bit mask for clearing main status. + */ #define PF_CLEAR_STATUS 0b00111111 /** * @brief Game types */ enum activity_type : uint8_t { - /// "Playing ..." + /** + * @brief "Playing ..." + */ at_game = 0, - /// "Streaming ..." + + /** + * @brief "Streaming ..." + */ at_streaming = 1, - /// "Listening to..." + + /** + * @brief "Listening to..." + */ at_listening = 2, - /// "Watching..." + + /** + * @brief "Watching..." + */ at_watching = 3, - /// "Emoji..." + + /** + * @brief "Emoji..." + */ at_custom = 4, - /// "Competing in..." + + /** + * @brief "Competing in..." + */ at_competing = 5 }; @@ -118,23 +208,49 @@ enum activity_type : uint8_t { * @brief Activity types for rich presence */ enum activity_flags { - /// In an instance + /** + * @brief In an instance. + */ af_instance = 0b000000001, - /// Joining + + /** + * @brief Joining. + */ af_join = 0b000000010, - /// Spectating + + /** + * @brief Spectating. + */ af_spectate = 0b000000100, - /// Sending join request + + /** + * @brief Sending join request. + */ af_join_request = 0b000001000, - /// Synchronising + + /** + * @brief Synchronising. + */ af_sync = 0b000010000, - /// Playing + + /** + * @brief Playing. + */ af_play = 0b000100000, - /// Party privacy friends + + /** + * @brief Party privacy friends. + */ af_party_privacy_friends = 0b001000000, - /// Party privacy voice channel + + /** + * @brief Party privacy voice channel. + */ af_party_privacy_voice_channel = 0b010000000, - /// Embedded + + /** + * @brief Embedded. + */ af_embedded = 0b100000000 }; @@ -143,10 +259,13 @@ enum activity_flags { */ struct DPP_EXPORT activity_button { public: - /** The text shown on the button (1-32 characters) + /** + * @brief The text shown on the button (1-32 characters). */ std::string label; - /** The url opened when clicking the button (1-512 characters). It's may be empty + + /** + * @brief The url opened when clicking the button (1-512 characters, can be empty). * * @note Bots cannot access the activity button URLs. */ @@ -161,16 +280,23 @@ struct DPP_EXPORT activity_button { */ struct DPP_EXPORT activity_assets { public: - /** The large asset image which usually contain snowflake ID or prefixed image ID + /** + * @brief The large asset image which usually contain snowflake ID or prefixed image ID. */ std::string large_image; - /** Text displayed when hovering over the large image of the activity + + /** + * @brief Text displayed when hovering over the large image of the activity. */ std::string large_text; - /** The small asset image which usually contain snowflake ID or prefixed image ID + + /** + * @brief The small asset image which usually contain snowflake ID or prefixed image ID. */ std::string small_image; - /** Text displayed when hovering over the small image of the activity + + /** + * @brief Text displayed when hovering over the small image of the activity. */ std::string small_text; @@ -179,17 +305,22 @@ struct DPP_EXPORT activity_assets { }; /** - * @brief Secrets for Rich Presence joining and spectating + * @brief Secrets for Rich Presence joining and spectating. */ struct DPP_EXPORT activity_secrets { public: - /** The secret for joining a party + /** + * @brief The secret for joining a party. */ std::string join; - /** The secret for spectating a game + + /** + * @brief The secret for spectating a game. */ std::string spectate; - /** The secret for a specific instanced match + + /** + * @brief The secret for a specific instanced match. */ std::string match; @@ -202,13 +333,18 @@ struct DPP_EXPORT activity_secrets { */ struct DPP_EXPORT activity_party { public: - /** The ID of the party + /** + * @brief The ID of the party. */ snowflake id; - /** The party's current size. Used to show the party's current size + + /** + * @brief The party's current size. Used to show the party's current size. */ int32_t current_size; - /** The party's maximum size. Used to show the party's maximum size + + /** + * @brief The party's maximum size. Used to show the party's maximum size. */ int32_t maximum_size; @@ -221,56 +357,85 @@ struct DPP_EXPORT activity_party { */ class DPP_EXPORT activity { public: - /** Name of activity - * e.g. "Fortnite" + /** + * @brief Name of activity (e.g. "Fortnite", "Mr Boom's Firework Factory", etc). */ std::string name; - /** State of activity or the custom user status. - * e.g. "Waiting in lobby" + + /** + * @brief State of activity or the custom user status (e.g. "Waiting in lobby"). */ std::string state; - /** What the player is currently doing + + /** + * @brief What the player is currently doing. */ std::string details; - /** Images for the presence and their hover texts + + /** + * @brief Images for the presence and their hover texts. */ activity_assets assets; - /** URL. - * Only applicable for certain sites such a YouTube - * Alias: details + + /** + * @brief URL of activity (this is also named details). + * + * @note Only applicable for certain sites such a YouTube */ std::string url; - /** The custom buttons shown in the Rich Presence (max 2) + + /** + * @brief The custom buttons shown in the Rich Presence (max 2). */ std::vector buttons; - /** The emoji used for the custom status + + /** + * @brief The emoji used for the custom status. */ dpp::emoji emoji; - /** Information of the current party if there is one + + /** + * @brief Information of the current party if there is one. */ activity_party party; - /** Secrets for rich presence joining and spectating + + /** + * @brief Secrets for rich presence joining and spectating. */ activity_secrets secrets; - /** Activity type + + /** + * @brief Activity type. */ activity_type type; - /** Time activity was created + + /** + * @brief Time activity was created. */ time_t created_at; - /** Start time. e.g. when game was started + + /** + * @brief Start time. e.g. when game was started. */ time_t start; - /** End time, e.g. for songs on spotify + + /** + * @brief End time, e.g. for songs on spotify. */ time_t end; - /** Creating application (e.g. a linked account on the user's client) + + /** + * @brief Creating application (e.g. a linked account on the user's client). */ snowflake application_id; - /** Flags bitmask from dpp::activity_flags + + /** + * @brief Flags bitmask from dpp::activity_flags. */ uint8_t flags; - /** Whether or not the activity is an instanced game session + + /** + * @brief Whether or not the activity is an instanced game session. */ bool is_instance; @@ -336,16 +501,26 @@ class DPP_EXPORT presence : public json_interface { virtual json to_json_impl(bool with_id = false) const; public: - /** The user the presence applies to */ - snowflake user_id; + /** + * @brief The user the presence applies to. + */ + snowflake user_id; - /** Guild ID. Apparently, Discord supports this internally but the client doesn't... */ - snowflake guild_id; + /** + * @brief Guild ID. + * + * @note Apparently, Discord supports this internally, but the client doesn't... + */ + snowflake guild_id; - /** Flags bitmask containing dpp::presence_flags */ - uint8_t flags; + /** + * @brief Flags bitmask containing dpp::presence_flags + */ + uint8_t flags; - /** List of activities */ + /** + * @brief List of activities + */ std::vector activities; /** Constructor */ @@ -371,27 +546,32 @@ class DPP_EXPORT presence : public json_interface { /** Destructor */ ~presence(); - /** The users status on desktop + /** + * @brief The users status on desktop * @return The user's status on desktop */ presence_status desktop_status() const; - /** The user's status on web + /** + * @brief The user's status on web * @return The user's status on web */ presence_status web_status() const; - /** The user's status on mobile + /** + * @brief The user's status on mobile * @return The user's status on mobile */ presence_status mobile_status() const; - /** The user's status as shown to other users + /** + * @brief The user's status as shown to other users * @return The user's status as shown to other users */ presence_status status() const; - /** Build JSON from this object. + /** + * @brief Build JSON from this object. * * @note This excludes any part of the presence object that are not valid for websockets and bots, * and includes websocket opcode 3. You will not get what you expect if you call this on a user's @@ -403,7 +583,9 @@ class DPP_EXPORT presence : public json_interface { json to_json(bool with_id = false) const; // Intentional shadow of json_interface, mostly present for documentation }; -/** A container of presences */ +/** + * @brief A container of presences + */ typedef std::unordered_map presence_map; } // namespace dpp diff --git a/include/dpp/prune.h b/include/dpp/prune.h index 3dc15169af..9952b841f2 100644 --- a/include/dpp/prune.h +++ b/include/dpp/prune.h @@ -48,23 +48,29 @@ struct DPP_EXPORT prune : public json_interface { public: /** - * Destroy this prune object + * @brief Destroy this prune object */ virtual ~prune() = default; - /** Number of days to include in the prune + /** + * @brief Number of days to include in the prune. */ uint32_t days = 0; - /** Roles to include in the prune (empty to include everyone) + + /** + * @brief Roles to include in the prune (empty to include everyone). */ std::vector include_roles; - /** True if the count of pruneable users should be returned - * (discord recommend not using this on big guilds) + + /** + * @brief True if the count of pruneable users should be returned. + * @warning Discord recommend not using this on big guilds. */ bool compute_prune_count; /** - * Build JSON from this object. + * @brief Build JSON from this object. + * * @param with_prune_count True if the prune count boolean is to be set in the built JSON * @return The JSON of the prune object */ diff --git a/include/dpp/queues.h b/include/dpp/queues.h index 232cbe98eb..e3f2640ed4 100644 --- a/include/dpp/queues.h +++ b/include/dpp/queues.h @@ -37,31 +37,69 @@ namespace dpp { * @brief Error values. Most of these are currently unused in https_client. */ enum http_error { - /// Request successful + /** + * @brief Request successful. + */ h_success = 0, - /// Status unknown + + /** + * @brief Status unknown. + */ h_unknown, - /// Connect failed + + /** + * @brief Connect failed. + */ h_connection, - /// Invalid local ip address + + /** + * @brief Invalid local ip address. + */ h_bind_ip_address, - /// Read error + + /** + * @brief Read error. + */ h_read, - /// Write error + + /** + * @brief Write error. + */ h_write, - /// Too many 30x redirects + + /** + * @brief Too many 30x redirects. + */ h_exceed_redirect_count, - /// Request cancelled + + /** + * @brief Request cancelled. + */ h_canceled, - /// SSL connection error + + /** + * @brief SSL connection error. + */ h_ssl_connection, - /// SSL cert loading error + + /** + * @brief SSL cert loading error. + */ h_ssl_loading_certs, - /// SSL server verification error + + /** + * @brief SSL server verification error. + */ h_ssl_server_verification, - /// Unsupported multipart boundary characters + + /** + * @brief Unsupported multipart boundary characters. + */ h_unsupported_multipart_boundary_chars, - /// Compression error + + /** + * @brief Compression error. + */ h_compression, }; @@ -70,32 +108,65 @@ enum http_error { * rate limit figures, and returned request body. */ struct DPP_EXPORT http_request_completion_t { - /** @brief HTTP headers of response */ + /** + * @brief HTTP headers of response. + */ std::multimap headers; - /** @brief HTTP status, e.g. 200 = OK, 404 = Not found, 429 = Rate limited */ + + /** + * @brief HTTP status (e.g. 200 = OK, 404 = Not found, 429 = Rate limited, etc). + */ uint16_t status = 0; - /** @brief Error status (e.g. if the request could not connect at all) */ + + /** + * @brief Error status (e.g. if the request could not connect at all). + */ http_error error = h_success; - /** @brief Ratelimit bucket */ + + /** + * @brief Ratelimit bucket. + */ std::string ratelimit_bucket; - /** @brief Ratelimit limit of requests */ + + /** + * @brief Ratelimit limit of requests. + */ uint64_t ratelimit_limit = 0; - /** @brief Ratelimit remaining requests */ + + /** + * @brief Ratelimit remaining requests. + */ uint64_t ratelimit_remaining = 0; - /** @brief Ratelimit reset after (seconds) */ + + /** + * @brief Ratelimit reset after (seconds). + */ uint64_t ratelimit_reset_after = 0; - /** @brief Ratelimit retry after (seconds) */ + + /** + * @brief Ratelimit retry after (seconds). + */ uint64_t ratelimit_retry_after = 0; - /** @brief True if this request has caused us to be globally rate limited */ + + /** + * @brief True if this request has caused us to be globally rate limited . + */ bool ratelimit_global = false; - /** @brief Reply body */ + + /** + * @brief Reply body. + */ std::string body; - /** @brief Ping latency */ + + /** + * @brief Ping latency. + */ double latency; }; /** * @brief Results of HTTP requests are called back to these std::function types. + * * @note Returned http_completion_events are called ASYNCHRONOUSLY in your * code which means they execute in a separate thread. The completion events * arrive in order. @@ -106,15 +177,29 @@ typedef std::function http_completion_ev * @brief Various types of http method supported by the Discord API */ enum http_method { - /// GET + /** + * @brief GET. + */ m_get, - /// POST + + /** + * @brief POST. + */ m_post, - /// PUT + + /** + * @brief PUT. + */ m_put, - /// PATCH + + /** + * @brief PATCH. + */ m_patch, - /// DELETE + + /** + * @brief DELETE. + */ m_delete }; @@ -129,36 +214,79 @@ enum http_method { * request_queue class. */ class DPP_EXPORT http_request { - /** @brief Completion callback */ + /** + * @brief Completion callback. + */ http_completion_event complete_handler; - /** @brief True if request has been made */ + + /** + * @brief True if request has been made. + */ bool completed; - /** @brief True for requests that are not going to discord (rate limits code skipped) */ + + /** + * @brief True for requests that are not going to discord (rate limits code skipped). + */ bool non_discord; public: - /** @brief Endpoint name e.g. /api/users */ + /** + * @brief Endpoint name e.g. /api/users. + */ std::string endpoint; - /** @brief Major and minor parameters */ + + /** + * @brief Major and minor parameters. + */ std::string parameters; - /** @brief Postdata for POST and PUT */ + + /** + * @brief Postdata for POST and PUT. + */ std::string postdata; - /** @brief HTTP method for request */ + + /** + * @brief HTTP method for request. + */ http_method method; - /** @brief Audit log reason for Discord requests, if non-empty */ + + /** + * @brief Audit log reason for Discord requests, if non-empty. + */ std::string reason; - /** @brief Upload file name (server side) */ + + /** + * @brief Upload file name (server side). + */ std::vector file_name; - /** @brief Upload file contents (binary) */ + + /** + * @brief Upload file contents (binary). + */ std::vector file_content; - /** @brief Upload file mime types (application/octet-stream if unspecified) */ + + /** + * @brief Upload file mime types (application/octet-stream if unspecified). + */ std::vector file_mimetypes; - /** @brief Request mime type */ + + /** + * @brief Request mime type. + */ std::string mimetype; - /** @brief Request headers (non-discord requests only) */ + + /** + * @brief Request headers (non-discord requests only). + */ std::multimap req_headers; - /** @brief Waiting for rate limit to expire */ + + /** + * @brief Waiting for rate limit to expire. + */ bool waiting; - /** @brief HTTP protocol */ + + /** + * @brief HTTP protocol. + */ std::string protocol; /** @@ -229,15 +357,29 @@ class DPP_EXPORT http_request { * each endpoint. */ struct DPP_EXPORT bucket_t { - /** @brief Request limit */ + /** + * @brief Request limit. + */ uint64_t limit; - /** @brief Requests remaining */ + + /** + * @brief Requests remaining. + */ uint64_t remaining; - /** @brief Ratelimit of this bucket resets after this many seconds */ + + /** + * @brief Rate-limit of this bucket resets after this many seconds. + */ uint64_t reset_after; - /** @brief Ratelimit of this bucket can be retried after this many seconds */ + + /** + * @brief Rate-limit of this bucket can be retried after this many seconds. + */ uint64_t retry_after; - /** @brief Timestamp this buckets counters were updated */ + + /** + * @brief Timestamp this buckets counters were updated. + */ time_t timestamp; }; @@ -253,47 +395,47 @@ struct DPP_EXPORT bucket_t { class DPP_EXPORT in_thread { private: /** - * @brief True if ending + * @brief True if ending. */ bool terminating; /** - * @brief Request queue that owns this in_thread + * @brief Request queue that owns this in_thread. */ class request_queue* requests; /** - * @brief The cluster that owns this in_thread + * @brief The cluster that owns this in_thread. */ class cluster* creator; /** - * @brief Inbound queue mutex thread safety + * @brief Inbound queue mutex thread safety. */ std::shared_mutex in_mutex; /** - * @brief Inbound queue thread + * @brief Inbound queue thread. */ std::thread* in_thr; /** - * @brief Inbound queue condition, signalled when there are requests to fulfill + * @brief Inbound queue condition, signalled when there are requests to fulfill. */ std::condition_variable in_ready; /** - * @brief Ratelimit bucket counters + * @brief Rate-limit bucket counters. */ std::map buckets; /** - * @brief Queue of requests to be made + * @brief Queue of requests to be made. */ std::map> requests_in; /** - * @brief Inbound queue thread loop + * @brief Inbound queue thread loop. * @param index Thread index */ void in_loop(uint32_t index); diff --git a/include/dpp/restresults.h b/include/dpp/restresults.h index a340b50ebc..e1dba02f27 100644 --- a/include/dpp/restresults.h +++ b/include/dpp/restresults.h @@ -99,22 +99,34 @@ struct DPP_EXPORT gateway : public json_interface { gateway& fill_from_json_impl(nlohmann::json* j); public: - /// Gateway websocket url + /** + * @brief Gateway websocket url. + */ std::string url; - /// Number of suggested shards to start + /** + * @brief Number of suggested shards to start. + */ uint32_t shards; - /// Total number of sessions that can be started + /** + * @brief Total number of sessions that can be started. + */ uint32_t session_start_total; - /// How many sessions are left + /** + * @brief How many sessions are left. + */ uint32_t session_start_remaining; - /// How many seconds until the session start quota resets + /** + * @brief How many seconds until the session start quota resets. + */ uint32_t session_start_reset_after; - /// How many sessions can be started at the same time + /** + * @brief How many sessions can be started at the same time. + */ uint32_t session_start_max_concurrency; /** @@ -219,18 +231,22 @@ struct DPP_EXPORT error_detail { * @brief Object name which is in error */ std::string object; + /** * @brief Field name which is in error */ std::string field; + /** * @brief Error code */ std::string code; + /** * @brief Error reason (full message) */ std::string reason; + /** * @brief Object field index */ @@ -245,15 +261,18 @@ struct DPP_EXPORT error_info { * @brief Error code */ uint32_t code = 0; + /** * @brief Error message * */ std::string message; + /** * @brief Field specific error descriptions */ std::vector errors; + /** * @brief Human readable error message constructed from the above */ @@ -264,17 +283,23 @@ struct DPP_EXPORT error_info { * @brief The results of a REST call wrapped in a convenient struct */ struct DPP_EXPORT confirmation_callback_t { - /** Information about the HTTP call used to make the request */ + /** + * @brief Information about the HTTP call used to make the request. + */ http_request_completion_t http_info; - /** Value returned, wrapped in variant */ + /** + * @brief Value returned, wrapped in variant. + */ confirmable_t value; - /** Owner/creator of the callback object */ + /** + * @brief Owner/creator of the callback object. + */ const class cluster* bot; /** - * @brief Construct a new confirmation callback t object + * @brief Construct a new confirmation callback t object. */ confirmation_callback_t() = default;