Skip to content

Commit

Permalink
Intent calculator added
Browse files Browse the repository at this point in the history
  • Loading branch information
MegalithOfficial committed Jun 10, 2023
1 parent d0f1dad commit 90d07fb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
37 changes: 18 additions & 19 deletions src/base/client/BitFields/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,43 @@ export class BitField {
* Bit Fields
* @readonly
*/
this.data = [];

for (let index = 0; index < bitfields.length; index++) this.data.push(this.resolve(bitfields[ index ]));
this.data = bitfields.reduce((acc, bitfield) => acc | this.constructor.resolve(bitfield), 0);
};

/**
* @readonly
*/
static Flags = {};

add(...bitfield) {
// nasıl deniyoruz komut ne ne komutu direkt intents'i başlattım node ile tmm console access ver pls
for (const bit of bits) {

add(...bitfields) {
for (const bitfield of bitfields) {
this.data |= this.constructor.resolve(bitfield);
}
};
}

remove(...bitfield) {

};
remove(...bitfields) {
for (const bitfield of bitfields) {
this.data &= ~this.constructor.resolve(bitfield);
}
}

has(bitfield) {

};
return (this.data & this.constructor.resolve(bitfield)) !== 0;
}

toJSON() {
return (typeof this.bitfields === 'number' ? this.bitfields : this.bitfields.toString());
};
return this.data;
}

static resolve(bitfield) {
if (typeof bitfield === 'string') {
if (bitfield in this.constructor?.Flags) {
return this.constructor?.Flags[ bitfield ];
if (bitfield in this.Flags) {
return this.Flags[bitfield];
}
throw new Error(`Invalid bitfield: ${bitfield}`);
} else if (typeof bitfield === 'number') {
return bitfield;
}
throw new Error(`Invalid bitfield: ${bitfield}`);
};
};
}
}
30 changes: 27 additions & 3 deletions src/base/client/BitFields/Intents.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,32 @@ export class Intents extends BitField {
*/
static Flags = IntentsFlags;

/**
* Intents
/**
* @readonly
*/
};
static PRIVILEGED = {
GUILD_PRESENCES: true,
GUILD_MEMBERS: true,
MESSAGE_CONTENT: true,
};

/**
* Calculates intents
* @param {...Intents} intents
* @returns {Number}
*/
calculateIntents(...intents) {
return intents.reduce((acc, intent) => acc | (1 << intent), 0);
}

/**
* Is intent Privileged.
* @param {Intents} intent
* @returns
*/
isPrivileged(intent) {
return !!Object.prototype.hasOwnProperty.call(this.constructor.PRIVILEGED, intent);
}
}

console.log(new Intents().calculateIntents(IntentsFlags.Intents.GuildMessages, IntentsFlags.Intents.GuildInvites))

0 comments on commit 90d07fb

Please sign in to comment.