Skip to content

Commit

Permalink
feat(Role): add flags (discordjs#9694)
Browse files Browse the repository at this point in the history
Co-authored-by: n1ck_pro <59617443+N1ckPro@users.noreply.github.com>
  • Loading branch information
jaw0r3k and N1ckPro committed Aug 12, 2023
1 parent d3a7002 commit 52da4ed
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/structures/MessageAttachment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const AttachmentFlags = require('../util/AttachmentFlags');
const Util = require('../util/Util');

/**
Expand Down Expand Up @@ -169,6 +170,16 @@ class MessageAttachment {
} else {
this.waveform ??= null;
}

if ('flags' in data) {
/**
* The flags of this attachment
* @type {Readonly<AttachmentFlags>}
*/
this.flags = new AttachmentFlags(data.flags).freeze();
} else {
this.flags ??= new AttachmentFlags().freeze();
}
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/structures/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Base = require('./Base');
const { Error } = require('../errors');
const Permissions = require('../util/Permissions');
const SnowflakeUtil = require('../util/SnowflakeUtil');
const RoleFlags = require('../util/RoleFlags');

let deprecationEmittedForComparePositions = false;

Expand Down Expand Up @@ -142,6 +143,16 @@ class Role extends Base {
this.tags.guildConnections = true;
}
}

if ('flags' in data) {
/**
* The flags of this role
* @type {Readonly<RoleFlags>}
*/
this.flags = new RoleFlags(data.flags).freeze();
} else {
this.flags ??= new RoleFlags().freeze();
}
}

/**
Expand Down
37 changes: 37 additions & 0 deletions src/util/RoleFlags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict';

const BitField = require('./BitField');

/**
* Data structure that makes it easy to interact with an {@link GuildMember#flags} bitfield.
* @extends {BitField}
*/
class RoleFlags extends BitField {}

/**
* @name RoleFlags
* @kind constructor
* @memberof RoleFlags
* @param {BitFieldResolvable} [bits=0] Bit(s) to read from
*/

/**
* Numeric guild member flags. All available properties:
* * `IN_PROMPT`
* @type {Object}
* @see {@link https://discord.com/developers/docs/topics/permissions#role-object-role-flags}
*/
RoleFlags.FLAGS = {
IN_PROMPT: 1 << 0,
};

/**
* Data that can be resolved to give a role flag bitfield. This can be:
* * A string (see {@link RoleFlags.FLAGS})
* * A role flag
* * An instance of RoleFlags
* * An Array of RoleFlagsResolvable
* @typedef {string|number|RoleFlags|RoleFlagsResolvable[]} RoleFlagsResolvable
*/

module.exports = RoleFlags;
9 changes: 9 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,7 @@ export class Role extends Base {
/** @deprecated This will be removed in the next major version, see https://github.com/discordjs/discord.js/issues/7091 */
public deleted: boolean;
public readonly editable: boolean;
public flags: Readonly<RoleFlags>;
public guild: Guild;
public readonly hexColor: HexColorString;
public hoist: boolean;
Expand Down Expand Up @@ -2193,6 +2194,14 @@ export class Role extends Base {
public static comparePositions(role1: Role, role2: Role): number;
}

export class RoleFlags extends BitField<RoleFlagsString> {
public static FLAGS: Record<RoleFlagsString, number>;
public static resolve(bit?: BitFieldResolvable<RoleFlagsString, number>): number;
}

export type RoleFlagsString =
| 'IN_PROMPT';

export class SelectMenuInteraction<Cached extends CacheType = CacheType> extends MessageComponentInteraction<Cached> {
public constructor(client: Client, data: RawMessageSelectMenuInteractionData);
public readonly component: CacheTypeReducer<
Expand Down

0 comments on commit 52da4ed

Please sign in to comment.