mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
refactor(integration): turn undefined into null and consistency (#7209)
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
const Base = require('./Base');
|
||||
const IntegrationApplication = require('./IntegrationApplication');
|
||||
const { IntegrationExpireBehaviors } = require('../util/Constants');
|
||||
|
||||
/**
|
||||
* The information account for an integration
|
||||
@@ -55,17 +56,21 @@ class Integration extends Base {
|
||||
*/
|
||||
this.enabled = data.enabled;
|
||||
|
||||
/**
|
||||
* Whether this integration is syncing
|
||||
* @type {?boolean}
|
||||
*/
|
||||
this.syncing = data.syncing;
|
||||
if ('syncing' in data) {
|
||||
/**
|
||||
* Whether this integration is syncing
|
||||
* @type {?boolean}
|
||||
*/
|
||||
this.syncing = data.syncing;
|
||||
} else {
|
||||
this.syncing ??= null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The role that this integration uses for subscribers
|
||||
* @type {?Role}
|
||||
*/
|
||||
this.role = this.guild.roles.cache.get(data.role_id);
|
||||
this.role = this.guild.roles.resolve(data.role_id);
|
||||
|
||||
if ('enable_emoticons' in data) {
|
||||
/**
|
||||
@@ -84,7 +89,7 @@ class Integration extends Base {
|
||||
*/
|
||||
this.user = this.client.users._add(data.user);
|
||||
} else {
|
||||
this.user = null;
|
||||
this.user ??= null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,11 +98,15 @@ class Integration extends Base {
|
||||
*/
|
||||
this.account = data.account;
|
||||
|
||||
/**
|
||||
* The last time this integration was last synced
|
||||
* @type {?number}
|
||||
*/
|
||||
this.syncedAt = data.synced_at;
|
||||
if ('synced_at' in data) {
|
||||
/**
|
||||
* The timestamp at which this integration was last synced at
|
||||
* @type {?number}
|
||||
*/
|
||||
this.syncedTimestamp = Date.parse(data.synced_at);
|
||||
} else {
|
||||
this.syncedTimestamp ??= null;
|
||||
}
|
||||
|
||||
if ('subscriber_count' in data) {
|
||||
/**
|
||||
@@ -122,6 +131,15 @@ class Integration extends Base {
|
||||
this._patch(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* The date at which this integration was last synced at
|
||||
* @type {?Date}
|
||||
* @readonly
|
||||
*/
|
||||
get syncedAt() {
|
||||
return this.syncedTimestamp && new Date(this.syncedTimestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* All roles that are managed by this integration
|
||||
* @type {Collection<Snowflake, Role>}
|
||||
@@ -136,17 +154,21 @@ class Integration extends Base {
|
||||
if ('expire_behavior' in data) {
|
||||
/**
|
||||
* The behavior of expiring subscribers
|
||||
* @type {?number}
|
||||
* @type {?IntegrationExpireBehavior}
|
||||
*/
|
||||
this.expireBehavior = data.expire_behavior;
|
||||
this.expireBehavior = IntegrationExpireBehaviors[data.expire_behavior];
|
||||
} else {
|
||||
this.expireBehavior ??= null;
|
||||
}
|
||||
|
||||
if ('expire_grace_period' in data) {
|
||||
/**
|
||||
* The grace period before expiring subscribers
|
||||
* The grace period (in days) before expiring subscribers
|
||||
* @type {?number}
|
||||
*/
|
||||
this.expireGracePeriod = data.expire_grace_period;
|
||||
} else {
|
||||
this.expireGracePeriod ??= null;
|
||||
}
|
||||
|
||||
if ('application' in data) {
|
||||
|
||||
@@ -367,7 +367,6 @@ 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
|
||||
|
||||
11
packages/discord.js/typings/index.d.ts
vendored
11
packages/discord.js/typings/index.d.ts
vendored
@@ -1241,16 +1241,17 @@ export class Integration extends Base {
|
||||
public account: IntegrationAccount;
|
||||
public application: IntegrationApplication | null;
|
||||
public enabled: boolean;
|
||||
public expireBehavior: number | undefined;
|
||||
public expireGracePeriod: number | undefined;
|
||||
public expireBehavior: IntegrationExpireBehaviors | null;
|
||||
public expireGracePeriod: number | null;
|
||||
public guild: Guild;
|
||||
public id: Snowflake | string;
|
||||
public name: string;
|
||||
public role: Role | undefined;
|
||||
public role: Role | null;
|
||||
public enableEmoticons: boolean | null;
|
||||
public readonly roles: Collection<Snowflake, Role>;
|
||||
public syncedAt: number | undefined;
|
||||
public syncing: boolean | undefined;
|
||||
public readonly syncedAt: Date | null;
|
||||
public syncedTimestamp: number | null;
|
||||
public syncing: boolean | null;
|
||||
public type: IntegrationType;
|
||||
public user: User | null;
|
||||
public subscriberCount: number | null;
|
||||
|
||||
Reference in New Issue
Block a user