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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  # Note: this package is currently in the early stages of development and testing
4
4
 
5
5
  `revbot.js` is a Node.js library for building bots on the Revolt platform. It provides an easy-to-use interface for interacting with Revolt's API, managing events, and handling various bot functionalities. NOTE: node 21 is required to run this
6
- [revolt server](https://rvlt.gg/2NcCgYZ0) [docs](https://jade3375.github.io/revbot.js/)
6
+ [revolt server](https://stt.gg/cFSwBt4R) [docs](https://jade3375.github.io/revbot.js/)
7
7
 
8
8
  ## Installation
9
9
 
package/dist/index.d.mts CHANGED
@@ -2190,6 +2190,8 @@ declare class WebSocketClient {
2190
2190
  reconnecting: Promise<unknown> | null;
2191
2191
  /** Whether the WebSocket client is ready. */
2192
2192
  ready: boolean;
2193
+ /** The number of reconnection attempts made. */
2194
+ retryCount: number;
2193
2195
  /**
2194
2196
  * Creates a new WebSocketClient instance.
2195
2197
  *
@@ -2272,7 +2274,7 @@ declare class WebSocketClient {
2272
2274
  *
2273
2275
  * @returns {Promise<void>} A promise that resolves when the connection is destroyed.
2274
2276
  */
2275
- destroy(): Promise<void>;
2277
+ destroy(isUserInitiated?: boolean): Promise<void>;
2276
2278
  }
2277
2279
 
2278
2280
  /**
package/dist/index.d.ts CHANGED
@@ -2190,6 +2190,8 @@ declare class WebSocketClient {
2190
2190
  reconnecting: Promise<unknown> | null;
2191
2191
  /** Whether the WebSocket client is ready. */
2192
2192
  ready: boolean;
2193
+ /** The number of reconnection attempts made. */
2194
+ retryCount: number;
2193
2195
  /**
2194
2196
  * Creates a new WebSocketClient instance.
2195
2197
  *
@@ -2272,7 +2274,7 @@ declare class WebSocketClient {
2272
2274
  *
2273
2275
  * @returns {Promise<void>} A promise that resolves when the connection is destroyed.
2274
2276
  */
2275
- destroy(): Promise<void>;
2277
+ destroy(isUserInitiated?: boolean): Promise<void>;
2276
2278
  }
2277
2279
 
2278
2280
  /**
package/dist/index.js CHANGED
@@ -3304,7 +3304,7 @@ var import_node_events = require("events");
3304
3304
  var import_axios4 = __toESM(require("axios"));
3305
3305
 
3306
3306
  // package.json
3307
- var version = "0.2.0";
3307
+ var version = "0.2.1";
3308
3308
 
3309
3309
  // src/rest/restUtils/rateLimitQueue.ts
3310
3310
  var import_axios3 = __toESM(require("axios"));
@@ -4306,6 +4306,8 @@ var WebSocketClient = class {
4306
4306
  this.reconnecting = null;
4307
4307
  /** Whether the WebSocket client is ready. */
4308
4308
  this.ready = false;
4309
+ /** The number of reconnection attempts made. */
4310
+ this.retryCount = 0;
4309
4311
  }
4310
4312
  /**
4311
4313
  * Logs a debug message.
@@ -4445,6 +4447,8 @@ var WebSocketClient = class {
4445
4447
  break;
4446
4448
  case "Authenticated" /* AUTHENTICATED */:
4447
4449
  this.connected = true;
4450
+ this.retryCount = 0;
4451
+ this.debug(`Successfully authenticated.`);
4448
4452
  break;
4449
4453
  case "Pong" /* PONG */:
4450
4454
  this.debug(`Received a heartbeat.`);
@@ -4504,6 +4508,15 @@ var WebSocketClient = class {
4504
4508
  * @returns {Promise<this>} A promise that resolves when the connection is established.
4505
4509
  */
4506
4510
  connect() {
4511
+ this.retryCount = this.retryCount + 1;
4512
+ if (this.retryCount > 10) {
4513
+ this.debug("Max retry attempts reached");
4514
+ return Promise.reject(
4515
+ new Error(
4516
+ "Max retry attempts reached on WS connection, try again later."
4517
+ )
4518
+ );
4519
+ }
4507
4520
  return new Promise((resolve) => __async(this, null, function* () {
4508
4521
  var _a, _b, _c, _d;
4509
4522
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
@@ -4531,7 +4544,7 @@ var WebSocketClient = class {
4531
4544
  *
4532
4545
  * @returns {Promise<void>} A promise that resolves when the connection is destroyed.
4533
4546
  */
4534
- destroy() {
4547
+ destroy(isUserInitiated) {
4535
4548
  return new Promise((resolve) => {
4536
4549
  var _a;
4537
4550
  this.setHeartbeatTimer(-1);
@@ -4540,11 +4553,20 @@ var WebSocketClient = class {
4540
4553
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
4541
4554
  this.socket.addEventListener("close", () => {
4542
4555
  this.socket = null;
4556
+ if (!isUserInitiated) {
4557
+ setTimeout(() => this.connect(), 1e3);
4558
+ }
4543
4559
  resolve();
4544
4560
  });
4545
4561
  this.socket.close();
4562
+ if (!isUserInitiated) {
4563
+ setTimeout(() => this.connect(), 1e3);
4564
+ }
4546
4565
  } else {
4547
4566
  this.socket = null;
4567
+ if (!isUserInitiated) {
4568
+ setTimeout(() => this.connect(), 1e3);
4569
+ }
4548
4570
  resolve();
4549
4571
  }
4550
4572
  });
@@ -4636,7 +4658,7 @@ var client2 = class extends BaseClient {
4636
4658
  this.token = null;
4637
4659
  this.user = null;
4638
4660
  this.readyAt = null;
4639
- yield this.ws.destroy();
4661
+ yield this.ws.destroy(true);
4640
4662
  });
4641
4663
  }
4642
4664
  /**