cloudstorm 0.4.0 → 0.4.3
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/README.md +2 -4
- package/dist/Client.js +6 -16
- package/dist/Intents.d.ts +2 -0
- package/dist/Intents.js +3 -1
- package/dist/Shard.d.ts +0 -1
- package/dist/Shard.js +2 -9
- package/dist/ShardManager.js +12 -30
- package/dist/Types.d.ts +4 -31
- package/dist/connector/DiscordConnector.d.ts +5 -4
- package/dist/connector/DiscordConnector.js +67 -93
- package/dist/structures/BetterWs.d.ts +17 -54
- package/dist/structures/BetterWs.js +504 -154
- package/dist/structures/RatelimitBucket.js +3 -7
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -14
package/README.md
CHANGED
|
@@ -17,9 +17,7 @@ const { Client } = require("cloudstorm");
|
|
|
17
17
|
const bot = new Client(token, { intents: ["GUILDS"] });
|
|
18
18
|
const startup = async () => {
|
|
19
19
|
await bot.connect();
|
|
20
|
-
bot.on("ready", () =>
|
|
21
|
-
console.log("Bot received ready event");
|
|
22
|
-
});
|
|
20
|
+
bot.on("ready", () => console.log("Bot received ready event"););
|
|
23
21
|
};
|
|
24
22
|
startup().catch(e => {
|
|
25
23
|
console.error("Error on startup!");
|
|
@@ -44,7 +42,7 @@ So an event you receive may look like this:
|
|
|
44
42
|
"roles": [],
|
|
45
43
|
"status": "offline",
|
|
46
44
|
"user": {
|
|
47
|
-
|
|
45
|
+
"id": "id"
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
}
|
package/dist/Client.js
CHANGED
|
@@ -4,13 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
const version = require("../package.json").version;
|
|
6
6
|
const events_1 = require("events");
|
|
7
|
-
let Erlpack;
|
|
8
|
-
try {
|
|
9
|
-
Erlpack = require("erlpack");
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
Erlpack = null;
|
|
13
|
-
}
|
|
14
7
|
const Constants_1 = __importDefault(require("./Constants"));
|
|
15
8
|
const snowtransfer_1 = require("snowtransfer");
|
|
16
9
|
const ShardManager_1 = __importDefault(require("./ShardManager"));
|
|
@@ -24,9 +17,8 @@ class Client extends events_1.EventEmitter {
|
|
|
24
17
|
*/
|
|
25
18
|
constructor(token, options = {}) {
|
|
26
19
|
super();
|
|
27
|
-
if (!token)
|
|
20
|
+
if (!token)
|
|
28
21
|
throw new Error("Missing token!");
|
|
29
|
-
}
|
|
30
22
|
this.options = {
|
|
31
23
|
largeGuildThreshold: 250,
|
|
32
24
|
firstShardId: 0,
|
|
@@ -37,7 +29,7 @@ class Client extends events_1.EventEmitter {
|
|
|
37
29
|
token: "",
|
|
38
30
|
ws: {
|
|
39
31
|
compress: true,
|
|
40
|
-
|
|
32
|
+
encoding: "json"
|
|
41
33
|
}
|
|
42
34
|
};
|
|
43
35
|
this._restClient = options.snowtransferInstance ? options.snowtransferInstance : new snowtransfer_1.SnowTransfer(token);
|
|
@@ -95,8 +87,7 @@ class Client extends events_1.EventEmitter {
|
|
|
95
87
|
* });
|
|
96
88
|
*/
|
|
97
89
|
async presenceUpdate(data) {
|
|
98
|
-
|
|
99
|
-
void undefined;
|
|
90
|
+
return this.shardManager.presenceUpdate(data);
|
|
100
91
|
}
|
|
101
92
|
/**
|
|
102
93
|
* Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager.
|
|
@@ -159,9 +150,8 @@ class Client extends events_1.EventEmitter {
|
|
|
159
150
|
* });
|
|
160
151
|
*/
|
|
161
152
|
requestGuildMembers(shardId, data) {
|
|
162
|
-
if (!data.guild_id)
|
|
153
|
+
if (!data.guild_id)
|
|
163
154
|
throw new Error("You need to pass a guild_id");
|
|
164
|
-
}
|
|
165
155
|
return this.shardManager.requestGuildMembers(shardId, data);
|
|
166
156
|
}
|
|
167
157
|
/**
|
|
@@ -169,8 +159,8 @@ class Client extends events_1.EventEmitter {
|
|
|
169
159
|
* @param gatewayUrl Base gateway wss url to update the cached endpoint to.
|
|
170
160
|
*/
|
|
171
161
|
_updateEndpoint(gatewayUrl) {
|
|
172
|
-
var _a;
|
|
173
|
-
this.options.endpoint = `${gatewayUrl}?v=${Constants_1.default.GATEWAY_VERSION}&encoding=${
|
|
162
|
+
var _a, _b;
|
|
163
|
+
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" : ""}`;
|
|
174
164
|
}
|
|
175
165
|
}
|
|
176
166
|
Client.default = Client;
|
package/dist/Intents.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export declare const flags: {
|
|
|
14
14
|
DIRECT_MESSAGES: number;
|
|
15
15
|
DIRECT_MESSAGE_REACTIONS: number;
|
|
16
16
|
DIRECT_MESSAGE_TYPING: number;
|
|
17
|
+
MESSAGE_CONTENT: number;
|
|
18
|
+
GUILD_SCHEDULED_EVENTS: number;
|
|
17
19
|
};
|
|
18
20
|
export declare const privileged: number;
|
|
19
21
|
export declare const all: number;
|
package/dist/Intents.js
CHANGED
|
@@ -17,8 +17,10 @@ exports.flags = {
|
|
|
17
17
|
DIRECT_MESSAGES: 1 << 12,
|
|
18
18
|
DIRECT_MESSAGE_REACTIONS: 1 << 13,
|
|
19
19
|
DIRECT_MESSAGE_TYPING: 1 << 14,
|
|
20
|
+
MESSAGE_CONTENT: 1 << 15,
|
|
21
|
+
GUILD_SCHEDULED_EVENTS: 1 >> 16
|
|
20
22
|
};
|
|
21
|
-
exports.privileged = exports.flags.GUILD_MEMBERS | exports.flags.GUILD_PRESENCES | exports.flags.
|
|
23
|
+
exports.privileged = exports.flags.GUILD_MEMBERS | exports.flags.GUILD_PRESENCES | exports.flags.MESSAGE_CONTENT;
|
|
22
24
|
exports.all = Object.values(exports.flags).reduce((acc, p) => acc | p, 0);
|
|
23
25
|
exports.non_privileged = exports.all & ~exports.privileged;
|
|
24
26
|
function resolve(bit = 0) {
|
package/dist/Shard.d.ts
CHANGED
package/dist/Shard.js
CHANGED
|
@@ -40,15 +40,8 @@ class Shard extends events_1.EventEmitter {
|
|
|
40
40
|
this.ready = false;
|
|
41
41
|
this.emit("disconnect", ...args);
|
|
42
42
|
});
|
|
43
|
-
this.connector.on("
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
this.connector.on("ready", (resume) => {
|
|
47
|
-
this.emit("ready", resume);
|
|
48
|
-
});
|
|
49
|
-
this.connector.on("queueIdentify", () => {
|
|
50
|
-
this.emit("queueIdentify", this.id);
|
|
51
|
-
});
|
|
43
|
+
this.connector.on("ready", (resume) => this.emit("ready", resume));
|
|
44
|
+
this.connector.on("queueIdentify", () => this.emit("queueIdentify", this.id));
|
|
52
45
|
}
|
|
53
46
|
/**
|
|
54
47
|
* Time in ms it took for Discord to ackknowledge an OP 1 HEARTBEAT.
|
package/dist/ShardManager.js
CHANGED
|
@@ -15,9 +15,8 @@ class ShardManager {
|
|
|
15
15
|
constructor(client) {
|
|
16
16
|
this.client = client;
|
|
17
17
|
this.options = client.options;
|
|
18
|
-
if (!this.options.connectQueueInterval)
|
|
18
|
+
if (!this.options.connectQueueInterval)
|
|
19
19
|
this.options.connectQueueInterval = 1000 * 5;
|
|
20
|
-
}
|
|
21
20
|
this.shards = {};
|
|
22
21
|
this.connectQueue = [];
|
|
23
22
|
this.lastConnectionAttempt = null;
|
|
@@ -92,9 +91,6 @@ class ShardManager {
|
|
|
92
91
|
this.client.emit("shardReady", { id: shard.id, ready: !resume });
|
|
93
92
|
this._checkReady();
|
|
94
93
|
});
|
|
95
|
-
shard.on("error", (error) => {
|
|
96
|
-
this.client.emit("error", error);
|
|
97
|
-
});
|
|
98
94
|
shard.on("disconnect", (code, reason, gracefulClose) => {
|
|
99
95
|
this.client.emit("debug", `Websocket of shard ${shard.id} closed with code ${code} and reason: ${reason ? reason : "None"}`);
|
|
100
96
|
if (code === 1000 && gracefulClose) {
|
|
@@ -117,9 +113,8 @@ class ShardManager {
|
|
|
117
113
|
_checkReady() {
|
|
118
114
|
for (const shardId in this.shards) {
|
|
119
115
|
if (this.shards[shardId]) {
|
|
120
|
-
if (!this.shards[shardId].ready)
|
|
116
|
+
if (!this.shards[shardId].ready)
|
|
121
117
|
return;
|
|
122
|
-
}
|
|
123
118
|
}
|
|
124
119
|
}
|
|
125
120
|
this.client.emit("ready");
|
|
@@ -130,9 +125,8 @@ class ShardManager {
|
|
|
130
125
|
_checkDisconnect() {
|
|
131
126
|
for (const shardId in this.shards) {
|
|
132
127
|
if (this.shards[shardId]) {
|
|
133
|
-
if (this.shards[shardId].connector.status !== "disconnected")
|
|
128
|
+
if (this.shards[shardId].connector.status !== "disconnected")
|
|
134
129
|
return;
|
|
135
|
-
}
|
|
136
130
|
}
|
|
137
131
|
}
|
|
138
132
|
this.client.emit("disconnected");
|
|
@@ -157,14 +151,10 @@ class ShardManager {
|
|
|
157
151
|
shardPresenceUpdate(shardId, data) {
|
|
158
152
|
return new Promise((res, rej) => {
|
|
159
153
|
const shard = this.shards[shardId];
|
|
160
|
-
if (!shard)
|
|
154
|
+
if (!shard)
|
|
161
155
|
rej(new Error(`Shard ${shardId} does not exist`));
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
shard.once("ready", () => {
|
|
165
|
-
shard.presenceUpdate(data).then(result => res(result)).catch(e => rej(e));
|
|
166
|
-
});
|
|
167
|
-
}
|
|
156
|
+
if (!shard.ready)
|
|
157
|
+
shard.once("ready", () => shard.presenceUpdate(data).then(result => res(result)).catch(e => rej(e)));
|
|
168
158
|
shard.presenceUpdate(data).then(result => res(result)).catch(e => rej(e));
|
|
169
159
|
});
|
|
170
160
|
}
|
|
@@ -176,14 +166,10 @@ class ShardManager {
|
|
|
176
166
|
voiceStateUpdate(shardId, data) {
|
|
177
167
|
return new Promise((res, rej) => {
|
|
178
168
|
const shard = this.shards[shardId];
|
|
179
|
-
if (!shard)
|
|
169
|
+
if (!shard)
|
|
180
170
|
rej(new Error(`Shard ${shardId} does not exist`));
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
shard.once("ready", () => {
|
|
184
|
-
shard.voiceStateUpdate(data).then(result => res(result)).catch(e => rej(e));
|
|
185
|
-
});
|
|
186
|
-
}
|
|
171
|
+
if (!shard.ready)
|
|
172
|
+
shard.once("ready", () => shard.voiceStateUpdate(data).then(result => res(result)).catch(e => rej(e)));
|
|
187
173
|
shard.voiceStateUpdate(data).then(result => res(result)).catch(e => rej(e));
|
|
188
174
|
});
|
|
189
175
|
}
|
|
@@ -195,14 +181,10 @@ class ShardManager {
|
|
|
195
181
|
requestGuildMembers(shardId, data) {
|
|
196
182
|
return new Promise((res, rej) => {
|
|
197
183
|
const shard = this.shards[shardId];
|
|
198
|
-
if (!shard)
|
|
184
|
+
if (!shard)
|
|
199
185
|
rej(new Error(`Shard ${shardId} does not exist`));
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
shard.once("ready", () => {
|
|
203
|
-
shard.requestGuildMembers(data).then(result => res(result)).catch(e => rej(e));
|
|
204
|
-
});
|
|
205
|
-
}
|
|
186
|
+
if (!shard.ready)
|
|
187
|
+
shard.once("ready", () => shard.requestGuildMembers(data).then(result => res(result)).catch(e => rej(e)));
|
|
206
188
|
shard.requestGuildMembers(data).then(result => res(result)).catch(e => rej(e));
|
|
207
189
|
});
|
|
208
190
|
}
|
package/dist/Types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import Constants from "./Constants";
|
|
2
1
|
export interface IntentFlags {
|
|
3
2
|
GUILDS: number;
|
|
4
3
|
GUILD_MEMBERS: number;
|
|
@@ -18,53 +17,27 @@ export interface IntentFlags {
|
|
|
18
17
|
}
|
|
19
18
|
export declare type IntentResolvable = number | Array<number> | keyof IntentFlags | Array<keyof IntentFlags>;
|
|
20
19
|
export interface IWSMessage {
|
|
21
|
-
op:
|
|
20
|
+
op: import("discord-typings").GatewayOpcode;
|
|
22
21
|
d?: any;
|
|
23
22
|
s?: number;
|
|
24
|
-
t?:
|
|
23
|
+
t?: import("discord-typings").GatewayEvent;
|
|
25
24
|
}
|
|
26
25
|
export interface IGatewayMessage extends IWSMessage {
|
|
27
26
|
shard_id: number;
|
|
28
27
|
}
|
|
29
|
-
export interface IPresenceActivity {
|
|
30
|
-
name: string;
|
|
31
|
-
type?: 0 | 1 | 2 | 3 | 5;
|
|
32
|
-
url?: string;
|
|
33
|
-
}
|
|
34
|
-
export interface IPresence {
|
|
35
|
-
status?: "online" | "idle" | "dnd" | "offline";
|
|
36
|
-
afk?: boolean;
|
|
37
|
-
since?: boolean;
|
|
38
|
-
activities?: Array<IPresenceActivity> | null;
|
|
39
|
-
}
|
|
40
28
|
export interface IClientOptions {
|
|
41
29
|
largeGuildThreshold?: number;
|
|
42
30
|
firstShardId?: number;
|
|
43
31
|
lastShardId?: number;
|
|
44
32
|
shardAmount?: number;
|
|
45
33
|
reconnect?: boolean;
|
|
46
|
-
initialPresence?:
|
|
34
|
+
initialPresence?: import("discord-typings").GatewayPresenceUpdate;
|
|
47
35
|
intents?: IntentResolvable;
|
|
48
36
|
connectQueueInterval?: number;
|
|
49
37
|
snowtransferInstance?: import("snowtransfer").SnowTransfer;
|
|
50
38
|
ws?: IClientWSOptions;
|
|
51
39
|
}
|
|
52
|
-
export interface IVoiceStateUpdate {
|
|
53
|
-
guild_id: string;
|
|
54
|
-
channel_id?: string | null;
|
|
55
|
-
self_mute?: boolean;
|
|
56
|
-
self_deaf?: boolean;
|
|
57
|
-
}
|
|
58
|
-
export interface IRequestGuildMembers {
|
|
59
|
-
guild_id: string;
|
|
60
|
-
query?: string | null;
|
|
61
|
-
limit?: number;
|
|
62
|
-
}
|
|
63
|
-
export interface IShardReady {
|
|
64
|
-
id: number;
|
|
65
|
-
ready: boolean;
|
|
66
|
-
}
|
|
67
40
|
export interface IClientWSOptions {
|
|
68
41
|
compress?: boolean;
|
|
69
|
-
|
|
42
|
+
encoding?: "etf" | "json";
|
|
70
43
|
}
|
|
@@ -5,8 +5,8 @@ interface ConnectorEvents {
|
|
|
5
5
|
queueIdentify: [number];
|
|
6
6
|
event: [import("../Types").IWSMessage];
|
|
7
7
|
ready: [boolean];
|
|
8
|
-
error: [string];
|
|
9
8
|
disconnect: [number, string, boolean];
|
|
9
|
+
stateChange: ["connecting" | "identifying" | "resuming" | "ready" | "disconnected"];
|
|
10
10
|
}
|
|
11
11
|
interface DiscordConnector {
|
|
12
12
|
addListener<E extends keyof ConnectorEvents>(event: E, listener: (...args: ConnectorEvents[E]) => any): this;
|
|
@@ -33,16 +33,17 @@ declare class DiscordConnector extends EventEmitter {
|
|
|
33
33
|
client: import("../Client");
|
|
34
34
|
options: import("../Client")["options"];
|
|
35
35
|
reconnect: boolean;
|
|
36
|
-
betterWs: BetterWs
|
|
36
|
+
betterWs: BetterWs;
|
|
37
37
|
heartbeatTimeout: NodeJS.Timeout | null;
|
|
38
38
|
heartbeatInterval: number;
|
|
39
39
|
_trace: string | null;
|
|
40
40
|
seq: number;
|
|
41
|
-
status:
|
|
41
|
+
status: "connecting" | "identifying" | "resuming" | "ready" | "disconnected";
|
|
42
42
|
sessionId: string | null;
|
|
43
43
|
lastACKAt: number;
|
|
44
44
|
lastHeartbeatSend: number;
|
|
45
45
|
latency: number;
|
|
46
|
+
private _closing;
|
|
46
47
|
static readonly default: typeof DiscordConnector;
|
|
47
48
|
/**
|
|
48
49
|
* Create a new Discord Connector.
|
|
@@ -53,7 +54,7 @@ declare class DiscordConnector extends EventEmitter {
|
|
|
53
54
|
/**
|
|
54
55
|
* Connect to Discord.
|
|
55
56
|
*/
|
|
56
|
-
connect(): void
|
|
57
|
+
connect(): Promise<void>;
|
|
57
58
|
/**
|
|
58
59
|
* Close the websocket connection and disconnect.
|
|
59
60
|
*/
|