From 97294b4798f1c3d5b6a87947b026b2b588c327de Mon Sep 17 00:00:00 2001 From: AA1999 Date: Sun, 21 Jan 2024 17:34:56 +0330 Subject: [PATCH 1/6] Added dpp::cluster::guild_member_timeout_remove and its sync/coro versions 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. --- include/dpp/cluster.h | 13 +++++++++++++ include/dpp/cluster_coro_calls.h | 14 ++++++++++++++ include/dpp/cluster_sync_calls.h | 17 +++++++++++++++++ src/dpp/cluster/guild_member.cpp | 4 ++++ src/dpp/cluster_coro_calls.cpp | 4 ++++ src/dpp/cluster_sync_calls.cpp | 5 +++++ 6 files changed, 57 insertions(+) diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index eb275d96bf..45b79dd0ea 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -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 * diff --git a/include/dpp/cluster_coro_calls.h b/include/dpp/cluster_coro_calls.h index 21431c9dfa..5ba256c101 100644 --- a/include/dpp/cluster_coro_calls.h +++ b/include/dpp/cluster_coro_calls.h @@ -1236,6 +1236,20 @@ */ [[nodiscard]] async 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 co_guild_member_timeout_remove(snowflake guild_id, snowflake user_id); + /** * @brief Remove role from guild member * diff --git a/include/dpp/cluster_sync_calls.h b/include/dpp/cluster_sync_calls.h index 140b9ba5a1..2ecdbbc73d 100644 --- a/include/dpp/cluster_sync_calls.h +++ b/include/dpp/cluster_sync_calls.h @@ -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 * diff --git a/src/dpp/cluster/guild_member.cpp b/src/dpp/cluster/guild_member.cpp index e851e9c7ad..2533895203 100644 --- a/src/dpp/cluster/guild_member.cpp +++ b/src/dpp/cluster/guild_member.cpp @@ -96,6 +96,10 @@ void cluster::guild_member_timeout(snowflake guild_id, snowflake user_id, time_t rest_request(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(this, API_PATH "/guilds", std::to_string(guild_id), "members/" + std::to_string(user_id) + "/roles/" + std::to_string(role_id), m_delete, "", callback); diff --git a/src/dpp/cluster_coro_calls.cpp b/src/dpp/cluster_coro_calls.cpp index 28f0eca82a..20e9119cc3 100644 --- a/src/dpp/cluster_coro_calls.cpp +++ b/src/dpp/cluster_coro_calls.cpp @@ -411,6 +411,10 @@ async cluster::co_guild_member_timeout(snowflake guild_ return async{ this, static_cast(&cluster::guild_member_timeout), guild_id, user_id, communication_disabled_until }; } +async cluster::co_guild_member_timeout(snowflake guild_id, snowflake user_id) { + return co_guild_member_timeout_remove(guild_id, user_id, 0); +} + async cluster::co_guild_member_delete_role(snowflake guild_id, snowflake user_id, snowflake role_id) { return async{ this, static_cast(&cluster::guild_member_delete_role), guild_id, user_id, role_id }; } diff --git a/src/dpp/cluster_sync_calls.cpp b/src/dpp/cluster_sync_calls.cpp index 876c0d0327..cdc885a863 100644 --- a/src/dpp/cluster_sync_calls.cpp +++ b/src/dpp/cluster_sync_calls.cpp @@ -409,6 +409,11 @@ confirmation cluster::guild_member_timeout_sync(snowflake guild_id, snowflake us return dpp::sync(this, static_cast(&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(this, static_cast(&cluster::guild_member_delete_role), guild_id, user_id, role_id); } From c90e444aa303cf54a090a82c7be50873a51748c2 Mon Sep 17 00:00:00 2001 From: AA1999 Date: Sun, 21 Jan 2024 17:50:59 +0330 Subject: [PATCH 2/6] Fixed one compilation error that wasn't caught on the compiler for some reason (assuming because DPP_CORO wasn't on) --- src/dpp/cluster_coro_calls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpp/cluster_coro_calls.cpp b/src/dpp/cluster_coro_calls.cpp index 20e9119cc3..fd89cc00e5 100644 --- a/src/dpp/cluster_coro_calls.cpp +++ b/src/dpp/cluster_coro_calls.cpp @@ -412,7 +412,7 @@ async cluster::co_guild_member_timeout(snowflake guild_ } async cluster::co_guild_member_timeout(snowflake guild_id, snowflake user_id) { - return co_guild_member_timeout_remove(guild_id, user_id, 0); + return co_guild_member_timeout(guild_id, user_id, 0); } async cluster::co_guild_member_delete_role(snowflake guild_id, snowflake user_id, snowflake role_id) { From db8a858bbe333b78bf845653eebc9fadf0e9376a Mon Sep 17 00:00:00 2001 From: AA1999 Date: Sun, 21 Jan 2024 17:52:15 +0330 Subject: [PATCH 3/6] Fixed another stupid mistake, this should be all --- src/dpp/cluster_coro_calls.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpp/cluster_coro_calls.cpp b/src/dpp/cluster_coro_calls.cpp index fd89cc00e5..b07d75e8e7 100644 --- a/src/dpp/cluster_coro_calls.cpp +++ b/src/dpp/cluster_coro_calls.cpp @@ -411,7 +411,7 @@ async cluster::co_guild_member_timeout(snowflake guild_ return async{ this, static_cast(&cluster::guild_member_timeout), guild_id, user_id, communication_disabled_until }; } -async cluster::co_guild_member_timeout(snowflake guild_id, snowflake user_id) { +async cluster::co_guild_member_timeout_remove(snowflake guild_id, snowflake user_id) { return co_guild_member_timeout(guild_id, user_id, 0); } From f9b64438f35168f6e40d471aba37b3c4bb12a5d9 Mon Sep 17 00:00:00 2001 From: AA1999 Date: Wed, 24 Jan 2024 00:09:34 +0330 Subject: [PATCH 4/6] Since they're auto-generated, removed the sync and coro variants. --- include/dpp/cluster_coro_calls.h | 14 -------------- include/dpp/cluster_sync_calls.h | 17 ----------------- src/dpp/cluster_coro_calls.cpp | 4 ---- src/dpp/cluster_sync_calls.cpp | 4 ---- 4 files changed, 39 deletions(-) diff --git a/include/dpp/cluster_coro_calls.h b/include/dpp/cluster_coro_calls.h index 5ba256c101..21431c9dfa 100644 --- a/include/dpp/cluster_coro_calls.h +++ b/include/dpp/cluster_coro_calls.h @@ -1236,20 +1236,6 @@ */ [[nodiscard]] async 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 co_guild_member_timeout_remove(snowflake guild_id, snowflake user_id); - /** * @brief Remove role from guild member * diff --git a/include/dpp/cluster_sync_calls.h b/include/dpp/cluster_sync_calls.h index 2ecdbbc73d..140b9ba5a1 100644 --- a/include/dpp/cluster_sync_calls.h +++ b/include/dpp/cluster_sync_calls.h @@ -1512,23 +1512,6 @@ 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 * diff --git a/src/dpp/cluster_coro_calls.cpp b/src/dpp/cluster_coro_calls.cpp index b07d75e8e7..28f0eca82a 100644 --- a/src/dpp/cluster_coro_calls.cpp +++ b/src/dpp/cluster_coro_calls.cpp @@ -411,10 +411,6 @@ async cluster::co_guild_member_timeout(snowflake guild_ return async{ this, static_cast(&cluster::guild_member_timeout), guild_id, user_id, communication_disabled_until }; } -async cluster::co_guild_member_timeout_remove(snowflake guild_id, snowflake user_id) { - return co_guild_member_timeout(guild_id, user_id, 0); -} - async cluster::co_guild_member_delete_role(snowflake guild_id, snowflake user_id, snowflake role_id) { return async{ this, static_cast(&cluster::guild_member_delete_role), guild_id, user_id, role_id }; } diff --git a/src/dpp/cluster_sync_calls.cpp b/src/dpp/cluster_sync_calls.cpp index cdc885a863..fd070d293d 100644 --- a/src/dpp/cluster_sync_calls.cpp +++ b/src/dpp/cluster_sync_calls.cpp @@ -409,10 +409,6 @@ confirmation cluster::guild_member_timeout_sync(snowflake guild_id, snowflake us return dpp::sync(this, static_cast(&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(this, static_cast(&cluster::guild_member_delete_role), guild_id, user_id, role_id); From 55e8a739a3dde0ae15c37c1ef722ab8741f4f6d1 Mon Sep 17 00:00:00 2001 From: AA1999 Date: Wed, 24 Jan 2024 00:21:42 +0330 Subject: [PATCH 5/6] Removed extra function call because it must use a specific forma. --- src/dpp/cluster/guild_member.cpp | 4 +++- src/dpp/cluster_sync_calls.cpp | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dpp/cluster/guild_member.cpp b/src/dpp/cluster/guild_member.cpp index 2533895203..5921d5a2b1 100644 --- a/src/dpp/cluster/guild_member.cpp +++ b/src/dpp/cluster/guild_member.cpp @@ -97,7 +97,9 @@ void cluster::guild_member_timeout(snowflake guild_id, snowflake user_id, time_t } 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); + json j; + j["communication_disabled_until"] = json::value_t::null; + rest_request(this, API_PATH "/guilds", std::to_string(guild_id), "members/" + std::to_string(user_id), m_patch, j.dump(), callback); } diff --git a/src/dpp/cluster_sync_calls.cpp b/src/dpp/cluster_sync_calls.cpp index fd070d293d..876c0d0327 100644 --- a/src/dpp/cluster_sync_calls.cpp +++ b/src/dpp/cluster_sync_calls.cpp @@ -409,7 +409,6 @@ confirmation cluster::guild_member_timeout_sync(snowflake guild_id, snowflake us return dpp::sync(this, static_cast(&cluster::guild_member_timeout), guild_id, user_id, communication_disabled_until); } - confirmation cluster::guild_member_delete_role_sync(snowflake guild_id, snowflake user_id, snowflake role_id) { return dpp::sync(this, static_cast(&cluster::guild_member_delete_role), guild_id, user_id, role_id); } From 24385b5ac7779d5195a946db1071d440ab50746a Mon Sep 17 00:00:00 2001 From: AA1999 Date: Wed, 24 Jan 2024 15:01:26 +0330 Subject: [PATCH 6/6] Updated cluster.h timestamp so that the autogenerated files will be autogenerated --- include/dpp/cluster_coro_calls.h | 14 ++++++++++++++ include/dpp/cluster_sync_calls.h | 17 +++++++++++++++++ src/dpp/cluster_coro_calls.cpp | 4 ++++ src/dpp/cluster_sync_calls.cpp | 4 ++++ 4 files changed, 39 insertions(+) diff --git a/include/dpp/cluster_coro_calls.h b/include/dpp/cluster_coro_calls.h index 21431c9dfa..018af88503 100644 --- a/include/dpp/cluster_coro_calls.h +++ b/include/dpp/cluster_coro_calls.h @@ -1236,6 +1236,20 @@ */ [[nodiscard]] async co_guild_member_timeout(snowflake guild_id, snowflake user_id, time_t communication_disabled_until); +/** + * @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 dpp::cluster::guild_member_timeout_remove + * @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 + * @return confirmation returned object on completion + * \memberof dpp::cluster + */ +[[nodiscard]] async co_guild_member_timeout_remove(snowflake guild_id, snowflake user_id); + /** * @brief Remove role from guild member * diff --git a/include/dpp/cluster_sync_calls.h b/include/dpp/cluster_sync_calls.h index 140b9ba5a1..6764719a83 100644 --- a/include/dpp/cluster_sync_calls.h +++ b/include/dpp/cluster_sync_calls.h @@ -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. + * A shortcut for guild_member_timeout(guild_id, user_id, 0, callback) + * Fires a `Guild Member Update` Gateway event. + * @see dpp::cluster::guild_member_timeout_remove + * @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 + * @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 * diff --git a/src/dpp/cluster_coro_calls.cpp b/src/dpp/cluster_coro_calls.cpp index 28f0eca82a..5f8ae7b971 100644 --- a/src/dpp/cluster_coro_calls.cpp +++ b/src/dpp/cluster_coro_calls.cpp @@ -411,6 +411,10 @@ async cluster::co_guild_member_timeout(snowflake guild_ return async{ this, static_cast(&cluster::guild_member_timeout), guild_id, user_id, communication_disabled_until }; } +async cluster::co_guild_member_timeout_remove(snowflake guild_id, snowflake user_id) { + return async{ this, static_cast(&cluster::guild_member_timeout_remove), guild_id, user_id }; +} + async cluster::co_guild_member_delete_role(snowflake guild_id, snowflake user_id, snowflake role_id) { return async{ this, static_cast(&cluster::guild_member_delete_role), guild_id, user_id, role_id }; } diff --git a/src/dpp/cluster_sync_calls.cpp b/src/dpp/cluster_sync_calls.cpp index 876c0d0327..a19ec593fc 100644 --- a/src/dpp/cluster_sync_calls.cpp +++ b/src/dpp/cluster_sync_calls.cpp @@ -409,6 +409,10 @@ confirmation cluster::guild_member_timeout_sync(snowflake guild_id, snowflake us return dpp::sync(this, static_cast(&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 dpp::sync(this, static_cast(&cluster::guild_member_timeout_remove), guild_id, user_id); +} + confirmation cluster::guild_member_delete_role_sync(snowflake guild_id, snowflake user_id, snowflake role_id) { return dpp::sync(this, static_cast(&cluster::guild_member_delete_role), guild_id, user_id, role_id); }