11#[ cfg( feature = "model" ) ]
22use crate :: builder:: { Builder as _, GetEntitlements } ;
33#[ cfg( feature = "model" ) ]
4- use crate :: http:: CacheHttp ;
4+ use crate :: http:: { CacheHttp , Http } ;
55use crate :: model:: prelude:: * ;
66
77/// A premium offering that can be made available to an application's users and guilds.
@@ -46,6 +46,10 @@ enum_number! {
4646 #[ serde( from = "u8" , into = "u8" ) ]
4747 #[ non_exhaustive]
4848 pub enum SkuKind {
49+ /// A durable one-time purchase.
50+ Durable = 2 ,
51+ /// A consumable one-time purchase.
52+ Consumable = 3 ,
4953 /// Represents a recurring subscription.
5054 Subscription = 5 ,
5155 /// A system-generated group for each SKU created of type [`SkuKind::Subscription`].
@@ -98,6 +102,8 @@ pub struct Entitlement {
98102 pub ends_at : Option < Timestamp > ,
99103 /// The ID of the guild that is granted access to the SKU.
100104 pub guild_id : Option < GuildId > ,
105+ /// For consumable items, whether or not the entitlement has been consumed.
106+ pub consumed : Option < bool > ,
101107}
102108
103109impl Entitlement {
@@ -110,6 +116,21 @@ impl Entitlement {
110116 )
111117 }
112118
119+ /// For a one-time purchase consumable SKU (of kind [`Consumable`]), marks the entitlement as
120+ /// consumed. On success, the [`consumed`] field will be set to `Some(true)`.
121+ ///
122+ /// # Errors
123+ ///
124+ /// Will fail if the corresponding SKU is not of kind [`Consumable`].
125+ ///
126+ /// [`Consumable`]: SkuKind::Consumable
127+ /// [`consumed`]: Entitlement::consumed
128+ pub async fn consume ( & mut self , http : & Http ) -> Result < ( ) > {
129+ http. consume_entitlement ( self . id ) . await ?;
130+ self . consumed = Some ( true ) ;
131+ Ok ( ( ) )
132+ }
133+
113134 /// Returns all entitlements for the current application, active and expired.
114135 ///
115136 /// # Errors
@@ -133,6 +154,20 @@ enum_number! {
133154 #[ serde( from = "u8" , into = "u8" ) ]
134155 #[ non_exhaustive]
135156 pub enum EntitlementKind {
157+ /// Entitlement was purchased by a user.
158+ Purchase = 1 ,
159+ /// Entitlement for a Discord Nitro subscription.
160+ PremiumSubscription = 2 ,
161+ /// Entitlement was gifted by an app developer.
162+ DeveloperGift = 3 ,
163+ /// Entitlement was purchased by a developer in application test mode.
164+ TestModePurchase = 4 ,
165+ /// Entitlement was granted when the corresponding SKU was free.
166+ FreePurchase = 5 ,
167+ /// Entitlement was gifted by another user.
168+ UserGift = 6 ,
169+ /// Entitlement was claimed by user for free as a Nitro Subscriber.
170+ PremiumPurchase = 7 ,
136171 /// Entitlement was purchased as an app subscription.
137172 ApplicationSubscription = 8 ,
138173 _ => Unknown ( u8 ) ,
0 commit comments