Skip to content

Commit

Permalink
Add support for consuming one-time entitlements
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Jun 20, 2024
1 parent 05899ff commit f66367a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/routes/Applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,18 @@ export default class Applications {
}).then(data => data.map(d => new ApplicationCommand(d, this._manager.client)));
}

/**
* Mark an entitlement as consumed.
* @param applicationID The ID of the application to the entitlement is for.
* @param entitlementID The ID of the entitlement to consume.
*/
async consumeEntitlement(applicationID: string, entitlementID: string): Promise<void> {
await this._manager.authRequest<void>({
method: "POST",
path: Routes.CONSUME_ENTITLEMENT(applicationID, entitlementID)
});
}

/**
* Create a global application command.
* @param applicationID The ID of the application.
Expand Down
5 changes: 5 additions & 0 deletions lib/structures/BaseEntitlement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export default class BaseEntitlement extends Base {
this.userID = data.user_id;
}

/** Mark this entitlement as consumed. */
async consume(): Promise<void> {
return this.client.rest.applications.consumeEntitlement(this.applicationID, this.id);
}

override toJSON(): JSONBaseEntitlement {
return {
...super.toJSON(),
Expand Down
8 changes: 8 additions & 0 deletions lib/structures/ClientApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ export default class ClientApplication extends Base {
return this.client.rest.applications.bulkEditGuildCommands(this.id, guildID, options);
}

/**
* Mark an entitlement as consumed.
* @param entitlementID The ID of the entitlement to consume.
*/
async consumeEntitlement(entitlementID: string): Promise<void> {
return this.client.rest.applications.consumeEntitlement(this.id, entitlementID);
}

/**
* Create a global application command.
* @param options The options for creating the command.
Expand Down
1 change: 1 addition & 0 deletions lib/util/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export const INTERACTION_CALLBACK = (interactionID: string, int
export const APPLICATION = "/applications/@me";
export const ENTITLEMENTS = (applicationID: string) => encode`/applications/${applicationID}/entitlements`;
export const ENTITLEMENT = (applicationID: string, entitlementID: string) => encode`/applications/${applicationID}/entitlements/${entitlementID}`;
export const CONSUME_ENTITLEMENT = (applicationID: string, entitlementID: string) => encode`/applications/${applicationID}/entitlements/${entitlementID}/consume`;
export const SKUS = (applicationID: string) => encode`/applications/${applicationID}/skus`;

// Misc
Expand Down

0 comments on commit f66367a

Please sign in to comment.