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/ShardManager.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
const Shard_1 = __importDefault(require("./Shard"));
|
|
6
|
-
const RatelimitBucket_1 = __importDefault(require("./structures/RatelimitBucket"));
|
|
7
|
-
/**
|
|
8
|
-
* Class used for managing shards for the user.
|
|
9
|
-
*
|
|
10
|
-
* This class is automatically instantiated by the library and is documented for reference.
|
|
11
|
-
*/
|
|
12
|
-
class ShardManager {
|
|
13
|
-
/**
|
|
14
|
-
* Create a new ShardManager.
|
|
15
|
-
*/
|
|
16
|
-
constructor(client) {
|
|
17
|
-
this.concurrencyBucket = null;
|
|
18
|
-
this.client = client;
|
|
19
|
-
this.options = client.options;
|
|
20
|
-
this.shards = {};
|
|
21
|
-
this.identifyBucket = new RatelimitBucket_1.default(1000, 1000 * 60 * 60 * 24, 1000 * 60 * 60 * 24);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Create shard instances and add them to the connection queue.
|
|
25
|
-
*/
|
|
26
|
-
spawn() {
|
|
27
|
-
if (!this.concurrencyBucket)
|
|
28
|
-
throw new Error("Trying to spawn shards without calling Client.connect()");
|
|
29
|
-
for (const id of (this.options.shards === "auto" ? Array(this.options.totalShards).fill(0).map((_, index) => index) : this.options.shards || [0])) {
|
|
30
|
-
this.client.emit("debug", `Spawned shard ${id}`);
|
|
31
|
-
this.shards[id] = new Shard_1.default(id, this.client);
|
|
32
|
-
this._addListener(this.shards[id]);
|
|
33
|
-
this.shards[id].connector.connect();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Disconnect all shards facilitated by this manager.
|
|
38
|
-
*/
|
|
39
|
-
disconnect() {
|
|
40
|
-
for (const shardKey in this.shards) {
|
|
41
|
-
this.shards[shardKey].disconnect();
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Add event listeners to a shard to that the manager can act on received events.
|
|
46
|
-
* @param shard Shard to add the event listeners to.
|
|
47
|
-
*/
|
|
48
|
-
_addListener(shard) {
|
|
49
|
-
shard.on("ready", (resume) => {
|
|
50
|
-
shard.ready = true;
|
|
51
|
-
this.client.emit("debug", `Shard ${shard.id} ${resume ? "has resumed" : "is ready"}`);
|
|
52
|
-
this.client.emit("shardReady", { id: shard.id, ready: !resume });
|
|
53
|
-
this._checkReady();
|
|
54
|
-
});
|
|
55
|
-
shard.on("queueIdentify", (shardId) => {
|
|
56
|
-
var _a;
|
|
57
|
-
if (!this.shards[shardId])
|
|
58
|
-
return this.client.emit("debug", `Received a queueIdentify event for shard ${shardId} but it does not exist. Was it removed?`);
|
|
59
|
-
this.client.emit("debug", `Shard ${shardId} is ready to identify`);
|
|
60
|
-
(_a = this.concurrencyBucket) === null || _a === void 0 ? void 0 : _a.queue(() => {
|
|
61
|
-
this.identifyBucket.queue(() => this.shards[shardId].connector.identify());
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
shard.on("disconnect", (code, reason, gracefulClose) => {
|
|
65
|
-
this.client.emit("debug", `Websocket of shard ${shard.id} closed with code ${code} and reason: ${reason ? reason : "None"}`);
|
|
66
|
-
if (code === 1000 && gracefulClose)
|
|
67
|
-
return this._checkDisconnect();
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Checks if all shards spawned by this manager are ready.
|
|
72
|
-
*/
|
|
73
|
-
_checkReady() {
|
|
74
|
-
for (const shardId in this.shards) {
|
|
75
|
-
if (this.shards[shardId]) {
|
|
76
|
-
if (!this.shards[shardId].ready)
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
this.client.emit("ready");
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Checks if all shards spawned by this manager are disconnected.
|
|
84
|
-
*/
|
|
85
|
-
_checkDisconnect() {
|
|
86
|
-
for (const shardId in this.shards) {
|
|
87
|
-
if (this.shards[shardId]) {
|
|
88
|
-
if (this.shards[shardId].connector.status !== "disconnected")
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
this.client.emit("disconnected");
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Update the status of all currently connected shards which have been spawned by this manager.
|
|
96
|
-
* @param data Data to send.
|
|
97
|
-
*/
|
|
98
|
-
async presenceUpdate(data) {
|
|
99
|
-
for (const shardKey in this.shards) {
|
|
100
|
-
if (this.shards[shardKey]) {
|
|
101
|
-
const shard = this.shards[shardKey];
|
|
102
|
-
this.shardPresenceUpdate(shard.id, data);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Update the status of a single connected shard which has been spawned by this manager.
|
|
108
|
-
* @param shardId id of the shard.
|
|
109
|
-
* @param data Data to send.
|
|
110
|
-
*/
|
|
111
|
-
shardPresenceUpdate(shardId, data) {
|
|
112
|
-
return new Promise((res, rej) => {
|
|
113
|
-
const shard = this.shards[shardId];
|
|
114
|
-
if (!shard)
|
|
115
|
-
rej(new Error(`Shard ${shardId} does not exist`));
|
|
116
|
-
if (!shard.ready)
|
|
117
|
-
shard.once("ready", () => shard.presenceUpdate(data).then(result => res(result)).catch(e => rej(e)));
|
|
118
|
-
shard.presenceUpdate(data).then(result => res(result)).catch(e => rej(e));
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Send an OP 4 VOICE_STATE_UPDATE with a certain shard.
|
|
123
|
-
* @param shardId id of the shard.
|
|
124
|
-
* @param data Data to send.
|
|
125
|
-
*/
|
|
126
|
-
voiceStateUpdate(shardId, data) {
|
|
127
|
-
return new Promise((res, rej) => {
|
|
128
|
-
const shard = this.shards[shardId];
|
|
129
|
-
if (!shard)
|
|
130
|
-
rej(new Error(`Shard ${shardId} does not exist`));
|
|
131
|
-
if (!shard.ready)
|
|
132
|
-
shard.once("ready", () => shard.voiceStateUpdate(data).then(result => res(result)).catch(e => rej(e)));
|
|
133
|
-
shard.voiceStateUpdate(data).then(result => res(result)).catch(e => rej(e));
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Send an OP 8 REQUEST_GUILD_MEMBERS with a certain shard.
|
|
138
|
-
* @param shardId id of the shard.
|
|
139
|
-
* @param data Data to send.
|
|
140
|
-
*/
|
|
141
|
-
requestGuildMembers(shardId, data) {
|
|
142
|
-
return new Promise((res, rej) => {
|
|
143
|
-
const shard = this.shards[shardId];
|
|
144
|
-
if (!shard)
|
|
145
|
-
rej(new Error(`Shard ${shardId} does not exist`));
|
|
146
|
-
if (!shard.ready)
|
|
147
|
-
shard.once("ready", () => shard.requestGuildMembers(data).then(result => res(result)).catch(e => rej(e)));
|
|
148
|
-
shard.requestGuildMembers(data).then(result => res(result)).catch(e => rej(e));
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
ShardManager.default = ShardManager;
|
|
153
|
-
module.exports = ShardManager;
|
package/dist/Types.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export declare type IntentFlags = (typeof import("./Intents"))["flags"];
|
|
2
|
-
export declare type IntentResolvable = number | Array<number> | keyof IntentFlags | Array<keyof IntentFlags>;
|
|
3
|
-
export interface IWSMessage {
|
|
4
|
-
op: import("discord-typings").GatewayOpcode;
|
|
5
|
-
d?: any;
|
|
6
|
-
s?: number;
|
|
7
|
-
t?: import("discord-typings").GatewayEvent;
|
|
8
|
-
}
|
|
9
|
-
export interface IGatewayMessage extends IWSMessage {
|
|
10
|
-
shard_id: number;
|
|
11
|
-
}
|
|
12
|
-
export interface IClientOptions {
|
|
13
|
-
largeGuildThreshold?: number;
|
|
14
|
-
/**
|
|
15
|
-
* A note on "auto" sharding:
|
|
16
|
-
* "auto" will always start at 0 as there is no way to know the next available shard id.
|
|
17
|
-
* If you have more than one "cluster", you must specify an Array of shard ids. along with totalShards
|
|
18
|
-
*/
|
|
19
|
-
shards?: "auto" | Array<number>;
|
|
20
|
-
/**
|
|
21
|
-
* Ignored and overwrote if using "auto" sharding.
|
|
22
|
-
* The total number of shards expected across all clusters.
|
|
23
|
-
*/
|
|
24
|
-
totalShards?: number;
|
|
25
|
-
reconnect?: boolean;
|
|
26
|
-
initialPresence?: import("discord-typings").GatewayPresenceUpdate;
|
|
27
|
-
intents?: IntentResolvable;
|
|
28
|
-
snowtransferInstance?: import("snowtransfer").SnowTransfer;
|
|
29
|
-
ws?: IClientWSOptions;
|
|
30
|
-
}
|
|
31
|
-
export interface IClientWSOptions {
|
|
32
|
-
compress?: boolean;
|
|
33
|
-
encoding?: "etf" | "json";
|
|
34
|
-
}
|
package/dist/Types.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { EventEmitter } from "events";
|
|
4
|
-
import BetterWs from "../structures/BetterWs";
|
|
5
|
-
interface ConnectorEvents {
|
|
6
|
-
queueIdentify: [number];
|
|
7
|
-
event: [import("../Types").IWSMessage];
|
|
8
|
-
ready: [boolean];
|
|
9
|
-
disconnect: [number, string, boolean];
|
|
10
|
-
stateChange: ["connecting" | "identifying" | "resuming" | "ready" | "disconnected"];
|
|
11
|
-
}
|
|
12
|
-
interface DiscordConnector {
|
|
13
|
-
addListener<E extends keyof ConnectorEvents>(event: E, listener: (...args: ConnectorEvents[E]) => any): this;
|
|
14
|
-
emit<E extends keyof ConnectorEvents>(event: E, ...args: ConnectorEvents[E]): boolean;
|
|
15
|
-
eventNames(): Array<keyof ConnectorEvents>;
|
|
16
|
-
listenerCount(event: keyof ConnectorEvents): number;
|
|
17
|
-
listeners(event: keyof ConnectorEvents): Array<(...args: Array<any>) => any>;
|
|
18
|
-
off<E extends keyof ConnectorEvents>(event: E, listener: (...args: ConnectorEvents[E]) => any): this;
|
|
19
|
-
on<E extends keyof ConnectorEvents>(event: E, listener: (...args: ConnectorEvents[E]) => any): this;
|
|
20
|
-
once<E extends keyof ConnectorEvents>(event: E, listener: (...args: ConnectorEvents[E]) => any): this;
|
|
21
|
-
prependListener<E extends keyof ConnectorEvents>(event: E, listener: (...args: ConnectorEvents[E]) => any): this;
|
|
22
|
-
prependOnceListener<E extends keyof ConnectorEvents>(event: E, listener: (...args: ConnectorEvents[E]) => any): this;
|
|
23
|
-
rawListeners(event: keyof ConnectorEvents): Array<(...args: Array<any>) => any>;
|
|
24
|
-
removeAllListeners(event?: keyof ConnectorEvents): this;
|
|
25
|
-
removeListener<E extends keyof ConnectorEvents>(event: E, listener: (...args: ConnectorEvents[E]) => any): this;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Class used for acting based on received events.
|
|
29
|
-
*
|
|
30
|
-
* This class is automatically instantiated by the library and is documented for reference.
|
|
31
|
-
*/
|
|
32
|
-
declare class DiscordConnector extends EventEmitter {
|
|
33
|
-
id: number;
|
|
34
|
-
client: import("../Client");
|
|
35
|
-
options: import("../Client")["options"];
|
|
36
|
-
reconnect: boolean;
|
|
37
|
-
betterWs: BetterWs;
|
|
38
|
-
heartbeatTimeout: NodeJS.Timeout | null;
|
|
39
|
-
heartbeatInterval: number;
|
|
40
|
-
_trace: string | null;
|
|
41
|
-
seq: number;
|
|
42
|
-
status: "connecting" | "identifying" | "resuming" | "ready" | "disconnected";
|
|
43
|
-
sessionId: string | null;
|
|
44
|
-
lastACKAt: number;
|
|
45
|
-
lastHeartbeatSend: number;
|
|
46
|
-
latency: number;
|
|
47
|
-
private _closing;
|
|
48
|
-
identifyAddress: string;
|
|
49
|
-
resumeAddress: string | null;
|
|
50
|
-
static readonly default: typeof DiscordConnector;
|
|
51
|
-
/**
|
|
52
|
-
* Create a new Discord Connector.
|
|
53
|
-
* @param id id of the shard that created this class.
|
|
54
|
-
* @param client Main client instance.
|
|
55
|
-
*/
|
|
56
|
-
constructor(id: number, client: import("../Client"));
|
|
57
|
-
/**
|
|
58
|
-
* Connect to Discord.
|
|
59
|
-
*/
|
|
60
|
-
connect(): Promise<void>;
|
|
61
|
-
/**
|
|
62
|
-
* Close the websocket connection and disconnect.
|
|
63
|
-
*/
|
|
64
|
-
disconnect(): Promise<void>;
|
|
65
|
-
/**
|
|
66
|
-
* Called with a parsed Websocket message to execute further actions.
|
|
67
|
-
* @param message Message that was received.
|
|
68
|
-
*/
|
|
69
|
-
private messageAction;
|
|
70
|
-
/**
|
|
71
|
-
* Reset this connector to be ready to resume or hard reconnect, then connect.
|
|
72
|
-
* @param resume Whether or not the client intends to send an OP 6 RESUME later.
|
|
73
|
-
*/
|
|
74
|
-
private _reconnect;
|
|
75
|
-
/**
|
|
76
|
-
* Hard reset this connector.
|
|
77
|
-
*/
|
|
78
|
-
private reset;
|
|
79
|
-
/**
|
|
80
|
-
* Clear the heart beat interval, set it to null and set the cached heartbeat_interval as 0.
|
|
81
|
-
*/
|
|
82
|
-
private clearHeartBeat;
|
|
83
|
-
/**
|
|
84
|
-
* Send an OP 2 IDENTIFY to the gateway or an OP 6 RESUME if forceful identify is falsy.
|
|
85
|
-
* @param force Whether CloudStorm should send an OP 2 IDENTIFY even if there's a session that could be resumed.
|
|
86
|
-
*/
|
|
87
|
-
identify(force?: boolean): Promise<void>;
|
|
88
|
-
/**
|
|
89
|
-
* Send an OP 6 RESUME to the gateway.
|
|
90
|
-
*/
|
|
91
|
-
private resume;
|
|
92
|
-
/**
|
|
93
|
-
* Send an OP 1 HEARTBEAT to the gateway.
|
|
94
|
-
*/
|
|
95
|
-
private heartbeat;
|
|
96
|
-
/**
|
|
97
|
-
* Handle dispatch events.
|
|
98
|
-
* @param message Message received from the websocket.
|
|
99
|
-
*/
|
|
100
|
-
private handleDispatch;
|
|
101
|
-
/**
|
|
102
|
-
* Handle a close from the underlying websocket.
|
|
103
|
-
* @param code Websocket close code.
|
|
104
|
-
* @param reason Close reason if any.
|
|
105
|
-
*/
|
|
106
|
-
private handleWsClose;
|
|
107
|
-
/**
|
|
108
|
-
* Send an OP 3 PRESENCE_UPDATE to the gateway.
|
|
109
|
-
* @param data Presence data to send.
|
|
110
|
-
*/
|
|
111
|
-
presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
112
|
-
/**
|
|
113
|
-
* Send an OP 4 VOICE_STATE_UPDATE to the gateway.
|
|
114
|
-
* @param data Voice state update data to send.
|
|
115
|
-
*/
|
|
116
|
-
voiceStateUpdate(data: import("discord-typings").VoiceStateUpdatePayload & {
|
|
117
|
-
self_deaf?: boolean;
|
|
118
|
-
self_mute?: boolean;
|
|
119
|
-
}): Promise<void>;
|
|
120
|
-
/**
|
|
121
|
-
* Send an OP 8 REQUEST_GUILD_MEMBERS to the gateway.
|
|
122
|
-
* @param data Data to send.
|
|
123
|
-
*/
|
|
124
|
-
requestGuildMembers(data: import("discord-typings").GuildRequestMembersPayload & {
|
|
125
|
-
limit?: number;
|
|
126
|
-
}): Promise<void>;
|
|
127
|
-
/**
|
|
128
|
-
* Checks presence data and fills in missing elements.
|
|
129
|
-
* @param data Data to send.
|
|
130
|
-
* @returns Data after it's fixed/checked.
|
|
131
|
-
*/
|
|
132
|
-
private _checkPresenceData;
|
|
133
|
-
/**
|
|
134
|
-
* Checks voice state update data and fills in missing elements.
|
|
135
|
-
* @param data Data to send.
|
|
136
|
-
* @returns Data after it's fixed/checked.
|
|
137
|
-
*/
|
|
138
|
-
private _checkVoiceStateUpdateData;
|
|
139
|
-
/**
|
|
140
|
-
* Checks request guild members data and fills in missing elements.
|
|
141
|
-
* @param data Data to send.
|
|
142
|
-
* @returns Data after it's fixed/checked.
|
|
143
|
-
*/
|
|
144
|
-
private _checkRequestGuildMembersData;
|
|
145
|
-
}
|
|
146
|
-
export = DiscordConnector;
|