Skip to content

Commit

Permalink
feat: create sync and coro calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandserver committed Oct 19, 2024
1 parent b458345 commit cc874ea
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
27 changes: 25 additions & 2 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2009,7 +2009,7 @@
/**
* @brief Get all guild stickers
* @see dpp::cluster::guild_stickers_get
* @see https://discord.com/developers/docs/resources/sticker#get-guild-stickers
* @see https://discord.com/developers/docs/resources/sticker#list-guild-stickers
* @param guild_id Guild ID of the guild where the sticker is
* @return sticker_map returned object on completion
* \memberof dpp::cluster
Expand All @@ -2029,7 +2029,7 @@
/**
* @brief Get a list of available sticker packs
* @see dpp::cluster::sticker_packs_get
* @see https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs
* @see https://discord.com/developers/docs/resources/sticker#list-sticker-packs
* @return sticker_pack_map returned object on completion
* \memberof dpp::cluster
*/
Expand Down Expand Up @@ -2367,6 +2367,17 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_current_user_set_voice_state(snowflake guild_id, snowflake channel_id, bool suppress = false, time_t request_to_speak_timestamp = 0);

/**
* @brief Get the bot's voice state in a guild without a Gateway connection
*
* @see dpp::cluster::current_user_get_voice_state
* @see https://discord.com/developers/docs/resources/voice#get-current-user-voice-state
* @param guild_id Guild to get the voice state for
* @return voicestate returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_current_user_get_voice_state(snowflake guild_id);

/**
* @brief Set a user's voice state on a stage channel
*
Expand All @@ -2391,6 +2402,18 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_user_set_voice_state(snowflake user_id, snowflake guild_id, snowflake channel_id, bool suppress = false);

/**
* @brief Get a user's voice state in a guild without a Gateway connection
*
* @see dpp::cluster::user_get_voice_state
* @see https://discord.com/developers/docs/resources/voice#get-user-voice-state
* @param guild_id Guild to get the voice state for
* @param user_id The user to get the voice state of
* @return voicestate returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_user_get_voice_state(snowflake guild_id, snowflake user_id);

/**
* @brief Get current user's connections (linked accounts, e.g. steam, xbox).
* This call requires the oauth2 `connections` scope and cannot be executed
Expand Down
35 changes: 33 additions & 2 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,7 @@ DPP_DEPRECATED("Please use coroutines instead of sync functions: https://dpp.dev
/**
* @brief Get all guild stickers
* @see dpp::cluster::guild_stickers_get
* @see https://discord.com/developers/docs/resources/sticker#get-guild-stickers
* @see https://discord.com/developers/docs/resources/sticker#list-guild-stickers
* @param guild_id Guild ID of the guild where the sticker is
* @return sticker_map returned object on completion
* \memberof dpp::cluster
Expand Down Expand Up @@ -2649,7 +2649,7 @@ DPP_DEPRECATED("Please use coroutines instead of sync functions: https://dpp.dev
/**
* @brief Get a list of available sticker packs
* @see dpp::cluster::sticker_packs_get
* @see https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs
* @see https://discord.com/developers/docs/resources/sticker#list-sticker-packs
* @return sticker_pack_map returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
Expand Down Expand Up @@ -3095,6 +3095,21 @@ DPP_DEPRECATED("Please use coroutines instead of sync functions: https://dpp.dev
*/
DPP_DEPRECATED("Please use coroutines instead of sync functions: https://dpp.dev/coro-introduction.html") confirmation current_user_set_voice_state_sync(snowflake guild_id, snowflake channel_id, bool suppress = false, time_t request_to_speak_timestamp = 0);

/**
* @brief Get the bot's voice state in a guild without a Gateway connection
*
* @see dpp::cluster::current_user_get_voice_state
* @see https://discord.com/developers/docs/resources/voice#get-current-user-voice-state
* @param guild_id Guild to get the voice state for
* @return voicestate returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @deprecated This function is deprecated, please use coroutines instead.
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
DPP_DEPRECATED("Please use coroutines instead of sync functions: https://dpp.dev/coro-introduction.html") voicestate current_user_get_voice_state_sync(snowflake guild_id);

/**
* @brief Set a user's voice state on a stage channel
*
Expand Down Expand Up @@ -3123,6 +3138,22 @@ DPP_DEPRECATED("Please use coroutines instead of sync functions: https://dpp.dev
*/
DPP_DEPRECATED("Please use coroutines instead of sync functions: https://dpp.dev/coro-introduction.html") confirmation user_set_voice_state_sync(snowflake user_id, snowflake guild_id, snowflake channel_id, bool suppress = false);

/**
* @brief Get a user's voice state in a guild without a Gateway connection
*
* @see dpp::cluster::user_get_voice_state
* @see https://discord.com/developers/docs/resources/voice#get-user-voice-state
* @param guild_id Guild to get the voice state for
* @param user_id The user to get the voice state of
* @return voicestate returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @deprecated This function is deprecated, please use coroutines instead.
* @warning This function is a blocking (synchronous) call and should only be used from within a separate thread.
* Avoid direct use of this function inside an event handler.
*/
DPP_DEPRECATED("Please use coroutines instead of sync functions: https://dpp.dev/coro-introduction.html") voicestate user_get_voice_state_sync(snowflake guild_id, snowflake user_id);

/**
* @brief Get current user's connections (linked accounts, e.g. steam, xbox).
* This call requires the oauth2 `connections` scope and cannot be executed
Expand Down
1 change: 1 addition & 0 deletions include/dpp/restresults.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ typedef std::variant<
ban_map,
voiceregion,
voiceregion_map,
voicestate,
integration,
integration_map,
webhook,
Expand Down
8 changes: 8 additions & 0 deletions src/dpp/cluster_coro_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,18 @@ async<confirmation_callback_t> cluster::co_current_user_set_voice_state(snowflak
return async{ this, static_cast<void (cluster::*)(snowflake, snowflake, bool, time_t, command_completion_event_t)>(&cluster::current_user_set_voice_state), guild_id, channel_id, suppress, request_to_speak_timestamp };
}

async<confirmation_callback_t> cluster::co_current_user_get_voice_state(snowflake guild_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::current_user_get_voice_state), guild_id };
}

async<confirmation_callback_t> cluster::co_user_set_voice_state(snowflake user_id, snowflake guild_id, snowflake channel_id, bool suppress) {
return async{ this, static_cast<void (cluster::*)(snowflake, snowflake, snowflake, bool, command_completion_event_t)>(&cluster::user_set_voice_state), user_id, guild_id, channel_id, suppress };
}

async<confirmation_callback_t> cluster::co_user_get_voice_state(snowflake guild_id, snowflake user_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, snowflake, command_completion_event_t)>(&cluster::user_get_voice_state), guild_id, user_id };
}

async<confirmation_callback_t> cluster::co_current_user_connections_get() {
return async{ this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::current_user_connections_get) };
}
Expand Down
8 changes: 8 additions & 0 deletions src/dpp/cluster_sync_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,10 +781,18 @@ confirmation cluster::current_user_set_voice_state_sync(snowflake guild_id, snow
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(snowflake, snowflake, bool, time_t, command_completion_event_t)>(&cluster::current_user_set_voice_state), guild_id, channel_id, suppress, request_to_speak_timestamp);
}

voicestate cluster::current_user_get_voice_state_sync(snowflake guild_id) {
return dpp::sync<voicestate>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::current_user_get_voice_state), guild_id);
}

confirmation cluster::user_set_voice_state_sync(snowflake user_id, snowflake guild_id, snowflake channel_id, bool suppress) {
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(snowflake, snowflake, snowflake, bool, command_completion_event_t)>(&cluster::user_set_voice_state), user_id, guild_id, channel_id, suppress);
}

voicestate cluster::user_get_voice_state_sync(snowflake guild_id, snowflake user_id) {
return dpp::sync<voicestate>(this, static_cast<void (cluster::*)(snowflake, snowflake, command_completion_event_t)>(&cluster::user_get_voice_state), guild_id, user_id);
}

connection_map cluster::current_user_connections_get_sync() {
return dpp::sync<connection_map>(this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::current_user_connections_get));
}
Expand Down

0 comments on commit cc874ea

Please sign in to comment.