feat: Intents bitfield (#3844)

* feat: Intents bitfield

* suggestion: properly construct Intents.ALL

* fix: actually document the ws option

* suggestion: remove disabledEvents in favor of intents

* suggestion: remove obsolete check, validate falsy values

Co-Authored-By: SpaceEEC <spaceeec@yahoo.com>

* fix: GUILD_BANS flag

* fix: exception for intents check in ws options

Co-Authored-By: SpaceEEC <spaceeec@yahoo.com>

* docs: IntentsResolvable

Co-Authored-By: SpaceEEC <spaceeec@yahoo.com>

* Update Client.js

Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
Co-authored-by: Crawl <icrawltogo@gmail.com>
This commit is contained in:
Souji
2020-02-29 15:20:16 +01:00
committed by GitHub
parent b58813ace8
commit 8a2f8938be
6 changed files with 101 additions and 10 deletions

76
src/util/Intents.js Normal file
View File

@@ -0,0 +1,76 @@
'use strict';
const BitField = require('./BitField');
/**
* Data structure that makes it easy to calculate intents.
* @extends {BitField}
*/
class Intents extends BitField {}
/**
* Data that can be resolved to give a permission number. This can be:
* * A string (see {@link Intents.FLAGS})
* * An intents flag
* * An instance of Intents
* * An array of IntentsResolvable
* @typedef {string|number|Intents|IntentsResolvable[]} IntentsResolvable
*/
/**
* Numeric websocket intents. All available properties:
* * `GUILDS`
* * `GUILD_MEMBERS`
* * `GUILD_BANS`
* * `GUILD_EMOJIS`
* * `GUILD_INTEGRATIONS`
* * `GUILD_WEBHOOKS`
* * `GUILD_INVITES`
* * `GUILD_VOICE_STATES`
* * `GUILD_PRESENCES`
* * `GUILD_MESSAGES`
* * `GUILD_MESSAGE_REACTIONS`
* * `GUILD_MESSAGE_TYPING`
* * `DIRECT_MESSAGES`
* * `DIRECT_MESSAGE_REACTIONS`
* * `DIRECT_MESSAGE_TYPING`
* @type {Object}
* @see {@link https://discordapp.com/developers/docs/topics/gateway#list-of-intents}
*/
Intents.FLAGS = {
GUILDS: 1 << 0,
GUILD_MEMBERS: 1 << 1,
GUILD_BANS: 1 << 2,
GUILD_EMOJIS: 1 << 3,
GUILD_INTEGRATIONS: 1 << 4,
GUILD_WEBHOOKS: 1 << 5,
GUILD_INVITES: 1 << 6,
GUILD_VOICE_STATES: 1 << 7,
GUILD_PRESENCES: 1 << 8,
GUILD_MESSAGES: 1 << 9,
GUILD_MESSAGE_REACTIONS: 1 << 10,
GUILD_MESSAGE_TYPING: 1 << 11,
DIRECT_MESSAGES: 1 << 12,
DIRECT_MESSAGE_REACTIONS: 1 << 13,
DIRECT_MESSAGE_TYPING: 1 << 14,
};
/**
* Bitfield representing all privileged intents
* @type {number}
* @see {@link https://discordapp.com/developers/docs/topics/gateway#privileged-intents}
*/
Intents.PRIVILEGED = Intents.FLAGS.GUILD_MEMBERS | Intents.FLAGS.GUILD_PRESENCES;
/**
* Bitfield representing all intents combined
* @type {number}
*/
Intents.ALL = Object.values(Intents.FLAGS).reduce((acc, p) => acc | p, 0);
/**
* Bitfield representing all non-privileged intents
* @type {number}
*/
Intents.NON_PRIVILEGED = Intents.ALL & ~Intents.PRIVILEGED;
module.exports = Intents;