mirror of
https://github.com/musix-org/musix-oss
synced 2025-07-04 17:04:29 +00:00
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
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 UserProfile
|
|
* @name UserProfile#client
|
|
* @type {Client}
|
|
* @readonly
|
|
*/
|
|
Object.defineProperty(this, 'client', { value: user.client });
|
|
|
|
/**
|
|
* The guilds that the client user and the user share
|
|
* @type {Collection<Snowflake, Guild>}
|
|
*/
|
|
this.mutualGuilds = new Collection();
|
|
|
|
/**
|
|
* The user's connections
|
|
* @type {Collection<Snowflake, UserConnection>}
|
|
*/
|
|
this.connections = new Collection();
|
|
|
|
this.setup(data);
|
|
}
|
|
|
|
setup(data) {
|
|
/**
|
|
* If the user has Discord Premium
|
|
* @type {boolean}
|
|
*/
|
|
this.premium = data.premium;
|
|
|
|
/**
|
|
* The date since which the user has had Discord Premium
|
|
* @type {?Date}
|
|
*/
|
|
this.premiumSince = data.premium_since ? new Date(data.premium_since) : null;
|
|
|
|
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;
|