Added User Class

This commit is contained in:
hydrabolt
2015-08-23 19:33:52 +01:00
parent a9bd6cd59c
commit 344f8d73a4
11 changed files with 320 additions and 262 deletions

View File

@@ -1,37 +1,51 @@
"use strict";
exports.User = function (username, id, discriminator, avatar) {
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
if (!id) {
//there's no second argument
var user = username;
username = user.username;
id = user.id;
discriminator = user.discriminator;
avatar = user.avatar;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var User = (function () {
function User(data) {
_classCallCheck(this, User);
this.username = data.username;
this.discriminator = data.discriminator;
this.id = data.id;
this.avatar = data.avatar;
}
this.username = username;
this.discriminator = discriminator;
this.id = id;
this.avatar = avatar;
};
// access using user.avatarURL;
exports.User.prototype.getAvatarURL = function () {
if (!this.avatar) return false;
return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg";
};
_createClass(User, [{
key: "mention",
value: function mention() {
return "<@" + this.id + ">";
}
}, {
key: "toString",
value: function toString() {
/*
if we embed a user in a String - like so:
"Yo " + user + " what's up?"
It would generate something along the lines of:
"Yo @hydrabolt what's up?"
*/
return this.mention();
}
}, {
key: "equals",
value: function equals(object) {
return object.id === this.id;
}
}, {
key: "avatarURL",
get: function get() {
if (!this.avatar) return null;
return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg";
}
}]);
exports.User.prototype.mention = function () {
return "<@" + this.id + ">";
};
return User;
})();
exports.User.prototype.equals = function (otherUser) {
return otherUser.id === this.id;
};
exports.User.prototype.equalsStrict = function (otherUser) {
return this.username === otherUser.username && this.discriminator === otherUser.discriminator && this.id === otherUser.id && this.avatar === otherUser.avatar;
};
module.exports = User;