djs-selfbot-v11
Version:
Selfbot module Discord
118 lines (108 loc) • 3 kB
JavaScript
const Collection = require('../util/Collection');
const UserConnection = require('./UserConnection');
const Constants = require('../util/Constants');
const UserFlags = require('../util/UserFlags');
/**
* 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 ID of the user
* @type {Snowflake}
*/
this.userid = data.user.id;
/**
* The username of the user
* @type {string}
*/
this.username = data.user.username;
/**
* A discriminator based on username for the user
* @type {string}
*/
this.discriminator = data.user.discriminator;
/**
* The ID of the user's avatar
* @type {string}
*/
this.avatar = data.user.avatar;
/**
* The ID of the user's banner
* @type {?string}
*/
this.banner = data.user.banner;
/**
* The user's bio
* @type {?string}
*/
this.bio = data.user.bio;
/**
* The user's flags
* @type {?integer}
*/
this.flags = new UserFlags(data.user.public_flags)
/**
* The date since which the user has had Discord Premium
* @type {?Date}
*/
this.premiumSince = data.premium_since ? new Date(data.premium_since) : null;
/**
* The date since which the user has been boosting a guild
* @type {?Date}
*/
this.premiumServerSince = data.premium_guild_since ? new Date(data.premium_guild_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));
}
}
get bannerURL() {
if (!this.banner) return null;
return Constants.Endpoints.User(this.userid).Banner(this.client.options.http.cdn, this.banner);
}
/**
* A link to the user's avatar
* @type {?string}
* @readonly
*/
get avatarURL() {
if (!this.avatar) return null;
return Constants.Endpoints.User(this.userid).Avatar(this.client.options.http.cdn, this.avatar);
}
}
module.exports = UserProfile;