Skip to content

Commit

Permalink
feat(Role): add flags
Browse files Browse the repository at this point in the history
  • Loading branch information
N1ckPro committed Jul 10, 2023
1 parent 719e54a commit 8220cd9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/discord.js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,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 @@ -405,6 +405,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 @@ -161,6 +161,7 @@ import {
APIGuildOnboardingPrompt,
APIGuildOnboardingPromptOption,
GuildOnboardingPromptType,
// RoleFlags,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
Expand Down Expand Up @@ -2510,6 +2511,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 @@ -2545,6 +2547,13 @@ export class Role extends Base {
public toString(): RoleMention;
}

export type RoleFlagsString = any; // keyof typeof RoleFlags;

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

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

0 comments on commit 8220cd9

Please sign in to comment.