cloudstorm 0.5.8 → 0.6.1
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/dist/index.d.ts +686 -7
- package/dist/index.js +2 -28
- package/dist/index.js.map +1 -0
- package/package.json +10 -10
- package/dist/Client.d.ts +0 -167
- package/dist/Client.js +0 -196
- package/dist/Constants.d.ts +0 -49
- package/dist/Constants.js +0 -51
- package/dist/Intents.d.ts +0 -25
- package/dist/Intents.js +0 -36
- package/dist/Shard.d.ts +0 -74
- package/dist/Shard.js +0 -87
- package/dist/ShardManager.d.ts +0 -71
- package/dist/ShardManager.js +0 -153
- package/dist/Types.d.ts +0 -34
- package/dist/Types.js +0 -2
- package/dist/connector/DiscordConnector.d.ts +0 -146
- package/dist/connector/DiscordConnector.js +0 -444
- package/dist/structures/BetterWs.d.ts +0 -50
- package/dist/structures/BetterWs.js +0 -545
- package/dist/structures/RatelimitBucket.d.ts +0 -44
- package/dist/structures/RatelimitBucket.js +0 -104
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/Client.js
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
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
|
-
const Constants_1 = __importDefault(require("./Constants"));
|
|
8
|
-
const snowtransfer_1 = require("snowtransfer");
|
|
9
|
-
const ShardManager_1 = __importDefault(require("./ShardManager"));
|
|
10
|
-
const RatelimitBucket_1 = __importDefault(require("./structures/RatelimitBucket"));
|
|
11
|
-
/**
|
|
12
|
-
* Main class used for receiving events and interacting with the Discord gateway.
|
|
13
|
-
*/
|
|
14
|
-
class Client extends events_1.EventEmitter {
|
|
15
|
-
/**
|
|
16
|
-
* Create a new Client to connect to the Discord gateway.
|
|
17
|
-
* @param token Token received from creating a discord bot user, which will be used to connect to the gateway.
|
|
18
|
-
*/
|
|
19
|
-
constructor(token, options = {}) {
|
|
20
|
-
super();
|
|
21
|
-
if (!token)
|
|
22
|
-
throw new Error("Missing token!");
|
|
23
|
-
this.options = {
|
|
24
|
-
largeGuildThreshold: 250,
|
|
25
|
-
shards: "auto",
|
|
26
|
-
reconnect: true,
|
|
27
|
-
intents: 0,
|
|
28
|
-
token: "",
|
|
29
|
-
ws: {
|
|
30
|
-
compress: true,
|
|
31
|
-
encoding: "json"
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
this._restClient = options.snowtransferInstance ? options.snowtransferInstance : new snowtransfer_1.SnowTransfer(token);
|
|
35
|
-
delete options.snowtransferInstance;
|
|
36
|
-
this.token = token.startsWith("Bot ") ? token.substring(4) : token;
|
|
37
|
-
Object.assign(this.options, options);
|
|
38
|
-
this.options.token = token;
|
|
39
|
-
this.shardManager = new ShardManager_1.default(this);
|
|
40
|
-
this.version = version;
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Create one or more connections (depending on the selected amount of shards) to the Discord gateway.
|
|
44
|
-
* @returns This function returns a promise which is solely used for awaiting the getGateway() method's return value.
|
|
45
|
-
*/
|
|
46
|
-
async connect() {
|
|
47
|
-
const initial = await this.fetchConnectInfo();
|
|
48
|
-
if (this.options.shards === "auto")
|
|
49
|
-
this.options.totalShards = initial;
|
|
50
|
-
this.shardManager.spawn();
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Method to grab initial connection info from Discord.
|
|
54
|
-
* Should only be called automatically by the lib unless you are a large bot with a max_concurrency not equal to 1.
|
|
55
|
-
* If you are a large bot, you should call this method at a rate of your own discretion to update your max_concurrency cached value to have up to date bucket info.
|
|
56
|
-
* @returns The amount of shards the bot should spawn if set to auto.
|
|
57
|
-
*/
|
|
58
|
-
async fetchConnectInfo() {
|
|
59
|
-
const gateway = await this.getGatewayBot();
|
|
60
|
-
this._updateEndpoint(gateway.url);
|
|
61
|
-
const oldQueueConcurrency = [];
|
|
62
|
-
const oldQueueIdentify = [];
|
|
63
|
-
if (this.shardManager.concurrencyBucket && this.shardManager.concurrencyBucket.fnQueue.length) {
|
|
64
|
-
oldQueueConcurrency.push(...this.shardManager.concurrencyBucket.fnQueue.map(i => [i.fn, i.callback]));
|
|
65
|
-
this.shardManager.concurrencyBucket.dropQueue();
|
|
66
|
-
}
|
|
67
|
-
if (this.shardManager.identifyBucket.fnQueue.length)
|
|
68
|
-
oldQueueIdentify.push(...this.shardManager.identifyBucket.fnQueue.map(i => [i.fn, i.callback]));
|
|
69
|
-
this.shardManager.identifyBucket.dropQueue();
|
|
70
|
-
this.shardManager.concurrencyBucket = new RatelimitBucket_1.default(gateway.session_start_limit.max_concurrency, 5000);
|
|
71
|
-
this.shardManager.identifyBucket.remaining = gateway.session_start_limit.remaining;
|
|
72
|
-
this.shardManager.identifyBucket.limitReset = gateway.session_start_limit.reset_after;
|
|
73
|
-
for (const [fn, callback] of oldQueueConcurrency) {
|
|
74
|
-
this.shardManager.concurrencyBucket.queue(fn).then(callback);
|
|
75
|
-
}
|
|
76
|
-
for (const [fn, callback] of oldQueueIdentify) {
|
|
77
|
-
this.shardManager.identifyBucket.queue(fn).then(callback);
|
|
78
|
-
}
|
|
79
|
-
return gateway.shards;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Get the gateway endpoint to connect to.
|
|
83
|
-
* @returns String url with the Gateway Endpoint to connect to.
|
|
84
|
-
*/
|
|
85
|
-
async getGateway() {
|
|
86
|
-
const gatewayData = await this._restClient.bot.getGateway();
|
|
87
|
-
return gatewayData.url;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Get the GatewayData including recommended amount of shards and other helpful info.
|
|
91
|
-
* @returns Object with url and shards to use to connect to discord.
|
|
92
|
-
*/
|
|
93
|
-
async getGatewayBot() {
|
|
94
|
-
return this._restClient.bot.getGatewayBot();
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Disconnect the bot gracefully,
|
|
98
|
-
* you will receive a 'disconnected' event once the ShardManager successfully closes all shard websocket connections.
|
|
99
|
-
*/
|
|
100
|
-
disconnect() {
|
|
101
|
-
return this.shardManager.disconnect();
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of all shards facilitated by this client's ShardManager.
|
|
105
|
-
* @returns Promise that's resolved once all shards have sent the websocket payload.
|
|
106
|
-
*
|
|
107
|
-
* @example
|
|
108
|
-
* // Connect to Discord and set status to do not disturb and game to "Memes are Dreams".
|
|
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.
|
|
115
|
-
* client.presenceUpdate({ status: "dnd", game: { name: "Memes are Dreams" } });
|
|
116
|
-
* });
|
|
117
|
-
*/
|
|
118
|
-
async presenceUpdate(data) {
|
|
119
|
-
return this.shardManager.presenceUpdate(data);
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager.
|
|
123
|
-
* @param shardId id of the shard that should update it's status.
|
|
124
|
-
* @param data Presence data to send.
|
|
125
|
-
* @returns Promise that's resolved once the shard has sent the websocket payload.
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* // Connect to Discord and set status to do not disturb and game to "Im shard 0".
|
|
129
|
-
* const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
|
|
130
|
-
* const token = "token";
|
|
131
|
-
* const client = new CloudStorm.Client(token);
|
|
132
|
-
* client.connect();
|
|
133
|
-
* client.once("ready", () => {
|
|
134
|
-
* // Client is connected to Discord and is ready, so we can update the status of shard 0.
|
|
135
|
-
* client.shardPresenceUpdate(0, { status: "dnd", game: { name: "Im shard 0" } });
|
|
136
|
-
* });
|
|
137
|
-
*/
|
|
138
|
-
shardStatusUpdate(shardId, data) {
|
|
139
|
-
return this.shardManager.shardPresenceUpdate(shardId, data);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Send an OP 4 VOICE_STATE_UPDATE to Discord. this does **not** allow you to send audio with CloudStorm itself,
|
|
143
|
-
* it just provides the necessary data for another application to send audio data to Discord.
|
|
144
|
-
* @param shardId id of the shard that should send the payload.
|
|
145
|
-
* @param data Voice state update data to send.
|
|
146
|
-
* @returns Promise that's resolved once the payload was sent to Discord.
|
|
147
|
-
*
|
|
148
|
-
* @example
|
|
149
|
-
* // Connect to Discord and join a voice channel
|
|
150
|
-
* const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
|
|
151
|
-
* const token = "token";
|
|
152
|
-
* const client = new CloudStorm.Client(token);
|
|
153
|
-
* client.connect();
|
|
154
|
-
* client.once("ready", () => {
|
|
155
|
-
* // Client is connected to Discord and is ready, so we can join a voice channel.
|
|
156
|
-
* // We will use shard 0 as the shard to send the payload.
|
|
157
|
-
* client.voiceStateUpdate(0, { guild_id: "id", channel_id: "id", self_mute: false, self_deaf: false });
|
|
158
|
-
* });
|
|
159
|
-
*/
|
|
160
|
-
voiceStateUpdate(shardId, data) {
|
|
161
|
-
return this.shardManager.voiceStateUpdate(shardId, data);
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
|
|
165
|
-
* @param shardId id of the shard that should send the payload.
|
|
166
|
-
* @param data Request guild members data to send.
|
|
167
|
-
* @returns Promise that's resolved once the payload was send to Discord.
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* // Connect to Discord and request guild members.
|
|
171
|
-
* const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
|
|
172
|
-
* const token = "token";
|
|
173
|
-
* const client = new CloudStorm.Client(token);
|
|
174
|
-
* client.connect();
|
|
175
|
-
* client.once("ready", () => {
|
|
176
|
-
* // Client is connected to Discord and is ready, so we can send the request guild members payload.
|
|
177
|
-
* // We will use shard 0 as the shard to send the payload.
|
|
178
|
-
* client.requestGuildMembers(0, { guild_id: "id" });
|
|
179
|
-
* });
|
|
180
|
-
*/
|
|
181
|
-
requestGuildMembers(shardId, data) {
|
|
182
|
-
if (!data.guild_id)
|
|
183
|
-
throw new Error("You need to pass a guild_id");
|
|
184
|
-
return this.shardManager.requestGuildMembers(shardId, data);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Update the endpoint shard websockets will connect to.
|
|
188
|
-
* @param gatewayUrl Base gateway wss url to update the cached endpoint to.
|
|
189
|
-
*/
|
|
190
|
-
_updateEndpoint(gatewayUrl) {
|
|
191
|
-
var _a, _b;
|
|
192
|
-
this.options.endpoint = `${gatewayUrl}?v=${Constants_1.default.GATEWAY_VERSION}&encoding=${((_a = this.options.ws) === null || _a === void 0 ? void 0 : _a.encoding) === "etf" ? "etf" : "json"}${((_b = this.options.ws) === null || _b === void 0 ? void 0 : _b.compress) ? "&compress=zlib-stream" : ""}`;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
Client.default = Client;
|
|
196
|
-
module.exports = Client;
|
package/dist/Constants.d.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
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;
|
package/dist/Constants.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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;
|
package/dist/Intents.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
MESSAGE_CONTENT: number;
|
|
18
|
-
GUILD_SCHEDULED_EVENTS: number;
|
|
19
|
-
};
|
|
20
|
-
export declare const privileged: number;
|
|
21
|
-
export declare const all: number;
|
|
22
|
-
export declare const non_privileged: number;
|
|
23
|
-
export declare function resolve(bit?: import("./Types").IntentResolvable): number;
|
|
24
|
-
declare const _default: typeof import("./Intents");
|
|
25
|
-
export default _default;
|
package/dist/Intents.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
MESSAGE_CONTENT: 1 << 15,
|
|
21
|
-
GUILD_SCHEDULED_EVENTS: 1 >> 16
|
|
22
|
-
};
|
|
23
|
-
exports.privileged = exports.flags.GUILD_MEMBERS | exports.flags.GUILD_PRESENCES | exports.flags.MESSAGE_CONTENT;
|
|
24
|
-
exports.all = Object.values(exports.flags).reduce((acc, p) => acc | p, 0);
|
|
25
|
-
exports.non_privileged = exports.all & ~exports.privileged;
|
|
26
|
-
function resolve(bit = 0) {
|
|
27
|
-
if (typeof bit === "number" && bit >= 0)
|
|
28
|
-
return bit;
|
|
29
|
-
if (typeof bit === "string" && exports.flags[bit])
|
|
30
|
-
return exports.flags[bit] | 0;
|
|
31
|
-
if (Array.isArray(bit))
|
|
32
|
-
return bit.map((p) => resolve(p)).reduce((prev, p) => prev | p, 0);
|
|
33
|
-
throw new RangeError("BITFIELD_INVALID");
|
|
34
|
-
}
|
|
35
|
-
exports.resolve = resolve;
|
|
36
|
-
exports.default = exports;
|
package/dist/Shard.d.ts
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import { EventEmitter } from "events";
|
|
3
|
-
import DiscordConnector from "./connector/DiscordConnector";
|
|
4
|
-
interface ShardEvents {
|
|
5
|
-
disconnect: [number, string, boolean];
|
|
6
|
-
ready: [boolean];
|
|
7
|
-
queueIdentify: [number];
|
|
8
|
-
}
|
|
9
|
-
interface Shard {
|
|
10
|
-
addListener<E extends keyof ShardEvents>(event: E, listener: (...args: ShardEvents[E]) => any): this;
|
|
11
|
-
emit<E extends keyof ShardEvents>(event: E, ...args: ShardEvents[E]): boolean;
|
|
12
|
-
eventNames(): Array<keyof ShardEvents>;
|
|
13
|
-
listenerCount(event: keyof ShardEvents): number;
|
|
14
|
-
listeners(event: keyof ShardEvents): Array<(...args: Array<any>) => any>;
|
|
15
|
-
off<E extends keyof ShardEvents>(event: E, listener: (...args: ShardEvents[E]) => any): this;
|
|
16
|
-
on<E extends keyof ShardEvents>(event: E, listener: (...args: ShardEvents[E]) => any): this;
|
|
17
|
-
once<E extends keyof ShardEvents>(event: E, listener: (...args: ShardEvents[E]) => any): this;
|
|
18
|
-
prependListener<E extends keyof ShardEvents>(event: E, listener: (...args: ShardEvents[E]) => any): this;
|
|
19
|
-
prependOnceListener<E extends keyof ShardEvents>(event: E, listener: (...args: ShardEvents[E]) => any): this;
|
|
20
|
-
rawListeners(event: keyof ShardEvents): Array<(...args: Array<any>) => any>;
|
|
21
|
-
removeAllListeners(event?: keyof ShardEvents): this;
|
|
22
|
-
removeListener<E extends keyof ShardEvents>(event: E, listener: (...args: ShardEvents[E]) => any): this;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Shard class, which provides a wrapper around the DiscordConnector with metadata like the id of the shard.
|
|
26
|
-
*
|
|
27
|
-
* This class is automatically instantiated by the library and is documented for reference.
|
|
28
|
-
*/
|
|
29
|
-
declare class Shard extends EventEmitter {
|
|
30
|
-
id: number;
|
|
31
|
-
client: import("./Client");
|
|
32
|
-
ready: boolean;
|
|
33
|
-
connector: DiscordConnector;
|
|
34
|
-
static readonly default: typeof Shard;
|
|
35
|
-
/**
|
|
36
|
-
* Create a new Shard.
|
|
37
|
-
* @param id id of the shard.
|
|
38
|
-
* @param client Main class used for forwarding events.
|
|
39
|
-
*/
|
|
40
|
-
constructor(id: number, client: import("./Client"));
|
|
41
|
-
/**
|
|
42
|
-
* Time in ms it took for Discord to ackknowledge an OP 1 HEARTBEAT.
|
|
43
|
-
*/
|
|
44
|
-
get latency(): number;
|
|
45
|
-
/**
|
|
46
|
-
* Create a new connection to Discord.
|
|
47
|
-
*/
|
|
48
|
-
connect(): void;
|
|
49
|
-
/**
|
|
50
|
-
* Close the current connection to Discord.
|
|
51
|
-
*/
|
|
52
|
-
disconnect(): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Send an OP 3 PRESENCE_UPDATE to Discord.
|
|
55
|
-
* @param data Data to send.
|
|
56
|
-
*/
|
|
57
|
-
presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
58
|
-
/**
|
|
59
|
-
* Send an OP 4 VOICE_STATE_UPDATE to Discord.
|
|
60
|
-
* @param data Data to send
|
|
61
|
-
*/
|
|
62
|
-
voiceStateUpdate(data: import("discord-typings").VoiceStateUpdatePayload & {
|
|
63
|
-
self_deaf?: boolean;
|
|
64
|
-
self_mute?: boolean;
|
|
65
|
-
}): Promise<void>;
|
|
66
|
-
/**
|
|
67
|
-
* Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
|
|
68
|
-
* @param data Data to send.
|
|
69
|
-
*/
|
|
70
|
-
requestGuildMembers(data: import("discord-typings").GuildRequestMembersPayload & {
|
|
71
|
-
limit?: number;
|
|
72
|
-
}): Promise<void>;
|
|
73
|
-
}
|
|
74
|
-
export = Shard;
|
package/dist/Shard.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
const events_1 = require("events");
|
|
6
|
-
const DiscordConnector_1 = __importDefault(require("./connector/DiscordConnector"));
|
|
7
|
-
const Constants_1 = require("./Constants");
|
|
8
|
-
/**
|
|
9
|
-
* Shard class, which provides a wrapper around the DiscordConnector with metadata like the id of the shard.
|
|
10
|
-
*
|
|
11
|
-
* This class is automatically instantiated by the library and is documented for reference.
|
|
12
|
-
*/
|
|
13
|
-
class Shard extends events_1.EventEmitter {
|
|
14
|
-
/**
|
|
15
|
-
* Create a new Shard.
|
|
16
|
-
* @param id id of the shard.
|
|
17
|
-
* @param client Main class used for forwarding events.
|
|
18
|
-
*/
|
|
19
|
-
constructor(id, client) {
|
|
20
|
-
super();
|
|
21
|
-
this.id = id;
|
|
22
|
-
this.client = client;
|
|
23
|
-
this.ready = false;
|
|
24
|
-
this.connector = new DiscordConnector_1.default(id, client);
|
|
25
|
-
this.connector.on("event", (event) => {
|
|
26
|
-
const newEvent = Object.assign(event, { shard_id: this.id });
|
|
27
|
-
this.client.emit("event", newEvent);
|
|
28
|
-
switch (event.op) {
|
|
29
|
-
case Constants_1.GATEWAY_OP_CODES.DISPATCH:
|
|
30
|
-
this.client.emit("dispatch", newEvent);
|
|
31
|
-
break;
|
|
32
|
-
case Constants_1.GATEWAY_OP_CODES.VOICE_STATE_UPDATE:
|
|
33
|
-
this.client.emit("voiceStateUpdate", newEvent);
|
|
34
|
-
break;
|
|
35
|
-
default:
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
this.connector.on("disconnect", (...args) => {
|
|
40
|
-
this.ready = false;
|
|
41
|
-
this.emit("disconnect", ...args);
|
|
42
|
-
});
|
|
43
|
-
this.connector.on("ready", (resume) => this.emit("ready", resume));
|
|
44
|
-
this.connector.on("queueIdentify", () => this.emit("queueIdentify", this.id));
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Time in ms it took for Discord to ackknowledge an OP 1 HEARTBEAT.
|
|
48
|
-
*/
|
|
49
|
-
get latency() {
|
|
50
|
-
return this.connector.latency;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Create a new connection to Discord.
|
|
54
|
-
*/
|
|
55
|
-
connect() {
|
|
56
|
-
this.connector.connect();
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Close the current connection to Discord.
|
|
60
|
-
*/
|
|
61
|
-
disconnect() {
|
|
62
|
-
return this.connector.disconnect();
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Send an OP 3 PRESENCE_UPDATE to Discord.
|
|
66
|
-
* @param data Data to send.
|
|
67
|
-
*/
|
|
68
|
-
presenceUpdate(data) {
|
|
69
|
-
return this.connector.presenceUpdate(data);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Send an OP 4 VOICE_STATE_UPDATE to Discord.
|
|
73
|
-
* @param data Data to send
|
|
74
|
-
*/
|
|
75
|
-
voiceStateUpdate(data) {
|
|
76
|
-
return this.connector.voiceStateUpdate(data);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
|
|
80
|
-
* @param data Data to send.
|
|
81
|
-
*/
|
|
82
|
-
requestGuildMembers(data) {
|
|
83
|
-
return this.connector.requestGuildMembers(data);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
Shard.default = Shard;
|
|
87
|
-
module.exports = Shard;
|
package/dist/ShardManager.d.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import Shard from "./Shard";
|
|
2
|
-
import RatelimitBucket from "./structures/RatelimitBucket";
|
|
3
|
-
/**
|
|
4
|
-
* Class used for managing shards for the user.
|
|
5
|
-
*
|
|
6
|
-
* This class is automatically instantiated by the library and is documented for reference.
|
|
7
|
-
*/
|
|
8
|
-
declare class ShardManager {
|
|
9
|
-
client: import("./Client");
|
|
10
|
-
options: import("./Client")["options"];
|
|
11
|
-
shards: {
|
|
12
|
-
[id: number]: Shard;
|
|
13
|
-
};
|
|
14
|
-
identifyBucket: RatelimitBucket;
|
|
15
|
-
concurrencyBucket: RatelimitBucket | null;
|
|
16
|
-
static readonly default: typeof ShardManager;
|
|
17
|
-
/**
|
|
18
|
-
* Create a new ShardManager.
|
|
19
|
-
*/
|
|
20
|
-
constructor(client: import("./Client"));
|
|
21
|
-
/**
|
|
22
|
-
* Create shard instances and add them to the connection queue.
|
|
23
|
-
*/
|
|
24
|
-
spawn(): void;
|
|
25
|
-
/**
|
|
26
|
-
* Disconnect all shards facilitated by this manager.
|
|
27
|
-
*/
|
|
28
|
-
disconnect(): void;
|
|
29
|
-
/**
|
|
30
|
-
* Add event listeners to a shard to that the manager can act on received events.
|
|
31
|
-
* @param shard Shard to add the event listeners to.
|
|
32
|
-
*/
|
|
33
|
-
private _addListener;
|
|
34
|
-
/**
|
|
35
|
-
* Checks if all shards spawned by this manager are ready.
|
|
36
|
-
*/
|
|
37
|
-
private _checkReady;
|
|
38
|
-
/**
|
|
39
|
-
* Checks if all shards spawned by this manager are disconnected.
|
|
40
|
-
*/
|
|
41
|
-
private _checkDisconnect;
|
|
42
|
-
/**
|
|
43
|
-
* Update the status of all currently connected shards which have been spawned by this manager.
|
|
44
|
-
* @param data Data to send.
|
|
45
|
-
*/
|
|
46
|
-
presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
47
|
-
/**
|
|
48
|
-
* Update the status of a single connected shard which has been spawned by this manager.
|
|
49
|
-
* @param shardId id of the shard.
|
|
50
|
-
* @param data Data to send.
|
|
51
|
-
*/
|
|
52
|
-
shardPresenceUpdate(shardId: number, data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
53
|
-
/**
|
|
54
|
-
* Send an OP 4 VOICE_STATE_UPDATE with a certain shard.
|
|
55
|
-
* @param shardId id of the shard.
|
|
56
|
-
* @param data Data to send.
|
|
57
|
-
*/
|
|
58
|
-
voiceStateUpdate(shardId: number, data: import("discord-typings").VoiceStateUpdatePayload & {
|
|
59
|
-
self_deaf?: boolean;
|
|
60
|
-
self_mute?: boolean;
|
|
61
|
-
}): Promise<void>;
|
|
62
|
-
/**
|
|
63
|
-
* Send an OP 8 REQUEST_GUILD_MEMBERS with a certain shard.
|
|
64
|
-
* @param shardId id of the shard.
|
|
65
|
-
* @param data Data to send.
|
|
66
|
-
*/
|
|
67
|
-
requestGuildMembers(shardId: number, data: import("discord-typings").GuildRequestMembersPayload & {
|
|
68
|
-
limit?: number;
|
|
69
|
-
}): Promise<void>;
|
|
70
|
-
}
|
|
71
|
-
export = ShardManager;
|