mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
prevent further user inaccuracies
This commit is contained in:
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.
|
||||
|
||||
Reference in New Issue
Block a user