Skip to content

Commit

Permalink
feat: Added the ability to set voice channel statuses (#1064)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 authored Jan 12, 2024
1 parent 468a197 commit 3237a74
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3703,6 +3703,17 @@ class DPP_EXPORT cluster {
*/
void skus_get(command_completion_event_t callback = utility::log_error());

/**
* @brief Set the status of a voice channel.
*
* @see https://github.com/discord/discord-api-docs/pull/6400 (please replace soon).
* @param channel_id The channel to update.
* @param status The new status for the channel.
* @param callback Function to call when the API call completes.
* On success the callback will contain a dpp::confirmation 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 channel_set_voice_status(snowflake channel_id, const std::string& status, command_completion_event_t callback = utility::log_error());

#include <dpp/cluster_sync_calls.h>
#ifdef DPP_CORO
#include <dpp/cluster_coro_calls.h>
Expand Down
12 changes: 12 additions & 0 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,18 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_channels_get(snowflake guild_id);

/**
* @brief Set the status of a voice channel.
*
* @see dpp::cluster::channel_set_voice_status
* @see https://github.com/discord/discord-api-docs/pull/6400 (please replace soon).
* @param channel_id The channel to update.
* @param status The new status for the channel.
* @return confirmation returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_channel_set_voice_status(snowflake channel_id, const std::string& status);

/**
* @brief Create a dm channel
* @see dpp::cluster::create_dm_channel
Expand Down
15 changes: 15 additions & 0 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,21 @@ confirmation channel_typing_sync(snowflake cid);
*/
channel_map channels_get_sync(snowflake guild_id);

/**
* @brief Set the status of a voice channel.
*
* @see dpp::cluster::channel_set_voice_status
* @see https://github.com/discord/discord-api-docs/pull/6400 (please replace soon).
* @param channel_id The channel to update.
* @param status The new status for the channel.
* @return confirmation returned object on completion
* \memberof dpp::cluster
* @throw dpp::rest_exception upon failure to execute REST function
* @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.
*/
confirmation channel_set_voice_status_sync(snowflake channel_id, const std::string& status);

/**
* @brief Create a dm channel
* @see dpp::cluster::create_dm_channel
Expand Down
5 changes: 5 additions & 0 deletions src/dpp/cluster/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,9 @@ void cluster::channels_get(snowflake guild_id, command_completion_event_t callba
rest_request_list<channel>(this, API_PATH "/guilds", std::to_string(guild_id), "channels", m_get, "", callback);
}

void cluster::channel_set_voice_status(snowflake channel_id, const std::string& status, command_completion_event_t callback) {
json j({ {"status", status} });
rest_request<confirmation>(this, API_PATH "/channels", std::to_string(channel_id), "voice-status", m_put, j.dump(), callback);
}

} // namespace dpp
4 changes: 4 additions & 0 deletions src/dpp/cluster_coro_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ async<confirmation_callback_t> cluster::co_channels_get(snowflake guild_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::channels_get), guild_id };
}

async<confirmation_callback_t> cluster::co_channel_set_voice_status(snowflake channel_id, const std::string& status) {
return async{ this, static_cast<void (cluster::*)(snowflake, const std::string&, command_completion_event_t)>(&cluster::channel_set_voice_status), channel_id, status };
}

async<confirmation_callback_t> cluster::co_create_dm_channel(snowflake user_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::create_dm_channel), user_id };
}
Expand Down
4 changes: 4 additions & 0 deletions src/dpp/cluster_sync_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ channel_map cluster::channels_get_sync(snowflake guild_id) {
return dpp::sync<channel_map>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::channels_get), guild_id);
}

confirmation cluster::channel_set_voice_status_sync(snowflake channel_id, const std::string& status) {
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(snowflake, const std::string&, command_completion_event_t)>(&cluster::channel_set_voice_status), channel_id, status);
}

channel cluster::create_dm_channel_sync(snowflake user_id) {
return dpp::sync<channel>(this, static_cast<void (cluster::*)(snowflake, command_completion_event_t)>(&cluster::create_dm_channel), user_id);
}
Expand Down

0 comments on commit 3237a74

Please sign in to comment.