fix(Invite): support for group dm invites (#2603)

* fix(Invite): support group dm invites

* refactor(Invite): mark all optional properties as nullable and default them to null
This commit is contained in:
SpaceEEC
2018-07-18 11:39:34 +02:00
committed by GitHub
parent e0378cf350
commit 36806612bf

View File

@@ -3,7 +3,7 @@ const Base = require('./Base');
/** /**
* Represents an invitation to a guild channel. * Represents an invitation to a guild channel.
* <warn>The only guaranteed properties are `code`, `guild` and `channel`. Other properties can be missing.</warn> * <warn>The only guaranteed properties are `code` and `channel`. Other properties can be missing.</warn>
* @extends {Base} * @extends {Base}
*/ */
class Invite extends Base { class Invite extends Base {
@@ -15,9 +15,9 @@ class Invite extends Base {
_patch(data) { _patch(data) {
/** /**
* The guild the invite is for * The guild the invite is for
* @type {Guild} * @type {?Guild}
*/ */
this.guild = this.client.guilds.add(data.guild, false); this.guild = data.guild ? this.client.guilds.add(data.guild, false) : null;
/** /**
* The code for this invite * The code for this invite
@@ -27,59 +27,57 @@ class Invite extends Base {
/** /**
* The approximate number of online members of the guild this invite is for * The approximate number of online members of the guild this invite is for
* @type {number} * @type {?number}
*/ */
this.presenceCount = data.approximate_presence_count; this.presenceCount = data.approximate_presence_count || null;
/** /**
* The approximate total number of members of the guild this invite is for * The approximate total number of members of the guild this invite is for
* @type {number} * @type {?number}
*/ */
this.memberCount = data.approximate_member_count; this.memberCount = data.approximate_member_count || null;
/** /**
* The number of text channels the guild this invite goes to has * The number of text channels the guild this invite goes to has
* @type {number} * @type {?number}
*/ */
this.textChannelCount = data.guild.text_channel_count; this.textChannelCount = data.guild ? data.guild.text_channel_count : null;
/** /**
* The number of voice channels the guild this invite goes to has * The number of voice channels the guild this invite goes to has
* @type {number} * @type {?number}
*/ */
this.voiceChannelCount = data.guild.voice_channel_count; this.voiceChannelCount = data.guild ? data.guild.voice_channel_count : null;
/** /**
* Whether or not this invite is temporary * Whether or not this invite is temporary
* @type {boolean} * @type {?boolean}
*/ */
this.temporary = data.temporary; this.temporary = data.temporary || null;
/** /**
* The maximum age of the invite, in seconds * The maximum age of the invite, in seconds
* @type {?number} * @type {?number}
*/ */
this.maxAge = data.max_age; this.maxAge = data.max_age || null;
/** /**
* How many times this invite has been used * How many times this invite has been used
* @type {number} * @type {?number}
*/ */
this.uses = data.uses; this.uses = data.uses || null;
/** /**
* The maximum uses of this invite * The maximum uses of this invite
* @type {number} * @type {?number}
*/ */
this.maxUses = data.max_uses; this.maxUses = data.max_uses || null;
if (data.inviter) { /**
/** * The user who created this invite
* The user who created this invite * @type {?User}
* @type {?User} */
*/ this.inviter = data.inviter ? this.client.users.add(data.inviter) : null;
this.inviter = this.client.users.add(data.inviter);
}
/** /**
* The channel the invite is for * The channel the invite is for
@@ -89,36 +87,36 @@ class Invite extends Base {
/** /**
* The timestamp the invite was created at * The timestamp the invite was created at
* @type {number} * @type {?number}
*/ */
this.createdTimestamp = new Date(data.created_at).getTime(); this.createdTimestamp = new Date(data.created_at).getTime() || null;
} }
/** /**
* The time the invite was created at * The time the invite was created at
* @type {Date} * @type {?Date}
* @readonly * @readonly
*/ */
get createdAt() { get createdAt() {
return new Date(this.createdTimestamp); return this.createdTimestamp ? new Date(this.createdTimestamp) : null;
} }
/** /**
* The timestamp the invite will expire at * The timestamp the invite will expire at
* @type {number} * @type {?number}
* @readonly * @readonly
*/ */
get expiresTimestamp() { get expiresTimestamp() {
return this.createdTimestamp + (this.maxAge * 1000); return this.createdTimestamp ? this.createdTimestamp + (this.maxAge * 1000) : null;
} }
/** /**
* The time the invite will expire at * The time the invite will expire at
* @type {Date} * @type {?Date}
* @readonly * @readonly
*/ */
get expiresAt() { get expiresAt() {
return new Date(this.expiresTimestamp); return this.expiresTimestamp ? new Date(this.expiresTimestamp) : null;
} }
/** /**