Skip to content

Commit 90d07fb

Browse files
Intent calculator added
1 parent d0f1dad commit 90d07fb

2 files changed

Lines changed: 45 additions & 22 deletions

File tree

src/base/client/BitFields/Base.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,43 @@ export class BitField {
2020
* Bit Fields
2121
* @readonly
2222
*/
23-
this.data = [];
24-
25-
for (let index = 0; index < bitfields.length; index++) this.data.push(this.resolve(bitfields[ index ]));
23+
this.data = bitfields.reduce((acc, bitfield) => acc | this.constructor.resolve(bitfield), 0);
2624
};
2725

2826
/**
2927
* @readonly
3028
*/
3129
static Flags = {};
3230

33-
add(...bitfield) {
34-
// nasıl deniyoruz komut ne ne komutu direkt intents'i başlattım node ile tmm console access ver pls
35-
for (const bit of bits) {
36-
31+
add(...bitfields) {
32+
for (const bitfield of bitfields) {
33+
this.data |= this.constructor.resolve(bitfield);
3734
}
38-
};
35+
}
3936

40-
remove(...bitfield) {
41-
42-
};
37+
remove(...bitfields) {
38+
for (const bitfield of bitfields) {
39+
this.data &= ~this.constructor.resolve(bitfield);
40+
}
41+
}
4342

4443
has(bitfield) {
45-
46-
};
44+
return (this.data & this.constructor.resolve(bitfield)) !== 0;
45+
}
4746

4847
toJSON() {
49-
return (typeof this.bitfields === 'number' ? this.bitfields : this.bitfields.toString());
50-
};
48+
return this.data;
49+
}
5150

5251
static resolve(bitfield) {
5352
if (typeof bitfield === 'string') {
54-
if (bitfield in this.constructor?.Flags) {
55-
return this.constructor?.Flags[ bitfield ];
53+
if (bitfield in this.Flags) {
54+
return this.Flags[bitfield];
5655
}
5756
throw new Error(`Invalid bitfield: ${bitfield}`);
5857
} else if (typeof bitfield === 'number') {
5958
return bitfield;
6059
}
6160
throw new Error(`Invalid bitfield: ${bitfield}`);
62-
};
63-
};
61+
}
62+
}

src/base/client/BitFields/Intents.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,32 @@ export class Intents extends BitField {
2121
*/
2222
static Flags = IntentsFlags;
2323

24-
/**
25-
* Intents
24+
/**
2625
* @readonly
2726
*/
28-
};
27+
static PRIVILEGED = {
28+
GUILD_PRESENCES: true,
29+
GUILD_MEMBERS: true,
30+
MESSAGE_CONTENT: true,
31+
};
32+
33+
/**
34+
* Calculates intents
35+
* @param {...Intents} intents
36+
* @returns {Number}
37+
*/
38+
calculateIntents(...intents) {
39+
return intents.reduce((acc, intent) => acc | (1 << intent), 0);
40+
}
41+
42+
/**
43+
* Is intent Privileged.
44+
* @param {Intents} intent
45+
* @returns
46+
*/
47+
isPrivileged(intent) {
48+
return !!Object.prototype.hasOwnProperty.call(this.constructor.PRIVILEGED, intent);
49+
}
50+
}
51+
52+
console.log(new Intents().calculateIntents(IntentsFlags.Intents.GuildMessages, IntentsFlags.Intents.GuildInvites))

0 commit comments

Comments
 (0)