Skip to content

Commit

Permalink
Added dpp::cluster::guild_member_timeout_remove and its sync/coro ver…
Browse files Browse the repository at this point in the history
…sions which is just a shortcut of the normal dpp::cluster::guild_member_timeout with the communication_disable_until variable set to 0. This is added for user convenience. Also added documentation for all versions.
  • Loading branch information
AA1999 committed Jan 21, 2024
1 parent 3237a74 commit 97294b4
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -2389,6 +2389,19 @@ class DPP_EXPORT cluster {
*/
void guild_member_timeout(snowflake guild_id, snowflake user_id, time_t communication_disabled_until, command_completion_event_t callback = utility::log_error());

/**
* @brief Remove the timeout of a guild member.
* A shortcut for guild_member_timeout(guild_id, user_id, 0, callback)
* Fires a `Guild Member Update` Gateway event.
* @see https://discord.com/developers/docs/resources/guild#modify-guild-member
* @note This method supports audit log reasons set by the cluster::set_audit_reason() method.
* @param guild_id Guild ID to remove the member timeout from
* @param user_id User ID to remove the timeout for
* @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 guild_member_timeout_remove(snowflake guild_id, snowflake user_id, command_completion_event_t callback = utility::log_error());

/**
* @brief Add guild ban
*
Expand Down
14 changes: 14 additions & 0 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,20 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_guild_member_timeout(snowflake guild_id, snowflake user_id, time_t communication_disabled_until);

/**
* @brief Remove the timeout of a guild member
* Shortcut to co_guild_member_timeout(guild_id, user_id, 0)
* Fires a `Guild Member Update` Gateway event.
* @see dpp::cluster::guild_member_timeout
* @see https://discord.com/developers/docs/resources/guild#modify-guild-member
* @note This method supports audit log reasons set by the cluster::set_audit_reason() method.
* @param guild_id Guild ID remove the member timeout from
* @param user_id User ID to remove the timeout for
* @return confirmation returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_guild_member_timeout_remove(snowflake guild_id, snowflake user_id);

/**
* @brief Remove role from guild member
*
Expand Down
17 changes: 17 additions & 0 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -1512,6 +1512,23 @@ confirmation guild_member_kick_sync(snowflake guild_id, snowflake user_id);
*/
confirmation guild_member_timeout_sync(snowflake guild_id, snowflake user_id, time_t communication_disabled_until);

/**
* @brief Remove the timeout of a guild member
* Shortcut for guild_member_timeout_sync(guild_id, user_id, 0)
* Fires a `Guild Member Update` Gateway event.
* @see dpp::cluster::guild_member_timeout
* @see https://discord.com/developers/docs/resources/guild#modify-guild-member
* @note This method supports audit log reasons set by the cluster::set_audit_reason() method.
* @param guild_id Guild ID to remove timeout from the member in
* @param user_id User ID to set the timeout for
* @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 guild_member_timeout_remove_sync(snowflake guild_id, snowflake user_id);

/**
* @brief Remove role from guild member
*
Expand Down
4 changes: 4 additions & 0 deletions src/dpp/cluster/guild_member.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ void cluster::guild_member_timeout(snowflake guild_id, snowflake user_id, time_t
rest_request<confirmation>(this, API_PATH "/guilds", std::to_string(guild_id), "members/" + std::to_string(user_id), m_patch, j.dump(), callback);
}

void cluster::guild_member_timeout_remove(snowflake guild_id, snowflake user_id, command_completion_event_t callback) {
guild_member_timeout(guild_id, user_id, 0, callback);
}


void cluster::guild_member_delete_role(snowflake guild_id, snowflake user_id, snowflake role_id, command_completion_event_t callback) {
rest_request<confirmation>(this, API_PATH "/guilds", std::to_string(guild_id), "members/" + std::to_string(user_id) + "/roles/" + std::to_string(role_id), m_delete, "", callback);
Expand Down
4 changes: 4 additions & 0 deletions src/dpp/cluster_coro_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ async<confirmation_callback_t> cluster::co_guild_member_timeout(snowflake guild_
return async{ this, static_cast<void (cluster::*)(snowflake, snowflake, time_t, command_completion_event_t)>(&cluster::guild_member_timeout), guild_id, user_id, communication_disabled_until };
}

async<confirmation_callback_t> cluster::co_guild_member_timeout(snowflake guild_id, snowflake user_id) {
return co_guild_member_timeout_remove(guild_id, user_id, 0);
}

async<confirmation_callback_t> cluster::co_guild_member_delete_role(snowflake guild_id, snowflake user_id, snowflake role_id) {
return async{ this, static_cast<void (cluster::*)(snowflake, snowflake, snowflake, command_completion_event_t)>(&cluster::guild_member_delete_role), guild_id, user_id, role_id };
}
Expand Down
5 changes: 5 additions & 0 deletions src/dpp/cluster_sync_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ confirmation cluster::guild_member_timeout_sync(snowflake guild_id, snowflake us
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(snowflake, snowflake, time_t, command_completion_event_t)>(&cluster::guild_member_timeout), guild_id, user_id, communication_disabled_until);
}

confirmation cluster::guild_member_timeout_remove_sync(snowflake guild_id, snowflake user_id) {
return guild_member_timeout_sync(guild_id, user_id, 0);
}


confirmation cluster::guild_member_delete_role_sync(snowflake guild_id, snowflake user_id, snowflake role_id) {
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(snowflake, snowflake, snowflake, command_completion_event_t)>(&cluster::guild_member_delete_role), guild_id, user_id, role_id);
}
Expand Down

0 comments on commit 97294b4

Please sign in to comment.