add .toObject() method to structures (#522)

* add .toObject() method to structures

* add compiled PMChannel change from last commit

* uncomment members in VoiceChannel toObject method
This commit is contained in:
Brian Tanner
2016-08-16 23:53:07 +07:00
committed by abal
parent e42178181d
commit fdfd41dd8c
21 changed files with 426 additions and 58 deletions

View File

@@ -51,6 +51,36 @@ var User = (function (_Equality) {
return this.mention();
};
User.prototype.toObject = function toObject() {
var keys = ['id', 'username', 'discriminator', 'avatar', 'bot', 'status', 'game', 'note', 'voiceState', 'speaking'],
obj = {};
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var k = _ref;
obj[k] = this[k];
}
obj.typing = {
since: this.typing.since,
channelID: this.typing.channel ? this.typing.channel.id : null
};
obj.voiceChannelID = this.voiceChannel ? this.voiceChannel.id : null;
return obj;
};
User.prototype.equalsStrict = function equalsStrict(obj) {
if (obj instanceof User) return this.id === obj.id && this.username === obj.username && this.discriminator === obj.discriminator && this.avatar === obj.avatar && this.status === obj.status && (this.game === obj.game || this.game && obj.game && this.game.name === obj.game.name);else return false;
};