feat(Role): add flags (#9694)

Co-authored-by: n1ck_pro <59617443+N1ckPro@users.noreply.github.com>
This commit is contained in:
Jaw0r3k 2023-08-12 14:18:50 +02:00 committed by Vlad Frangu
parent d0fd79c14a
commit a222e537c1
4 changed files with 68 additions and 0 deletions

View file

@ -1,5 +1,6 @@
'use strict';
const AttachmentFlags = require('../util/AttachmentFlags');
const Util = require('../util/Util');
/**
@ -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();
}
}
/**

View file

@ -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;
@ -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();
}
}
/**

37
src/util/RoleFlags.js Normal file
View file

@ -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
typings/index.d.ts vendored
View file

@ -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;
@ -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<