mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +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);
|
const oldUser = cloneObject(client.user);
|
||||||
client.user.setup(data);
|
client.user.patch(data);
|
||||||
client.emit(Constants.Events.USER_UPDATE, oldUser, client.user);
|
client.emit(Constants.Events.USER_UPDATE, oldUser, client.user);
|
||||||
return {
|
return {
|
||||||
old: oldUser,
|
old: oldUser,
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class PresenceUpdateHandler extends AbstractHandler {
|
|||||||
|
|
||||||
if (!same) {
|
if (!same) {
|
||||||
const oldUser = cloneObject(user);
|
const oldUser = cloneObject(user);
|
||||||
user.setup(data.user);
|
user.patch(data.user);
|
||||||
client.emit(Constants.Events.PRESENCE_UPDATE, oldUser, user);
|
client.emit(Constants.Events.PRESENCE_UPDATE, oldUser, user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
const TextBasedChannel = require('./interface/TextBasedChannel');
|
const TextBasedChannel = require('./interface/TextBasedChannel');
|
||||||
const Constants = require('../util/Constants');
|
const Constants = require('../util/Constants');
|
||||||
|
|
||||||
|
function defined(p) {
|
||||||
|
return typeof p !== 'undefined';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a User on Discord.
|
* Represents a User on Discord.
|
||||||
* @implements {TextBasedChannel}
|
* @implements {TextBasedChannel}
|
||||||
@@ -17,6 +21,24 @@ class User {
|
|||||||
if (data) this.setup(data);
|
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) {
|
setup(data) {
|
||||||
/**
|
/**
|
||||||
* The ID of the User
|
* The ID of the User
|
||||||
@@ -36,13 +58,11 @@ class User {
|
|||||||
*/
|
*/
|
||||||
this.discriminator = data.discriminator;
|
this.discriminator = data.discriminator;
|
||||||
|
|
||||||
if (typeof data.avatar !== 'undefined') {
|
/**
|
||||||
/**
|
* The ID of the user's avatar
|
||||||
* The ID of the user's avatar
|
* @type {string}
|
||||||
* @type {string}
|
*/
|
||||||
*/
|
this.avatar = data.avatar;
|
||||||
this.avatar = data.avatar;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the User is a Bot.
|
* Whether or not the User is a Bot.
|
||||||
|
|||||||
Reference in New Issue
Block a user