Skip to content

Commit

Permalink
feat: premium app subscriptions (#833)
Browse files Browse the repository at this point in the history
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: Almeida <almeidx@pm.me>
  • Loading branch information
4 people authored Oct 22, 2023
1 parent f51c2d9 commit ba08061
Show file tree
Hide file tree
Showing 28 changed files with 1,176 additions and 8 deletions.
56 changes: 55 additions & 1 deletion deno/gateway/v10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type {
PresenceUpdateStatus,
AutoModerationRuleTriggerType,
APIAuditLogEntry,
APIEntitlement,
} from '../payloads/v10/mod.ts';
import type { Nullable } from '../utils/internals.ts';

Expand Down Expand Up @@ -268,6 +269,9 @@ export enum GatewayDispatchEvents {
AutoModerationRuleDelete = 'AUTO_MODERATION_RULE_DELETE',
AutoModerationActionExecution = 'AUTO_MODERATION_ACTION_EXECUTION',
GuildAuditLogEntryCreate = 'GUILD_AUDIT_LOG_ENTRY_CREATE',
EntitlementCreate = 'ENTITLEMENT_CREATE',
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
EntitlementDelete = 'ENTITLEMENT_DELETE',
}

export type GatewaySendPayload =
Expand Down Expand Up @@ -341,7 +345,8 @@ export type GatewayDispatchPayload =
| GatewayVoiceServerUpdateDispatch
| GatewayVoiceStateUpdateDispatch
| GatewayWebhooksUpdateDispatch
| GatewayGuildAuditLogEntryCreateDispatch;
| GatewayGuildAuditLogEntryCreateDispatch
| GatewayEntitlementModifyDispatch;

// #region Dispatch Payloads

Expand Down Expand Up @@ -672,6 +677,55 @@ export interface GatewayChannelPinsUpdateDispatchData {
last_pin_timestamp?: string | null;
}

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
*/
export type GatewayEntitlementModifyDispatchData = APIEntitlement;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
*/
export type GatewayEntitlementModifyDispatch = DataPayload<
| GatewayDispatchEvents.EntitlementCreate
| GatewayDispatchEvents.EntitlementUpdate
| GatewayDispatchEvents.EntitlementDelete,
GatewayEntitlementModifyDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
*/
export type GatewayEntitlementCreateDispatchData = GatewayEntitlementModifyDispatchData;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
*/
export type GatewayEntitlementCreateDispatch = GatewayEntitlementModifyDispatch;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
*/
export type GatewayEntitlementUpdateDispatchData = GatewayEntitlementModifyDispatchData;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
*/
export type GatewayEntitlementUpdateDispatch = GatewayEntitlementModifyDispatch;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
*/
export type GatewayEntitlementDeleteDispatchData = GatewayEntitlementModifyDispatchData;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
*/
export type GatewayEntitlementDeleteDispatch = GatewayEntitlementModifyDispatch;

/**
* https://discord.com/developers/docs/topics/gateway-events#guild-create
*/
Expand Down
56 changes: 55 additions & 1 deletion deno/gateway/v9.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import type {
APIAuditLogEntry,
} from '../payloads/v9/mod.ts';
import type { Nullable } from '../utils/internals.ts';
import type { APIEntitlement } from '../v10.ts';

export * from './common.ts';

Expand Down Expand Up @@ -267,6 +268,9 @@ export enum GatewayDispatchEvents {
AutoModerationRuleDelete = 'AUTO_MODERATION_RULE_DELETE',
AutoModerationActionExecution = 'AUTO_MODERATION_ACTION_EXECUTION',
GuildAuditLogEntryCreate = 'GUILD_AUDIT_LOG_ENTRY_CREATE',
EntitlementCreate = 'ENTITLEMENT_CREATE',
EntitlementUpdate = 'ENTITLEMENT_UPDATE',
EntitlementDelete = 'ENTITLEMENT_DELETE',
}

export type GatewaySendPayload =
Expand Down Expand Up @@ -340,7 +344,8 @@ export type GatewayDispatchPayload =
| GatewayVoiceServerUpdateDispatch
| GatewayVoiceStateUpdateDispatch
| GatewayWebhooksUpdateDispatch
| GatewayGuildAuditLogEntryCreateDispatch;
| GatewayGuildAuditLogEntryCreateDispatch
| GatewayEntitlementModifyDispatch;

// #region Dispatch Payloads

Expand Down Expand Up @@ -671,6 +676,55 @@ export interface GatewayChannelPinsUpdateDispatchData {
last_pin_timestamp?: string | null;
}

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
*/
export type GatewayEntitlementModifyDispatchData = APIEntitlement;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
*/
export type GatewayEntitlementModifyDispatch = DataPayload<
| GatewayDispatchEvents.EntitlementCreate
| GatewayDispatchEvents.EntitlementUpdate
| GatewayDispatchEvents.EntitlementDelete,
GatewayEntitlementModifyDispatchData
>;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
*/
export type GatewayEntitlementCreateDispatchData = GatewayEntitlementModifyDispatchData;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-create
*/
export type GatewayEntitlementCreateDispatch = GatewayEntitlementModifyDispatch;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
*/
export type GatewayEntitlementUpdateDispatchData = GatewayEntitlementModifyDispatchData;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-update
*/
export type GatewayEntitlementUpdateDispatch = GatewayEntitlementModifyDispatch;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
*/
export type GatewayEntitlementDeleteDispatchData = GatewayEntitlementModifyDispatchData;

/**
* https://discord.com/developers/docs/topics/gateway-events#entitlement-delete
*/
export type GatewayEntitlementDeleteDispatch = GatewayEntitlementModifyDispatch;

/**
* https://discord.com/developers/docs/topics/gateway-events#guild-update
*/
Expand Down
5 changes: 5 additions & 0 deletions deno/payloads/v10/_interactions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
ThreadChannelType,
} from '../channel.ts';
import type { APIGuildMember } from '../guild.ts';
import type { APIEntitlement } from '../monetization.ts';
import type { APIUser } from '../user.ts';
import type { InteractionType } from './responses.ts';

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

export type APIDMInteractionWrapper<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<
Expand Down
11 changes: 10 additions & 1 deletion deno/payloads/v10/_interactions/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export type APIInteractionResponse =
| APIInteractionResponseDeferredMessageUpdate
| APIInteractionResponseUpdateMessage
| APIApplicationCommandAutocompleteResponse
| APIModalInteractionResponse;
| APIModalInteractionResponse
| APIPremiumRequiredInteractionResponse;

export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
Expand All @@ -40,6 +41,10 @@ export interface APIModalInteractionResponse {
data: APIModalInteractionResponseCallbackData;
}

export interface APIPremiumRequiredInteractionResponse {
type: InteractionResponseType.PremiumRequired;
}

export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
Expand Down Expand Up @@ -91,6 +96,10 @@ export enum InteractionResponseType {
* Respond to an interaction with an modal for a user to fill-out
*/
Modal,
/**
* Respond to an interaction with an upgrade button, only available for apps with monetization enabled
*/
PremiumRequired,
}

/**
Expand Down
1 change: 1 addition & 0 deletions deno/payloads/v10/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './template.ts';
export * from './user.ts';
export * from './voice.ts';
export * from './webhook.ts';
export * from './monetization.ts';
115 changes: 115 additions & 0 deletions deno/payloads/v10/monetization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import type { Snowflake } from '../../globals.ts';

/**
* https://discord.com/developers/docs/monetization/entitlements#entitlement-object-entitlement-structure
*/
export interface APIEntitlement {
/**
* ID of the entitlement
*/
id: Snowflake;
/**
* ID of the SKU
*/
sku_id: Snowflake;
/**
* ID of the user that is granted access to the entitlement's sku
*/
user_id?: Snowflake;
/**
* ID of the guild that is granted access to the entitlement's sku
*/
guild_id?: Snowflake;
/**
* ID of the parent application
*/
application_id: Snowflake;
/**
* Type of entitlement
*/
type: EntitlementType;
/**
* Whether the entitlement was deleted
*/
deleted: boolean;
/**
* Start date at which the entitlement is valid. Not present when using test entitlements.
*/
starts_at?: string;
/**
* Date at which the entitlement is no longer valid. Not present when using test entitlements.
*/
ends_at?: string;
}

/**
* https://discord.com/developers/docs/monetization/entitlements#entitlement-object-entitlement-types
*/
export enum EntitlementType {
/**
* Entitlement was purchased as an app subscription
*/
ApplicationSubscription = 8,
}

/**
* https://discord.com/developers/docs/monetization/skus#sku-object-sku-structure
*/
export interface APISKU {
/**
* ID of SKU
*/
id: Snowflake;
/**
* Type of SKU
*/
type: SKUType;
/**
* ID of the parent application
*/
application_id: Snowflake;
/**
* Customer-facing name of your premium offering
*/
name: string;
/**
* System-generated URL slug based on the SKU's name
*/
slug: string;
/**
* SKU flags combined as a bitfield
*
* See https://en.wikipedia.org/wiki/Bit_field
*/
flags: SKUFlags;
}

/**
* https://discord.com/developers/docs/monetization/skus#sku-object-sku-flags
*/
export enum SKUFlags {
/**
* SKU is available for purchase
*/
Available = 1 << 2,
/**
* Recurring SKU that can be purchased by a user and applied to a single server.
* Grants access to every user in that server.
*/
GuildSubscription = 1 << 7,
/**
* Recurring SKU purchased by a user for themselves. Grants access to the purchasing user in every server.
*/
UserSubscription = 1 << 8,
}

export enum SKUType {
/**
* Represents a recurring subscription
*/
Subscription = 5,
/**
* System-generated group for each Subscription SKU created
*/
SubscriptionGroup = 6,
}
5 changes: 5 additions & 0 deletions deno/payloads/v9/_interactions/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
ThreadChannelType,
} from '../channel.ts';
import type { APIGuildMember } from '../guild.ts';
import type { APIEntitlement } from '../monetization.ts';
import type { APIUser } from '../user.ts';
import type { InteractionType } from './responses.ts';

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

export type APIDMInteractionWrapper<Original extends APIBaseInteraction<InteractionType, unknown>> = Omit<
Expand Down
11 changes: 10 additions & 1 deletion deno/payloads/v9/_interactions/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export type APIInteractionResponse =
| APIInteractionResponseDeferredMessageUpdate
| APIInteractionResponseUpdateMessage
| APIApplicationCommandAutocompleteResponse
| APIModalInteractionResponse;
| APIModalInteractionResponse
| APIPremiumRequiredInteractionResponse;

export interface APIInteractionResponsePong {
type: InteractionResponseType.Pong;
Expand All @@ -40,6 +41,10 @@ export interface APIModalInteractionResponse {
data: APIModalInteractionResponseCallbackData;
}

export interface APIPremiumRequiredInteractionResponse {
type: InteractionResponseType.PremiumRequired;
}

export interface APIInteractionResponseChannelMessageWithSource {
type: InteractionResponseType.ChannelMessageWithSource;
data: APIInteractionResponseCallbackData;
Expand Down Expand Up @@ -91,6 +96,10 @@ export enum InteractionResponseType {
* Respond to an interaction with an modal for a user to fill-out
*/
Modal,
/**
* Respond to an interaction with an upgrade button, only available for apps with monetization enabled
*/
PremiumRequired,
}

/**
Expand Down
1 change: 1 addition & 0 deletions deno/payloads/v9/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ export * from './template.ts';
export * from './user.ts';
export * from './voice.ts';
export * from './webhook.ts';
export * from './monetization.ts';
Loading

1 comment on commit ba08061

@vercel
Copy link

@vercel vercel bot commented on ba08061 Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.