From 83374bdbf4fccc98e7f14d2d7786be0686a61496 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 28 Apr 2021 10:47:05 +0200 Subject: [PATCH 1/9] fix(Bitfield): has must return false it bit is undefined --- src/util/BitField.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/BitField.js b/src/util/BitField.js index fe32332f4fd7..894799013093 100644 --- a/src/util/BitField.js +++ b/src/util/BitField.js @@ -41,6 +41,7 @@ class BitField { * @returns {boolean} */ has(bit) { + if (typeof bit === 'undefined') return false; if (Array.isArray(bit)) return bit.every(p => this.has(p)); bit = this.constructor.resolve(bit); return (this.bitfield & bit) === bit; From 41285af435522602f3d41bc147443a91a42436a4 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 30 Apr 2021 13:06:43 +0200 Subject: [PATCH 2/9] Update src/util/BitField.js Co-authored-by: Vlad Frangu --- src/util/BitField.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/BitField.js b/src/util/BitField.js index 894799013093..aa4ef8349005 100644 --- a/src/util/BitField.js +++ b/src/util/BitField.js @@ -41,9 +41,9 @@ class BitField { * @returns {boolean} */ has(bit) { - if (typeof bit === 'undefined') return false; if (Array.isArray(bit)) return bit.every(p => this.has(p)); bit = this.constructor.resolve(bit); + if (bit === this.constructor.defaultBit) return false; return (this.bitfield & bit) === bit; } From 1e3c8cafc6d635f9327d0b1d32e338eab0e9ba8d Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 7 May 2021 20:37:23 +0200 Subject: [PATCH 3/9] fix(BitField): throw an error if bit to resolve is undefined --- src/util/BitField.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/util/BitField.js b/src/util/BitField.js index aa4ef8349005..49e6d5af7206 100644 --- a/src/util/BitField.js +++ b/src/util/BitField.js @@ -43,7 +43,6 @@ class BitField { has(bit) { if (Array.isArray(bit)) return bit.every(p => this.has(p)); bit = this.constructor.resolve(bit); - if (bit === this.constructor.defaultBit) return false; return (this.bitfield & bit) === bit; } @@ -144,7 +143,6 @@ class BitField { */ static resolve(bit) { const { defaultBit } = this; - if (typeof bit === 'undefined') return defaultBit; if (typeof defaultBit === typeof bit && bit >= defaultBit) return bit; if (bit instanceof BitField) return bit.bitfield; if (Array.isArray(bit)) return bit.map(p => this.resolve(p)).reduce((prev, p) => prev | p, defaultBit); From 39bd4f07eae5515d42646ca4bc41021e96ae4191 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 7 May 2021 21:14:55 +0200 Subject: [PATCH 4/9] fix(BitField): keep consistency for recursive has calls --- src/util/BitField.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/util/BitField.js b/src/util/BitField.js index 49e6d5af7206..9a56a6958cad 100644 --- a/src/util/BitField.js +++ b/src/util/BitField.js @@ -38,10 +38,11 @@ class BitField { /** * Checks whether the bitfield has a bit, or multiple bits. * @param {BitFieldResolvable} bit Bit(s) to check for + * @param {...*} hasParams Additional parameters for the has method, if any * @returns {boolean} */ - has(bit) { - if (Array.isArray(bit)) return bit.every(p => this.has(p)); + has(bit, ...hasParams) { + if (Array.isArray(bit)) return bit.every(p => this.has(p, ...hasParams)); bit = this.constructor.resolve(bit); return (this.bitfield & bit) === bit; } From e2f343bb5d1b375fa07b511777dcde05e5017a7b Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 7 May 2021 21:16:59 +0200 Subject: [PATCH 5/9] typings(BitField): ...hasParam for has --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 84b249657d38..a794974032a1 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -203,7 +203,7 @@ declare module 'discord.js' { public any(bit: BitFieldResolvable): boolean; public equals(bit: BitFieldResolvable): boolean; public freeze(): Readonly>; - public has(bit: BitFieldResolvable): boolean; + public has(bit: BitFieldResolvable, ...hasParam: readonly unknown[]): boolean; public missing(bits: BitFieldResolvable, ...hasParam: readonly unknown[]): S[]; public remove(...bits: BitFieldResolvable[]): BitField; public serialize(...hasParam: readonly unknown[]): Record; From ae896e60c2fe7ba140cfb3511a6e7d1627e25877 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 7 May 2021 21:27:17 +0200 Subject: [PATCH 6/9] fix(Permissions): pass checkAdmin to BitField#has --- src/util/Permissions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/Permissions.js b/src/util/Permissions.js index 249c8ba767ea..733537ca495a 100644 --- a/src/util/Permissions.js +++ b/src/util/Permissions.js @@ -41,7 +41,7 @@ class Permissions extends BitField { * @returns {boolean} */ has(permission, checkAdmin = true) { - return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.has(permission); + return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.has(permission, checkAdmin); } } From d31c7797a962e02934d977fec40892ab0eaceb5f Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 9 Jun 2021 14:29:57 +0200 Subject: [PATCH 7/9] revert(Permissions): revert to default behavior --- src/util/Permissions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/Permissions.js b/src/util/Permissions.js index 733537ca495a..249c8ba767ea 100644 --- a/src/util/Permissions.js +++ b/src/util/Permissions.js @@ -41,7 +41,7 @@ class Permissions extends BitField { * @returns {boolean} */ has(permission, checkAdmin = true) { - return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.has(permission, checkAdmin); + return (checkAdmin && super.has(this.constructor.FLAGS.ADMINISTRATOR)) || super.has(permission); } } From 3a2db52292fbd5586487a040b28981a197f2d77d Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 9 Jun 2021 14:30:38 +0200 Subject: [PATCH 8/9] revert(BitField): revert changes + fix(BitField): letting resolve handle arrays --- src/util/BitField.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/BitField.js b/src/util/BitField.js index 9a56a6958cad..e4fd104a54f1 100644 --- a/src/util/BitField.js +++ b/src/util/BitField.js @@ -38,11 +38,9 @@ class BitField { /** * Checks whether the bitfield has a bit, or multiple bits. * @param {BitFieldResolvable} bit Bit(s) to check for - * @param {...*} hasParams Additional parameters for the has method, if any * @returns {boolean} */ - has(bit, ...hasParams) { - if (Array.isArray(bit)) return bit.every(p => this.has(p, ...hasParams)); + has(bit) { bit = this.constructor.resolve(bit); return (this.bitfield & bit) === bit; } From 6b994a91cdd5ef4653ae64b432e3aa3a74bafecd Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 9 Jun 2021 14:31:19 +0200 Subject: [PATCH 9/9] revert(typings): revert changes --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index a794974032a1..84b249657d38 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -203,7 +203,7 @@ declare module 'discord.js' { public any(bit: BitFieldResolvable): boolean; public equals(bit: BitFieldResolvable): boolean; public freeze(): Readonly>; - public has(bit: BitFieldResolvable, ...hasParam: readonly unknown[]): boolean; + public has(bit: BitFieldResolvable): boolean; public missing(bits: BitFieldResolvable, ...hasParam: readonly unknown[]): S[]; public remove(...bits: BitFieldResolvable[]): BitField; public serialize(...hasParam: readonly unknown[]): Record;