diff --git a/src/structures/User.js b/src/structures/User.js index 349c55cb0..5d9ed47dd 100644 --- a/src/structures/User.js +++ b/src/structures/User.js @@ -224,7 +224,7 @@ class User { * @returns {Promise} */ 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)); } /** diff --git a/src/structures/UserProfile.js b/src/structures/UserProfile.js index 192bc1e63..c89d62c8a 100644 --- a/src/structures/UserProfile.js +++ b/src/structures/UserProfile.js @@ -1,4 +1,5 @@ const Collection = require('../util/Collection'); +const { UserFlags } = require('../util/Constants'); const UserConnection = require('./UserConnection'); /** @@ -40,7 +41,14 @@ class UserProfile { * If the user has Discord Premium * @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 @@ -57,6 +65,19 @@ class UserProfile { 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; diff --git a/src/util/Constants.js b/src/util/Constants.js index 27293e319..3370b02af 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -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 = { DEFAULT: 0x000000, AQUA: 0x1ABC9C,