mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 13:03:31 +01:00
2.7.1, user updates are now tracked
This commit is contained in:
30
index.js
30
index.js
@@ -468,7 +468,18 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
} else if ( dat.t === "PRESENCE_UPDATE" ) {
|
} else if ( dat.t === "PRESENCE_UPDATE" ) {
|
||||||
|
|
||||||
var data = dat.d;
|
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 ) ] );
|
self.triggerEvent( "presence", [ new User( data.user ), data.status, self.serverList.filter( "id", data.guild_id, true ) ] );
|
||||||
|
|
||||||
} else if ( dat.t === "GUILD_DELETE" ) {
|
} else if ( dat.t === "GUILD_DELETE" ) {
|
||||||
@@ -1002,6 +1013,23 @@ exports.isUserID = function( id ) {
|
|||||||
return ( ( id + "" ).length === 17 && !isNaN( 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 ) {
|
exports.Client.prototype.addPM = function( pm ) {
|
||||||
this.PMList.add( pm );
|
this.PMList.add( pm );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,3 +29,9 @@ 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 );
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js",
|
"name": "discord.js",
|
||||||
"version": "2.7.0",
|
"version": "2.7.1",
|
||||||
"description": "A way to interface with the Discord API",
|
"description": "A way to interface with the Discord API",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user