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,22 @@ 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+ #[ cfg( feature = "model" ) ]
129+ pub async fn consume ( & mut self , http : & Http ) -> Result < ( ) > {
130+ http. consume_entitlement ( self . id ) . await ?;
131+ self . consumed = Some ( true ) ;
132+ Ok ( ( ) )
133+ }
134+
113135 /// Returns all entitlements for the current application, active and expired.
114136 ///
115137 /// # Errors
@@ -133,6 +155,20 @@ enum_number! {
133155 #[ serde( from = "u8" , into = "u8" ) ]
134156 #[ non_exhaustive]
135157 pub enum EntitlementKind {
158+ /// Entitlement was purchased by a user.
159+ Purchase = 1 ,
160+ /// Entitlement for a Discord Nitro subscription.
161+ PremiumSubscription = 2 ,
162+ /// Entitlement was gifted by an app developer.
163+ DeveloperGift = 3 ,
164+ /// Entitlement was purchased by a developer in application test mode.
165+ TestModePurchase = 4 ,
166+ /// Entitlement was granted when the corresponding SKU was free.
167+ FreePurchase = 5 ,
168+ /// Entitlement was gifted by another user.
169+ UserGift = 6 ,
170+ /// Entitlement was claimed by user for free as a Nitro Subscriber.
171+ PremiumPurchase = 7 ,
136172 /// Entitlement was purchased as an app subscription.
137173 ApplicationSubscription = 8 ,
138174 _ => Unknown ( u8 ) ,
0 commit comments