mirror of
https://github.com/danbulant/discord.js
synced 2026-06-06 16:22:08 +00:00
feat(Permissions): add new method Permissions#any (#3450)
* Add new method Permissions#any * Update src/util/BitField.js This is much better Co-Authored-By: bdistin <bdistin@gmail.com> * Remove unreachable code * Gotta keep the linter happy * Apply bdistin suggested change to both methods
This commit is contained in:
parent
4fc461c2f9
commit
a6810e2eaa
3 changed files with 22 additions and 2 deletions
|
|
@ -17,6 +17,15 @@ class BitField {
|
||||||
this.bitfield = this.constructor.resolve(bits);
|
this.bitfield = this.constructor.resolve(bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the bitfield has a bit, or any of multiple bits.
|
||||||
|
* @param {BitFieldResolvable} bit Bit(s) to check for
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
any(bit) {
|
||||||
|
return (this.bitfield & this.constructor.resolve(bit)) !== 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if this bitfield equals another
|
* Checks if this bitfield equals another
|
||||||
* @param {BitFieldResolvable} bit Bit(s) to check for
|
* @param {BitFieldResolvable} bit Bit(s) to check for
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,16 @@ class Permissions extends BitField {
|
||||||
* @typedef {string|number|Permissions|PermissionResolvable[]} PermissionResolvable
|
* @typedef {string|number|Permissions|PermissionResolvable[]} PermissionResolvable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether the bitfield has a permission, or any of multiple permissions.
|
||||||
|
* @param {PermissionResolvable} permission Permission(s) to check for
|
||||||
|
* @param {boolean} [checkAdmin=true] Whether to allow the administrator permission to override
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
any(permission, checkAdmin = true) {
|
||||||
|
return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.any(permission);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether the bitfield has a permission, or multiple permissions.
|
* Checks whether the bitfield has a permission, or multiple permissions.
|
||||||
* @param {PermissionResolvable} permission Permission(s) to check for
|
* @param {PermissionResolvable} permission Permission(s) to check for
|
||||||
|
|
@ -25,8 +35,7 @@ class Permissions extends BitField {
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
has(permission, checkAdmin = true) {
|
has(permission, checkAdmin = true) {
|
||||||
if (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) return true;
|
return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.has(permission);
|
||||||
return super.has(permission);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
|
|
@ -99,6 +99,7 @@ declare module 'discord.js' {
|
||||||
constructor(bits?: BitFieldResolvable<S>);
|
constructor(bits?: BitFieldResolvable<S>);
|
||||||
public bitfield: number;
|
public bitfield: number;
|
||||||
public add(...bits: BitFieldResolvable<S>[]): BitField<S>;
|
public add(...bits: BitFieldResolvable<S>[]): BitField<S>;
|
||||||
|
public any(bit: BitFieldResolvable<S>): boolean;
|
||||||
public equals(bit: BitFieldResolvable<S>): boolean;
|
public equals(bit: BitFieldResolvable<S>): boolean;
|
||||||
public freeze(): Readonly<BitField<S>>;
|
public freeze(): Readonly<BitField<S>>;
|
||||||
public has(bit: BitFieldResolvable<S>): boolean;
|
public has(bit: BitFieldResolvable<S>): boolean;
|
||||||
|
|
@ -1111,6 +1112,7 @@ declare module 'discord.js' {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Permissions extends BitField<PermissionString> {
|
export class Permissions extends BitField<PermissionString> {
|
||||||
|
public any(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
|
||||||
public has(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
|
public has(permission: PermissionResolvable, checkAdmin?: boolean): boolean;
|
||||||
|
|
||||||
public static ALL: number;
|
public static ALL: number;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue