1
1
#[ cfg( feature = "model" ) ]
2
2
use crate :: builder:: { Builder as _, GetEntitlements } ;
3
3
#[ cfg( feature = "model" ) ]
4
- use crate :: http:: CacheHttp ;
4
+ use crate :: http:: { CacheHttp , Http } ;
5
5
use crate :: model:: prelude:: * ;
6
6
7
7
/// A premium offering that can be made available to an application's users and guilds.
@@ -46,6 +46,10 @@ enum_number! {
46
46
#[ serde( from = "u8" , into = "u8" ) ]
47
47
#[ non_exhaustive]
48
48
pub enum SkuKind {
49
+ /// A durable one-time purchase.
50
+ Durable = 2 ,
51
+ /// A consumable one-time purchase.
52
+ Consumable = 3 ,
49
53
/// Represents a recurring subscription.
50
54
Subscription = 5 ,
51
55
/// A system-generated group for each SKU created of type [`SkuKind::Subscription`].
@@ -98,6 +102,8 @@ pub struct Entitlement {
98
102
pub ends_at : Option < Timestamp > ,
99
103
/// The ID of the guild that is granted access to the SKU.
100
104
pub guild_id : Option < GuildId > ,
105
+ /// For consumable items, whether or not the entitlement has been consumed.
106
+ pub consumed : Option < bool > ,
101
107
}
102
108
103
109
impl Entitlement {
@@ -110,6 +116,21 @@ impl Entitlement {
110
116
)
111
117
}
112
118
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
+
113
134
/// Returns all entitlements for the current application, active and expired.
114
135
///
115
136
/// # Errors
@@ -133,6 +154,20 @@ enum_number! {
133
154
#[ serde( from = "u8" , into = "u8" ) ]
134
155
#[ non_exhaustive]
135
156
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 ,
136
171
/// Entitlement was purchased as an app subscription.
137
172
ApplicationSubscription = 8 ,
138
173
_ => Unknown ( u8 ) ,
0 commit comments