seyfert 2.2.1-dev-13381595851.0 → 2.2.1-dev-13478083325.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.
@@ -261,7 +261,14 @@ exports.ReplaceRegex = {
261
261
  },
262
262
  };
263
263
  async function magicImport(path) {
264
- return new Function('path', 'return import(`file:///${path}?update=${Date.now()}`)')(path);
264
+ try {
265
+ if ('Deno' in globalThis)
266
+ throw new Error('https://github.com/denoland/deno/issues/26136');
267
+ return require(path);
268
+ }
269
+ catch {
270
+ return new Function('path', 'return import(`file:///${path}?update=${Date.now()}`)')(path);
271
+ }
265
272
  }
266
273
  function fakePromise(value) {
267
274
  if (value instanceof Promise)
@@ -24,8 +24,9 @@ export declare class Shard {
24
24
  bucket: DynamicBucket;
25
25
  offlineSendQueue: ((_?: unknown) => void)[];
26
26
  pendingGuilds: Set<string>;
27
- options: MakeRequired<ShardOptions, 'properties' | 'ratelimitOptions'>;
27
+ options: MakeRequired<ShardOptions, 'properties' | 'ratelimitOptions' | 'reconnectTimeout' | 'connectionTimeout'>;
28
28
  isReady: boolean;
29
+ connectionTimeout?: NodeJS.Timeout;
29
30
  private requestGuildMembersChunk;
30
31
  constructor(id: number, options: ShardOptions);
31
32
  get latency(): number;
@@ -41,7 +42,7 @@ export declare class Shard {
41
42
  resume(): Promise<void>;
42
43
  heartbeat(requested: boolean): void;
43
44
  disconnect(code?: ShardSocketCloseCodes): void;
44
- reconnect(): Promise<void>;
45
+ reconnect(code?: ShardSocketCloseCodes): Promise<void>;
45
46
  onpacket(packet: GatewayReceivePayload): void | Promise<void>;
46
47
  requestGuildMember(options: Omit<GatewayRequestGuildMembersDataWithQuery, 'nonce'> | Omit<GatewayRequestGuildMembersDataWithUserIds, 'nonce'>): Promise<{
47
48
  members: APIGuildMember[];
@@ -27,6 +27,7 @@ class Shard {
27
27
  pendingGuilds = new Set();
28
28
  options;
29
29
  isReady = false;
30
+ connectionTimeout;
30
31
  requestGuildMembersChunk = new Map();
31
32
  constructor(id, options) {
32
33
  this.id = id;
@@ -36,6 +37,8 @@ class Shard {
36
37
  rateLimitResetInterval: 60_000,
37
38
  maxRequestsPerRateLimitTick: 120,
38
39
  },
40
+ reconnectTimeout: 10e3,
41
+ connectionTimeout: 30e3,
39
42
  }, options);
40
43
  this.logger = new common_1.Logger({
41
44
  name: `[Shard #${id}]`,
@@ -78,6 +81,7 @@ class Shard {
78
81
  }
79
82
  clearTimeout(this.heart.nodeInterval);
80
83
  this.debugger?.debug(`[Shard #${this.id}] Connecting to ${this.currentGatewayURL}`);
84
+ this.connectionTimeout = setTimeout(() => this.reconnect(shared_1.ShardSocketCloseCodes.Timeout), this.options.connectionTimeout);
81
85
  // @ts-expect-error Use native websocket when using Bun
82
86
  // biome-ignore lint/correctness/noUndeclaredVariables: /\
83
87
  this.websocket = new basesocket_1.BaseSocket(typeof Bun === 'undefined' ? 'ws' : 'bun', this.currentGatewayURL);
@@ -146,12 +150,15 @@ class Shard {
146
150
  }));
147
151
  }
148
152
  disconnect(code = shared_1.ShardSocketCloseCodes.Shutdown) {
153
+ clearTimeout(this.connectionTimeout);
154
+ this.connectionTimeout = undefined;
149
155
  this.debugger?.info(`[Shard #${this.id}] Disconnecting`);
150
156
  this.close(code, 'Shard down request');
151
157
  }
152
- async reconnect() {
158
+ async reconnect(code = shared_1.ShardSocketCloseCodes.Reconnect) {
153
159
  this.debugger?.info(`[Shard #${this.id}] Reconnecting`);
154
- this.disconnect(shared_1.ShardSocketCloseCodes.Reconnect);
160
+ this.disconnect(code);
161
+ await (0, common_1.delay)(this.options.reconnectTimeout);
155
162
  await this.connect();
156
163
  }
157
164
  onpacket(packet) {
@@ -161,6 +168,8 @@ class Shard {
161
168
  this.debugger?.debug(`[Shard #${this.id}]`, packet.t ? packet.t : types_1.GatewayOpcodes[packet.op], this.data.resume_seq);
162
169
  switch (packet.op) {
163
170
  case types_1.GatewayOpcodes.Hello: {
171
+ clearTimeout(this.connectionTimeout);
172
+ this.connectionTimeout = undefined;
164
173
  clearInterval(this.heart.nodeInterval);
165
174
  this.heart.interval = packet.d.heartbeat_interval;
166
175
  this.heartbeat(false);
@@ -197,12 +206,16 @@ class Shard {
197
206
  switch (packet.t) {
198
207
  case types_1.GatewayDispatchEvents.Resumed:
199
208
  {
209
+ clearTimeout(this.connectionTimeout);
210
+ this.connectionTimeout = undefined;
200
211
  this.isReady = true;
201
212
  this.offlineSendQueue.map(resolve => resolve());
202
213
  this.options.handlePayload(this.id, packet);
203
214
  }
204
215
  break;
205
216
  case types_1.GatewayDispatchEvents.Ready: {
217
+ clearTimeout(this.connectionTimeout);
218
+ this.connectionTimeout = undefined;
206
219
  if ((0, common_1.hasIntent)(this.options.intents, 'Guilds')) {
207
220
  for (let i = 0; i < packet.d.guilds.length; i++) {
208
221
  this.pendingGuilds.add(packet.d.guilds.at(i).id);
@@ -314,6 +327,8 @@ class Shard {
314
327
  case types_1.GatewayCloseCodes.UnknownOpcode:
315
328
  case types_1.GatewayCloseCodes.InvalidSeq:
316
329
  case types_1.GatewayCloseCodes.SessionTimedOut:
330
+ // shard failed to connect, try connecting from scratch
331
+ case shared_1.ShardSocketCloseCodes.Timeout:
317
332
  {
318
333
  this.data.resume_seq = 0;
319
334
  this.data.session_id = undefined;
@@ -68,6 +68,8 @@ class ShardManager extends Map {
68
68
  debugger: this.debugger,
69
69
  compress: this.options.compress ?? false,
70
70
  presence: this.options.presence?.(shardId, -1),
71
+ connectionTimeout: this.options.connectionTimeout,
72
+ reconnectTimeout: this.options.reconnectTimeout,
71
73
  });
72
74
  this.set(shardId, shard);
73
75
  return shard;
@@ -39,6 +39,8 @@ export interface ShardManagerOptions extends ShardDetails {
39
39
  interval: number;
40
40
  percentage: number;
41
41
  };
42
+ reconnectTimeout?: number;
43
+ connectionTimeout?: number;
42
44
  }
43
45
  export interface CustomManagerAdapter {
44
46
  postMessage(workerId: number, body: unknown): Awaitable<unknown>;
@@ -105,13 +107,16 @@ export interface ShardOptions extends ShardDetails {
105
107
  debugger?: Logger;
106
108
  compress: boolean;
107
109
  presence?: GatewayPresenceUpdateData;
110
+ reconnectTimeout?: number;
111
+ connectionTimeout?: number;
108
112
  }
109
113
  export declare enum ShardSocketCloseCodes {
110
114
  Shutdown = 3000,
111
115
  ZombiedConnection = 3010,
112
116
  Reconnect = 3020,
113
117
  Resharding = 3030,
114
- ShutdownAll = 3040
118
+ ShutdownAll = 3040,
119
+ Timeout = 3050
115
120
  }
116
121
  export interface WorkerData {
117
122
  intents: number;
@@ -8,4 +8,5 @@ var ShardSocketCloseCodes;
8
8
  ShardSocketCloseCodes[ShardSocketCloseCodes["Reconnect"] = 3020] = "Reconnect";
9
9
  ShardSocketCloseCodes[ShardSocketCloseCodes["Resharding"] = 3030] = "Resharding";
10
10
  ShardSocketCloseCodes[ShardSocketCloseCodes["ShutdownAll"] = 3040] = "ShutdownAll";
11
+ ShardSocketCloseCodes[ShardSocketCloseCodes["Timeout"] = 3050] = "Timeout";
11
12
  })(ShardSocketCloseCodes || (exports.ShardSocketCloseCodes = ShardSocketCloseCodes = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "seyfert",
3
- "version": "2.2.1-dev-13381595851.0",
3
+ "version": "2.2.1-dev-13478083325.0",
4
4
  "description": "The most advanced framework for discord bots",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",