discord-sb.js 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discord-sb.js",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "An unofficial discord.js fork for creating selfbots",
5
5
  "main": "./src/index.js",
6
6
  "types": "./typings/index.d.ts",
@@ -24,6 +24,8 @@ class WebSocketShard extends EventEmitter {
24
24
  constructor(manager, id) {
25
25
  super();
26
26
 
27
+ this.getConnectionState = () => (this.connection ? CONNECTION_STATE[this.connection.readyState] : 'No Connection');
28
+
27
29
  /**
28
30
  * The WebSocketManager of the shard
29
31
  * @type {WebSocketManager}
@@ -251,7 +253,7 @@ class WebSocketShard extends EventEmitter {
251
253
 
252
254
  if (this.connection) {
253
255
  this.debug(`A connection object was found. Cleaning up before continuing.
254
- State: ${CONNECTION_STATE[this.connection.readyState]}`);
256
+ State: ${this.getConnectionState()}`);
255
257
  this.destroy({ emit: false });
256
258
  }
257
259
 
@@ -819,18 +821,18 @@ class WebSocketShard extends EventEmitter {
819
821
 
820
822
  this.debug(
821
823
  `[WebSocket] Destroy: Attempting to close the WebSocket. | WS State: ${
822
- CONNECTION_STATE[this.connection?.readyState ?? WebSocket.CLOSED]
824
+ this.connection ? this.getConnectionState() : CONNECTION_STATE[WebSocket.CLOSED]
823
825
  }`,
824
826
  );
825
827
  // Step 1: Close the WebSocket connection, if any, otherwise, emit DESTROYED
826
828
  if (this.connection) {
827
829
  // If the connection is currently opened, we will (hopefully) receive close
828
- if (this.connection.readyState === WebSocket.OPEN) {
830
+ if (this.connection?.readyState === WebSocket.OPEN) {
829
831
  this.connection.close(closeCode);
830
- this.debug(`[WebSocket] Close: Tried closing. | WS State: ${CONNECTION_STATE[this.connection.readyState]}`);
832
+ this.debug(`[WebSocket] Close: Tried closing. | WS State: ${this.getConnectionState()}`);
831
833
  } else {
832
834
  // Connection is not OPEN
833
- this.debug(`WS State: ${CONNECTION_STATE[this.connection.readyState]}`);
835
+ this.debug(`WS State: ${this.getConnectionState()}`);
834
836
  // Attempt to close the connection just in case
835
837
  try {
836
838
  this.connection.close(closeCode);
@@ -838,7 +840,7 @@ class WebSocketShard extends EventEmitter {
838
840
  this.debug(
839
841
  `[WebSocket] Close: Something went wrong while closing the WebSocket: ${
840
842
  err.message || err
841
- }. Forcefully terminating the connection | WS State: ${CONNECTION_STATE[this.connection.readyState]}`,
843
+ }. Forcefully terminating the connection | WS State: ${this.getConnectionState()}`,
842
844
  );
843
845
  this.connection.terminate();
844
846
  }