cloudstorm 0.1.4 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,7 +1,7 @@
1
- Copyright 2018 DasWolke
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright 2022 DasWolke
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,47 +1,61 @@
1
- # CloudStorm
2
-
3
- ## A minimal discord gateway library
4
-
5
- Part of the WeatherStack
6
-
7
- CloudStorm is a small library specially made to **only** cover the Gateway area of the discord api.
8
-
9
- It makes no assumptions about the rest of your stack, therefore you can use it anywhere as long as you use node 8 or higher.
10
-
11
- ### Some of the things that make CloudStorm awesome:
12
- - Standalone discord gateway connection
13
- - zlib-stream, etf and json support
14
- - Well documented
15
-
16
- ### Gotchas with CloudStorm:
17
- You may wonder how you you are able to get the id of a shard where an event originated from, but don't fear, CloudStorm helps you with that by adding a `shard_id` property to the events that are forwarded.
18
-
19
- So an event you receive may look like this:
20
- ```json
21
- {
22
- "op":0,
23
- "t":"PRESENCE_UPDATE",
24
- "s":1337,
25
- "shard_id":0,
26
- "d": {
27
- "game": null,
28
- "guild_id": "id",
29
- "nick": null,
30
- "roles": [],
31
- "status": "offline",
32
- "user": {
33
- "id": "id"
34
- }
35
- }
36
- }
37
- ```
38
- #### Microservice Bots:
39
- I've written a general whitepaper on the idea of microservice bots, which you can find on gist: [Microservice Bot Whitepaper](https://gist.github.com/DasWolke/c9d7dfe6a78445011162a12abd32091d)
40
-
41
- #### Documentation:
42
- You can find the docs at [https://daswolke.github.io/CloudStorm/](https://daswolke.github.io/CloudStorm/)
43
-
44
- #### Installation:
45
- To install CloudStorm, make sure that you have node 8 or higher and npm installed on your computer.
46
-
47
- Then run the following command in a terminal `npm install cloudstorm`
1
+ # A minimal discord gateway library
2
+
3
+ Part of the WeatherStack
4
+
5
+ CloudStorm is a small library specially made to **only** cover the Gateway area of the discord api.
6
+
7
+ It makes no assumptions about the rest of your stack, therefore you can use it anywhere as long as you use node 12 or higher.
8
+
9
+ ## Some of the things that make CloudStorm awesome:
10
+ - Standalone discord gateway connection
11
+ - zlib-stream, etf and json support
12
+ - Well documented
13
+
14
+ ## Example:
15
+ ```js
16
+ const { Client } = require("cloudstorm");
17
+ const bot = new Client(token, { intents: ["GUILDS"] });
18
+ const startup = async () => {
19
+ await bot.connect();
20
+ bot.on("ready", () => {
21
+ console.log("Bot received ready event");
22
+ });
23
+ };
24
+ startup().catch(e => {
25
+ console.error("Error on startup!");
26
+ console.error(e);
27
+ });
28
+ ```
29
+
30
+ ## Gotchas with CloudStorm:
31
+ You may wonder how you you are able to get the id of a shard where an event originated from, but don't fear, CloudStorm helps you with that by adding a `shard_id` property to the events that are forwarded.
32
+
33
+ So an event you receive may look like this:
34
+ ```json
35
+ {
36
+ "op":0,
37
+ "t":"PRESENCE_UPDATE",
38
+ "s":1337,
39
+ "shard_id":0,
40
+ "d": {
41
+ "game": null,
42
+ "guild_id": "id",
43
+ "nick": null,
44
+ "roles": [],
45
+ "status": "offline",
46
+ "user": {
47
+ "id": "id"
48
+ }
49
+ }
50
+ }
51
+ ```
52
+ ### Microservice Bots:
53
+ I've written a general whitepaper on the idea of microservice bots, which you can find on gist: [Microservice Bot Whitepaper](https://gist.github.com/DasWolke/c9d7dfe6a78445011162a12abd32091d)
54
+
55
+ ### Documentation:
56
+ You can find the docs at [https://daswolke.github.io/CloudStorm/](https://daswolke.github.io/CloudStorm/)
57
+
58
+ ### Installation:
59
+ To install CloudStorm, make sure that you have node 12 or higher and npm installed on your computer.
60
+
61
+ Then run the following command in a terminal `npm install cloudstorm`
@@ -0,0 +1,160 @@
1
+ /// <reference types="node" />
2
+ import { EventEmitter } from "events";
3
+ import ShardManager from "./ShardManager";
4
+ interface ClientEvents {
5
+ debug: [string];
6
+ rawSend: [import("./Types").IWSMessage];
7
+ rawReceive: [import("./Types").IGatewayMessage];
8
+ event: [import("./Types").IGatewayMessage];
9
+ dispatch: [import("./Types").IGatewayMessage];
10
+ voiceStateUpdate: [import("./Types").IGatewayMessage];
11
+ shardReady: [{
12
+ id: number;
13
+ ready: boolean;
14
+ }];
15
+ error: [string];
16
+ ready: [];
17
+ disconnected: [];
18
+ }
19
+ interface Client {
20
+ addListener<E extends keyof ClientEvents>(event: E, listener: (...args: ClientEvents[E]) => any): this;
21
+ emit<E extends keyof ClientEvents>(event: E, ...args: ClientEvents[E]): boolean;
22
+ eventNames(): Array<keyof ClientEvents>;
23
+ listenerCount(event: keyof ClientEvents): number;
24
+ listeners(event: keyof ClientEvents): Array<(...args: Array<any>) => any>;
25
+ off<E extends keyof ClientEvents>(event: E, listener: (...args: ClientEvents[E]) => any): this;
26
+ on<E extends keyof ClientEvents>(event: E, listener: (...args: ClientEvents[E]) => any): this;
27
+ once<E extends keyof ClientEvents>(event: E, listener: (...args: ClientEvents[E]) => any): this;
28
+ prependListener<E extends keyof ClientEvents>(event: E, listener: (...args: ClientEvents[E]) => any): this;
29
+ prependOnceListener<E extends keyof ClientEvents>(event: E, listener: (...args: ClientEvents[E]) => any): this;
30
+ rawListeners(event: keyof ClientEvents): Array<(...args: Array<any>) => any>;
31
+ removeAllListeners(event?: keyof ClientEvents): this;
32
+ removeListener<E extends keyof ClientEvents>(event: E, listener: (...args: ClientEvents[E]) => any): this;
33
+ }
34
+ /**
35
+ * Main class used for receiving events and interacting with the Discord gateway.
36
+ */
37
+ declare class Client extends EventEmitter {
38
+ token: string;
39
+ options: Omit<import("./Types").IClientOptions, "snowtransferInstance"> & {
40
+ token: string;
41
+ endpoint?: string;
42
+ };
43
+ shardManager: ShardManager;
44
+ version: string;
45
+ private _restClient;
46
+ static readonly default: typeof Client;
47
+ /**
48
+ * Create a new Client to connect to the Discord gateway.
49
+ * @param token Token received from creating a discord bot user, which will be used to connect to the gateway.
50
+ */
51
+ constructor(token: string, options?: import("./Types").IClientOptions);
52
+ /**
53
+ * Create one or more connections (depending on the selected amount of shards) to the Discord gateway.
54
+ * @returns This function returns a promise which is solely used for awaiting the getGateway() method's return value.
55
+ */
56
+ connect(): Promise<void>;
57
+ /**
58
+ * Get the gateway endpoint to connect to.
59
+ * @returns String url with the Gateway Endpoint to connect to.
60
+ */
61
+ getGateway(): Promise<string>;
62
+ /**
63
+ * Get the GatewayData including recommended amount of shards.
64
+ * @returns Object with url and shards to use to connect to discord.
65
+ */
66
+ getGatewayBot(): Promise<{
67
+ url: string;
68
+ shards: number;
69
+ session_start_limit: import("discord-typings").SessionStartLimit;
70
+ }>;
71
+ /**
72
+ * Disconnect the bot gracefully,
73
+ * you will receive a 'disconnected' event once the ShardManager successfully closes all shard websocket connections.
74
+ */
75
+ disconnect(): void;
76
+ /**
77
+ * Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of all shards facilitated by this client's ShardManager.
78
+ * @returns Promise that's resolved once all shards have sent the websocket payload.
79
+ *
80
+ * @example
81
+ * // Connect to Discord and set status to do not disturb and game to "Memes are Dreams".
82
+ * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
83
+ * const token = "token";
84
+ * const client = new CloudStorm.Client(token);
85
+ * client.connect();
86
+ * client.once("ready", () => {
87
+ * // Client is connected to Discord and is ready, so we can update the status.
88
+ * client.presenceUpdate({ status: "dnd", game: { name: "Memes are Dreams" } });
89
+ * });
90
+ */
91
+ presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
92
+ /**
93
+ * Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager.
94
+ * @param shardId id of the shard that should update it's status.
95
+ * @param data Presence data to send.
96
+ * @returns Promise that's resolved once the shard has sent the websocket payload.
97
+ *
98
+ * @example
99
+ * // Connect to Discord and set status to do not disturb and game to "Im shard 0".
100
+ * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
101
+ * const token = "token";
102
+ * const client = new CloudStorm.Client(token);
103
+ * client.connect();
104
+ * client.once("ready", () => {
105
+ * // Client is connected to Discord and is ready, so we can update the status of shard 0.
106
+ * client.shardPresenceUpdate(0, { status: "dnd", game: { name: "Im shard 0" } });
107
+ * });
108
+ */
109
+ shardStatusUpdate(shardId: number, data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
110
+ /**
111
+ * Send an OP 4 VOICE_STATE_UPDATE to Discord. this does **not** allow you to send audio with CloudStorm itself,
112
+ * it just provides the necessary data for another application to send audio data to Discord.
113
+ * @param shardId id of the shard that should send the payload.
114
+ * @param data Voice state update data to send.
115
+ * @returns Promise that's resolved once the payload was sent to Discord.
116
+ *
117
+ * @example
118
+ * // Connect to Discord and join a voice channel
119
+ * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
120
+ * const token = "token";
121
+ * const client = new CloudStorm.Client(token);
122
+ * client.connect();
123
+ * client.once("ready", () => {
124
+ * // Client is connected to Discord and is ready, so we can join a voice channel.
125
+ * // We will use shard 0 as the shard to send the payload.
126
+ * client.voiceStateUpdate(0, { guild_id: "id", channel_id: "id", self_mute: false, self_deaf: false });
127
+ * });
128
+ */
129
+ voiceStateUpdate(shardId: number, data: import("discord-typings").VoiceStateUpdatePayload & {
130
+ self_deaf?: boolean;
131
+ self_mute?: boolean;
132
+ }): Promise<void>;
133
+ /**
134
+ * Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
135
+ * @param shardId id of the shard that should send the payload.
136
+ * @param data Request guild members data to send.
137
+ * @returns Promise that's resolved once the payload was send to Discord.
138
+ *
139
+ * @example
140
+ * // Connect to Discord and request guild members.
141
+ * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
142
+ * const token = "token";
143
+ * const client = new CloudStorm.Client(token);
144
+ * client.connect();
145
+ * client.once("ready", () => {
146
+ * // Client is connected to Discord and is ready, so we can send the request guild members payload.
147
+ * // We will use shard 0 as the shard to send the payload.
148
+ * client.requestGuildMembers(0, { guild_id: "id" });
149
+ * });
150
+ */
151
+ requestGuildMembers(shardId: number, data: import("discord-typings").GuildRequestMembersPayload & {
152
+ limit?: number;
153
+ }): Promise<void>;
154
+ /**
155
+ * Update the endpoint shard websockets will connect to.
156
+ * @param gatewayUrl Base gateway wss url to update the cached endpoint to.
157
+ */
158
+ private _updateEndpoint;
159
+ }
160
+ export = Client;
package/dist/Client.js ADDED
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ const version = require("../package.json").version;
6
+ const events_1 = require("events");
7
+ let Erlpack;
8
+ try {
9
+ Erlpack = require("erlpack");
10
+ }
11
+ catch (e) {
12
+ Erlpack = null;
13
+ }
14
+ const Constants_1 = __importDefault(require("./Constants"));
15
+ const snowtransfer_1 = require("snowtransfer");
16
+ const ShardManager_1 = __importDefault(require("./ShardManager"));
17
+ /**
18
+ * Main class used for receiving events and interacting with the Discord gateway.
19
+ */
20
+ class Client extends events_1.EventEmitter {
21
+ /**
22
+ * Create a new Client to connect to the Discord gateway.
23
+ * @param token Token received from creating a discord bot user, which will be used to connect to the gateway.
24
+ */
25
+ constructor(token, options = {}) {
26
+ super();
27
+ if (!token) {
28
+ throw new Error("Missing token!");
29
+ }
30
+ this.options = {
31
+ largeGuildThreshold: 250,
32
+ firstShardId: 0,
33
+ lastShardId: 0,
34
+ shardAmount: 1,
35
+ reconnect: true,
36
+ intents: 0,
37
+ token: "",
38
+ ws: {
39
+ compress: true,
40
+ socket: undefined
41
+ }
42
+ };
43
+ this._restClient = options.snowtransferInstance ? options.snowtransferInstance : new snowtransfer_1.SnowTransfer(token);
44
+ delete options.snowtransferInstance;
45
+ this.token = token.startsWith("Bot ") ? token.substring(4) : token;
46
+ Object.assign(this.options, options);
47
+ this.options.token = token;
48
+ this.shardManager = new ShardManager_1.default(this);
49
+ this.version = version;
50
+ }
51
+ /**
52
+ * Create one or more connections (depending on the selected amount of shards) to the Discord gateway.
53
+ * @returns This function returns a promise which is solely used for awaiting the getGateway() method's return value.
54
+ */
55
+ async connect() {
56
+ const gateway = await this.getGateway();
57
+ this._updateEndpoint(gateway);
58
+ this.shardManager.spawn();
59
+ }
60
+ /**
61
+ * Get the gateway endpoint to connect to.
62
+ * @returns String url with the Gateway Endpoint to connect to.
63
+ */
64
+ async getGateway() {
65
+ const gatewayData = await this._restClient.bot.getGateway();
66
+ return gatewayData.url;
67
+ }
68
+ /**
69
+ * Get the GatewayData including recommended amount of shards.
70
+ * @returns Object with url and shards to use to connect to discord.
71
+ */
72
+ async getGatewayBot() {
73
+ return this._restClient.bot.getGatewayBot();
74
+ }
75
+ /**
76
+ * Disconnect the bot gracefully,
77
+ * you will receive a 'disconnected' event once the ShardManager successfully closes all shard websocket connections.
78
+ */
79
+ disconnect() {
80
+ return this.shardManager.disconnect();
81
+ }
82
+ /**
83
+ * Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of all shards facilitated by this client's ShardManager.
84
+ * @returns Promise that's resolved once all shards have sent the websocket payload.
85
+ *
86
+ * @example
87
+ * // Connect to Discord and set status to do not disturb and game to "Memes are Dreams".
88
+ * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
89
+ * const token = "token";
90
+ * const client = new CloudStorm.Client(token);
91
+ * client.connect();
92
+ * client.once("ready", () => {
93
+ * // Client is connected to Discord and is ready, so we can update the status.
94
+ * client.presenceUpdate({ status: "dnd", game: { name: "Memes are Dreams" } });
95
+ * });
96
+ */
97
+ async presenceUpdate(data) {
98
+ await this.shardManager.presenceUpdate(data);
99
+ void undefined;
100
+ }
101
+ /**
102
+ * Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager.
103
+ * @param shardId id of the shard that should update it's status.
104
+ * @param data Presence data to send.
105
+ * @returns Promise that's resolved once the shard has sent the websocket payload.
106
+ *
107
+ * @example
108
+ * // Connect to Discord and set status to do not disturb and game to "Im shard 0".
109
+ * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
110
+ * const token = "token";
111
+ * const client = new CloudStorm.Client(token);
112
+ * client.connect();
113
+ * client.once("ready", () => {
114
+ * // Client is connected to Discord and is ready, so we can update the status of shard 0.
115
+ * client.shardPresenceUpdate(0, { status: "dnd", game: { name: "Im shard 0" } });
116
+ * });
117
+ */
118
+ shardStatusUpdate(shardId, data) {
119
+ return this.shardManager.shardPresenceUpdate(shardId, data);
120
+ }
121
+ /**
122
+ * Send an OP 4 VOICE_STATE_UPDATE to Discord. this does **not** allow you to send audio with CloudStorm itself,
123
+ * it just provides the necessary data for another application to send audio data to Discord.
124
+ * @param shardId id of the shard that should send the payload.
125
+ * @param data Voice state update data to send.
126
+ * @returns Promise that's resolved once the payload was sent to Discord.
127
+ *
128
+ * @example
129
+ * // Connect to Discord and join a voice channel
130
+ * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
131
+ * const token = "token";
132
+ * const client = new CloudStorm.Client(token);
133
+ * client.connect();
134
+ * client.once("ready", () => {
135
+ * // Client is connected to Discord and is ready, so we can join a voice channel.
136
+ * // We will use shard 0 as the shard to send the payload.
137
+ * client.voiceStateUpdate(0, { guild_id: "id", channel_id: "id", self_mute: false, self_deaf: false });
138
+ * });
139
+ */
140
+ voiceStateUpdate(shardId, data) {
141
+ return this.shardManager.voiceStateUpdate(shardId, data);
142
+ }
143
+ /**
144
+ * Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
145
+ * @param shardId id of the shard that should send the payload.
146
+ * @param data Request guild members data to send.
147
+ * @returns Promise that's resolved once the payload was send to Discord.
148
+ *
149
+ * @example
150
+ * // Connect to Discord and request guild members.
151
+ * const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
152
+ * const token = "token";
153
+ * const client = new CloudStorm.Client(token);
154
+ * client.connect();
155
+ * client.once("ready", () => {
156
+ * // Client is connected to Discord and is ready, so we can send the request guild members payload.
157
+ * // We will use shard 0 as the shard to send the payload.
158
+ * client.requestGuildMembers(0, { guild_id: "id" });
159
+ * });
160
+ */
161
+ requestGuildMembers(shardId, data) {
162
+ if (!data.guild_id) {
163
+ throw new Error("You need to pass a guild_id");
164
+ }
165
+ return this.shardManager.requestGuildMembers(shardId, data);
166
+ }
167
+ /**
168
+ * Update the endpoint shard websockets will connect to.
169
+ * @param gatewayUrl Base gateway wss url to update the cached endpoint to.
170
+ */
171
+ _updateEndpoint(gatewayUrl) {
172
+ var _a;
173
+ this.options.endpoint = `${gatewayUrl}?v=${Constants_1.default.GATEWAY_VERSION}&encoding=${Erlpack ? "etf" : "json"}${((_a = this.options.ws) === null || _a === void 0 ? void 0 : _a.compress) ? "&compress=zlib-stream" : ""}`;
174
+ }
175
+ }
176
+ Client.default = Client;
177
+ module.exports = Client;
@@ -0,0 +1,49 @@
1
+ export declare const GATEWAY_OP_CODES: {
2
+ /**
3
+ * Receive.
4
+ */
5
+ DISPATCH: 0;
6
+ /**
7
+ * Send/Receive.
8
+ */
9
+ HEARTBEAT: 1;
10
+ /**
11
+ * Send.
12
+ */
13
+ IDENTIFY: 2;
14
+ /**
15
+ * Send.
16
+ */
17
+ PRESENCE_UPDATE: 3;
18
+ /**
19
+ * Send.
20
+ */
21
+ VOICE_STATE_UPDATE: 4;
22
+ /**
23
+ * Send.
24
+ */
25
+ RESUME: 6;
26
+ /**
27
+ * Receive.
28
+ */
29
+ RECONNECT: 7;
30
+ /**
31
+ * Send.
32
+ */
33
+ REQUEST_GUILD_MEMBERS: 8;
34
+ /**
35
+ * Receive.
36
+ */
37
+ INVALID_SESSION: 9;
38
+ /**
39
+ * Receive.
40
+ */
41
+ HELLO: 10;
42
+ /**
43
+ * Receive.
44
+ */
45
+ HEARTBEAT_ACK: 11;
46
+ };
47
+ export declare const GATEWAY_VERSION = 10;
48
+ declare const _default: typeof import("./Constants");
49
+ export default _default;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GATEWAY_VERSION = exports.GATEWAY_OP_CODES = void 0;
4
+ exports.GATEWAY_OP_CODES = {
5
+ /**
6
+ * Receive.
7
+ */
8
+ DISPATCH: 0,
9
+ /**
10
+ * Send/Receive.
11
+ */
12
+ HEARTBEAT: 1,
13
+ /**
14
+ * Send.
15
+ */
16
+ IDENTIFY: 2,
17
+ /**
18
+ * Send.
19
+ */
20
+ PRESENCE_UPDATE: 3,
21
+ /**
22
+ * Send.
23
+ */
24
+ VOICE_STATE_UPDATE: 4,
25
+ /**
26
+ * Send.
27
+ */
28
+ RESUME: 6,
29
+ /**
30
+ * Receive.
31
+ */
32
+ RECONNECT: 7,
33
+ /**
34
+ * Send.
35
+ */
36
+ REQUEST_GUILD_MEMBERS: 8,
37
+ /**
38
+ * Receive.
39
+ */
40
+ INVALID_SESSION: 9,
41
+ /**
42
+ * Receive.
43
+ */
44
+ HELLO: 10,
45
+ /**
46
+ * Receive.
47
+ */
48
+ HEARTBEAT_ACK: 11
49
+ };
50
+ exports.GATEWAY_VERSION = 10;
51
+ exports.default = exports;
@@ -0,0 +1,23 @@
1
+ export declare const flags: {
2
+ GUILDS: number;
3
+ GUILD_MEMBERS: number;
4
+ GUILD_BANS: number;
5
+ GUILD_EMOJIS_AND_STICKERS: number;
6
+ GUILD_INTEGRATIONS: number;
7
+ GUILD_WEBHOOKS: number;
8
+ GUILD_INVITES: number;
9
+ GUILD_VOICE_STATES: number;
10
+ GUILD_PRESENCES: number;
11
+ GUILD_MESSAGES: number;
12
+ GUILD_MESSAGE_REACTIONS: number;
13
+ GUILD_MESSAGE_TYPING: number;
14
+ DIRECT_MESSAGES: number;
15
+ DIRECT_MESSAGE_REACTIONS: number;
16
+ DIRECT_MESSAGE_TYPING: number;
17
+ };
18
+ export declare const privileged: number;
19
+ export declare const all: number;
20
+ export declare const non_privileged: number;
21
+ export declare function resolve(bit?: import("./Types").IntentResolvable): number;
22
+ declare const _default: typeof import("./Intents");
23
+ export default _default;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolve = exports.non_privileged = exports.all = exports.privileged = exports.flags = void 0;
4
+ exports.flags = {
5
+ GUILDS: 1 << 0,
6
+ GUILD_MEMBERS: 1 << 1,
7
+ GUILD_BANS: 1 << 2,
8
+ GUILD_EMOJIS_AND_STICKERS: 1 << 3,
9
+ GUILD_INTEGRATIONS: 1 << 4,
10
+ GUILD_WEBHOOKS: 1 << 5,
11
+ GUILD_INVITES: 1 << 6,
12
+ GUILD_VOICE_STATES: 1 << 7,
13
+ GUILD_PRESENCES: 1 << 8,
14
+ GUILD_MESSAGES: 1 << 9,
15
+ GUILD_MESSAGE_REACTIONS: 1 << 10,
16
+ GUILD_MESSAGE_TYPING: 1 << 11,
17
+ DIRECT_MESSAGES: 1 << 12,
18
+ DIRECT_MESSAGE_REACTIONS: 1 << 13,
19
+ DIRECT_MESSAGE_TYPING: 1 << 14,
20
+ };
21
+ exports.privileged = exports.flags.GUILD_MEMBERS | exports.flags.GUILD_PRESENCES | exports.flags.GUILD_MESSAGES;
22
+ exports.all = Object.values(exports.flags).reduce((acc, p) => acc | p, 0);
23
+ exports.non_privileged = exports.all & ~exports.privileged;
24
+ function resolve(bit = 0) {
25
+ if (typeof bit === "number" && bit >= 0)
26
+ return bit;
27
+ if (typeof bit === "string" && exports.flags[bit])
28
+ return exports.flags[bit] | 0;
29
+ if (Array.isArray(bit))
30
+ return bit.map((p) => resolve(p)).reduce((prev, p) => prev | p, 0);
31
+ throw new RangeError("BITFIELD_INVALID");
32
+ }
33
+ exports.resolve = resolve;
34
+ exports.default = exports;