cloudstorm 0.3.2 → 0.4.2
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 +1 -1
- package/README.md +3 -5
- package/dist/Client.d.ts +15 -6
- package/dist/Client.js +8 -18
- package/dist/Constants.d.ts +1 -1
- package/dist/Constants.js +1 -1
- package/dist/Intents.d.ts +2 -0
- package/dist/Intents.js +3 -1
- package/dist/Shard.d.ts +8 -4
- package/dist/Shard.js +2 -9
- package/dist/ShardManager.d.ts +9 -4
- package/dist/ShardManager.js +14 -32
- package/dist/Types.d.ts +4 -31
- package/dist/connector/DiscordConnector.d.ts +12 -7
- package/dist/connector/DiscordConnector.js +66 -96
- package/dist/structures/BetterWs.d.ts +17 -54
- package/dist/structures/BetterWs.js +503 -154
- package/dist/structures/RatelimitBucket.js +3 -7
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -15
package/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright
|
|
1
|
+
Copyright 2022 DasWolke
|
|
2
2
|
|
|
3
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
4
|
|
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
|
}
|
|
@@ -56,6 +54,6 @@ I've written a general whitepaper on the idea of microservice bots, which you ca
|
|
|
56
54
|
You can find the docs at [https://daswolke.github.io/CloudStorm/](https://daswolke.github.io/CloudStorm/)
|
|
57
55
|
|
|
58
56
|
### Installation:
|
|
59
|
-
To install CloudStorm, make sure that you have node
|
|
57
|
+
To install CloudStorm, make sure that you have node 12 or higher and npm installed on your computer.
|
|
60
58
|
|
|
61
59
|
Then run the following command in a terminal `npm install cloudstorm`
|
package/dist/Client.d.ts
CHANGED
|
@@ -41,7 +41,7 @@ declare class Client extends EventEmitter {
|
|
|
41
41
|
endpoint?: string;
|
|
42
42
|
};
|
|
43
43
|
shardManager: ShardManager;
|
|
44
|
-
version:
|
|
44
|
+
version: string;
|
|
45
45
|
private _restClient;
|
|
46
46
|
static readonly default: typeof Client;
|
|
47
47
|
/**
|
|
@@ -63,7 +63,11 @@ declare class Client extends EventEmitter {
|
|
|
63
63
|
* Get the GatewayData including recommended amount of shards.
|
|
64
64
|
* @returns Object with url and shards to use to connect to discord.
|
|
65
65
|
*/
|
|
66
|
-
getGatewayBot(): Promise<
|
|
66
|
+
getGatewayBot(): Promise<{
|
|
67
|
+
url: string;
|
|
68
|
+
shards: number;
|
|
69
|
+
session_start_limit: import("discord-typings").SessionStartLimit;
|
|
70
|
+
}>;
|
|
67
71
|
/**
|
|
68
72
|
* Disconnect the bot gracefully,
|
|
69
73
|
* you will receive a 'disconnected' event once the ShardManager successfully closes all shard websocket connections.
|
|
@@ -84,7 +88,7 @@ declare class Client extends EventEmitter {
|
|
|
84
88
|
* client.presenceUpdate({ status: "dnd", game: { name: "Memes are Dreams" } });
|
|
85
89
|
* });
|
|
86
90
|
*/
|
|
87
|
-
presenceUpdate(data: import("
|
|
91
|
+
presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
88
92
|
/**
|
|
89
93
|
* Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager.
|
|
90
94
|
* @param shardId id of the shard that should update it's status.
|
|
@@ -102,7 +106,7 @@ declare class Client extends EventEmitter {
|
|
|
102
106
|
* client.shardPresenceUpdate(0, { status: "dnd", game: { name: "Im shard 0" } });
|
|
103
107
|
* });
|
|
104
108
|
*/
|
|
105
|
-
shardStatusUpdate(shardId: number, data: import("
|
|
109
|
+
shardStatusUpdate(shardId: number, data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
106
110
|
/**
|
|
107
111
|
* Send an OP 4 VOICE_STATE_UPDATE to Discord. this does **not** allow you to send audio with CloudStorm itself,
|
|
108
112
|
* it just provides the necessary data for another application to send audio data to Discord.
|
|
@@ -122,7 +126,10 @@ declare class Client extends EventEmitter {
|
|
|
122
126
|
* client.voiceStateUpdate(0, { guild_id: "id", channel_id: "id", self_mute: false, self_deaf: false });
|
|
123
127
|
* });
|
|
124
128
|
*/
|
|
125
|
-
voiceStateUpdate(shardId: number, data: import("
|
|
129
|
+
voiceStateUpdate(shardId: number, data: import("discord-typings").VoiceStateUpdatePayload & {
|
|
130
|
+
self_deaf?: boolean;
|
|
131
|
+
self_mute?: boolean;
|
|
132
|
+
}): Promise<void>;
|
|
126
133
|
/**
|
|
127
134
|
* Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
|
|
128
135
|
* @param shardId id of the shard that should send the payload.
|
|
@@ -141,7 +148,9 @@ declare class Client extends EventEmitter {
|
|
|
141
148
|
* client.requestGuildMembers(0, { guild_id: "id" });
|
|
142
149
|
* });
|
|
143
150
|
*/
|
|
144
|
-
requestGuildMembers(shardId: number, data: import("
|
|
151
|
+
requestGuildMembers(shardId: number, data: import("discord-typings").GuildRequestMembersPayload & {
|
|
152
|
+
limit?: number;
|
|
153
|
+
}): Promise<void>;
|
|
145
154
|
/**
|
|
146
155
|
* Update the endpoint shard websockets will connect to.
|
|
147
156
|
* @param gatewayUrl Base gateway wss url to update the cached endpoint to.
|
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);
|
|
@@ -53,8 +45,8 @@ class Client extends events_1.EventEmitter {
|
|
|
53
45
|
* @returns This function returns a promise which is solely used for awaiting the getGateway() method's return value.
|
|
54
46
|
*/
|
|
55
47
|
async connect() {
|
|
56
|
-
const
|
|
57
|
-
this._updateEndpoint(
|
|
48
|
+
const gateway = await this.getGateway();
|
|
49
|
+
this._updateEndpoint(gateway);
|
|
58
50
|
this.shardManager.spawn();
|
|
59
51
|
}
|
|
60
52
|
/**
|
|
@@ -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/Constants.d.ts
CHANGED
package/dist/Constants.js
CHANGED
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
|
@@ -3,7 +3,6 @@ import { EventEmitter } from "events";
|
|
|
3
3
|
import DiscordConnector from "./connector/DiscordConnector";
|
|
4
4
|
interface ShardEvents {
|
|
5
5
|
disconnect: [number, string, boolean];
|
|
6
|
-
error: [string];
|
|
7
6
|
ready: [boolean];
|
|
8
7
|
queueIdentify: [number];
|
|
9
8
|
}
|
|
@@ -55,16 +54,21 @@ declare class Shard extends EventEmitter {
|
|
|
55
54
|
* Send an OP 3 PRESENCE_UPDATE to Discord.
|
|
56
55
|
* @param data Data to send.
|
|
57
56
|
*/
|
|
58
|
-
presenceUpdate(data: import("
|
|
57
|
+
presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
59
58
|
/**
|
|
60
59
|
* Send an OP 4 VOICE_STATE_UPDATE to Discord.
|
|
61
60
|
* @param data Data to send
|
|
62
61
|
*/
|
|
63
|
-
voiceStateUpdate(data: import("
|
|
62
|
+
voiceStateUpdate(data: import("discord-typings").VoiceStateUpdatePayload & {
|
|
63
|
+
self_deaf?: boolean;
|
|
64
|
+
self_mute?: boolean;
|
|
65
|
+
}): Promise<void>;
|
|
64
66
|
/**
|
|
65
67
|
* Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.
|
|
66
68
|
* @param data Data to send.
|
|
67
69
|
*/
|
|
68
|
-
requestGuildMembers(data: import("
|
|
70
|
+
requestGuildMembers(data: import("discord-typings").GuildRequestMembersPayload & {
|
|
71
|
+
limit?: number;
|
|
72
|
+
}): Promise<void>;
|
|
69
73
|
}
|
|
70
74
|
export = Shard;
|
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.d.ts
CHANGED
|
@@ -56,24 +56,29 @@ declare class ShardManager {
|
|
|
56
56
|
* Update the status of all currently connected shards which have been spawned by this manager.
|
|
57
57
|
* @param data Data to send.
|
|
58
58
|
*/
|
|
59
|
-
presenceUpdate(data
|
|
59
|
+
presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
60
60
|
/**
|
|
61
61
|
* Update the status of a single connected shard which has been spawned by this manager.
|
|
62
62
|
* @param shardId id of the shard.
|
|
63
63
|
* @param data Data to send.
|
|
64
64
|
*/
|
|
65
|
-
shardPresenceUpdate(shardId: number, data
|
|
65
|
+
shardPresenceUpdate(shardId: number, data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
66
66
|
/**
|
|
67
67
|
* Send an OP 4 VOICE_STATE_UPDATE with a certain shard.
|
|
68
68
|
* @param shardId id of the shard.
|
|
69
69
|
* @param data Data to send.
|
|
70
70
|
*/
|
|
71
|
-
voiceStateUpdate(shardId: number, data: import("
|
|
71
|
+
voiceStateUpdate(shardId: number, data: import("discord-typings").VoiceStateUpdatePayload & {
|
|
72
|
+
self_deaf?: boolean;
|
|
73
|
+
self_mute?: boolean;
|
|
74
|
+
}): Promise<void>;
|
|
72
75
|
/**
|
|
73
76
|
* Send an OP 8 REQUEST_GUILD_MEMBERS with a certain shard.
|
|
74
77
|
* @param shardId id of the shard.
|
|
75
78
|
* @param data Data to send.
|
|
76
79
|
*/
|
|
77
|
-
requestGuildMembers(shardId: number, data: import("
|
|
80
|
+
requestGuildMembers(shardId: number, data: import("discord-typings").GuildRequestMembersPayload & {
|
|
81
|
+
limit?: number;
|
|
82
|
+
}): Promise<void>;
|
|
78
83
|
}
|
|
79
84
|
export = ShardManager;
|
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");
|
|
@@ -141,7 +135,7 @@ class ShardManager {
|
|
|
141
135
|
* Update the status of all currently connected shards which have been spawned by this manager.
|
|
142
136
|
* @param data Data to send.
|
|
143
137
|
*/
|
|
144
|
-
async presenceUpdate(data
|
|
138
|
+
async presenceUpdate(data) {
|
|
145
139
|
for (const shardKey in this.shards) {
|
|
146
140
|
if (this.shards[shardKey]) {
|
|
147
141
|
const shard = this.shards[shardKey];
|
|
@@ -154,17 +148,13 @@ class ShardManager {
|
|
|
154
148
|
* @param shardId id of the shard.
|
|
155
149
|
* @param data Data to send.
|
|
156
150
|
*/
|
|
157
|
-
shardPresenceUpdate(shardId, data
|
|
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,12 +33,12 @@ 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;
|
|
@@ -53,7 +53,7 @@ declare class DiscordConnector extends EventEmitter {
|
|
|
53
53
|
/**
|
|
54
54
|
* Connect to Discord.
|
|
55
55
|
*/
|
|
56
|
-
connect(): void
|
|
56
|
+
connect(): Promise<void>;
|
|
57
57
|
/**
|
|
58
58
|
* Close the websocket connection and disconnect.
|
|
59
59
|
*/
|
|
@@ -104,17 +104,22 @@ declare class DiscordConnector extends EventEmitter {
|
|
|
104
104
|
* Send an OP 3 PRESENCE_UPDATE to the gateway.
|
|
105
105
|
* @param data Presence data to send.
|
|
106
106
|
*/
|
|
107
|
-
presenceUpdate(data
|
|
107
|
+
presenceUpdate(data: import("discord-typings").GatewayPresenceUpdate): Promise<void>;
|
|
108
108
|
/**
|
|
109
109
|
* Send an OP 4 VOICE_STATE_UPDATE to the gateway.
|
|
110
110
|
* @param data Voice state update data to send.
|
|
111
111
|
*/
|
|
112
|
-
voiceStateUpdate(data: import("
|
|
112
|
+
voiceStateUpdate(data: import("discord-typings").VoiceStateUpdatePayload & {
|
|
113
|
+
self_deaf?: boolean;
|
|
114
|
+
self_mute?: boolean;
|
|
115
|
+
}): Promise<void>;
|
|
113
116
|
/**
|
|
114
117
|
* Send an OP 8 REQUEST_GUILD_MEMBERS to the gateway.
|
|
115
118
|
* @param data Data to send.
|
|
116
119
|
*/
|
|
117
|
-
requestGuildMembers(data: import("
|
|
120
|
+
requestGuildMembers(data: import("discord-typings").GuildRequestMembersPayload & {
|
|
121
|
+
limit?: number;
|
|
122
|
+
}): Promise<void>;
|
|
118
123
|
/**
|
|
119
124
|
* Checks presence data and fills in missing elements.
|
|
120
125
|
* @param data Data to send.
|