fix(Partials): correctly set properties as nullable (#4636)

This commit is contained in:
Sugden
2020-08-12 20:26:59 +01:00
committed by GitHub
parent b6ddd4ce41
commit 980243f2d5
4 changed files with 143 additions and 98 deletions

View File

@@ -26,60 +26,78 @@ class User extends Base {
*/
this.id = data.id;
/**
* Whether or not the user is a bot
* @type {boolean}
* @name User#bot
*/
this.bot = Boolean(data.bot);
this._patch(data);
}
_patch(data) {
/**
* The username of the user
* @type {?string}
* @name User#username
*/
if (data.username) this.username = data.username;
if (typeof this.bot !== 'boolean') {
/**
* Whether or not the user is a bot
* @type {?boolean}
* @name User#bot
*/
this.bot = 'bot' in data ? Boolean(data.bot) : null;
}
/**
* A discriminator based on username for the user
* @type {?string}
* @name User#discriminator
*/
if (data.discriminator) this.discriminator = data.discriminator;
if ('username' in data) {
/**
* The username of the user
* @type {?string}
* @name User#username
*/
this.username = data.username;
} else if (typeof this.username !== 'string') {
this.username = null;
}
/**
* The ID of the user's avatar
* @type {?string}
* @name User#avatar
*/
if (typeof data.avatar !== 'undefined') this.avatar = data.avatar;
if ('discriminator' in data) {
/**
* A discriminator based on username for the user
* @type {?string}
* @name User#discriminator
*/
this.discriminator = data.discriminator;
} else if (typeof this.discriminator !== 'string') {
this.discriminator = null;
}
if (typeof data.bot !== 'undefined') this.bot = Boolean(data.bot);
if ('avatar' in data) {
/**
* The ID of the user's avatar
* @type {?string}
* @name User#avatar
*/
this.avatar = data.avatar;
} else if (typeof this.avatar !== 'string') {
this.avatar = null;
}
/**
* Whether the user is an Official Discord System user (part of the urgent message system)
* @type {?boolean}
* @name User#system
*/
if (typeof data.system !== 'undefined') this.system = Boolean(data.system);
if ('system' in data) {
/**
* Whether the user is an Official Discord System user (part of the urgent message system)
* @type {?boolean}
* @name User#system
*/
this.system = Boolean(data.system);
}
/**
* The locale of the user's client (ISO 639-1)
* @type {?string}
* @name User#locale
*/
if (data.locale) this.locale = data.locale;
if ('locale' in data) {
/**
* The locale of the user's client (ISO 639-1)
* @type {?string}
* @name User#locale
*/
this.locale = data.locale;
}
/**
* The flags for this user
* @type {?UserFlags}
* @name User#flags
*/
if (typeof data.public_flags !== 'undefined') this.flags = new UserFlags(data.public_flags);
if ('public_flags' in data) {
/**
* The flags for this user
* @type {?UserFlags}
* @name User#flags
*/
this.flags = new UserFlags(data.public_flags);
}
/**
* The ID of the last message sent by the user, if one was sent