2.7.1, user updates are now tracked

This commit is contained in:
hydrabolt
2015-08-20 18:57:39 +01:00
parent c2607997dc
commit be787e0951
3 changed files with 56 additions and 22 deletions

View File

@@ -468,7 +468,18 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
} else if ( dat.t === "PRESENCE_UPDATE" ) {
var data = dat.d;
var getUser = self.getUser(data.user.id);
if ( getUser ) {
//user already exists
var usr = new User( data.user );
if ( usr.equalsStrict( getUser ) ) {
//no changes, actually a presence.
} else {
if(self.updateUserReferences( data.user.id, getUser, new User( data.user ) )){
self.triggerEvent("userupdate", [getUser, usr]);
}
}
}
self.triggerEvent( "presence", [ new User( data.user ), data.status, self.serverList.filter( "id", data.guild_id, true ) ] );
} else if ( dat.t === "GUILD_DELETE" ) {
@@ -1002,6 +1013,23 @@ exports.isUserID = function( id ) {
return ( ( id + "" ).length === 17 && !isNaN( id ) );
}
exports.Client.prototype.updateUserReferences = function( id, oldUser, user ) {
if ( oldUser.equalsStrict( user ) ) {
return false;
}
for ( server of this.serverList.contents ) {
server.members.updateElement( oldUser, user );
}
this.debug( "Updated references to " + oldUser.username + " to " + this.getUser( id ).username );
return true;
}
exports.Client.prototype.addPM = function( pm ) {
this.PMList.add( pm );
}

View File

@@ -1,31 +1,37 @@
exports.User = function(username, id, discriminator, avatar){
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;
}
if ( !id ) { //there's no second argument
var user = username;
username = user.username;
id = user.id;
discriminator = user.discriminator;
avatar = user.avatar;
}
this.username = username;
this.discriminator = discriminator;
this.id = id;
this.avatar = avatar;
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.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.mention = function() {
return "<@" + this.id + ">";
}
exports.User.prototype.equals = function(otherUser){
exports.User.prototype.equals = function( otherUser ) {
return otherUser.id === this.id;
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 );
}

View File

@@ -1,6 +1,6 @@
{
"name": "discord.js",
"version": "2.7.0",
"version": "2.7.1",
"description": "A way to interface with the Discord API",
"main": "index.js",
"scripts": {