diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-12-22 18:53:21 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-12-22 18:53:21 +1100 |
commit | 4591de58050fb1f0c004eacdc4f86d3c6f31db3c (patch) | |
tree | 9bf2e81972bdc5a408e3d588a130fda03193848c | |
parent | Merge pull request #918 from Puyodead1/refactor/patch/disable-qr-login (diff) | |
download | server-4591de58050fb1f0c004eacdc4f86d3c6f31db3c.tar.xz |
Allow BitField's to be passed as number strings. Pretty sure it fixes #722
-rw-r--r-- | src/util/util/BitField.ts | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/util/util/BitField.ts b/src/util/util/BitField.ts index 4e606660..e2f4e2a5 100644 --- a/src/util/util/BitField.ts +++ b/src/util/util/BitField.ts @@ -136,12 +136,22 @@ export class BitField { static resolve(bit: BitFieldResolvable = BigInt(0)): bigint { // @ts-ignore const FLAGS = this.FLAGS || this.constructor?.FLAGS; + + if (typeof bit === "string") { + if (typeof FLAGS[bit] !== "undefined") + return FLAGS[bit]; + else + bit = BigInt(bit); + } + if ( (typeof bit === "number" || typeof bit === "bigint") && bit >= BigInt(0) ) return BigInt(bit); + if (bit instanceof BitField) return bit.bitfield; + if (Array.isArray(bit)) { // @ts-ignore const resolve = this.constructor?.resolve || this.resolve; @@ -149,8 +159,7 @@ export class BitField { .map((p) => resolve.call(this, p)) .reduce((prev, p) => BigInt(prev) | BigInt(p), BigInt(0)); } - if (typeof bit === "string" && typeof FLAGS[bit] !== "undefined") - return FLAGS[bit]; + throw new RangeError("BITFIELD_INVALID: " + bit); } } |