Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Role): add flags #9694

Merged
merged 3 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports.MessageFlagsBitField = require('./util/MessageFlagsBitField');
exports.Options = require('./util/Options');
exports.Partials = require('./util/Partials');
exports.PermissionsBitField = require('./util/PermissionsBitField');
exports.RoleFlagsBitField = require('./util/RoleFlagsBitField');
exports.ShardEvents = require('./util/ShardEvents');
exports.Status = require('./util/Status');
exports.SnowflakeUtil = require('@sapphire/snowflake').DiscordSnowflake;
Expand Down
11 changes: 11 additions & 0 deletions packages/discord.js/src/structures/Role.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { PermissionFlagsBits } = require('discord-api-types/v10');
const Base = require('./Base');
const { DiscordjsError, ErrorCodes } = require('../errors');
const PermissionsBitField = require('../util/PermissionsBitField');
const RoleFlagsBitField = require('../util/RoleFlagsBitField');

/**
* Represents a role on Discord.
Expand Down Expand Up @@ -101,6 +102,16 @@ class Role extends Base {

if ('unicode_emoji' in data) this.unicodeEmoji = data.unicode_emoji;

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

/**
* The tags this role has
* @type {?Object}
Expand Down
5 changes: 5 additions & 0 deletions packages/discord.js/src/util/APITypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-payloads/common#PermissionFlagsBits}
*/

/**
* @external RoleFlags
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/RoleFlags}
*/

/**
* @external RESTGetAPIGuildThreadsResult
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10#RESTGetAPIGuildThreadsResult}
Expand Down
26 changes: 26 additions & 0 deletions packages/discord.js/src/util/RoleFlagsBitField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const { RoleFlags } = require('discord-api-types/v10');
const BitField = require('./BitField');

/**
* Data structure that makes it easy to interact with a {@link Role#flags} bitfield.
* @extends {BitField}
*/
class RoleFlagsBitField extends BitField {
/**
* Numeric role flags.
* @type {RoleFlags}
* @memberof RoleFlagsBitField
*/
static Flags = RoleFlags;
}

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

module.exports = RoleFlagsBitField;
9 changes: 9 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ import {
APIGuildOnboardingPromptOption,
GuildOnboardingPromptType,
AttachmentFlags,
RoleFlags,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -2524,6 +2525,7 @@ export class Role extends Base {
public get createdAt(): Date;
public get createdTimestamp(): number;
public get editable(): boolean;
public flags: RoleFlagsBitField;
public guild: Guild;
public get hexColor(): HexColorString;
public hoist: boolean;
Expand Down Expand Up @@ -2559,6 +2561,13 @@ export class Role extends Base {
public toString(): RoleMention;
}

export type RoleFlagsString = keyof typeof RoleFlags;

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

export class StringSelectMenuInteraction<
Cached extends CacheType = CacheType,
> extends MessageComponentInteraction<Cached> {
Expand Down