mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
Fixed User#fetchProfile, UserProfile#premium and added #flags (#1629)
* Fixed User#fetchProfile, UserProfile#premium and added #flags * made UserProfile#flags a getter and stored the raw bitfield under UserProfile#_flags * lowercased Flags
This commit is contained in:
@@ -224,7 +224,7 @@ class User {
|
|||||||
* @returns {Promise<UserProfile>}
|
* @returns {Promise<UserProfile>}
|
||||||
*/
|
*/
|
||||||
fetchProfile() {
|
fetchProfile() {
|
||||||
return this.client.api.users[this.id].profile.get().then(data => new UserProfile(data));
|
return this.client.api.users[this.id].profile.get().then(data => new UserProfile(this, data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const Collection = require('../util/Collection');
|
const Collection = require('../util/Collection');
|
||||||
|
const { UserFlags } = require('../util/Constants');
|
||||||
const UserConnection = require('./UserConnection');
|
const UserConnection = require('./UserConnection');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +41,14 @@ class UserProfile {
|
|||||||
* If the user has Discord Premium
|
* If the user has Discord Premium
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
this.premium = data.premium;
|
this.premium = Boolean(data.premium_since);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Bitfield of the users' flags
|
||||||
|
* @type {number}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
this._flags = data.user.flags;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The date since which the user has had Discord Premium
|
* The date since which the user has had Discord Premium
|
||||||
@@ -57,6 +65,19 @@ class UserProfile {
|
|||||||
this.connections.set(connection.id, new UserConnection(this.user, connection));
|
this.connections.set(connection.id, new UserConnection(this.user, connection));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The flags the user has
|
||||||
|
* @type {UserFlags[]}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
get flags() {
|
||||||
|
const flags = [];
|
||||||
|
for (const [name, flag] of Object.entries(UserFlags)) {
|
||||||
|
if ((this._flags & flag) === flag) flags.push(name);
|
||||||
|
}
|
||||||
|
return flags;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = UserProfile;
|
module.exports = UserProfile;
|
||||||
|
|||||||
@@ -481,6 +481,19 @@ exports.UserSettingsMap = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All flags users can have:
|
||||||
|
* - STAFF
|
||||||
|
* - PARTNER
|
||||||
|
* - HYPESQUAD
|
||||||
|
* @typedef {string} UserFlags
|
||||||
|
*/
|
||||||
|
exports.UserFlags = {
|
||||||
|
STAFF: 1 << 0,
|
||||||
|
PARTNER: 1 << 1,
|
||||||
|
HYPESQUAD: 1 << 2,
|
||||||
|
};
|
||||||
|
|
||||||
exports.Colors = {
|
exports.Colors = {
|
||||||
DEFAULT: 0x000000,
|
DEFAULT: 0x000000,
|
||||||
AQUA: 0x1ABC9C,
|
AQUA: 0x1ABC9C,
|
||||||
|
|||||||
Reference in New Issue
Block a user