Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions esm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const {
DiscordHTTPError,
DiscordRESTError,
DMChannel,
Entitlement,
ExtendedUser,
ForumChannel,
GroupChannel,
Expand All @@ -47,6 +48,8 @@ export const {
PublicThreadChannel,
RequestHandler,
Role,
SKU,
Subscription,
SequentialBucket,
Shard,
SharedStream,
Expand Down
102 changes: 100 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ declare namespace Eris {

// Message
type ActionRowComponents = Button | SelectMenu;
type Button = InteractionButton | URLButton;
type Button = InteractionButton | URLButton | PremiumButton;
type ButtonStyles = Constants["ButtonStyles"][keyof Constants["ButtonStyles"]];
type Component = ActionRow | ActionRowComponents;
type ImageFormat = Constants["ImageFormats"][number];
Expand Down Expand Up @@ -202,6 +202,13 @@ declare namespace Eris {
type WebhookPayloadEdit = Pick<WebhookPayload, "attachments" | "content" | "embed" | "embeds" | "file" | "allowedMentions" | "components">;
type WebhookTypes = Constants["WebhookTypes"][keyof Constants["WebhookTypes"]];

// Subscriptions
type EntitlementTypes = Constants["EntitlementTypes"][keyof Constants["EntitlementTypes"]];
type EntitlementOwnerTypes = Constants["EntitlementOwnerTypes"][keyof Constants["EntitlementOwnerTypes"]];
type SKUTypes = Constants["SKUTypes"][keyof Constants["SKUTypes"]];
type SKUFlags = Constants["SKUFlags"][keyof Constants["SKUFlags"]];
type SubscriptionStatuses = Constants["SubscriptionStatuses"][keyof Constants["SubscriptionStatuses"]];

// INTERFACES
// Internals
type JSONCache = Record<string, unknown>;
Expand Down Expand Up @@ -983,6 +990,12 @@ declare namespace Eris {
voiceStateUpdate: [member: Member, oldState: OldVoiceState];
warn: [message: string, id?: number];
webhooksUpdate: [data: WebhookData];
entitlementCreate: [entitlement: Entitlement];
entitlementUpdate: [entitlement: Entitlement];
entitlementDelete: [entitlement: Entitlement];
subscriptionCreate: [subscription: Subscription];
subscriptionDelete: [subscription: Subscription];
subscriptionUpdate: [subscription: Subscription];
}
interface ClientEvents extends EventListeners {
shardDisconnect: [err: Error | undefined, id: number];
Expand Down Expand Up @@ -1358,6 +1371,30 @@ declare namespace Eris {
reason?: string;
}

// Subscriptions
interface CreateTestEntitlementOptions {
skuID: string;
ownerID: string;
ownerType: EntitlementOwnerTypes;
}

interface GetEntitlementsOptions {
userID?: string;
skuIDs?: string[];
before?: number;
after?: number;
limit?: number;
guildID?: string;
excludeEnded?: boolean;
}

interface GetSKUSubscriptionsOptions {
userID: string;
before?: number;
after?: number;
limit?: number;
}

// Interaction
interface AutocompleteInteractionData {
id: string;
Expand Down Expand Up @@ -1590,7 +1627,7 @@ declare namespace Eris {
}
interface InteractionButton extends ButtonBase {
custom_id: string;
style: Exclude<ButtonStyles, Constants["ButtonStyles"]["LINK"]>;
style: Exclude<ButtonStyles, Constants["ButtonStyles"]["LINK"] | Constants["ButtonStyles"]["PREMIUM"]>;
}
interface MessageActivity {
party_id?: string;
Expand Down Expand Up @@ -1741,6 +1778,10 @@ declare namespace Eris {
style: Constants["ButtonStyles"]["LINK"];
url: string;
}
interface PremiumButton extends ButtonBase {
style: Constants["ButtonStyles"]["PREMIUM"];
sku_id: string;
}

// Presence
interface Activity<T extends ActivityType = ActivityType> extends ActivityPartial<T> {
Expand Down Expand Up @@ -2179,6 +2220,7 @@ declare namespace Eris {
bulkEditGuildCommands(guildID: string, commands: ApplicationCommandBulkEditOptions<true>[]): Promise<ApplicationCommand<true>[]>;
closeVoiceConnection(guildID: string): void;
connect(): Promise<void>;
consumeEntitlement(entitlementID: string): Promise<void>;
createAutoModerationRule(guildID: string, rule: AutoModerationCreateOptions): Promise<AutoModerationRule>;
createChannel(guildID: string, name: string): Promise<TextChannel>;
createChannel<T extends GuildChannelTypes>(guildID: string, name: string, type: T, options?: CreateChannelOptions): Promise<ChannelTypeConversion<T>>;
Expand Down Expand Up @@ -2209,12 +2251,15 @@ declare namespace Eris {
createMessage(channelID: string, content: MessageContent, file?: FileContent | FileContent[]): Promise<Message>;
createRole(guildID: string, options?: Role | RoleOptions, reason?: string): Promise<Role>;
createStageInstance(channelID: string, options: StageInstanceOptions): Promise<StageInstance>;
createTestEntitlement(options: CreateTestEntitlementOptions): Promise<Entitlement>;
createThread(channelID: string, options: CreateForumThreadOptions, file?: FileContent | FileContent[]): Promise<PublicThreadChannel<true>>;
createThread(channelID: string, options: CreateThreadWithoutMessageOptions, file?: FileContent | FileContent[]): Promise<NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>;
createThreadWithMessage(channelID: string, messageID: string, options: CreateThreadOptions): Promise<NewsThreadChannel | PublicThreadChannel>;
/** @deprecated */
createThreadWithoutMessage(channelID: string, options: CreateThreadWithoutMessageOptions): Promise<NewsThreadChannel | PrivateThreadChannel | PublicThreadChannel>;

crosspostMessage(channelID: string, messageID: string): Promise<Message>;

deleteAutoModerationRule(guildID: string, ruleID: string, reason?: string): Promise<void>;
deleteChannel(channelID: string, reason?: string): Promise<void>;
deleteChannelPermission(channelID: string, overwriteID: string, reason?: string): Promise<void>;
Expand All @@ -2234,6 +2279,7 @@ declare namespace Eris {
deleteMessages(channelID: string, messageIDs: string[], reason?: string): Promise<void>;
deleteRole(guildID: string, roleID: string, reason?: string): Promise<void>;
deleteStageInstance(channelID: string): Promise<void>;
deleteTestEntitlement(entitlementID: string): Promise<void>;
deleteWebhook(webhookID: string, token?: string, reason?: string): Promise<void>;
deleteWebhookMessage(webhookID: string, token: string, messageID: string): Promise<void>;
disconnect(options: { reconnect?: boolean | "auto" }): void;
Expand Down Expand Up @@ -2324,6 +2370,7 @@ declare namespace Eris {
getEmoji(emojiID: string): Promise<Emoji>;
getEmojis(): Promise<ApplicationEmojis>;
getEmojiGuild(emojiID: string): Promise<Guild>;
getEntitlements(options?: GetEntitlementsOptions): Promise<Entitlement[]>;
getGateway(): Promise<{ url: string }>;
getGuildAuditLog(guildID: string, options?: GetGuildAuditLogOptions): Promise<GuildAuditLog>;
/** @deprecated */
Expand Down Expand Up @@ -2389,6 +2436,11 @@ declare namespace Eris {
getRESTUser(userID: string): Promise<User>;
getRoleConnectionMetadataRecords(): Promise<ApplicationRoleConnectionMetadata[]>;
getSelf(): Promise<ExtendedUser>;
getSKUs(): Promise<SKU[]>;
getSKUSubscription(skuID: string, subscriptionID: string): Promise<Subscription>;

getSKUSubscriptions(skuID: string, options: GetSKUSubscriptionsOptions): Promise<Subscription[]>;

getSoundboardSounds(): Promise<SoundboardSound<false>[]>;
getStageInstance(channelID: string): Promise<StageInstance>;
getStickerPack(packID: string): Promise<StickerPack>;
Expand Down Expand Up @@ -2567,6 +2619,45 @@ declare namespace Eris {
unsendMessage(messageID: string): Promise<void>;
}

export class Entitlement extends Base {
applicationID: string;
consumed: boolean;
deleted: boolean;
endsAt?: number | null;
guildID?: string;
skuID: string;
startsAt?: number | null;
type: EntitlementTypes;
userID?: string;
consume(): Promise<void>;
}

export class SKU extends Base {
applicationID: string;
flags: SKUFlags;
name: string;
slug: string;
type: SKUTypes;
createTestEntitlement(ownerID: string, ownerType: EntitlementOwnerTypes): Promise<Entitlement>;
getEntitlements(options?: Omit<GetEntitlementsOptions, "skuIDs">): Promise<Entitlement[]>;
getSKUSubscription(subscriptionID: string): Promise<Subscription>;
getSKUSubscriptions(): Promise<Subscription[]>;
}

export class Subscription extends Base {
canceledAt: number | null;
country?: string;
currentPeriodEnd: number;

currentPeriodStart: number;

entitlementIDs: string[];
renewalSKUIDs: string[] | null;
skuIDs: string[];
status: SubscriptionStatuses;
userID: string;
}

export class ExtendedUser extends User {
email: string;
mfaEnabled: boolean;
Expand Down Expand Up @@ -2681,6 +2772,8 @@ declare namespace Eris {
createSoundboardSound(sound: GuildSoundboardSoundCreate, reason?: string): Promise<SoundboardSound>;
createSticker(options: CreateStickerOptions, reason?: string): Promise<Sticker>;
createTemplate(name: string, description?: string | null): Promise<GuildTemplate>;
createTestEntitlement(skuID: string): Promise<Entitlement>;

delete(): Promise<void>;
deleteAutoModerationRule(ruleID: string, reason?: string): Promise<void>;
deleteCommand(commandID: string): Promise<void>;
Expand Down Expand Up @@ -2733,6 +2826,8 @@ declare namespace Eris {
getDiscovery(): Promise<DiscoveryMetadata>;
/** @deprecated */
getEmbed(): Promise<Widget>;
getEntitlements(options?: Omit<GetEntitlementsOptions, "guildID">): Promise<Entitlement[]>;

getIntegrations(): Promise<GuildIntegration>;
getInvites(): Promise<Invite[]>;
getOnboarding(): Promise<GuildOnboarding>;
Expand Down Expand Up @@ -3527,9 +3622,12 @@ declare namespace Eris {
system: boolean;
username: string;
constructor(data: BaseData, client: Client);
createTestEntitlement(skuID: string): Promise<Entitlement>;
dynamicAvatarURL(format?: ImageFormat, size?: number): string;
dynamicBannerURL(format?: ImageFormat, size?: number): string | null;

getDMChannel(): Promise<DMChannel>;
getEntitlements(options?: Omit<GetEntitlementsOptions, "userID">): Promise<Entitlement[]>;
}

export class VoiceChannel extends GuildTextableChannel implements Invitable, Permissionable {
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Eris.Constants = require("./lib/Constants");
Eris.DiscordHTTPError = require("./lib/errors/DiscordHTTPError");
Eris.DiscordRESTError = require("./lib/errors/DiscordRESTError");
Eris.DMChannel = require("./lib/structures/DMChannel");
Eris.Entitlement = require("./lib/structures/Entitlement");
Eris.ExtendedUser = require("./lib/structures/ExtendedUser");
Eris.ForumChannel = require("./lib/structures/ForumChannel");
Eris.GroupChannel = require("./lib/structures/GroupChannel");
Expand All @@ -49,6 +50,8 @@ Eris.PrivateThreadChannel = require("./lib/structures/PrivateThreadChannel");
Eris.PublicThreadChannel = require("./lib/structures/PublicThreadChannel");
Eris.RequestHandler = require("./lib/rest/RequestHandler");
Eris.Role = require("./lib/structures/Role");
Eris.SKU = require("./lib/structures/SKU");
Eris.Subscription = require("./lib/structures/Subscription");
Eris.SequentialBucket = require("./lib/util/SequentialBucket");
Eris.Shard = require("./lib/gateway/Shard");
Eris.SharedStream = require("./lib/voice/SharedStream");
Expand Down
97 changes: 97 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const ThreadMember = require("./structures/ThreadMember");
const UnavailableGuild = require("./structures/UnavailableGuild");
const User = require("./structures/User");
const VoiceConnectionManager = require("./voice/VoiceConnectionManager");
const Entitlement = require("./structures/Entitlement");
const Subscription = require("./structures/Subscription");
const VoiceState = require("./structures/VoiceState");

let EventEmitter;
Expand Down Expand Up @@ -516,6 +518,15 @@ class Client extends EventEmitter {
}
}

/**
* For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed
* @arg {String} entitlementID The ID of the the entitlement
* @returns {Promise}
*/
consumeEntitlement(entitlementID) {
return this.requestHandler.request("POST", Endpoints.ENTITLEMENT_CONSUME(this.application.id, entitlementID), true);
}

/**
* Create an auto moderation rule
* @arg {String} guildID the ID of the guild to create the rule in
Expand Down Expand Up @@ -1075,6 +1086,22 @@ class Client extends EventEmitter {
}).then((instance) => new StageInstance(instance, this));
}

/**
* Create a test entitlement
* @arg {Object} options The options for creating a test entitlement
* @arg {String} options.skuID The ID of the SKU to grant the entitlement to
* @arg {String} options.ownerID The ID of the owner to create the entitlement for
* @arg {Number} options.ownerType The type of the owner to create the entitlement for
* @returns {Promise<Object>}
*/
createTestEntitlement(options) {
return this.requestHandler.request("POST", Endpoints.ENTITLEMENTS(this.application.id), true, {
sku_id: options.skuID,
owner_id: options.ownerID,
owner_type: options.ownerType,
}).then((entitlement) => new Entitlement(entitlement, this));
}

/**
* Create a thread in a channel
* @arg {String} channelID The ID of the channel
Expand Down Expand Up @@ -1440,6 +1467,15 @@ class Client extends EventEmitter {
return this.requestHandler.request("DELETE", Endpoints.STAGE_INSTANCE(channelID), true);
}

/**
* Delete a test entitlement
* @arg {String} entitlementID The ID of the entitlement
* @returns {Promise}
*/
deleteTestEntitlement(entitlementID) {
return this.requestHandler.request("DELETE", Endpoints.ENTITLEMENT(this.application.id, entitlementID), true);
}

/**
* Delete a webhook
* @arg {String} webhookID The ID of the webhook
Expand Down Expand Up @@ -2675,6 +2711,30 @@ class Client extends EventEmitter {
return this.requestHandler.request("GET", Endpoints.CUSTOM_EMOJI_GUILD(emojiID), true).then((result) => new Guild(result, this));
}

/**
* Get a list of entitlements for this application
* @arg {Object} [options] The options for the request
* @arg {String} [options.userID] The user ID to look up entitlements for
* @arg {Array<String>} [options.skuIDs] An optional list of SKU IDs to check entitlements for
* @arg {Number} [options.before] Retrieve entitlements before this entitlement ID
* @arg {Number} [options.after] Retrieve entitlements after this entitlement ID
* @arg {Number} [options.limit=100] The number of entitlements to return, 1-100, default 100
* @arg {String} [options.guildID] The guild ID to look up entitlements for
* @arg {Boolean} [options.excludeEnded] Whether or not ended entitlements should be omitted
* @returns {Promise<Array<Object>>}
*/
getEntitlements(options = {}) {
return this.requestHandler.request("GET", Endpoints.ENTITLEMENTS(this.application.id), true, {
user_id: options.userID,
sku_ids: options.skuIDs,
before: options.before,
after: options.after,
limit: options.limit,
guild_id: options.guildID,
exclude_ended: options.excludeEnded,
}).then((entitlements) => entitlements.map((entitlement) => new Entitlement(entitlement, this)));
}

/**
* Get info on connecting to the Discord gateway
* @returns {Promise<Object>} Resolves with an object containing gateway connection info
Expand Down Expand Up @@ -3459,6 +3519,43 @@ class Client extends EventEmitter {
return this.requestHandler.request("GET", Endpoints.USER("@me"), true).then((data) => new ExtendedUser(data, this));
}

/**
* Get a list of SKUs for a given application
* @returns {Promise<Array<Object>>}
*/
getSKUs() {
return this.requestHandler.request("GET", Endpoints.SKUS(this.application.id), true);
}

/**
* Get a subscription by its ID from an SKU
* @arg {String} [skuID] The id of the sku
* @arg {String} [subscriptionID] The id of the subscription
* @returns {Promise<Object>}
*/
getSKUSubscription(skuID, subscriptionID) {
return this.requestHandler.request("GET", Endpoints.SKU_SUBSCRIPTION(skuID, subscriptionID), true).then((subscription) => new Subscription(subscription));
}

/**
* Get a list of subscriptions from an SKU
* @arg {String} [skuID] The id of the sku
* @arg {Object} [options] The options for the request
* @arg {String} [options.userID] The user ID to look up subscriptions for. Required except for OAuth queries.
* @arg {Number} [options.before] Retrieve subscriptions before this ID
* @arg {Number} [options.after] Retrieve subscriptions after this ID
* @arg {Number} [options.limit=50] The number of subscriptions to return, 1-100, default 50
* @returns {Promise<Array<Subscription>>}
*/
getSKUSubscriptions(skuID, options = {}) {
return this.requestHandler.request("GET", Endpoints.SKU_SUBSCRIPTIONS(skuID), true, {
user_id: options.userID,
before: options.before,
after: options.after,
limit: options.limit,
}).then((subscriptions) => subscriptions.map((subscription) => new Subscription(subscription)));
}

/**
* Get the default soundboard sounds
* @returns {Promise<Array<SoundboardSound>>}
Expand Down
Loading