Skip to content

Commit ba08061

Browse files
jaw0r3kvladfranguJiralitealmeidx
authored
feat: premium app subscriptions (#833)
Co-authored-by: Vlad Frangu <[email protected]> Co-authored-by: Jiralite <[email protected]> Co-authored-by: Almeida <[email protected]>
1 parent f51c2d9 commit ba08061

File tree

28 files changed

+1176
-8
lines changed

28 files changed

+1176
-8
lines changed

deno/gateway/v10.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type {
3333
PresenceUpdateStatus,
3434
AutoModerationRuleTriggerType,
3535
APIAuditLogEntry,
36+
APIEntitlement,
3637
} from '../payloads/v10/mod.ts';
3738
import type { Nullable } from '../utils/internals.ts';
3839

@@ -268,6 +269,9 @@ export enum GatewayDispatchEvents {
268269
AutoModerationRuleDelete = 'AUTO_MODERATION_RULE_DELETE',
269270
AutoModerationActionExecution = 'AUTO_MODERATION_ACTION_EXECUTION',
270271
GuildAuditLogEntryCreate = 'GUILD_AUDIT_LOG_ENTRY_CREATE',
272+
EntitlementCreate = 'ENTITLEMENT_CREATE',
273+
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
274+
EntitlementDelete = 'ENTITLEMENT_DELETE',
271275
}
272276

273277
export type GatewaySendPayload =
@@ -341,7 +345,8 @@ export type GatewayDispatchPayload =
341345
| GatewayVoiceServerUpdateDispatch
342346
| GatewayVoiceStateUpdateDispatch
343347
| GatewayWebhooksUpdateDispatch
344-
| GatewayGuildAuditLogEntryCreateDispatch;
348+
| GatewayGuildAuditLogEntryCreateDispatch
349+
| GatewayEntitlementModifyDispatch;
345350

346351
// #region Dispatch Payloads
347352

@@ -672,6 +677,55 @@ export interface GatewayChannelPinsUpdateDispatchData {
672677
last_pin_timestamp?: string | null;
673678
}
674679

680+
/**
681+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
682+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
683+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
684+
*/
685+
export type GatewayEntitlementModifyDispatchData = APIEntitlement;
686+
687+
/**
688+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
689+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
690+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
691+
*/
692+
export type GatewayEntitlementModifyDispatch = DataPayload<
693+
| GatewayDispatchEvents.EntitlementCreate
694+
| GatewayDispatchEvents.EntitlementUpdate
695+
| GatewayDispatchEvents.EntitlementDelete,
696+
GatewayEntitlementModifyDispatchData
697+
>;
698+
699+
/**
700+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
701+
*/
702+
export type GatewayEntitlementCreateDispatchData = GatewayEntitlementModifyDispatchData;
703+
704+
/**
705+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
706+
*/
707+
export type GatewayEntitlementCreateDispatch = GatewayEntitlementModifyDispatch;
708+
709+
/**
710+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
711+
*/
712+
export type GatewayEntitlementUpdateDispatchData = GatewayEntitlementModifyDispatchData;
713+
714+
/**
715+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
716+
*/
717+
export type GatewayEntitlementUpdateDispatch = GatewayEntitlementModifyDispatch;
718+
719+
/**
720+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
721+
*/
722+
export type GatewayEntitlementDeleteDispatchData = GatewayEntitlementModifyDispatchData;
723+
724+
/**
725+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
726+
*/
727+
export type GatewayEntitlementDeleteDispatch = GatewayEntitlementModifyDispatch;
728+
675729
/**
676730
* https://discord.com/developers/docs/topics/gateway-events#guild-create
677731
*/

deno/gateway/v9.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import type {
3535
APIAuditLogEntry,
3636
} from '../payloads/v9/mod.ts';
3737
import type { Nullable } from '../utils/internals.ts';
38+
import type { APIEntitlement } from '../v10.ts';
3839

3940
export * from './common.ts';
4041

@@ -267,6 +268,9 @@ export enum GatewayDispatchEvents {
267268
AutoModerationRuleDelete = 'AUTO_MODERATION_RULE_DELETE',
268269
AutoModerationActionExecution = 'AUTO_MODERATION_ACTION_EXECUTION',
269270
GuildAuditLogEntryCreate = 'GUILD_AUDIT_LOG_ENTRY_CREATE',
271+
EntitlementCreate = 'ENTITLEMENT_CREATE',
272+
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
273+
EntitlementDelete = 'ENTITLEMENT_DELETE',
270274
}
271275

272276
export type GatewaySendPayload =
@@ -340,7 +344,8 @@ export type GatewayDispatchPayload =
340344
| GatewayVoiceServerUpdateDispatch
341345
| GatewayVoiceStateUpdateDispatch
342346
| GatewayWebhooksUpdateDispatch
343-
| GatewayGuildAuditLogEntryCreateDispatch;
347+
| GatewayGuildAuditLogEntryCreateDispatch
348+
| GatewayEntitlementModifyDispatch;
344349

345350
// #region Dispatch Payloads
346351

@@ -671,6 +676,55 @@ export interface GatewayChannelPinsUpdateDispatchData {
671676
last_pin_timestamp?: string | null;
672677
}
673678

679+
/**
680+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
681+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
682+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
683+
*/
684+
export type GatewayEntitlementModifyDispatchData = APIEntitlement;
685+
686+
/**
687+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
688+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
689+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
690+
*/
691+
export type GatewayEntitlementModifyDispatch = DataPayload<
692+
| GatewayDispatchEvents.EntitlementCreate
693+
| GatewayDispatchEvents.EntitlementUpdate
694+
| GatewayDispatchEvents.EntitlementDelete,
695+
GatewayEntitlementModifyDispatchData
696+
>;
697+
698+
/**
699+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
700+
*/
701+
export type GatewayEntitlementCreateDispatchData = GatewayEntitlementModifyDispatchData;
702+
703+
/**
704+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
705+
*/
706+
export type GatewayEntitlementCreateDispatch = GatewayEntitlementModifyDispatch;
707+
708+
/**
709+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
710+
*/
711+
export type GatewayEntitlementUpdateDispatchData = GatewayEntitlementModifyDispatchData;
712+
713+
/**
714+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
715+
*/
716+
export type GatewayEntitlementUpdateDispatch = GatewayEntitlementModifyDispatch;
717+
718+
/**
719+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
720+
*/
721+
export type GatewayEntitlementDeleteDispatchData = GatewayEntitlementModifyDispatchData;
722+
723+
/**
724+
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
725+
*/
726+
export type GatewayEntitlementDeleteDispatch = GatewayEntitlementModifyDispatch;
727+
674728
/**
675729
* https://discord.com/developers/docs/topics/gateway-events#guild-update
676730
*/

deno/payloads/v10/_interactions/base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
ThreadChannelType,
1111
} from '../channel.ts';
1212
import type { APIGuildMember } from '../guild.ts';
13+
import type { APIEntitlement } from '../monetization.ts';
1314
import type { APIUser } from '../user.ts';
1415
import type { InteractionType } from './responses.ts';
1516

@@ -130,6 +131,10 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
130131
* The guild's preferred locale, if invoked in a guild
131132
*/
132133
guild_locale?: LocaleString;
134+
/**
135+
* For monetized apps, any entitlements for the invoking user, representing access to premium SKUs
136+
*/
137+
entitlements: APIEntitlement[];
133138
}
134139

135140
export type APIDMInteractionWrapper<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<

deno/payloads/v10/_interactions/responses.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export type APIInteractionResponse =
2424
| APIInteractionResponseDeferredMessageUpdate
2525
| APIInteractionResponseUpdateMessage
2626
| APIApplicationCommandAutocompleteResponse
27-
| APIModalInteractionResponse;
27+
| APIModalInteractionResponse
28+
| APIPremiumRequiredInteractionResponse;
2829

2930
export interface APIInteractionResponsePong {
3031
type: InteractionResponseType.Pong;
@@ -40,6 +41,10 @@ export interface APIModalInteractionResponse {
4041
data: APIModalInteractionResponseCallbackData;
4142
}
4243

44+
export interface APIPremiumRequiredInteractionResponse {
45+
type: InteractionResponseType.PremiumRequired;
46+
}
47+
4348
export interface APIInteractionResponseChannelMessageWithSource {
4449
type: InteractionResponseType.ChannelMessageWithSource;
4550
data: APIInteractionResponseCallbackData;
@@ -91,6 +96,10 @@ export enum InteractionResponseType {
9196
* Respond to an interaction with an modal for a user to fill-out
9297
*/
9398
Modal,
99+
/**
100+
* Respond to an interaction with an upgrade button, only available for apps with monetization enabled
101+
*/
102+
PremiumRequired,
94103
}
95104

96105
/**

deno/payloads/v10/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export * from './template.ts';
1818
export * from './user.ts';
1919
export * from './voice.ts';
2020
export * from './webhook.ts';
21+
export * from './monetization.ts';

deno/payloads/v10/monetization.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import type { Snowflake } from '../../globals.ts';
2+
3+
/**
4+
* https://discord.com/developers/docs/monetization/entitlements#entitlement-object-entitlement-structure
5+
*/
6+
export interface APIEntitlement {
7+
/**
8+
* ID of the entitlement
9+
*/
10+
id: Snowflake;
11+
/**
12+
* ID of the SKU
13+
*/
14+
sku_id: Snowflake;
15+
/**
16+
* ID of the user that is granted access to the entitlement's sku
17+
*/
18+
user_id?: Snowflake;
19+
/**
20+
* ID of the guild that is granted access to the entitlement's sku
21+
*/
22+
guild_id?: Snowflake;
23+
/**
24+
* ID of the parent application
25+
*/
26+
application_id: Snowflake;
27+
/**
28+
* Type of entitlement
29+
*/
30+
type: EntitlementType;
31+
/**
32+
* Whether the entitlement was deleted
33+
*/
34+
deleted: boolean;
35+
/**
36+
* Start date at which the entitlement is valid. Not present when using test entitlements.
37+
*/
38+
starts_at?: string;
39+
/**
40+
* Date at which the entitlement is no longer valid. Not present when using test entitlements.
41+
*/
42+
ends_at?: string;
43+
}
44+
45+
/**
46+
* https://discord.com/developers/docs/monetization/entitlements#entitlement-object-entitlement-types
47+
*/
48+
export enum EntitlementType {
49+
/**
50+
* Entitlement was purchased as an app subscription
51+
*/
52+
ApplicationSubscription = 8,
53+
}
54+
55+
/**
56+
* https://discord.com/developers/docs/monetization/skus#sku-object-sku-structure
57+
*/
58+
export interface APISKU {
59+
/**
60+
* ID of SKU
61+
*/
62+
id: Snowflake;
63+
/**
64+
* Type of SKU
65+
*/
66+
type: SKUType;
67+
/**
68+
* ID of the parent application
69+
*/
70+
application_id: Snowflake;
71+
/**
72+
* Customer-facing name of your premium offering
73+
*/
74+
name: string;
75+
/**
76+
* System-generated URL slug based on the SKU's name
77+
*/
78+
slug: string;
79+
/**
80+
* SKU flags combined as a bitfield
81+
*
82+
* See https://en.wikipedia.org/wiki/Bit_field
83+
*/
84+
flags: SKUFlags;
85+
}
86+
87+
/**
88+
* https://discord.com/developers/docs/monetization/skus#sku-object-sku-flags
89+
*/
90+
export enum SKUFlags {
91+
/**
92+
* SKU is available for purchase
93+
*/
94+
Available = 1 << 2,
95+
/**
96+
* Recurring SKU that can be purchased by a user and applied to a single server.
97+
* Grants access to every user in that server.
98+
*/
99+
GuildSubscription = 1 << 7,
100+
/**
101+
* Recurring SKU purchased by a user for themselves. Grants access to the purchasing user in every server.
102+
*/
103+
UserSubscription = 1 << 8,
104+
}
105+
106+
export enum SKUType {
107+
/**
108+
* Represents a recurring subscription
109+
*/
110+
Subscription = 5,
111+
/**
112+
* System-generated group for each Subscription SKU created
113+
*/
114+
SubscriptionGroup = 6,
115+
}

deno/payloads/v9/_interactions/base.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type {
1010
ThreadChannelType,
1111
} from '../channel.ts';
1212
import type { APIGuildMember } from '../guild.ts';
13+
import type { APIEntitlement } from '../monetization.ts';
1314
import type { APIUser } from '../user.ts';
1415
import type { InteractionType } from './responses.ts';
1516

@@ -130,6 +131,10 @@ export interface APIBaseInteraction<Type extends InteractionType, Data> {
130131
* The guild's preferred locale, if invoked in a guild
131132
*/
132133
guild_locale?: LocaleString;
134+
/**
135+
* For monetized apps, any entitlements for the invoking user, representing access to premium SKUs
136+
*/
137+
entitlements: APIEntitlement[];
133138
}
134139

135140
export type APIDMInteractionWrapper<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<

deno/payloads/v9/_interactions/responses.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ export type APIInteractionResponse =
2424
| APIInteractionResponseDeferredMessageUpdate
2525
| APIInteractionResponseUpdateMessage
2626
| APIApplicationCommandAutocompleteResponse
27-
| APIModalInteractionResponse;
27+
| APIModalInteractionResponse
28+
| APIPremiumRequiredInteractionResponse;
2829

2930
export interface APIInteractionResponsePong {
3031
type: InteractionResponseType.Pong;
@@ -40,6 +41,10 @@ export interface APIModalInteractionResponse {
4041
data: APIModalInteractionResponseCallbackData;
4142
}
4243

44+
export interface APIPremiumRequiredInteractionResponse {
45+
type: InteractionResponseType.PremiumRequired;
46+
}
47+
4348
export interface APIInteractionResponseChannelMessageWithSource {
4449
type: InteractionResponseType.ChannelMessageWithSource;
4550
data: APIInteractionResponseCallbackData;
@@ -91,6 +96,10 @@ export enum InteractionResponseType {
9196
* Respond to an interaction with an modal for a user to fill-out
9297
*/
9398
Modal,
99+
/**
100+
* Respond to an interaction with an upgrade button, only available for apps with monetization enabled
101+
*/
102+
PremiumRequired,
94103
}
95104

96105
/**

deno/payloads/v9/mod.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ export * from './template.ts';
1818
export * from './user.ts';
1919
export * from './voice.ts';
2020
export * from './webhook.ts';
21+
export * from './monetization.ts';

0 commit comments

Comments
 (0)