Skip to content

Commit

Permalink
feat: Added consuming an entitlement
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Jun 13, 2024
1 parent c36b5de commit 8ffc955
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/dpp/cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -3780,6 +3780,16 @@ class DPP_EXPORT cluster {
*/
void entitlement_test_delete(snowflake entitlement_id, command_completion_event_t callback = utility::log_error());

/**
* @brief For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed.
*
* @see https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement
* @param entitlement_id The entitlement to mark as consumed.
* @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 entitlement_consume(snowflake entitlement_id, command_completion_event_t callback = utility::log_error());

/**
* @brief Returns all SKUs for a given application.
* @note Because of how Discord's SKU and subscription systems work, you will see two SKUs for your premium offering.
Expand Down
11 changes: 11 additions & 0 deletions include/dpp/cluster_coro_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,17 @@
*/
[[nodiscard]] async<confirmation_callback_t> co_entitlement_test_delete(snowflake entitlement_id);

/**
* @brief For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed.
*
* @see dpp::cluster::entitlement_consume
* @see https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement
* @param entitlement_id The entitlement to mark as consumed.
* @return confirmation returned object on completion
* \memberof dpp::cluster
*/
[[nodiscard]] async<confirmation_callback_t> co_entitlement_consume(snowflake entitlement_id);

/**
* @brief Get the gateway information for the bot using the token
* @see dpp::cluster::get_gateway_bot
Expand Down
14 changes: 14 additions & 0 deletions include/dpp/cluster_sync_calls.h
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,20 @@ entitlement entitlement_test_create_sync(const class entitlement& new_entitlemen
*/
confirmation entitlement_test_delete_sync(snowflake entitlement_id);

/**
* @brief For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed.
*
* @see dpp::cluster::entitlement_consume
* @see https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement
* @param entitlement_id The entitlement to mark as consumed.
* @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 entitlement_consume_sync(snowflake entitlement_id);

/**
* @brief Get the gateway information for the bot using the token
* @see dpp::cluster::get_gateway_bot
Expand Down
4 changes: 4 additions & 0 deletions src/dpp/cluster/entitlement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ void cluster::entitlement_test_delete(const class snowflake entitlement_id, comm
rest_request<confirmation>(this, API_PATH "/applications", me.id.str(), "entitlements/" + entitlement_id.str(), m_delete, "", callback);
}

void cluster::entitlement_consume(const class snowflake entitlement_id, command_completion_event_t callback) {
rest_request<confirmation>(this, API_PATH "/applications", me.id.str(), "entitlements/" + entitlement_id.str() + "/consume", m_post, "", 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 @@ -275,6 +275,10 @@ async<confirmation_callback_t> cluster::co_entitlement_test_delete(const class s
return async{ this, static_cast<void (cluster::*)(const class snowflake, command_completion_event_t)>(&cluster::entitlement_test_delete), entitlement_id };
}

async<confirmation_callback_t> cluster::co_entitlement_consume(const class snowflake entitlement_id) {
return async{ this, static_cast<void (cluster::*)(const class snowflake, command_completion_event_t)>(&cluster::entitlement_consume), entitlement_id };
}

async<confirmation_callback_t> cluster::co_get_gateway_bot() {
return async{ this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::get_gateway_bot) };
}
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 @@ -273,6 +273,10 @@ confirmation cluster::entitlement_test_delete_sync(const class snowflake entitle
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(const class snowflake, command_completion_event_t)>(&cluster::entitlement_test_delete), entitlement_id);
}

confirmation cluster::entitlement_consume_sync(const class snowflake entitlement_id) {
return dpp::sync<confirmation>(this, static_cast<void (cluster::*)(const class snowflake, command_completion_event_t)>(&cluster::entitlement_consume), entitlement_id);
}

gateway cluster::get_gateway_bot_sync() {
return dpp::sync<gateway>(this, static_cast<void (cluster::*)(command_completion_event_t)>(&cluster::get_gateway_bot));
}
Expand Down

0 comments on commit 8ffc955

Please sign in to comment.