Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Integration): add missing props and fix docs/types #6623

Merged
merged 4 commits into from Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/structures/Guild.js
Expand Up @@ -559,7 +559,7 @@ class Guild extends AnonymousGuild {
/**
* Fetches a collection of integrations to this guild.
* Resolves with a collection mapping integrations by their ids.
* @returns {Promise<Collection<string, Integration>>}
* @returns {Promise<Collection<Snowflake|string, Integration>>}
* @example
* // Fetch integrations
* guild.fetchIntegrations()
Expand Down
2 changes: 1 addition & 1 deletion src/structures/GuildAuditLogs.js
Expand Up @@ -174,7 +174,7 @@ class GuildAuditLogs {

/**
* Cached integrations
* @type {Collection<Snowflake, Integration>}
* @type {Collection<Snowflake|string, Integration>}
* @private
*/
this.integrations = new Collection();
Expand Down
47 changes: 39 additions & 8 deletions src/structures/Integration.js
Expand Up @@ -6,7 +6,7 @@ const IntegrationApplication = require('./IntegrationApplication');
/**
* The information account for an integration
* @typedef {Object} IntegrationAccount
* @property {string} id The id of the account
* @property {Snowflake|string} id The id of the account
* @property {string} name The name of the account
*/

Expand All @@ -25,7 +25,7 @@ class Integration extends Base {

/**
* The integration id
* @type {Snowflake}
* @type {Snowflake|string}
*/
this.id = data.id;

Expand All @@ -36,7 +36,7 @@ class Integration extends Base {
this.name = data.name;

/**
* The integration type (twitch, youtube, etc)
* The integration type (twitch, youtube or discord)
* @type {string}
*/
this.type = data.type;
Expand All @@ -49,16 +49,26 @@ class Integration extends Base {

/**
* Whether this integration is syncing
* @type {boolean}
* @type {?boolean}
*/
this.syncing = data.syncing;

/**
* The role that this integration uses for subscribers
* @type {Role}
* @type {?Role}
*/
this.role = this.guild.roles.cache.get(data.role_id);

if ('enable_emoticons' in data) {
/**
* Whether emoticons should be synced for this integration (twitch only currently)
* @type {?boolean}
*/
this.enableEmoticons = data.enable_emoticons;
} else {
this.enableEmoticons ??= null;
}

if (data.user) {
/**
* The user for this integration
Expand All @@ -77,9 +87,30 @@ class Integration extends Base {

/**
* The last time this integration was last synced
* @type {number}
* @type {?number}
*/
this.syncedAt = data.synced_at;

if ('subscriber_count' in data) {
/**
* How many subscribers this integration has
* @type {?number}
*/
this.subscriberCount = data.subscriber_count;
} else {
this.subscriberCount ??= null;
}

if ('revoked' in data) {
/**
* Whether this integration has been revoked
* @type {?boolean}
*/
this.revoked = data.revoked;
} else {
this.revoked ??= null;
}

this._patch(data);
}

Expand All @@ -96,13 +127,13 @@ class Integration extends Base {
_patch(data) {
/**
* The behavior of expiring subscribers
* @type {number}
* @type {?number}
*/
this.expireBehavior = data.expire_behavior;

/**
* The grace period before expiring subscribers
* @type {number}
* @type {?number}
*/
this.expireGracePeriod = data.expire_grace_period;

Expand Down
2 changes: 1 addition & 1 deletion src/structures/Role.js
Expand Up @@ -87,7 +87,7 @@ class Role extends Base {
* The tags this role has
* @type {?Object}
* @property {Snowflake} [botId] The id of the bot this role belongs to
* @property {Snowflake} [integrationId] The id of the integration this role belongs to
* @property {Snowflake|string} [integrationId] The id of the integration this role belongs to
* @property {true} [premiumSubscriberRole] Whether this is the guild's premium subscription role
*/
this.tags = data.tags ? {} : null;
Expand Down
9 changes: 9 additions & 0 deletions src/util/Constants.js
Expand Up @@ -352,6 +352,15 @@ exports.InviteScopes = [
'webhook.incoming',
];

// TODO: change Integration#expireBehavior to this and clean up Integration
/**
* The behavior of expiring subscribers for Integrations. This can be:
* * REMOVE_ROLE
* * KICK
* @typedef {string} IntegrationExpireBehavior
* @see {@link https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors}
*/
exports.IntegrationExpireBehaviors = createEnum(['REMOVE_ROLE', 'KICK']);
ImRodry marked this conversation as resolved.
Show resolved Hide resolved
/**
* The type of a message, e.g. `DEFAULT`. Here are the available types:
* * DEFAULT
Expand Down
27 changes: 18 additions & 9 deletions typings/index.d.ts
Expand Up @@ -724,7 +724,7 @@ export class Guild extends AnonymousGuild {
public editWelcomeScreen(data: WelcomeScreenEditData): Promise<WelcomeScreen>;
public equals(guild: Guild): boolean;
public fetchAuditLogs(options?: GuildAuditLogsFetchOptions): Promise<GuildAuditLogs>;
public fetchIntegrations(): Promise<Collection<string, Integration>>;
public fetchIntegrations(): Promise<Collection<Snowflake | string, Integration>>;
public fetchOwner(options?: FetchOwnerOptions): Promise<GuildMember>;
public fetchPreview(): Promise<GuildPreview>;
public fetchTemplates(): Promise<Collection<GuildTemplate['code'], GuildTemplate>>;
Expand Down Expand Up @@ -765,7 +765,7 @@ export class Guild extends AnonymousGuild {
export class GuildAuditLogs {
public constructor(guild: Guild, data: RawGuildAuditLogData);
private webhooks: Collection<Snowflake, Webhook>;
private integrations: Collection<Snowflake, Integration>;
private integrations: Collection<Snowflake | string, Integration>;

public entries: Collection<Snowflake, GuildAuditLogsEntry>;

Expand Down Expand Up @@ -975,17 +975,20 @@ export class Integration extends Base {
public account: IntegrationAccount;
public application: IntegrationApplication | null;
public enabled: boolean;
public expireBehavior: number;
public expireGracePeriod: number;
public expireBehavior: number | undefined;
public expireGracePeriod: number | undefined;
public guild: Guild;
public id: Snowflake;
public id: Snowflake | string;
public name: string;
public role: Role;
public role: Role | undefined;
public enableEmoticons: boolean | null;
public readonly roles: Collection<Snowflake, Role>;
public syncedAt: number;
public syncing: boolean;
public syncedAt: number | undefined;
public syncing: boolean | undefined;
public type: string;
public user: User | null;
public subscriberCount: number | null;
public revoked: boolean | null;
public delete(reason?: string): Promise<Integration>;
}

Expand Down Expand Up @@ -2335,6 +2338,7 @@ export const Constants: {
TextBasedChannelTypes: TextBasedChannelTypes[];
VoiceBasedChannelTypes: VoiceBasedChannelTypes[];
ClientApplicationAssetTypes: ConstantsClientApplicationAssetTypes;
IntegrationExpireBehaviors: IntegrationExpireBehaviors[];
InviteScopes: InviteScope[];
MessageTypes: MessageType[];
SystemMessageTypes: SystemMessageType[];
Expand Down Expand Up @@ -3283,7 +3287,10 @@ export interface ClientEvents {
message: [message: Message];
messageCreate: [message: Message];
messageDelete: [message: Message | PartialMessage];
messageReactionRemoveAll: [message: Message | PartialMessage, reactions: Collection<string | Snowflake, MessageReaction>];
messageReactionRemoveAll: [
message: Message | PartialMessage,
reactions: Collection<string | Snowflake, MessageReaction>,
];
messageReactionRemoveEmoji: [reaction: MessageReaction | PartialMessageReaction];
messageDeleteBulk: [messages: Collection<Snowflake, Message | PartialMessage>];
messageReactionAdd: [reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser];
Expand Down Expand Up @@ -4102,6 +4109,8 @@ export interface CreateInviteOptions {
targetType?: InviteTargetType;
}

export type IntegrationExpireBehaviors = 'REMOVE_ROLE' | 'KICK';

export type InviteResolvable = string;

export type InviteScope =
Expand Down