diff --git a/doxygen-awesome-css b/doxygen-awesome-css index 40e9b25b61..5b27b3a747 160000 --- a/doxygen-awesome-css +++ b/doxygen-awesome-css @@ -1 +1 @@ -Subproject commit 40e9b25b6174dd3b472d8868f63323a870dfeeb8 +Subproject commit 5b27b3a747ca1e559fa54149762cca0bad6036fb diff --git a/include/dpp/entitlement.h b/include/dpp/entitlement.h index dd7d1ae0d5..d69069856f 100644 --- a/include/dpp/entitlement.h +++ b/include/dpp/entitlement.h @@ -55,15 +55,29 @@ enum entitlement_type : uint8_t { /** * @brief Entitlement flags. */ -enum entitlement_flags : uint16_t { +enum entitlement_flags : uint8_t { /** * @brief Entitlement was deleted + * + * @note Only discord staff can delete an entitlement via + * their internal tooling. It should rarely happen except in cases + * of fraud or chargeback. */ - ent_deleted = 0b000000000000001, + ent_deleted = 0b0000001, + + /** + * @brief Entitlement was consumed. + * + * @note A consumed entitlement is a used-up one-off purchase. + */ + ent_consumed = 0b0000010, }; /** * @brief A definition of a discord entitlement. + * + * An entitlement is a user's connection to an SKU, basically a subscription + * or a one-off purchase. */ class DPP_EXPORT entitlement : public managed, public json_interface { protected: @@ -85,7 +99,11 @@ class DPP_EXPORT entitlement : public managed, public json_interface& sku_ids, snowflake before_id, snowflake after_id, uint8_t limit, snowflake guild_id, bool exclude_ended, command_completion_event_t callback) { json j; - if(user_id) { + if (!user_id.empty()) { j["user_id"] = user_id.str(); } - if(!sku_ids.empty()) { + if (!sku_ids.empty()) { /* Why can't Discord just be consistent and accept an array of ids???? * Why just out of nowhere introduce a "comma-delimited set of snowflakes", like what. * Just allow an array like you normally do!!!!!!!!!!!! @@ -46,17 +46,17 @@ void cluster::entitlements_get(snowflake user_id, const std::vector& j["sku_ids"] = ids; } - if(before_id) { + if (!before_id.empty()) { j["before_id"] = before_id.str(); } - if(after_id) { + if (!after_id.empty()) { j["after_id"] = after_id.str(); } j["limit"] = limit; - if(guild_id) { + if (!guild_id.empty()) { j["guild_id"] = guild_id.str(); } @@ -68,7 +68,7 @@ void cluster::entitlements_get(snowflake user_id, const std::vector& void cluster::entitlement_test_create(const class entitlement& new_entitlement, command_completion_event_t callback) { json j; j["sku_id"] = new_entitlement.sku_id.str(); - j["owner_id"] = new_entitlement.owner_id.str(); + j["owner_id"] = new_entitlement.guild_id.empty() ? new_entitlement.guild_id.str() : new_entitlement.user_id.str(); j["owner_type"] = new_entitlement.type; rest_request(this, API_PATH "/applications", me.id.str(), "entitlements", m_post, j, callback); } diff --git a/src/dpp/entitlement.cpp b/src/dpp/entitlement.cpp index 245eb3b383..f3ee034a04 100644 --- a/src/dpp/entitlement.cpp +++ b/src/dpp/entitlement.cpp @@ -34,12 +34,17 @@ entitlement& entitlement::fill_from_json_impl(nlohmann::json* j) { set_snowflake_not_null(j, "id", id); set_snowflake_not_null(j, "sku_id", sku_id); set_snowflake_not_null(j, "application_id", application_id); + set_snowflake_not_null(j, "promotion_id", promotion_id); + set_int8_not_null(j, "gift_code_flags", gift_code_flags); - /* Discord does separate these values, but asks for them as "owner_id" in the create event, just makes sense to make them as one as only one is ever set. */ - if(snowflake_not_null(j, "user_id")) { - set_snowflake_not_null(j, "user_id", owner_id); - } else if(snowflake_not_null(j, "guild_id")) { - set_snowflake_not_null(j, "guild_id", owner_id); + if (snowflake_not_null(j, "subscription_id")) { + set_snowflake_not_null(j, "subscription_id", subscription_id); + } + if (snowflake_not_null(j, "user_id")) { + set_snowflake_not_null(j, "user_id", user_id); + } + if (snowflake_not_null(j, "guild_id")) { + set_snowflake_not_null(j, "guild_id", guild_id); } type = static_cast(int8_not_null(j, "type")); @@ -47,14 +52,13 @@ entitlement& entitlement::fill_from_json_impl(nlohmann::json* j) { if (bool_not_null(j, "deleted")) { flags |= ent_deleted; } + if (bool_not_null(j, "consumed")) { + flags |= ent_consumed; + } set_ts_not_null(j, "starts_at", starts_at); set_ts_not_null(j, "ends_at", ends_at); - /* - * TODO: Look at the entitlement example on docs and see what we're missing, add it here after. Discord seems to be missing information in their structure as their example shows more data. - */ - return *this; } @@ -75,4 +79,8 @@ bool entitlement::is_deleted() const { return flags & entitlement_flags::ent_deleted; } +bool entitlement::is_consumed() const { + return flags & entitlement_flags::ent_consumed; +} + } // namespace dpp