prevent further user inaccuracies

This commit is contained in:
Amish Shah
2016-09-11 16:57:04 +01:00
parent 77e83fb85a
commit f0a9a1353f
4 changed files with 30 additions and 10 deletions

View File

@@ -1,6 +1,10 @@
const TextBasedChannel = require('./interface/TextBasedChannel');
const Constants = require('../util/Constants');
function defined(p) {
return typeof p !== 'undefined';
}
/**
* Represents a User on Discord.
* @implements {TextBasedChannel}
@@ -17,6 +21,24 @@ class User {
if (data) this.setup(data);
}
patch(data) {
for (const item of ['id', 'username', 'discriminator', 'game', 'avatar']) {
if (defined(data[item])) {
this[item] = data[item];
}
}
if (defined[data.bot]) {
this.bot = data.bot;
} else {
this.bot = this.bot || false;
}
if (defined[data.status]) {
this.status = data.status;
} else {
this.status = this.status || 'offline';
}
}
setup(data) {
/**
* The ID of the User
@@ -36,13 +58,11 @@ class User {
*/
this.discriminator = data.discriminator;
if (typeof data.avatar !== 'undefined') {
/**
* The ID of the user's avatar
* @type {string}
*/
this.avatar = data.avatar;
}
/**
* The ID of the user's avatar
* @type {string}
*/
this.avatar = data.avatar;
/**
* Whether or not the User is a Bot.