Skip to content

Commit

Permalink
feat: added endpoints to fetch a user's voice state (#1294)
Browse files Browse the repository at this point in the history
  • Loading branch information
Commandserver authored Oct 19, 2024
1 parent 73c4751 commit 71ae2c4
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 6 deletions.
25 changes: 23 additions & 2 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3662,7 +3662,7 @@ class DPP_EXPORT cluster {

/**
* @brief Get all guild stickers
* @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
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::sticker_map object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
Expand All @@ -3671,7 +3671,7 @@ class DPP_EXPORT cluster {

/**
* @brief Get a list of available sticker packs
* @see https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs
* @see https://discord.com/developers/docs/resources/sticker#list-sticker-packs
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::sticker_pack_map object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
Expand Down Expand Up @@ -3821,6 +3821,16 @@ class DPP_EXPORT cluster {
*/
void current_user_set_voice_state(snowflake guild_id, snowflake channel_id, bool suppress = false, time_t request_to_speak_timestamp = 0, command_completion_event_t callback = utility::log_error());

/**
* @brief Get the bot's voice state in a guild without a Gateway connection
*
* @see https://discord.com/developers/docs/resources/voice#get-current-user-voice-state
* @param guild_id Guild to get the voice state for
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::voicestate object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void current_user_get_voice_state(snowflake guild_id, command_completion_event_t callback);

/**
* @brief Set a user's voice state on a stage channel
*
Expand All @@ -3844,6 +3854,17 @@ class DPP_EXPORT cluster {
*/
void user_set_voice_state(snowflake user_id, snowflake guild_id, snowflake channel_id, bool suppress = false, command_completion_event_t callback = utility::log_error());

/**
* @brief Get a user's voice state in a guild without a Gateway connection
*
* @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
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::voicestate object in confirmation_callback_t::value. On failure, the value is undefined and confirmation_callback_t::is_error() method will return true. You can obtain full error details with confirmation_callback_t::get_error().
*/
void user_get_voice_state(snowflake guild_id, snowflake user_id, command_completion_event_t callback);

/**
* @brief Get all auto moderation rules for a guild
*
Expand Down
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/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ void cluster::current_user_set_voice_state(snowflake guild_id, snowflake channel
rest_request<confirmation>(this, API_PATH "/guilds", std::to_string(guild_id), "/voice-states/@me", m_patch, j.dump(-1, ' ', false, json::error_handler_t::replace), callback);
}

void cluster::current_user_get_voice_state(snowflake guild_id, command_completion_event_t callback) {
rest_request<voicestate>(this, API_PATH "/guilds", std::to_string(guild_id), "/voice-states/@me", m_get, "", callback);
}

void cluster::user_set_voice_state(snowflake user_id, snowflake guild_id, snowflake channel_id, bool suppress, command_completion_event_t callback) {
json j({
{"channel_id", channel_id},
Expand All @@ -89,6 +93,10 @@ void cluster::user_set_voice_state(snowflake user_id, snowflake guild_id, snowfl
rest_request<confirmation>(this, API_PATH "/guilds", std::to_string(guild_id), "/voice-states/" + std::to_string(user_id), m_patch, j.dump(-1, ' ', false, json::error_handler_t::replace), callback);
}

void cluster::user_get_voice_state(snowflake guild_id, snowflake user_id, command_completion_event_t callback) {
rest_request<voicestate>(this, API_PATH "/guilds", std::to_string(guild_id), "/voice-states/" + std::to_string(user_id), m_get, "", callback);
}

void cluster::current_user_connections_get(command_completion_event_t callback) {
rest_request_list<connection>(this, API_PATH "/users", "@me", "connections", m_get, "", callback);
}
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 71ae2c4

Please sign in to comment.