From 9c90b53e3869b596aab4c1eb6e0d5331dcbdc615 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Sat, 11 Sep 2021 02:23:59 +0100 Subject: [PATCH 1/4] feat(Integration): add missing props and fix docs/types --- src/structures/Integration.js | 43 ++++++++++++++++++++++++++++++----- src/util/Constants.js | 9 ++++++++ typings/index.d.ts | 18 ++++++++++----- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/structures/Integration.js b/src/structures/Integration.js index 846e047ddcb8..6c09b69caef2 100644 --- a/src/structures/Integration.js +++ b/src/structures/Integration.js @@ -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; @@ -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 @@ -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); } @@ -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; diff --git a/src/util/Constants.js b/src/util/Constants.js index 7ec2fa7b8f2e..d1f1efda3d89 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -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']); /** * The type of a message, e.g. `DEFAULT`. Here are the available types: * * DEFAULT diff --git a/typings/index.d.ts b/typings/index.d.ts index 1318b873efff..8d4ac874267c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -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 name: string; - public role: Role; + public role: Role | undefined; + public enableEmoticons: boolean | null; public readonly roles: Collection; - 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; } @@ -3283,7 +3286,10 @@ export interface ClientEvents { message: [message: Message]; messageCreate: [message: Message]; messageDelete: [message: Message | PartialMessage]; - messageReactionRemoveAll: [message: Message | PartialMessage, reactions: Collection]; + messageReactionRemoveAll: [ + message: Message | PartialMessage, + reactions: Collection, + ]; messageReactionRemoveEmoji: [reaction: MessageReaction | PartialMessageReaction]; messageDeleteBulk: [messages: Collection]; messageReactionAdd: [reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser]; From 4296d7bbfc957f4285c93310db199692c883978f Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Sat, 11 Sep 2021 02:39:11 +0100 Subject: [PATCH 2/4] docs(Integration): fix ID type --- src/structures/Guild.js | 2 +- src/structures/GuildAuditLogs.js | 2 +- src/structures/Integration.js | 4 ++-- src/structures/Role.js | 2 +- typings/index.d.ts | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 487478307f90..27a755f05a75 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -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>} + * @returns {Promise>} * @example * // Fetch integrations * guild.fetchIntegrations() diff --git a/src/structures/GuildAuditLogs.js b/src/structures/GuildAuditLogs.js index c3876ea262e5..b323de9876a2 100644 --- a/src/structures/GuildAuditLogs.js +++ b/src/structures/GuildAuditLogs.js @@ -174,7 +174,7 @@ class GuildAuditLogs { /** * Cached integrations - * @type {Collection} + * @type {Collection} * @private */ this.integrations = new Collection(); diff --git a/src/structures/Integration.js b/src/structures/Integration.js index 6c09b69caef2..674b7b8fb212 100644 --- a/src/structures/Integration.js +++ b/src/structures/Integration.js @@ -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 */ @@ -25,7 +25,7 @@ class Integration extends Base { /** * The integration id - * @type {Snowflake} + * @type {Snowflake|string} */ this.id = data.id; diff --git a/src/structures/Role.js b/src/structures/Role.js index 4d290243d98f..bdbffb6cc80b 100644 --- a/src/structures/Role.js +++ b/src/structures/Role.js @@ -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; diff --git a/typings/index.d.ts b/typings/index.d.ts index 8d4ac874267c..76df4559dfca 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -724,7 +724,7 @@ export class Guild extends AnonymousGuild { public editWelcomeScreen(data: WelcomeScreenEditData): Promise; public equals(guild: Guild): boolean; public fetchAuditLogs(options?: GuildAuditLogsFetchOptions): Promise; - public fetchIntegrations(): Promise>; + public fetchIntegrations(): Promise>; public fetchOwner(options?: FetchOwnerOptions): Promise; public fetchPreview(): Promise; public fetchTemplates(): Promise>; @@ -765,7 +765,7 @@ export class Guild extends AnonymousGuild { export class GuildAuditLogs { public constructor(guild: Guild, data: RawGuildAuditLogData); private webhooks: Collection; - private integrations: Collection; + private integrations: Collection; public entries: Collection; @@ -978,7 +978,7 @@ export class Integration extends Base { public expireBehavior: number | undefined; public expireGracePeriod: number | undefined; public guild: Guild; - public id: Snowflake; + public id: Snowflake | string; public name: string; public role: Role | undefined; public enableEmoticons: boolean | null; From b7b06ea9cda700d860ee30db646f6b86e1dec397 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Sat, 11 Sep 2021 02:47:03 +0100 Subject: [PATCH 3/4] types(Constants): add new enum --- typings/index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/typings/index.d.ts b/typings/index.d.ts index 76df4559dfca..48fa698b5e8c 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -2338,6 +2338,7 @@ export const Constants: { TextBasedChannelTypes: TextBasedChannelTypes[]; VoiceBasedChannelTypes: VoiceBasedChannelTypes[]; ClientApplicationAssetTypes: ConstantsClientApplicationAssetTypes; + IntegrationExpireBehaviors: IntegrationExpireBehaviors[]; InviteScopes: InviteScope[]; MessageTypes: MessageType[]; SystemMessageTypes: SystemMessageType[]; @@ -4108,6 +4109,8 @@ export interface CreateInviteOptions { targetType?: InviteTargetType; } +export type IntegrationExpireBehaviors = 'REMOVE_ROLE' | 'KICK'; + export type InviteResolvable = string; export type InviteScope = From 9d06f9e22427f9d38ec5e97f1975f07258d61075 Mon Sep 17 00:00:00 2001 From: Rodry <38259440+ImRodry@users.noreply.github.com> Date: Tue, 14 Sep 2021 23:22:27 +0100 Subject: [PATCH 4/4] style: add empty line Co-authored-by: Noel --- src/util/Constants.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/Constants.js b/src/util/Constants.js index d1f1efda3d89..e5f2322cbdf2 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -361,6 +361,7 @@ exports.InviteScopes = [ * @see {@link https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors} */ exports.IntegrationExpireBehaviors = createEnum(['REMOVE_ROLE', 'KICK']); + /** * The type of a message, e.g. `DEFAULT`. Here are the available types: * * DEFAULT