revbot.js 0.2.1 → 0.2.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/dist/index.mjs CHANGED
@@ -3228,7 +3228,7 @@ import { EventEmitter } from "node:events";
3228
3228
  import axios4, { AxiosError } from "axios";
3229
3229
 
3230
3230
  // package.json
3231
- var version = "0.2.0";
3231
+ var version = "0.2.1";
3232
3232
 
3233
3233
  // src/rest/restUtils/rateLimitQueue.ts
3234
3234
  import axios3 from "axios";
@@ -4230,6 +4230,8 @@ var WebSocketClient = class {
4230
4230
  this.reconnecting = null;
4231
4231
  /** Whether the WebSocket client is ready. */
4232
4232
  this.ready = false;
4233
+ /** The number of reconnection attempts made. */
4234
+ this.retryCount = 0;
4233
4235
  }
4234
4236
  /**
4235
4237
  * Logs a debug message.
@@ -4369,6 +4371,8 @@ var WebSocketClient = class {
4369
4371
  break;
4370
4372
  case "Authenticated" /* AUTHENTICATED */:
4371
4373
  this.connected = true;
4374
+ this.retryCount = 0;
4375
+ this.debug(`Successfully authenticated.`);
4372
4376
  break;
4373
4377
  case "Pong" /* PONG */:
4374
4378
  this.debug(`Received a heartbeat.`);
@@ -4428,6 +4432,15 @@ var WebSocketClient = class {
4428
4432
  * @returns {Promise<this>} A promise that resolves when the connection is established.
4429
4433
  */
4430
4434
  connect() {
4435
+ this.retryCount = this.retryCount + 1;
4436
+ if (this.retryCount > 10) {
4437
+ this.debug("Max retry attempts reached");
4438
+ return Promise.reject(
4439
+ new Error(
4440
+ "Max retry attempts reached on WS connection, try again later."
4441
+ )
4442
+ );
4443
+ }
4431
4444
  return new Promise((resolve) => __async(this, null, function* () {
4432
4445
  var _a, _b, _c, _d;
4433
4446
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
@@ -4455,7 +4468,7 @@ var WebSocketClient = class {
4455
4468
  *
4456
4469
  * @returns {Promise<void>} A promise that resolves when the connection is destroyed.
4457
4470
  */
4458
- destroy() {
4471
+ destroy(isUserInitiated) {
4459
4472
  return new Promise((resolve) => {
4460
4473
  var _a;
4461
4474
  this.setHeartbeatTimer(-1);
@@ -4464,11 +4477,20 @@ var WebSocketClient = class {
4464
4477
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
4465
4478
  this.socket.addEventListener("close", () => {
4466
4479
  this.socket = null;
4480
+ if (!isUserInitiated) {
4481
+ setTimeout(() => this.connect(), 1e3);
4482
+ }
4467
4483
  resolve();
4468
4484
  });
4469
4485
  this.socket.close();
4486
+ if (!isUserInitiated) {
4487
+ setTimeout(() => this.connect(), 1e3);
4488
+ }
4470
4489
  } else {
4471
4490
  this.socket = null;
4491
+ if (!isUserInitiated) {
4492
+ setTimeout(() => this.connect(), 1e3);
4493
+ }
4472
4494
  resolve();
4473
4495
  }
4474
4496
  });
@@ -4560,7 +4582,7 @@ var client2 = class extends BaseClient {
4560
4582
  this.token = null;
4561
4583
  this.user = null;
4562
4584
  this.readyAt = null;
4563
- yield this.ws.destroy();
4585
+ yield this.ws.destroy(true);
4564
4586
  });
4565
4587
  }
4566
4588
  /**