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,35 @@
exports.User = function( username, id, discriminator, avatar ) {
if ( !id ) { //there's no second argument
var user = username;
username = user.username;
id = user.id;
discriminator = user.discriminator;
avatar = user.avatar;
class User{
constructor( data ){
this.username = data.username;
this.discriminator = data.discriminator;
this.id = data.id;
this.avatar = data.avatar;
}
// access using user.avatarURL;
get avatarURL(){
if( !this.avatar )
return null;
return `https://discordapp.com/api/users/${this.id}/avatars/${this.avatar}.jpg`;
}
mention(){
return `<@${this.id}>`;
}
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();
}
equals(object){
return object.id === this.id;
}
this.username = username;
this.discriminator = discriminator;
this.id = id;
this.avatar = avatar;
}
exports.User.prototype.getAvatarURL = function() {
if ( !this.avatar )
return false;
return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg";
}
exports.User.prototype.mention = function() {
return "<@" + this.id + ">";
}
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;