mirror of
https://github.com/danbulant/discord.js
synced 2026-05-26 05:22:15 +00:00
prevent further user inaccuracies
This commit is contained in:
parent
77e83fb85a
commit
f0a9a1353f
4 changed files with 30 additions and 10 deletions
File diff suppressed because one or more lines are too long
|
|
@ -15,7 +15,7 @@ class UserUpdateAction extends Action {
|
|||
}
|
||||
|
||||
const oldUser = cloneObject(client.user);
|
||||
client.user.setup(data);
|
||||
client.user.patch(data);
|
||||
client.emit(Constants.Events.USER_UPDATE, oldUser, client.user);
|
||||
return {
|
||||
old: oldUser,
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class PresenceUpdateHandler extends AbstractHandler {
|
|||
|
||||
if (!same) {
|
||||
const oldUser = cloneObject(user);
|
||||
user.setup(data.user);
|
||||
user.patch(data.user);
|
||||
client.emit(Constants.Events.PRESENCE_UPDATE, oldUser, user);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||
const Constants = require('../util/Constants');
|
||||
|
||||
function defined(p) {
|
||||
return typeof p !== 'undefined';
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a User on Discord.
|
||||
* @implements {TextBasedChannel}
|
||||
|
|
@ -17,6 +21,24 @@ class User {
|
|||
if (data) this.setup(data);
|
||||
}
|
||||
|
||||
patch(data) {
|
||||
for (const item of ['id', 'username', 'discriminator', 'game', 'avatar']) {
|
||||
if (defined(data[item])) {
|
||||
this[item] = data[item];
|
||||
}
|
||||
}
|
||||
if (defined[data.bot]) {
|
||||
this.bot = data.bot;
|
||||
} else {
|
||||
this.bot = this.bot || false;
|
||||
}
|
||||
if (defined[data.status]) {
|
||||
this.status = data.status;
|
||||
} else {
|
||||
this.status = this.status || 'offline';
|
||||
}
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
/**
|
||||
* The ID of the User
|
||||
|
|
@ -36,13 +58,11 @@ class User {
|
|||
*/
|
||||
this.discriminator = data.discriminator;
|
||||
|
||||
if (typeof data.avatar !== 'undefined') {
|
||||
/**
|
||||
* The ID of the user's avatar
|
||||
* @type {string}
|
||||
*/
|
||||
this.avatar = data.avatar;
|
||||
}
|
||||
/**
|
||||
* The ID of the user's avatar
|
||||
* @type {string}
|
||||
*/
|
||||
this.avatar = data.avatar;
|
||||
|
||||
/**
|
||||
* Whether or not the User is a Bot.
|
||||
|
|
|
|||
Loading…
Reference in a new issue