Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added endpoints to fetch a user's voice state #1294

Merged
merged 18 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
19a4aa9
fix: interaction_modal_response::fill_from_json
Commandserver May 29, 2023
5f76c80
fixed component::fill_from_json which didn't parse some fields
Commandserver May 29, 2023
8a952bf
Merge pull request #86 from brainboxdotcc/dev
Commandserver Jun 2, 2023
6139229
feat: added setter methods to dpp::invite class
Commandserver Jun 2, 2023
5b7ca81
Merge pull request #87 from brainboxdotcc/dev
Commandserver Jul 8, 2023
4815cc2
feat: added role flag `IN_PROMPT`
Commandserver Jul 15, 2023
b2efb42
Merge pull request #93 from brainboxdotcc/dev
Commandserver Jul 19, 2023
cf5e227
Merge pull request #97 from brainboxdotcc/dev
Commandserver Jul 25, 2023
18c6911
Merge pull request #99 from brainboxdotcc/dev
Commandserver Jul 27, 2023
c4a6eee
Merge pull request #102 from brainboxdotcc/dev
Commandserver Aug 20, 2023
a47753a
Merge pull request #103 from brainboxdotcc/dev
Commandserver Aug 23, 2023
717f7e5
Merge pull request #105 from brainboxdotcc/dev
Commandserver Aug 26, 2023
d588861
Merge pull request #106 from brainboxdotcc/dev
Commandserver Sep 24, 2023
20dc2f0
Merge pull request #107 from brainboxdotcc/dev
Commandserver Oct 18, 2024
ec7edbc
feat: added approximate_user_install_count field to application class
Commandserver Oct 18, 2024
53894f6
feat: added current_user_get_voice_state and user_get_voice_state end…
Commandserver Oct 19, 2024
b458345
Merge pull request #108 from brainboxdotcc/dev
Commandserver Oct 19, 2024
cc874ea
feat: create sync and coro calls
Commandserver Oct 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading