Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(Role): add flags (#9694)
Co-authored-by: n1ck_pro <59617443+N1ckPro@users.noreply.github.com>
  • Loading branch information
2 people authored and vladfrangu committed Nov 5, 2023
1 parent d0fd79c commit a222e53
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
@@ -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
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
@@ -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
Expand Up @@ -2159,6 +2159,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 @@ -2194,6 +2195,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 a222e53

Please sign in to comment.