revbot.js 0.2.0 → 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";
@@ -3793,6 +3793,9 @@ var Message = class extends Event {
3793
3793
  handle(data) {
3794
3794
  return __async(this, null, function* () {
3795
3795
  var _a;
3796
+ if (data.system) {
3797
+ return {};
3798
+ }
3796
3799
  const channel = this.client.channels.cache.get(data.channel);
3797
3800
  if (channel == null ? void 0 : channel.isText()) {
3798
3801
  if (((_a = data.user) == null ? void 0 : _a.bot) && this.client.options.ignoreBots) {
@@ -4227,6 +4230,8 @@ var WebSocketClient = class {
4227
4230
  this.reconnecting = null;
4228
4231
  /** Whether the WebSocket client is ready. */
4229
4232
  this.ready = false;
4233
+ /** The number of reconnection attempts made. */
4234
+ this.retryCount = 0;
4230
4235
  }
4231
4236
  /**
4232
4237
  * Logs a debug message.
@@ -4366,6 +4371,8 @@ var WebSocketClient = class {
4366
4371
  break;
4367
4372
  case "Authenticated" /* AUTHENTICATED */:
4368
4373
  this.connected = true;
4374
+ this.retryCount = 0;
4375
+ this.debug(`Successfully authenticated.`);
4369
4376
  break;
4370
4377
  case "Pong" /* PONG */:
4371
4378
  this.debug(`Received a heartbeat.`);
@@ -4425,6 +4432,15 @@ var WebSocketClient = class {
4425
4432
  * @returns {Promise<this>} A promise that resolves when the connection is established.
4426
4433
  */
4427
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
+ }
4428
4444
  return new Promise((resolve) => __async(this, null, function* () {
4429
4445
  var _a, _b, _c, _d;
4430
4446
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN && this.ready) {
@@ -4452,7 +4468,7 @@ var WebSocketClient = class {
4452
4468
  *
4453
4469
  * @returns {Promise<void>} A promise that resolves when the connection is destroyed.
4454
4470
  */
4455
- destroy() {
4471
+ destroy(isUserInitiated) {
4456
4472
  return new Promise((resolve) => {
4457
4473
  var _a;
4458
4474
  this.setHeartbeatTimer(-1);
@@ -4461,11 +4477,20 @@ var WebSocketClient = class {
4461
4477
  if (((_a = this.socket) == null ? void 0 : _a.readyState) === WebSocket.OPEN) {
4462
4478
  this.socket.addEventListener("close", () => {
4463
4479
  this.socket = null;
4480
+ if (!isUserInitiated) {
4481
+ setTimeout(() => this.connect(), 1e3);
4482
+ }
4464
4483
  resolve();
4465
4484
  });
4466
4485
  this.socket.close();
4486
+ if (!isUserInitiated) {
4487
+ setTimeout(() => this.connect(), 1e3);
4488
+ }
4467
4489
  } else {
4468
4490
  this.socket = null;
4491
+ if (!isUserInitiated) {
4492
+ setTimeout(() => this.connect(), 1e3);
4493
+ }
4469
4494
  resolve();
4470
4495
  }
4471
4496
  });
@@ -4557,7 +4582,7 @@ var client2 = class extends BaseClient {
4557
4582
  this.token = null;
4558
4583
  this.user = null;
4559
4584
  this.readyAt = null;
4560
- yield this.ws.destroy();
4585
+ yield this.ws.destroy(true);
4561
4586
  });
4562
4587
  }
4563
4588
  /**