mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
added User#fetchProfile (#835)
* add User#fetchProfile * fix merge conflicts?
This commit is contained in:
@@ -167,6 +167,14 @@ class User {
|
||||
return this.client.rest.methods.unblockUser(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the profile of the user
|
||||
* @returns {Promise<UserProfile>}
|
||||
*/
|
||||
fetchProfile() {
|
||||
return this.client.rest.methods.fetchUserProfile(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the user is equal to another. It compares username, ID, discriminator, status and the game being played.
|
||||
* It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
|
||||
|
||||
48
src/structures/UserConnection.js
Normal file
48
src/structures/UserConnection.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* Represents a User Connection object (or "platform identity")
|
||||
*/
|
||||
class UserConnection {
|
||||
constructor(user, data) {
|
||||
/**
|
||||
* The user that owns the Connection
|
||||
* @type {User}
|
||||
*/
|
||||
this.user = user;
|
||||
|
||||
this.setup(data);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
/**
|
||||
* The type of the Connection
|
||||
* @type {string}
|
||||
*/
|
||||
this.type = data.type;
|
||||
|
||||
/**
|
||||
* The username of the connection account
|
||||
* @type {string}
|
||||
*/
|
||||
this.name = data.name;
|
||||
|
||||
/**
|
||||
* The id of the connection account
|
||||
* @type {string}
|
||||
*/
|
||||
this.id = data.id;
|
||||
|
||||
/**
|
||||
* Whether the connection is revoked
|
||||
* @type {Boolean}
|
||||
*/
|
||||
this.revoked = data.revoked;
|
||||
|
||||
/**
|
||||
* an array of partial server integrations (not yet implemented in this lib)
|
||||
* @type {Object[]}
|
||||
*/
|
||||
this.integrations = data.integrations;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserConnection;
|
||||
49
src/structures/UserProfile.js
Normal file
49
src/structures/UserProfile.js
Normal file
@@ -0,0 +1,49 @@
|
||||
const Collection = require('../util/Collection');
|
||||
const UserConnection = require('./UserConnection');
|
||||
|
||||
/**
|
||||
* Represents a user's profile on Discord.
|
||||
*/
|
||||
class UserProfile {
|
||||
constructor(user, data) {
|
||||
/**
|
||||
* The owner of the profile
|
||||
* @type {User}
|
||||
*/
|
||||
this.user = user;
|
||||
|
||||
/**
|
||||
* The Client that created the instance of the the User.
|
||||
* @type {Client}
|
||||
*/
|
||||
this.client = this.user.client;
|
||||
Object.defineProperty(this, 'client', { enumerable: false, configurable: false });
|
||||
|
||||
/**
|
||||
* Guilds that the ClientUser and the User share
|
||||
* @type {Collection<Guild>}
|
||||
*/
|
||||
this.mutualGuilds = new Collection();
|
||||
|
||||
/**
|
||||
* The user's connections
|
||||
* @type {Collection<UserConnection>}
|
||||
*/
|
||||
this.connections = new Collection();
|
||||
|
||||
this.setup(data);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
for (const guild of data.mutual_guilds) {
|
||||
if (this.client.guilds.has(guild.id)) {
|
||||
this.mutualGuilds.set(guild.id, this.client.guilds.get(guild.id));
|
||||
}
|
||||
}
|
||||
for (const connection of data.connected_accounts) {
|
||||
this.connections.set(connection.id, new UserConnection(this.user, connection));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserProfile;
|
||||
Reference in New Issue
Block a user