mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +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 Base = require('./Base');
|
||||||
const IntegrationApplication = require('./IntegrationApplication');
|
const IntegrationApplication = require('./IntegrationApplication');
|
||||||
|
const { IntegrationExpireBehaviors } = require('../util/Constants');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The information account for an integration
|
* The information account for an integration
|
||||||
@@ -55,17 +56,21 @@ class Integration extends Base {
|
|||||||
*/
|
*/
|
||||||
this.enabled = data.enabled;
|
this.enabled = data.enabled;
|
||||||
|
|
||||||
/**
|
if ('syncing' in data) {
|
||||||
* Whether this integration is syncing
|
/**
|
||||||
* @type {?boolean}
|
* Whether this integration is syncing
|
||||||
*/
|
* @type {?boolean}
|
||||||
this.syncing = data.syncing;
|
*/
|
||||||
|
this.syncing = data.syncing;
|
||||||
|
} else {
|
||||||
|
this.syncing ??= null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The role that this integration uses for subscribers
|
* The role that this integration uses for subscribers
|
||||||
* @type {?Role}
|
* @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) {
|
if ('enable_emoticons' in data) {
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +89,7 @@ class Integration extends Base {
|
|||||||
*/
|
*/
|
||||||
this.user = this.client.users._add(data.user);
|
this.user = this.client.users._add(data.user);
|
||||||
} else {
|
} else {
|
||||||
this.user = null;
|
this.user ??= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,11 +98,15 @@ class Integration extends Base {
|
|||||||
*/
|
*/
|
||||||
this.account = data.account;
|
this.account = data.account;
|
||||||
|
|
||||||
/**
|
if ('synced_at' in data) {
|
||||||
* The last time this integration was last synced
|
/**
|
||||||
* @type {?number}
|
* The timestamp at which this integration was last synced at
|
||||||
*/
|
* @type {?number}
|
||||||
this.syncedAt = data.synced_at;
|
*/
|
||||||
|
this.syncedTimestamp = Date.parse(data.synced_at);
|
||||||
|
} else {
|
||||||
|
this.syncedTimestamp ??= null;
|
||||||
|
}
|
||||||
|
|
||||||
if ('subscriber_count' in data) {
|
if ('subscriber_count' in data) {
|
||||||
/**
|
/**
|
||||||
@@ -122,6 +131,15 @@ class Integration extends Base {
|
|||||||
this._patch(data);
|
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
|
* All roles that are managed by this integration
|
||||||
* @type {Collection<Snowflake, Role>}
|
* @type {Collection<Snowflake, Role>}
|
||||||
@@ -136,17 +154,21 @@ class Integration extends Base {
|
|||||||
if ('expire_behavior' in data) {
|
if ('expire_behavior' in data) {
|
||||||
/**
|
/**
|
||||||
* The behavior of expiring subscribers
|
* 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) {
|
if ('expire_grace_period' in data) {
|
||||||
/**
|
/**
|
||||||
* The grace period before expiring subscribers
|
* The grace period (in days) before expiring subscribers
|
||||||
* @type {?number}
|
* @type {?number}
|
||||||
*/
|
*/
|
||||||
this.expireGracePeriod = data.expire_grace_period;
|
this.expireGracePeriod = data.expire_grace_period;
|
||||||
|
} else {
|
||||||
|
this.expireGracePeriod ??= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('application' in data) {
|
if ('application' in data) {
|
||||||
|
|||||||
@@ -367,7 +367,6 @@ exports.InviteScopes = [
|
|||||||
'webhook.incoming',
|
'webhook.incoming',
|
||||||
];
|
];
|
||||||
|
|
||||||
// TODO: change Integration#expireBehavior to this and clean up Integration
|
|
||||||
/**
|
/**
|
||||||
* The behavior of expiring subscribers for Integrations. This can be:
|
* The behavior of expiring subscribers for Integrations. This can be:
|
||||||
* * REMOVE_ROLE
|
* * 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 account: IntegrationAccount;
|
||||||
public application: IntegrationApplication | null;
|
public application: IntegrationApplication | null;
|
||||||
public enabled: boolean;
|
public enabled: boolean;
|
||||||
public expireBehavior: number | undefined;
|
public expireBehavior: IntegrationExpireBehaviors | null;
|
||||||
public expireGracePeriod: number | undefined;
|
public expireGracePeriod: number | null;
|
||||||
public guild: Guild;
|
public guild: Guild;
|
||||||
public id: Snowflake | string;
|
public id: Snowflake | string;
|
||||||
public name: string;
|
public name: string;
|
||||||
public role: Role | undefined;
|
public role: Role | null;
|
||||||
public enableEmoticons: boolean | null;
|
public enableEmoticons: boolean | null;
|
||||||
public readonly roles: Collection<Snowflake, Role>;
|
public readonly roles: Collection<Snowflake, Role>;
|
||||||
public syncedAt: number | undefined;
|
public readonly syncedAt: Date | null;
|
||||||
public syncing: boolean | undefined;
|
public syncedTimestamp: number | null;
|
||||||
|
public syncing: boolean | null;
|
||||||
public type: IntegrationType;
|
public type: IntegrationType;
|
||||||
public user: User | null;
|
public user: User | null;
|
||||||
public subscriberCount: number | null;
|
public subscriberCount: number | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user