seyfert 2.1.1-dev-12261178806.0 → 2.1.1-dev-12309212345.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/lib/cache/index.js +2 -0
- package/lib/client/client.d.ts +0 -1
- package/lib/client/client.js +8 -27
- package/lib/client/workerclient.d.ts +0 -3
- package/lib/client/workerclient.js +24 -73
- package/lib/common/shorters/guilds.d.ts +2 -2
- package/lib/common/shorters/messages.d.ts +1 -1
- package/lib/common/shorters/messages.js +6 -1
- package/lib/events/hooks/custom.d.ts +5 -1
- package/lib/events/hooks/custom.js +14 -1
- package/lib/structures/Guild.d.ts +1 -2
- package/lib/structures/Message.d.ts +1 -1
- package/lib/structures/Message.js +2 -2
- package/lib/structures/channels.d.ts +3 -3
- package/lib/structures/channels.js +1 -1
- package/lib/types/gateway.d.ts +12 -1
- package/lib/types/utils/index.d.ts +3 -0
- package/lib/types/utils/index.js +3 -0
- package/lib/websocket/discord/shard.d.ts +7 -5
- package/lib/websocket/discord/shard.js +60 -30
- package/lib/websocket/discord/sharder.d.ts +1 -1
- package/lib/websocket/discord/workermanager.js +3 -3
- package/package.json +1 -1
package/lib/cache/index.js
CHANGED
|
@@ -321,9 +321,11 @@ class Cache {
|
|
|
321
321
|
break;
|
|
322
322
|
case 'GUILD_CREATE':
|
|
323
323
|
case 'GUILD_UPDATE':
|
|
324
|
+
case 'RAW_GUILD_CREATE':
|
|
324
325
|
await this.guilds?.patch(event.d.id, { unavailable: false, ...event.d });
|
|
325
326
|
break;
|
|
326
327
|
case 'GUILD_DELETE':
|
|
328
|
+
case 'RAW_GUILD_DELETE':
|
|
327
329
|
if (event.d.unavailable) {
|
|
328
330
|
await this.guilds?.patch(event.d.id, event.d);
|
|
329
331
|
}
|
package/lib/client/client.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { BaseClient } from './base';
|
|
|
10
10
|
import { Collectors } from './collectors';
|
|
11
11
|
import { type ClientUserStructure, type MessageStructure } from './transformers';
|
|
12
12
|
export declare class Client<Ready extends boolean = boolean> extends BaseClient {
|
|
13
|
-
private __handleGuilds?;
|
|
14
13
|
gateway: ShardManager;
|
|
15
14
|
me: If<Ready, ClientUserStructure>;
|
|
16
15
|
options: Omit<ClientOptions, 'commands'> & {
|
package/lib/client/client.js
CHANGED
|
@@ -11,7 +11,6 @@ const collectors_1 = require("./collectors");
|
|
|
11
11
|
const transformers_1 = require("./transformers");
|
|
12
12
|
let parentPort;
|
|
13
13
|
class Client extends base_1.BaseClient {
|
|
14
|
-
__handleGuilds;
|
|
15
14
|
gateway;
|
|
16
15
|
me;
|
|
17
16
|
memberUpdateHandler = new memberUpdate_1.MemberUpdateHandler();
|
|
@@ -125,22 +124,6 @@ class Client extends base_1.BaseClient {
|
|
|
125
124
|
await this.events.execute(packet, this, shardId);
|
|
126
125
|
}
|
|
127
126
|
break;
|
|
128
|
-
case 'GUILD_DELETE':
|
|
129
|
-
case 'GUILD_CREATE': {
|
|
130
|
-
if (this.__handleGuilds?.includes(packet.d.id)) {
|
|
131
|
-
this.__handleGuilds?.splice(this.__handleGuilds.indexOf(packet.d.id), 1);
|
|
132
|
-
if (!this.__handleGuilds?.length && [...this.gateway.values()].every(shard => shard.data.session_id)) {
|
|
133
|
-
delete this.__handleGuilds;
|
|
134
|
-
await this.cache.onPacket(packet);
|
|
135
|
-
return this.events.runEvent('BOT_READY', this, this.me, -1);
|
|
136
|
-
}
|
|
137
|
-
if (!this.__handleGuilds?.length)
|
|
138
|
-
delete this.__handleGuilds;
|
|
139
|
-
return this.cache.onPacket(packet);
|
|
140
|
-
}
|
|
141
|
-
await this.events.execute(packet, this, shardId);
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
127
|
//rest of the events
|
|
145
128
|
default: {
|
|
146
129
|
switch (packet.t) {
|
|
@@ -157,23 +140,21 @@ class Client extends base_1.BaseClient {
|
|
|
157
140
|
}
|
|
158
141
|
break;
|
|
159
142
|
case 'READY': {
|
|
160
|
-
const ids = packet.d.guilds.map(x => x.id);
|
|
161
|
-
if ((0, common_1.hasIntent)(this.gateway.options.intents, 'Guilds')) {
|
|
162
|
-
this.__handleGuilds = this.__handleGuilds?.concat(ids) ?? ids;
|
|
163
|
-
}
|
|
164
143
|
this.botId = packet.d.user.id;
|
|
165
144
|
this.applicationId = packet.d.application.id;
|
|
166
145
|
this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
|
|
167
|
-
if (!this.__handleGuilds?.length) {
|
|
168
|
-
if ([...this.gateway.values()].every(shard => shard.data.session_id)) {
|
|
169
|
-
await this.events.runEvent('BOT_READY', this, this.me, -1);
|
|
170
|
-
}
|
|
171
|
-
delete this.__handleGuilds;
|
|
172
|
-
}
|
|
173
146
|
this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
|
|
174
147
|
await this.events.execute(packet, this, shardId);
|
|
175
148
|
break;
|
|
176
149
|
}
|
|
150
|
+
case 'GUILDS_READY':
|
|
151
|
+
{
|
|
152
|
+
await this.events.execute(packet, this, shardId);
|
|
153
|
+
if ([...this.gateway.values()].every(shard => shard.isReady)) {
|
|
154
|
+
await this.events.runEvent('BOT_READY', this, this.me, -1);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
break;
|
|
177
158
|
default:
|
|
178
159
|
await this.events.execute(packet, this, shardId);
|
|
179
160
|
break;
|
|
@@ -13,8 +13,6 @@ import type { ShardData } from '../websocket/discord/shared';
|
|
|
13
13
|
import { Collectors } from './collectors';
|
|
14
14
|
import { type ClientUserStructure } from './transformers';
|
|
15
15
|
export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
|
|
16
|
-
private __handleGuilds?;
|
|
17
|
-
private __handleGuildsResharding?;
|
|
18
16
|
memberUpdateHandler: MemberUpdateHandler;
|
|
19
17
|
presenceUpdateHandler: PresenceUpdateHandler;
|
|
20
18
|
collectors: Collectors;
|
|
@@ -26,7 +24,6 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
|
|
|
26
24
|
}>;
|
|
27
25
|
shards: Map<number, Shard>;
|
|
28
26
|
resharding: Map<number, Shard>;
|
|
29
|
-
private _ready?;
|
|
30
27
|
options: WorkerClientOptions;
|
|
31
28
|
constructor(options?: WorkerClientOptions);
|
|
32
29
|
get workerId(): number;
|
|
@@ -36,8 +36,6 @@ catch {
|
|
|
36
36
|
//
|
|
37
37
|
}
|
|
38
38
|
class WorkerClient extends base_1.BaseClient {
|
|
39
|
-
__handleGuilds;
|
|
40
|
-
__handleGuildsResharding;
|
|
41
39
|
memberUpdateHandler = new memberUpdate_1.MemberUpdateHandler();
|
|
42
40
|
presenceUpdateHandler = new presenceUpdate_1.PresenceUpdateHandler();
|
|
43
41
|
collectors = new collectors_1.Collectors();
|
|
@@ -46,7 +44,6 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
46
44
|
promises = new Map();
|
|
47
45
|
shards = new Map();
|
|
48
46
|
resharding = new Map();
|
|
49
|
-
_ready;
|
|
50
47
|
constructor(options) {
|
|
51
48
|
super(options);
|
|
52
49
|
if (options?.postMessage) {
|
|
@@ -111,14 +108,11 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
111
108
|
type: workerData.resharding ? 'WORKER_START_RESHARDING' : 'WORKER_START',
|
|
112
109
|
workerId: workerData.workerId,
|
|
113
110
|
});
|
|
114
|
-
if (workerData.resharding) {
|
|
115
|
-
this.__handleGuildsResharding = [];
|
|
116
|
-
}
|
|
117
111
|
await super.start(options);
|
|
118
112
|
await this.loadEvents(options.eventsDir);
|
|
119
113
|
}
|
|
120
114
|
async loadEvents(dir) {
|
|
121
|
-
dir ??= await this.getRC().then(x =>
|
|
115
|
+
dir ??= await this.getRC().then(x => x.locations.events);
|
|
122
116
|
if (dir) {
|
|
123
117
|
await this.events.load(dir);
|
|
124
118
|
this.logger.info('EventHandler loaded');
|
|
@@ -199,28 +193,10 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
199
193
|
...this.options.gateway?.properties,
|
|
200
194
|
},
|
|
201
195
|
handlePayload(_, payload) {
|
|
202
|
-
if (payload.t === '
|
|
203
|
-
|
|
204
|
-
if (indexOf !== -1) {
|
|
205
|
-
self.__handleGuildsResharding.splice(indexOf, 1);
|
|
206
|
-
if (!self.__handleGuildsResharding?.length && shardsConnected === workerData.shards.length) {
|
|
207
|
-
delete self.__handleGuildsResharding;
|
|
208
|
-
self.postMessage({
|
|
209
|
-
type: 'WORKER_READY_RESHARDING',
|
|
210
|
-
workerId: workerData.workerId,
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
if (payload.t !== 'READY')
|
|
216
|
-
return;
|
|
217
|
-
shardsConnected++;
|
|
218
|
-
const ids = payload.d.guilds.map(x => x.id);
|
|
219
|
-
if ((0, common_1.hasIntent)(workerData.intents, 'Guilds')) {
|
|
220
|
-
self.__handleGuildsResharding = self.__handleGuildsResharding?.concat(ids) ?? ids;
|
|
196
|
+
if (payload.t === 'READY') {
|
|
197
|
+
shardsConnected++;
|
|
221
198
|
}
|
|
222
|
-
if (shardsConnected === workerData.shards.length
|
|
223
|
-
delete self.__handleGuildsResharding;
|
|
199
|
+
else if (payload.t === 'GUILDS_READY' && shardsConnected === workerData.shards.length) {
|
|
224
200
|
self.postMessage({
|
|
225
201
|
type: 'WORKER_READY_RESHARDING',
|
|
226
202
|
workerId: workerData.workerId,
|
|
@@ -326,7 +302,6 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
326
302
|
break;
|
|
327
303
|
case 'WORKER_ALREADY_EXISTS_RESHARDING':
|
|
328
304
|
{
|
|
329
|
-
this.__handleGuildsResharding = [];
|
|
330
305
|
this.postMessage({
|
|
331
306
|
type: 'WORKER_START_RESHARDING',
|
|
332
307
|
workerId: workerData.workerId,
|
|
@@ -460,26 +435,6 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
460
435
|
await this.events.execute(packet, this, shardId);
|
|
461
436
|
}
|
|
462
437
|
break;
|
|
463
|
-
case 'GUILD_DELETE':
|
|
464
|
-
case 'GUILD_CREATE': {
|
|
465
|
-
if (this.__handleGuilds?.includes(packet.d.id)) {
|
|
466
|
-
this.__handleGuilds?.splice(this.__handleGuilds.indexOf(packet.d.id), 1);
|
|
467
|
-
if (!this.__handleGuilds?.length && [...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
468
|
-
delete this.__handleGuilds;
|
|
469
|
-
await this.cache.onPacket(packet);
|
|
470
|
-
this.postMessage({
|
|
471
|
-
type: 'WORKER_READY',
|
|
472
|
-
workerId: this.workerId,
|
|
473
|
-
});
|
|
474
|
-
return this.events.runEvent('WORKER_READY', this, this.me, -1);
|
|
475
|
-
}
|
|
476
|
-
if (!this.__handleGuilds?.length)
|
|
477
|
-
delete this.__handleGuilds;
|
|
478
|
-
return this.cache.onPacket(packet);
|
|
479
|
-
}
|
|
480
|
-
await this.events.execute(packet, this, shardId);
|
|
481
|
-
break;
|
|
482
|
-
}
|
|
483
438
|
default: {
|
|
484
439
|
switch (packet.t) {
|
|
485
440
|
case 'INTERACTION_CREATE':
|
|
@@ -494,35 +449,31 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
494
449
|
await this.handleCommand.message(packet.d, shardId);
|
|
495
450
|
}
|
|
496
451
|
break;
|
|
497
|
-
case 'READY':
|
|
452
|
+
case 'READY': {
|
|
453
|
+
this.botId = packet.d.user.id;
|
|
454
|
+
this.applicationId = packet.d.application.id;
|
|
455
|
+
this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
|
|
456
|
+
if ([...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
457
|
+
this.postMessage({
|
|
458
|
+
type: 'WORKER_SHARDS_CONNECTED',
|
|
459
|
+
workerId: this.workerId,
|
|
460
|
+
});
|
|
461
|
+
await this.events.runEvent('WORKER_SHARDS_CONNECTED', this, this.me, -1);
|
|
462
|
+
}
|
|
463
|
+
await this.events.execute(packet, this, shardId);
|
|
464
|
+
this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
case 'GUILDS_READY':
|
|
498
468
|
{
|
|
499
|
-
|
|
500
|
-
if ((0, common_1.hasIntent)(this.workerData.intents, 'Guilds')) {
|
|
501
|
-
this.__handleGuilds = this.__handleGuilds?.concat(ids) ?? ids;
|
|
502
|
-
}
|
|
503
|
-
this.botId = packet.d.user.id;
|
|
504
|
-
this.applicationId = packet.d.application.id;
|
|
505
|
-
this.me = transformers_1.Transformers.ClientUser(this, packet.d.user, packet.d.application);
|
|
506
|
-
await this.events.execute(packet, this, shardId);
|
|
507
|
-
if (!this._ready && [...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
508
|
-
this._ready = true;
|
|
469
|
+
if ([...this.shards.values()].every(shard => shard.isReady)) {
|
|
509
470
|
this.postMessage({
|
|
510
|
-
type: '
|
|
471
|
+
type: 'WORKER_READY',
|
|
511
472
|
workerId: this.workerId,
|
|
512
473
|
});
|
|
513
|
-
await this.events.runEvent('
|
|
474
|
+
await this.events.runEvent('WORKER_READY', this, this.me, -1);
|
|
514
475
|
}
|
|
515
|
-
|
|
516
|
-
if ([...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
517
|
-
this.postMessage({
|
|
518
|
-
type: 'WORKER_READY',
|
|
519
|
-
workerId: this.workerId,
|
|
520
|
-
});
|
|
521
|
-
await this.events.runEvent('WORKER_READY', this, this.me, -1);
|
|
522
|
-
}
|
|
523
|
-
delete this.__handleGuilds;
|
|
524
|
-
}
|
|
525
|
-
this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
|
|
476
|
+
await this.events.execute(packet, this, shardId);
|
|
526
477
|
}
|
|
527
478
|
break;
|
|
528
479
|
default:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type GuildStructure } from '../../client/transformers';
|
|
2
|
-
import {
|
|
2
|
+
import { type CreateStickerBodyRequest, Guild, GuildMember } from '../../structures';
|
|
3
3
|
import type { GuildWidgetStyle, RESTGetAPICurrentUserGuildsQuery, RESTPatchAPIAutoModerationRuleJSONBody, RESTPatchAPIChannelJSONBody, RESTPatchAPIGuildChannelPositionsJSONBody, RESTPatchAPIGuildJSONBody, RESTPatchAPIGuildStickerJSONBody, RESTPostAPIAutoModerationRuleJSONBody, RESTPostAPIGuildChannelJSONBody, RESTPostAPIGuildsJSONBody } from '../../types';
|
|
4
4
|
import { BaseShorter } from './base';
|
|
5
5
|
export declare class GuildShorter extends BaseShorter {
|
|
@@ -46,7 +46,7 @@ export declare class GuildShorter extends BaseShorter {
|
|
|
46
46
|
* @param force Whether to force fetching the channel from the API even if it exists in the cache.
|
|
47
47
|
* @returns A Promise that resolves to the fetched channel.
|
|
48
48
|
*/
|
|
49
|
-
fetch: (guildId: string, channelId: string, force?: boolean) => Promise<import("../../
|
|
49
|
+
fetch: (guildId: string, channelId: string, force?: boolean) => Promise<import("../../structures").AllChannels>;
|
|
50
50
|
/**
|
|
51
51
|
* Creates a new channel in the guild.
|
|
52
52
|
* @param guildId The ID of the guild.
|
|
@@ -7,7 +7,7 @@ export declare class MessageShorter extends BaseShorter {
|
|
|
7
7
|
edit(messageId: string, channelId: string, { files, ...body }: MessageUpdateBodyRequest): Promise<import("../../structures").Message>;
|
|
8
8
|
crosspost(messageId: string, channelId: string, reason?: string): Promise<import("../../structures").Message>;
|
|
9
9
|
delete(messageId: string, channelId: string, reason?: string): Promise<void>;
|
|
10
|
-
fetch(messageId: string, channelId: string): Promise<import("../../structures").Message>;
|
|
10
|
+
fetch(messageId: string, channelId: string, force?: boolean): Promise<import("../../structures").Message>;
|
|
11
11
|
purge(messages: string[], channelId: string, reason?: string): Promise<void | undefined>;
|
|
12
12
|
thread(channelId: string, messageId: string, options: RESTPostAPIChannelMessagesThreadsJSONBody & {
|
|
13
13
|
reason?: string;
|
|
@@ -54,7 +54,12 @@ class MessageShorter extends base_1.BaseShorter {
|
|
|
54
54
|
this.client.components.deleteValue(messageId, 'messageDelete');
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
fetch(messageId, channelId) {
|
|
57
|
+
async fetch(messageId, channelId, force = false) {
|
|
58
|
+
if (!force) {
|
|
59
|
+
const message = await this.client.cache.messages?.get(messageId);
|
|
60
|
+
if (message)
|
|
61
|
+
return message;
|
|
62
|
+
}
|
|
58
63
|
return this.client.proxy
|
|
59
64
|
.channels(channelId)
|
|
60
65
|
.messages(messageId)
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ClientUserStructure } from '../../client/transformers';
|
|
2
2
|
import type { UsingClient } from '../../commands';
|
|
3
|
+
import type { GatewayRawGuildCreateDispatch, GatewayRawGuildDeleteDispatch } from '../../types';
|
|
3
4
|
export declare const BOT_READY: (_self: UsingClient, me: ClientUserStructure) => import("../..").ClientUser;
|
|
4
5
|
export declare const WORKER_READY: (_self: UsingClient, me: ClientUserStructure) => import("../..").ClientUser;
|
|
5
6
|
export declare const WORKER_SHARDS_CONNECTED: (_self: UsingClient, me: ClientUserStructure) => import("../..").ClientUser;
|
|
7
|
+
export declare const RAW_GUILD_CREATE: (self: UsingClient, data: GatewayRawGuildCreateDispatch["d"]) => import("../..").Guild<"create">;
|
|
8
|
+
export declare const RAW_GUILD_DELETE: (self: UsingClient, data: GatewayRawGuildDeleteDispatch["d"]) => Promise<import("../../types").APIUnavailableGuild | import("../..").Guild<"cached">>;
|
|
9
|
+
export declare const GUILDS_READY: () => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WORKER_SHARDS_CONNECTED = exports.WORKER_READY = exports.BOT_READY = void 0;
|
|
3
|
+
exports.GUILDS_READY = exports.RAW_GUILD_DELETE = exports.RAW_GUILD_CREATE = exports.WORKER_SHARDS_CONNECTED = exports.WORKER_READY = exports.BOT_READY = void 0;
|
|
4
|
+
const transformers_1 = require("../../client/transformers");
|
|
4
5
|
const BOT_READY = (_self, me) => {
|
|
5
6
|
return me;
|
|
6
7
|
};
|
|
@@ -13,3 +14,15 @@ const WORKER_SHARDS_CONNECTED = (_self, me) => {
|
|
|
13
14
|
return me;
|
|
14
15
|
};
|
|
15
16
|
exports.WORKER_SHARDS_CONNECTED = WORKER_SHARDS_CONNECTED;
|
|
17
|
+
const RAW_GUILD_CREATE = (self, data) => {
|
|
18
|
+
return transformers_1.Transformers.Guild(self, data);
|
|
19
|
+
};
|
|
20
|
+
exports.RAW_GUILD_CREATE = RAW_GUILD_CREATE;
|
|
21
|
+
const RAW_GUILD_DELETE = async (self, data) => {
|
|
22
|
+
return (await self.cache.guilds?.get(data.id)) ?? data;
|
|
23
|
+
};
|
|
24
|
+
exports.RAW_GUILD_DELETE = RAW_GUILD_DELETE;
|
|
25
|
+
const GUILDS_READY = () => {
|
|
26
|
+
return;
|
|
27
|
+
};
|
|
28
|
+
exports.GUILDS_READY = GUILDS_READY;
|
|
@@ -8,7 +8,6 @@ import { GuildMember } from './GuildMember';
|
|
|
8
8
|
import { GuildRole } from './GuildRole';
|
|
9
9
|
import { GuildTemplate } from './GuildTemplate';
|
|
10
10
|
import { Sticker } from './Sticker';
|
|
11
|
-
import { BaseChannel } from './channels';
|
|
12
11
|
import { BaseGuild } from './extra/BaseGuild';
|
|
13
12
|
import type { DiscordBase } from './extra/DiscordBase';
|
|
14
13
|
export interface Guild extends ObjectToLower<Omit<APIGuild, 'stickers' | 'emojis' | 'roles'>>, DiscordBase {
|
|
@@ -70,7 +69,7 @@ export declare class Guild<State extends StructStates = 'api'> extends Guild_bas
|
|
|
70
69
|
};
|
|
71
70
|
channels: {
|
|
72
71
|
list: (force?: boolean) => Promise<import("./channels").AllChannels[]>;
|
|
73
|
-
fetch: (id: string, force?: boolean) => Promise<import("
|
|
72
|
+
fetch: (id: string, force?: boolean) => Promise<import("./channels").AllChannels>;
|
|
74
73
|
create: (body: import("../types").RESTPostAPIGuildChannelJSONBody) => Promise<import("./channels").AllChannels>;
|
|
75
74
|
delete: (id: string, reason?: string) => Promise<import("./channels").AllChannels>;
|
|
76
75
|
edit: (id: string, body: import("../types").RESTPatchAPIChannelJSONBody, reason?: string) => Promise<import("./channels").AllChannels>;
|
|
@@ -39,7 +39,7 @@ export interface Message extends BaseMessage, ObjectToLower<Omit<MessageData, 't
|
|
|
39
39
|
}
|
|
40
40
|
export declare class Message extends BaseMessage {
|
|
41
41
|
constructor(client: UsingClient, data: MessageData);
|
|
42
|
-
fetch(): Promise<Message>;
|
|
42
|
+
fetch(force?: boolean): Promise<Message>;
|
|
43
43
|
reply(body: Omit<MessageCreateBodyRequest, 'message_reference'>, fail?: boolean): Promise<Message>;
|
|
44
44
|
edit(body: MessageUpdateBodyRequest): Promise<Message>;
|
|
45
45
|
write(body: MessageCreateBodyRequest): Promise<Message>;
|
|
@@ -68,8 +68,8 @@ class Message extends BaseMessage {
|
|
|
68
68
|
constructor(client, data) {
|
|
69
69
|
super(client, data);
|
|
70
70
|
}
|
|
71
|
-
fetch() {
|
|
72
|
-
return this.client.messages.fetch(this.id, this.channelId);
|
|
71
|
+
fetch(force = false) {
|
|
72
|
+
return this.client.messages.fetch(this.id, this.channelId, force);
|
|
73
73
|
}
|
|
74
74
|
reply(body, fail = true) {
|
|
75
75
|
return this.write({
|
|
@@ -35,7 +35,7 @@ export declare class BaseNoEditableChannel<T extends ChannelType> extends Discor
|
|
|
35
35
|
guildId: string;
|
|
36
36
|
}>): {
|
|
37
37
|
list: (force?: boolean) => Promise<AllChannels[]>;
|
|
38
|
-
fetch: (id: string, force?: boolean) => Promise<
|
|
38
|
+
fetch: (id: string, force?: boolean) => Promise<AllChannels>;
|
|
39
39
|
create: (body: RESTPostAPIGuildChannelJSONBody) => Promise<AllChannels>;
|
|
40
40
|
delete: (id: string, reason?: string) => Promise<AllChannels>;
|
|
41
41
|
edit: (id: string, body: RESTPatchAPIChannelJSONBody, reason?: string) => Promise<AllChannels>;
|
|
@@ -109,7 +109,7 @@ export declare class MessagesMethods extends DiscordBase {
|
|
|
109
109
|
edit: (messageId: string, body: MessageUpdateBodyRequest) => Promise<import("./Message").Message>;
|
|
110
110
|
crosspost: (messageId: string, reason?: string) => Promise<import("./Message").Message>;
|
|
111
111
|
delete: (messageId: string, reason?: string) => Promise<void>;
|
|
112
|
-
fetch: (messageId: string) => Promise<import("./Message").Message>;
|
|
112
|
+
fetch: (messageId: string, force?: boolean) => Promise<import("./Message").Message>;
|
|
113
113
|
purge: (messages: string[], reason?: string) => Promise<void | undefined>;
|
|
114
114
|
list: (fetchOptions: RESTGetAPIChannelMessagesQuery) => Promise<import("./Message").Message[]>;
|
|
115
115
|
};
|
|
@@ -131,7 +131,7 @@ export declare class MessagesMethods extends DiscordBase {
|
|
|
131
131
|
edit: (messageId: string, body: MessageUpdateBodyRequest) => Promise<import("./Message").Message>;
|
|
132
132
|
crosspost: (messageId: string, reason?: string) => Promise<import("./Message").Message>;
|
|
133
133
|
delete: (messageId: string, reason?: string) => Promise<void>;
|
|
134
|
-
fetch: (messageId: string) => Promise<import("./Message").Message>;
|
|
134
|
+
fetch: (messageId: string, force?: boolean) => Promise<import("./Message").Message>;
|
|
135
135
|
purge: (messages: string[], reason?: string) => Promise<void | undefined>;
|
|
136
136
|
list: (fetchOptions: RESTGetAPIChannelMessagesQuery) => Promise<import("./Message").Message[]>;
|
|
137
137
|
};
|
|
@@ -164,7 +164,7 @@ class MessagesMethods extends DiscordBase_1.DiscordBase {
|
|
|
164
164
|
edit: (messageId, body) => ctx.client.messages.edit(messageId, ctx.channelId, body),
|
|
165
165
|
crosspost: (messageId, reason) => ctx.client.messages.crosspost(messageId, ctx.channelId, reason),
|
|
166
166
|
delete: (messageId, reason) => ctx.client.messages.delete(messageId, ctx.channelId, reason),
|
|
167
|
-
fetch: (messageId) => ctx.client.messages.fetch(messageId, ctx.channelId),
|
|
167
|
+
fetch: (messageId, force = false) => ctx.client.messages.fetch(messageId, ctx.channelId, force),
|
|
168
168
|
purge: (messages, reason) => ctx.client.messages.purge(messages, ctx.channelId, reason),
|
|
169
169
|
list: (fetchOptions) => ctx.client.messages.list(ctx.channelId, fetchOptions),
|
|
170
170
|
};
|
package/lib/types/gateway.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OmitInsert } from '../common';
|
|
1
2
|
import type { ChannelType, GatewayDispatchEvents, GatewayOpcodes, Snowflake } from './index';
|
|
2
3
|
import type { GatewayPresenceUpdate } from './payloads/gateway';
|
|
3
4
|
import type { APIApplication, APIApplicationCommandPermission, APIAuditLogEntry, APIAutoModerationAction, APIAutoModerationRule, APIChannel, APIEmoji, APIEntitlement, APIGuild, APIGuildIntegration, APIGuildMember, APIGuildScheduledEvent, APIInteraction, APIMessage, APIPartialEmoji, APIRole, APIStageInstance, APISticker, APISubscription, APIThreadChannel, APIThreadMember, APIUnavailableGuild, APIUser, APIVoiceState, AutoModerationRuleTriggerType, GatewayActivity, InviteTargetType, PresenceUpdateStatus, GatewayPresenceUpdate as RawGatewayPresenceUpdate, GatewayThreadListSync as RawGatewayThreadListSync, GatewayThreadMembersUpdate as RawGatewayThreadMembersUpdate } from './payloads/index';
|
|
@@ -17,7 +18,7 @@ export interface GatewayURLQuery {
|
|
|
17
18
|
*/
|
|
18
19
|
export type GatewaySendPayload = GatewayHeartbeat | GatewayIdentify | GatewayRequestGuildMembers | GatewayResume | GatewayUpdatePresence | GatewayVoiceStateUpdate | GatewayRequestSoundboardSounds;
|
|
19
20
|
export type GatewayReceivePayload = GatewayDispatchPayload | GatewayHeartbeatAck | GatewayHeartbeatRequest | GatewayHello | GatewayInvalidSession | GatewayReconnect;
|
|
20
|
-
export type GatewayDispatchPayload = GatewayApplicationCommandPermissionsUpdateDispatch | GatewayAutoModerationActionExecutionDispatch | GatewayAutoModerationRuleCreateDispatch | GatewayAutoModerationRuleDeleteDispatch | GatewayAutoModerationRuleModifyDispatch | GatewayChannelModifyDispatch | GatewayChannelPinsUpdateDispatch | GatewayEntitlementModifyDispatch | GatewayGuildAuditLogEntryCreateDispatch | GatewayGuildBanModifyDispatch | GatewayGuildCreateDispatch | GatewayGuildDeleteDispatch | GatewayGuildEmojisUpdateDispatch | GatewayGuildIntegrationsUpdateDispatch | GatewayGuildMemberAddDispatch | GatewayGuildMemberRemoveDispatch | GatewayGuildMembersChunkDispatch | GatewayGuildMemberUpdateDispatch | GatewayGuildModifyDispatch | GatewayGuildRoleDeleteDispatch | GatewayGuildRoleModifyDispatch | GatewayGuildScheduledEventCreateDispatch | GatewayGuildScheduledEventDeleteDispatch | GatewayGuildScheduledEventUpdateDispatch | GatewayGuildScheduledEventUserAddDispatch | GatewayGuildScheduledEventUserRemoveDispatch | GatewayGuildStickersUpdateDispatch | GatewayIntegrationCreateDispatch | GatewayIntegrationDeleteDispatch | GatewayIntegrationUpdateDispatch | GatewayInteractionCreateDispatch | GatewayInviteCreateDispatch | GatewayInviteDeleteDispatch | GatewayMessageCreateDispatch | GatewayMessageDeleteBulkDispatch | GatewayMessageDeleteDispatch | GatewayMessagePollVoteAddDispatch | GatewayMessagePollVoteRemoveDispatch | GatewayMessageReactionAddDispatch | GatewayMessageReactionRemoveAllDispatch | GatewayMessageReactionRemoveDispatch | GatewayMessageReactionRemoveEmojiDispatch | GatewayMessageUpdateDispatch | GatewayPresenceUpdateDispatch | GatewayReadyDispatch | GatewayResumedDispatch | GatewayStageInstanceCreateDispatch | GatewayStageInstanceDeleteDispatch | GatewayStageInstanceUpdateDispatch | GatewayThreadCreateDispatch | GatewayThreadDeleteDispatch | GatewayThreadListSyncDispatch | GatewayThreadMembersUpdateDispatch | GatewayThreadMemberUpdateDispatch | GatewayThreadUpdateDispatch | GatewayTypingStartDispatch | GatewayUserUpdateDispatch | GatewayVoiceServerUpdateDispatch | GatewayVoiceStateUpdateDispatch | GatewayWebhooksUpdateDispatch | GatewayGuildSoundboardSoundCreateDispatch | GatewayGuildSoundboardSoundDeleteDispatch | GatewayGuildSoundboardSoundUpdateDispatch | GatewayGuildSoundboardSoundsUpdateDispatch | GatewaySoundboardSoundsDispatch;
|
|
21
|
+
export type GatewayDispatchPayload = GatewayApplicationCommandPermissionsUpdateDispatch | GatewayAutoModerationActionExecutionDispatch | GatewayAutoModerationRuleCreateDispatch | GatewayAutoModerationRuleDeleteDispatch | GatewayAutoModerationRuleModifyDispatch | GatewayChannelModifyDispatch | GatewayChannelPinsUpdateDispatch | GatewayEntitlementModifyDispatch | GatewayGuildAuditLogEntryCreateDispatch | GatewayGuildBanModifyDispatch | GatewayGuildCreateDispatch | GatewayRawGuildCreateDispatch | GatewayGuildDeleteDispatch | GatewayRawGuildDeleteDispatch | GatewayGuildsReadyDispatch | GatewayGuildEmojisUpdateDispatch | GatewayGuildIntegrationsUpdateDispatch | GatewayGuildMemberAddDispatch | GatewayGuildMemberRemoveDispatch | GatewayGuildMembersChunkDispatch | GatewayGuildMemberUpdateDispatch | GatewayGuildModifyDispatch | GatewayGuildRoleDeleteDispatch | GatewayGuildRoleModifyDispatch | GatewayGuildScheduledEventCreateDispatch | GatewayGuildScheduledEventDeleteDispatch | GatewayGuildScheduledEventUpdateDispatch | GatewayGuildScheduledEventUserAddDispatch | GatewayGuildScheduledEventUserRemoveDispatch | GatewayGuildStickersUpdateDispatch | GatewayIntegrationCreateDispatch | GatewayIntegrationDeleteDispatch | GatewayIntegrationUpdateDispatch | GatewayInteractionCreateDispatch | GatewayInviteCreateDispatch | GatewayInviteDeleteDispatch | GatewayMessageCreateDispatch | GatewayMessageDeleteBulkDispatch | GatewayMessageDeleteDispatch | GatewayMessagePollVoteAddDispatch | GatewayMessagePollVoteRemoveDispatch | GatewayMessageReactionAddDispatch | GatewayMessageReactionRemoveAllDispatch | GatewayMessageReactionRemoveDispatch | GatewayMessageReactionRemoveEmojiDispatch | GatewayMessageUpdateDispatch | GatewayPresenceUpdateDispatch | GatewayReadyDispatch | GatewayResumedDispatch | GatewayStageInstanceCreateDispatch | GatewayStageInstanceDeleteDispatch | GatewayStageInstanceUpdateDispatch | GatewayThreadCreateDispatch | GatewayThreadDeleteDispatch | GatewayThreadListSyncDispatch | GatewayThreadMembersUpdateDispatch | GatewayThreadMemberUpdateDispatch | GatewayThreadUpdateDispatch | GatewayTypingStartDispatch | GatewayUserUpdateDispatch | GatewayVoiceServerUpdateDispatch | GatewayVoiceStateUpdateDispatch | GatewayWebhooksUpdateDispatch | GatewayGuildSoundboardSoundCreateDispatch | GatewayGuildSoundboardSoundDeleteDispatch | GatewayGuildSoundboardSoundUpdateDispatch | GatewayGuildSoundboardSoundsUpdateDispatch | GatewaySoundboardSoundsDispatch;
|
|
21
22
|
/**
|
|
22
23
|
* https://discord.com/developers/docs/topics/gateway-events#hello
|
|
23
24
|
*/
|
|
@@ -346,6 +347,9 @@ export type GatewayGuildModifyDispatchData = APIGuild;
|
|
|
346
347
|
* https://discord.com/developers/docs/topics/gateway-events#guild-create
|
|
347
348
|
*/
|
|
348
349
|
export type GatewayGuildCreateDispatch = DataPayload<GatewayDispatchEvents.GuildCreate, GatewayGuildCreateDispatchData>;
|
|
350
|
+
export type GatewayRawGuildCreateDispatch = OmitInsert<GatewayGuildCreateDispatch, 't', {
|
|
351
|
+
t: GatewayDispatchEvents.RawGuildCreate;
|
|
352
|
+
}>;
|
|
349
353
|
/**
|
|
350
354
|
* https://discord.com/developers/docs/topics/gateway-events#guild-create
|
|
351
355
|
* https://discord.com/developers/docs/topics/gateway-events#guild-create-guild-create-extra-fields
|
|
@@ -450,6 +454,13 @@ export type GatewayGuildUpdateDispatchData = GatewayGuildModifyDispatchData;
|
|
|
450
454
|
* https://discord.com/developers/docs/topics/gateway-events#guild-delete
|
|
451
455
|
*/
|
|
452
456
|
export type GatewayGuildDeleteDispatch = DataPayload<GatewayDispatchEvents.GuildDelete, GatewayGuildDeleteDispatchData>;
|
|
457
|
+
export type GatewayRawGuildDeleteDispatch = OmitInsert<GatewayGuildDeleteDispatch, 't', {
|
|
458
|
+
t: GatewayDispatchEvents.RawGuildDelete;
|
|
459
|
+
}>;
|
|
460
|
+
export type GatewayGuildsReadyDispatch = OmitInsert<GatewayReadyDispatch, 't' | 'd', {
|
|
461
|
+
t: GatewayDispatchEvents.GuildsReady;
|
|
462
|
+
d?: never;
|
|
463
|
+
}>;
|
|
453
464
|
/**
|
|
454
465
|
* https://discord.com/developers/docs/topics/gateway-events#guild-delete
|
|
455
466
|
*/
|
|
@@ -295,7 +295,10 @@ export declare enum GatewayDispatchEvents {
|
|
|
295
295
|
GuildBanAdd = "GUILD_BAN_ADD",
|
|
296
296
|
GuildBanRemove = "GUILD_BAN_REMOVE",
|
|
297
297
|
GuildCreate = "GUILD_CREATE",
|
|
298
|
+
RawGuildCreate = "RAW_GUILD_CREATE",
|
|
298
299
|
GuildDelete = "GUILD_DELETE",
|
|
300
|
+
RawGuildDelete = "RAW_GUILD_DELETE",
|
|
301
|
+
GuildsReady = "GUILDS_READY",
|
|
299
302
|
GuildEmojisUpdate = "GUILD_EMOJIS_UPDATE",
|
|
300
303
|
GuildIntegrationsUpdate = "GUILD_INTEGRATIONS_UPDATE",
|
|
301
304
|
GuildMemberAdd = "GUILD_MEMBER_ADD",
|
package/lib/types/utils/index.js
CHANGED
|
@@ -280,7 +280,10 @@ var GatewayDispatchEvents;
|
|
|
280
280
|
GatewayDispatchEvents["GuildBanAdd"] = "GUILD_BAN_ADD";
|
|
281
281
|
GatewayDispatchEvents["GuildBanRemove"] = "GUILD_BAN_REMOVE";
|
|
282
282
|
GatewayDispatchEvents["GuildCreate"] = "GUILD_CREATE";
|
|
283
|
+
GatewayDispatchEvents["RawGuildCreate"] = "RAW_GUILD_CREATE";
|
|
283
284
|
GatewayDispatchEvents["GuildDelete"] = "GUILD_DELETE";
|
|
285
|
+
GatewayDispatchEvents["RawGuildDelete"] = "RAW_GUILD_DELETE";
|
|
286
|
+
GatewayDispatchEvents["GuildsReady"] = "GUILDS_READY";
|
|
284
287
|
GatewayDispatchEvents["GuildEmojisUpdate"] = "GUILD_EMOJIS_UPDATE";
|
|
285
288
|
GatewayDispatchEvents["GuildIntegrationsUpdate"] = "GUILD_INTEGRATIONS_UPDATE";
|
|
286
289
|
GatewayDispatchEvents["GuildMemberAdd"] = "GUILD_MEMBER_ADD";
|
|
@@ -21,7 +21,9 @@ export declare class Shard {
|
|
|
21
21
|
heart: ShardHeart;
|
|
22
22
|
bucket: DynamicBucket;
|
|
23
23
|
offlineSendQueue: ((_?: unknown) => void)[];
|
|
24
|
+
pendingGuilds: Set<string>;
|
|
24
25
|
options: MakeRequired<ShardOptions, 'properties' | 'ratelimitOptions'>;
|
|
26
|
+
isReady: boolean;
|
|
25
27
|
constructor(id: number, options: ShardOptions);
|
|
26
28
|
get latency(): number;
|
|
27
29
|
get isOpen(): boolean;
|
|
@@ -34,16 +36,16 @@ export declare class Shard {
|
|
|
34
36
|
identify(): Promise<void>;
|
|
35
37
|
get resumable(): boolean;
|
|
36
38
|
resume(): Promise<void>;
|
|
37
|
-
heartbeat(requested: boolean):
|
|
38
|
-
disconnect():
|
|
39
|
+
heartbeat(requested: boolean): void;
|
|
40
|
+
disconnect(): void;
|
|
39
41
|
reconnect(): Promise<void>;
|
|
40
|
-
onpacket(packet: GatewayReceivePayload): Promise<void>;
|
|
42
|
+
onpacket(packet: GatewayReceivePayload): void | Promise<void>;
|
|
41
43
|
protected handleClosed(close: {
|
|
42
44
|
code: number;
|
|
43
45
|
reason: string;
|
|
44
46
|
}): Promise<void>;
|
|
45
|
-
close(code: number, reason: string):
|
|
46
|
-
protected handleMessage(data: string | Buffer):
|
|
47
|
+
close(code: number, reason: string): void;
|
|
48
|
+
protected handleMessage(data: string | Buffer): void | Promise<void>;
|
|
47
49
|
checkOffline(force: boolean): Promise<unknown>;
|
|
48
50
|
calculateSafeRequests(): number;
|
|
49
51
|
}
|
|
@@ -24,7 +24,9 @@ class Shard {
|
|
|
24
24
|
};
|
|
25
25
|
bucket;
|
|
26
26
|
offlineSendQueue = [];
|
|
27
|
+
pendingGuilds = new Set();
|
|
27
28
|
options;
|
|
29
|
+
isReady = false;
|
|
28
30
|
constructor(id, options) {
|
|
29
31
|
this.id = id;
|
|
30
32
|
this.options = (0, common_1.MergeOptions)({
|
|
@@ -127,11 +129,11 @@ class Shard {
|
|
|
127
129
|
},
|
|
128
130
|
});
|
|
129
131
|
}
|
|
130
|
-
|
|
132
|
+
heartbeat(requested) {
|
|
131
133
|
this.debugger?.debug(`[Shard #${this.id}] Sending ${requested ? '' : 'un'}requested heartbeat (Ack=${this.heart.ack})`);
|
|
132
134
|
if (!requested) {
|
|
133
135
|
if (!this.heart.ack) {
|
|
134
|
-
|
|
136
|
+
this.close(shared_1.ShardSocketCloseCodes.ZombiedConnection, 'Zombied connection');
|
|
135
137
|
return;
|
|
136
138
|
}
|
|
137
139
|
this.heart.ack = false;
|
|
@@ -142,33 +144,31 @@ class Shard {
|
|
|
142
144
|
d: this.data.resume_seq ?? null,
|
|
143
145
|
}));
|
|
144
146
|
}
|
|
145
|
-
|
|
147
|
+
disconnect() {
|
|
146
148
|
this.debugger?.info(`[Shard #${this.id}] Disconnecting`);
|
|
147
|
-
|
|
149
|
+
this.close(shared_1.ShardSocketCloseCodes.Shutdown, 'Shard down request');
|
|
148
150
|
}
|
|
149
151
|
async reconnect() {
|
|
150
152
|
this.debugger?.info(`[Shard #${this.id}] Reconnecting`);
|
|
151
|
-
|
|
153
|
+
this.disconnect();
|
|
152
154
|
await this.connect();
|
|
153
155
|
}
|
|
154
|
-
|
|
156
|
+
onpacket(packet) {
|
|
155
157
|
if (packet.s !== null) {
|
|
156
158
|
this.data.resume_seq = packet.s;
|
|
157
159
|
}
|
|
158
160
|
this.debugger?.debug(`[Shard #${this.id}]`, packet.t ? packet.t : types_1.GatewayOpcodes[packet.op], this.data.resume_seq);
|
|
159
161
|
switch (packet.op) {
|
|
160
|
-
case types_1.GatewayOpcodes.Hello:
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return this.resume();
|
|
168
|
-
}
|
|
169
|
-
await this.identify();
|
|
162
|
+
case types_1.GatewayOpcodes.Hello: {
|
|
163
|
+
clearInterval(this.heart.nodeInterval);
|
|
164
|
+
this.heart.interval = packet.d.heartbeat_interval;
|
|
165
|
+
this.heartbeat(false);
|
|
166
|
+
this.heart.nodeInterval = setInterval(() => this.heartbeat(false), this.heart.interval);
|
|
167
|
+
if (this.resumable) {
|
|
168
|
+
return this.resume();
|
|
170
169
|
}
|
|
171
|
-
|
|
170
|
+
return this.identify();
|
|
171
|
+
}
|
|
172
172
|
case types_1.GatewayOpcodes.HeartbeatAck:
|
|
173
173
|
{
|
|
174
174
|
this.heart.ack = true;
|
|
@@ -179,37 +179,66 @@ class Shard {
|
|
|
179
179
|
this.heartbeat(true);
|
|
180
180
|
break;
|
|
181
181
|
case types_1.GatewayOpcodes.Reconnect:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
case types_1.GatewayOpcodes.InvalidSession:
|
|
182
|
+
return this.reconnect();
|
|
183
|
+
case types_1.GatewayOpcodes.InvalidSession: {
|
|
185
184
|
if (packet.d) {
|
|
186
185
|
if (!this.resumable) {
|
|
187
186
|
return this.logger.fatal('This is a completely unexpected error message.');
|
|
188
187
|
}
|
|
189
|
-
|
|
188
|
+
return this.resume();
|
|
190
189
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
break;
|
|
190
|
+
this.data.resume_seq = 0;
|
|
191
|
+
this.data.session_id = undefined;
|
|
192
|
+
return this.identify();
|
|
193
|
+
}
|
|
197
194
|
case types_1.GatewayOpcodes.Dispatch:
|
|
198
195
|
{
|
|
199
196
|
switch (packet.t) {
|
|
200
197
|
case types_1.GatewayDispatchEvents.Resumed:
|
|
201
198
|
{
|
|
202
|
-
this.
|
|
199
|
+
this.isReady = true;
|
|
200
|
+
this.offlineSendQueue.map(resolve => resolve());
|
|
203
201
|
this.options.handlePayload(this.id, packet);
|
|
204
202
|
}
|
|
205
203
|
break;
|
|
206
204
|
case types_1.GatewayDispatchEvents.Ready: {
|
|
205
|
+
if ((0, common_1.hasIntent)(this.options.intents, 'Guilds')) {
|
|
206
|
+
for (let i = 0; i < packet.d.guilds.length; i++) {
|
|
207
|
+
this.pendingGuilds.add(packet.d.guilds.at(i).id);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
207
210
|
this.data.resume_gateway_url = packet.d.resume_gateway_url;
|
|
208
211
|
this.data.session_id = packet.d.session_id;
|
|
209
|
-
this.offlineSendQueue.map(
|
|
212
|
+
this.offlineSendQueue.map(resolve => resolve());
|
|
210
213
|
this.options.handlePayload(this.id, packet);
|
|
214
|
+
if (this.pendingGuilds.size === 0) {
|
|
215
|
+
this.isReady = true;
|
|
216
|
+
this.options.handlePayload(this.id, {
|
|
217
|
+
t: types_1.GatewayDispatchEvents.GuildsReady,
|
|
218
|
+
op: packet.op,
|
|
219
|
+
s: packet.s,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
211
222
|
break;
|
|
212
223
|
}
|
|
224
|
+
case types_1.GatewayDispatchEvents.GuildCreate:
|
|
225
|
+
case types_1.GatewayDispatchEvents.GuildDelete:
|
|
226
|
+
if (this.pendingGuilds.delete(packet.d.id)) {
|
|
227
|
+
packet.t = `RAW_${packet.t}`;
|
|
228
|
+
this.options.handlePayload(this.id, packet);
|
|
229
|
+
if (this.pendingGuilds.size === 0) {
|
|
230
|
+
this.isReady = true;
|
|
231
|
+
this.options.handlePayload(this.id, {
|
|
232
|
+
t: types_1.GatewayDispatchEvents.GuildsReady,
|
|
233
|
+
op: packet.op,
|
|
234
|
+
s: packet.s,
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
this.options.handlePayload(this.id, packet);
|
|
240
|
+
}
|
|
241
|
+
break;
|
|
213
242
|
default:
|
|
214
243
|
this.options.handlePayload(this.id, packet);
|
|
215
244
|
break;
|
|
@@ -219,6 +248,7 @@ class Shard {
|
|
|
219
248
|
}
|
|
220
249
|
}
|
|
221
250
|
async handleClosed(close) {
|
|
251
|
+
this.isReady = false;
|
|
222
252
|
clearInterval(this.heart.nodeInterval);
|
|
223
253
|
this.logger.warn(`${shared_1.ShardSocketCloseCodes[close.code] ?? types_1.GatewayCloseCodes[close.code] ?? close.code} (${close.code})`, close.reason);
|
|
224
254
|
switch (close.code) {
|
|
@@ -265,7 +295,7 @@ class Shard {
|
|
|
265
295
|
break;
|
|
266
296
|
}
|
|
267
297
|
}
|
|
268
|
-
|
|
298
|
+
close(code, reason) {
|
|
269
299
|
clearInterval(this.heart.nodeInterval);
|
|
270
300
|
if (!this.isOpen) {
|
|
271
301
|
return this.debugger?.warn(`[Shard #${this.id}] Is not open, reason:`, reason);
|
|
@@ -22,7 +22,7 @@ export declare class ShardManager extends Map<number, Shard> {
|
|
|
22
22
|
startResharder(): Promise<void>;
|
|
23
23
|
spawnBuckets(): Shard[][];
|
|
24
24
|
forceIdentify(shardId: number): Promise<void>;
|
|
25
|
-
disconnect(shardId: number):
|
|
25
|
+
disconnect(shardId: number): void | undefined;
|
|
26
26
|
disconnectAll(): void;
|
|
27
27
|
setShardPresence(shardId: number, payload: GatewayUpdatePresence['d']): void;
|
|
28
28
|
setPresence(payload: GatewayUpdatePresence['d']): void;
|
|
@@ -15,7 +15,7 @@ const structures_1 = require("../structures");
|
|
|
15
15
|
const timeout_1 = require("../structures/timeout");
|
|
16
16
|
class WorkerManager extends Map {
|
|
17
17
|
static prepareSpaces(options, logger) {
|
|
18
|
-
logger?.info('Preparing buckets'
|
|
18
|
+
logger?.info('Preparing buckets');
|
|
19
19
|
const chunks = structures_1.DynamicBucket.chunk(new Array(options.shardEnd - options.shardStart), options.shardsPerWorker);
|
|
20
20
|
chunks.forEach((shards, index) => {
|
|
21
21
|
for (let i = 0; i < shards.length; i++) {
|
|
@@ -342,7 +342,7 @@ class WorkerManager extends Map {
|
|
|
342
342
|
case 'WORKER_READY':
|
|
343
343
|
{
|
|
344
344
|
this.get(message.workerId).ready = true;
|
|
345
|
-
if ([...this.values()].every(w => w.ready)) {
|
|
345
|
+
if (this.size === this.totalWorkers && [...this.values()].every(w => w.ready)) {
|
|
346
346
|
this.postMessage(this.keys().next().value, {
|
|
347
347
|
type: 'BOT_READY',
|
|
348
348
|
});
|
|
@@ -529,7 +529,7 @@ class WorkerManager extends Map {
|
|
|
529
529
|
const percentage = (info.shards / ((this.totalShards * 2500) / 1000)) * 100;
|
|
530
530
|
if (percentage < this.options.resharding.percentage)
|
|
531
531
|
return this.debugger?.debug(`Percentage is not enough to reshard ${percentage}/${this.options.resharding.percentage}`);
|
|
532
|
-
this.debugger?.info(
|
|
532
|
+
this.debugger?.info(`Starting resharding process to ${info.shards}`);
|
|
533
533
|
this._info = info;
|
|
534
534
|
this.connectQueue.concurrency = info.session_start_limit.max_concurrency;
|
|
535
535
|
this.options.info.session_start_limit.max_concurrency = info.session_start_limit.max_concurrency;
|