mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
feat: User#flags (#4060)
* feat: user flags * fix: unnecessary negated statement * fix: wording for description * fix: an vs. a * feat: add verified bot and dev flags Co-Authored-By: Vlad Frangu <kingdgrizzle@gmail.com> * typings :verified bot and dev flags Co-Authored-By: Vlad Frangu <kingdgrizzle@gmail.com> * feat: mon's suggestion, async fetchFlags & jsdoc * feat: added to index.js * fix: typo * style: leveled flags * typings: update leveled flags Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
This commit is contained in:
@@ -28,6 +28,7 @@ module.exports = {
|
||||
SnowflakeUtil: require('./util/Snowflake'),
|
||||
Structures: require('./util/Structures'),
|
||||
SystemChannelFlags: require('./util/SystemChannelFlags'),
|
||||
UserFlags: require('./util/UserFlags'),
|
||||
Util: Util,
|
||||
version: require('../package.json').version,
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ const { Presence } = require('./Presence');
|
||||
const TextBasedChannel = require('./interfaces/TextBasedChannel');
|
||||
const { Error } = require('../errors');
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
const UserFlags = require('../util/UserFlags');
|
||||
|
||||
/**
|
||||
* Represents a user on Discord.
|
||||
@@ -73,6 +74,12 @@ class User extends Base {
|
||||
*/
|
||||
if (data.locale) this.locale = data.locale;
|
||||
|
||||
/**
|
||||
* The flags for this user
|
||||
* @type {?UserFlags}
|
||||
*/
|
||||
if (typeof data.public_flags !== 'undefined') this.flags = new UserFlags(data.public_flags);
|
||||
|
||||
/**
|
||||
* The ID of the last message sent by the user, if one was sent
|
||||
* @type {?Snowflake}
|
||||
@@ -255,6 +262,17 @@ class User extends Base {
|
||||
return equal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches this user's flags.
|
||||
* @returns {Promise<UserFlags>}
|
||||
*/
|
||||
async fetchFlags() {
|
||||
if (this.flags) return this.flags;
|
||||
const data = await this.client.api.users(this.id).get();
|
||||
this._patch(data);
|
||||
return this.flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches this user.
|
||||
* @returns {Promise<User>}
|
||||
|
||||
51
src/util/UserFlags.js
Normal file
51
src/util/UserFlags.js
Normal file
@@ -0,0 +1,51 @@
|
||||
'use strict';
|
||||
const BitField = require('./BitField');
|
||||
|
||||
/**
|
||||
* Data structure that makes it easy to interact with a {@link User#flags} bitfield.
|
||||
* @extends {BitField}
|
||||
*/
|
||||
class UserFlags extends BitField {}
|
||||
|
||||
/**
|
||||
* @name UserFlags
|
||||
* @kind constructor
|
||||
* @memberof UserFlags
|
||||
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
|
||||
*/
|
||||
|
||||
/**
|
||||
* Numeric user flags. All available properties:
|
||||
* * `DISCORD_EMPLOYEE`
|
||||
* * `DISCORD_PARTNER`
|
||||
* * `HYPESQUAD_EVENTS`
|
||||
* * `BUGHUNTER_LEVEL_1`
|
||||
* * `HOUSE_BRAVERY`
|
||||
* * `HOUSE_BRILLIANCE`
|
||||
* * `HOUSE_BALANCE`
|
||||
* * `EARLY_SUPPORTER`
|
||||
* * `TEAM_USER`
|
||||
* * `SYSTEM`
|
||||
* * `BUGHUNTER_LEVEL_2`
|
||||
* * `VERIFIED_BOT`
|
||||
* * `VERIFIED_DEVELOPER`
|
||||
* @type {Object}
|
||||
* @see {@link https://discordapp.com/developers/docs/resources/user#user-object-user-flags}
|
||||
*/
|
||||
UserFlags.FLAGS = {
|
||||
DISCORD_EMPLOYEE: 1 << 0,
|
||||
DISCORD_PARTNER: 1 << 1,
|
||||
HYPESQUAD_EVENTS: 1 << 2,
|
||||
BUGHUNTER_LEVEL_1: 1 << 3,
|
||||
HOUSE_BRAVERY: 1 << 6,
|
||||
HOUSE_BRILLIANCE: 1 << 7,
|
||||
HOUSE_BALANCE: 1 << 8,
|
||||
EARLY_SUPPORTER: 1 << 9,
|
||||
TEAM_USER: 1 << 10,
|
||||
SYSTEM: 1 << 12,
|
||||
BUGHUNTER_LEVEL_2: 1 << 14,
|
||||
VERIFIED_BOT: 1 << 16,
|
||||
VERIFIED_DEVELOPER: 1 << 17,
|
||||
};
|
||||
|
||||
module.exports = UserFlags;
|
||||
21
typings/index.d.ts
vendored
21
typings/index.d.ts
vendored
@@ -1469,6 +1469,7 @@ declare module 'discord.js' {
|
||||
public discriminator: string;
|
||||
public readonly defaultAvatarURL: string;
|
||||
public readonly dmChannel: DMChannel;
|
||||
public flags: Readonly<UserFlags>;
|
||||
public id: Snowflake;
|
||||
public lastMessageID: Snowflake | null;
|
||||
public locale: string;
|
||||
@@ -1489,6 +1490,11 @@ declare module 'discord.js' {
|
||||
public typingSinceIn(channel: ChannelResolvable): Date;
|
||||
}
|
||||
|
||||
export class UserFlags extends BitField<UserFlagsString> {
|
||||
public static FLAGS: Record<UserFlagsString, number>;
|
||||
public static resolve(bit?: BitFieldResolvable<UserFlagsString>): number;
|
||||
}
|
||||
|
||||
export class Util {
|
||||
public static basename(path: string, ext?: string): string;
|
||||
public static binaryToID(num: string): Snowflake;
|
||||
@@ -2978,6 +2984,21 @@ declare module 'discord.js' {
|
||||
timeout: NodeJS.Timeout;
|
||||
}
|
||||
|
||||
type UserFlagsString =
|
||||
| 'DISCORD_EMPLOYEE'
|
||||
| 'DISCORD_PARTNER'
|
||||
| 'HYPESQUAD_EVENTS'
|
||||
| 'BUGHUNTER_LEVEL_1'
|
||||
| 'HOUSE_BRAVERY'
|
||||
| 'HOUSE_BRILLIANCE'
|
||||
| 'HOUSE_BALANCE'
|
||||
| 'EARLY_SUPPORTER'
|
||||
| 'TEAM_USER'
|
||||
| 'SYSTEM'
|
||||
| 'BUGHUNTER_LEVEL_2'
|
||||
| 'VERIFIED_BOT'
|
||||
| 'VERIFIED_DEVELOPER';
|
||||
|
||||
type UserResolvable = User | Snowflake | Message | GuildMember;
|
||||
|
||||
type VerificationLevel = 'NONE' | 'LOW' | 'MEDIUM' | 'HIGH' | 'VERY_HIGH';
|
||||
|
||||
Reference in New Issue
Block a user