From 77a2e6dab0e4353f91b6dae501584bf31b7e4bc5 Mon Sep 17 00:00:00 2001 From: Phil B Date: Thu, 9 Jun 2022 23:30:36 +0200 Subject: [PATCH 1/3] deprecated cluster::guild_ban_add with reason param. Added a similar method without this reason param. --- include/dpp/cluster.h | 18 +++++++++++++++++- src/dpp/cluster/guild.cpp | 10 ++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index af90b6a3ed..8dc873d12b 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -2495,10 +2495,26 @@ class DPP_EXPORT cluster { * @param delete_message_days How many days of their user's messages to also delete * @param reason Reason for ban * @param callback Function to call when the API call completes. - * On success the callback will contain a dpp::ban 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(). + * 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(). + * @deprecated Discord deprecated the reason parameter in the json body. Use the similar method to this without the reason param and use cluster::set_audit_log_reason() to set the reason. */ void guild_ban_add(snowflake guild_id, snowflake user_id, uint32_t delete_message_days, const std::string &reason, command_completion_event_t callback = utility::log_error()); + /** + * @brief Add guild ban + * + * Create a guild ban, and optionally delete previous messages sent by the banned user. + * Requires the `BAN_MEMBERS` permission. Fires a `Guild Ban Add` Gateway event. + * @see https://discord.com/developers/docs/resources/guild#create-guild-ban + * @note This method supports audit log reasons set by the cluster::set_audit_reason() method. + * @param guild_id Guild ID to add ban to + * @param user_id User ID to ban + * @param delete_message_days How many days of their user's messages to also delete (0-7). Defaults to 0 + * @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_ban_add(snowflake guild_id, snowflake user_id, uint32_t delete_message_days = 0, command_completion_event_t callback = utility::log_error()); + /** * @brief Delete guild ban * diff --git a/src/dpp/cluster/guild.cpp b/src/dpp/cluster/guild.cpp index 6399e049cf..83b0e1d997 100644 --- a/src/dpp/cluster/guild.cpp +++ b/src/dpp/cluster/guild.cpp @@ -44,6 +44,16 @@ void cluster::guild_ban_add(snowflake guild_id, snowflake user_id, uint32_t dele } +void cluster::guild_ban_add(snowflake guild_id, snowflake user_id, uint32_t delete_message_days, command_completion_event_t callback) { + json j; + if (delete_message_days > 7) + delete_message_days = 7; + if (delete_message_days) + j["delete_message_days"] = delete_message_days; + rest_request(this, API_PATH "/guilds", std::to_string(guild_id), "bans/" + std::to_string(user_id), m_put, j.dump(), callback); +} + + void cluster::guild_ban_delete(snowflake guild_id, snowflake user_id, command_completion_event_t callback) { rest_request(this, API_PATH "/guilds", std::to_string(guild_id), "bans/" + std::to_string(user_id), m_delete, "", callback); } From 005b42eb03927ce0542150cb36eb6e54f3489036 Mon Sep 17 00:00:00 2001 From: Phil B Date: Thu, 9 Jun 2022 23:30:59 +0200 Subject: [PATCH 2/3] fix cluster::guild_begin_prune --- src/dpp/cluster/guild.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dpp/cluster/guild.cpp b/src/dpp/cluster/guild.cpp index 83b0e1d997..bea3a7f91f 100644 --- a/src/dpp/cluster/guild.cpp +++ b/src/dpp/cluster/guild.cpp @@ -133,7 +133,7 @@ void cluster::guild_get_prune_counts(snowflake guild_id, const struct prune& pru } void cluster::guild_begin_prune(snowflake guild_id, const struct prune& pruneinfo, command_completion_event_t callback) { - rest_request(this, API_PATH "/guilds", std::to_string(guild_id), "prune", m_get, pruneinfo.build_json(true), callback); + rest_request(this, API_PATH "/guilds", std::to_string(guild_id), "prune", m_post, pruneinfo.build_json(true), callback); } From c7bec362ebcb36c02f3546d0c643942d19211e69 Mon Sep 17 00:00:00 2001 From: Phil B Date: Thu, 9 Jun 2022 23:37:06 +0200 Subject: [PATCH 3/3] breaking: removed reason parameter from cluster::guild_ban_add method --- include/dpp/cluster.h | 17 ----------------- include/dpp/cluster_sync_calls.h | 7 +++---- src/dpp/cluster/guild.cpp | 12 ------------ src/dpp/cluster_sync_calls.cpp | 4 ++-- 4 files changed, 5 insertions(+), 35 deletions(-) diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index 8dc873d12b..f6aede8102 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -2483,23 +2483,6 @@ 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 Add guild ban - * - * Create a guild ban, and optionally delete previous messages sent by the banned user. - * Requires the `BAN_MEMBERS` permission. Fires a `Guild Ban Add` Gateway event. - * @see https://discord.com/developers/docs/resources/guild#create-guild-ban - * @note This method supports audit log reasons set by the cluster::set_audit_reason() method. - * @param guild_id Guild ID to add ban to - * @param user_id User ID to ban - * @param delete_message_days How many days of their user's messages to also delete - * @param reason Reason for ban - * @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(). - * @deprecated Discord deprecated the reason parameter in the json body. Use the similar method to this without the reason param and use cluster::set_audit_log_reason() to set the reason. - */ - void guild_ban_add(snowflake guild_id, snowflake user_id, uint32_t delete_message_days, const std::string &reason, command_completion_event_t callback = utility::log_error()); - /** * @brief Add guild ban * diff --git a/include/dpp/cluster_sync_calls.h b/include/dpp/cluster_sync_calls.h index 2f74bc45a9..940afd48cf 100644 --- a/include/dpp/cluster_sync_calls.h +++ b/include/dpp/cluster_sync_calls.h @@ -717,7 +717,7 @@ auditlog guild_auditlog_get_sync(snowflake guild_id); /** * @brief Add guild ban - * + * * Create a guild ban, and optionally delete previous messages sent by the banned user. * Requires the `BAN_MEMBERS` permission. Fires a `Guild Ban Add` Gateway event. * @see dpp::cluster::guild_ban_add @@ -725,15 +725,14 @@ auditlog guild_auditlog_get_sync(snowflake guild_id); * @note This method supports audit log reasons set by the cluster::set_audit_reason() method. * @param guild_id Guild ID to add ban to * @param user_id User ID to ban - * @param delete_message_days How many days of their user's messages to also delete - * @param reason Reason for ban + * @param delete_message_days How many days of their user's messages to also delete (0-7). Defaults to 0 * @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_ban_add_sync(snowflake guild_id, snowflake user_id, uint32_t delete_message_days, const std::string &reason); +confirmation guild_ban_add_sync(snowflake guild_id, snowflake user_id, uint32_t delete_message_days = 0); /** * @brief Delete guild ban diff --git a/src/dpp/cluster/guild.cpp b/src/dpp/cluster/guild.cpp index bea3a7f91f..59c7a5719e 100644 --- a/src/dpp/cluster/guild.cpp +++ b/src/dpp/cluster/guild.cpp @@ -32,18 +32,6 @@ void cluster::guild_auditlog_get(snowflake guild_id, command_completion_event_t } -void cluster::guild_ban_add(snowflake guild_id, snowflake user_id, uint32_t delete_message_days, const std::string &reason, command_completion_event_t callback) { - json j; - if (delete_message_days > 7) - delete_message_days = 7; - if (!reason.empty()) - j["reason"] = reason; - if (delete_message_days) - j["delete_message_days"] = delete_message_days; - rest_request(this, API_PATH "/guilds", std::to_string(guild_id), "bans/" + std::to_string(user_id), m_put, j.dump(), callback); -} - - void cluster::guild_ban_add(snowflake guild_id, snowflake user_id, uint32_t delete_message_days, command_completion_event_t callback) { json j; if (delete_message_days > 7) diff --git a/src/dpp/cluster_sync_calls.cpp b/src/dpp/cluster_sync_calls.cpp index f557ca7dae..49a0df0eed 100644 --- a/src/dpp/cluster_sync_calls.cpp +++ b/src/dpp/cluster_sync_calls.cpp @@ -216,8 +216,8 @@ auditlog cluster::guild_auditlog_get_sync(snowflake guild_id) { return dpp::sync(this, &cluster::guild_auditlog_get, guild_id); } -confirmation cluster::guild_ban_add_sync(snowflake guild_id, snowflake user_id, uint32_t delete_message_days, const std::string &reason) { - return dpp::sync(this, &cluster::guild_ban_add, guild_id, user_id, delete_message_days, reason); +confirmation cluster::guild_ban_add_sync(snowflake guild_id, snowflake user_id, uint32_t delete_message_days) { + return dpp::sync(this, &cluster::guild_ban_add, guild_id, user_id, delete_message_days); } confirmation cluster::guild_ban_delete_sync(snowflake guild_id, snowflake user_id) {