refactor: new node features (#5132)

Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
Sugden
2021-06-30 21:40:33 +01:00
committed by GitHub
parent f108746c15
commit 1e8f01253e
68 changed files with 305 additions and 360 deletions

View File

@@ -240,7 +240,7 @@ class WebSocketManager extends EventEmitter {
try {
await shard.connect();
} catch (error) {
if (error && error.code && UNRECOVERABLE_CLOSE_CODES.includes(error.code)) {
if (error?.code && UNRECOVERABLE_CLOSE_CODES.includes(error.code)) {
throw new Error(WSCodes[error.code]);
// Undefined if session is invalid, error event for regular closes
} else if (!error || error.code) {

View File

@@ -176,7 +176,7 @@ class WebSocketShard extends EventEmitter {
connect() {
const { gateway, client } = this.manager;
if (this.connection && this.connection.readyState === WebSocket.OPEN && this.status === Status.READY) {
if (this.connection?.readyState === WebSocket.OPEN && this.status === Status.READY) {
return Promise.resolve();
}
@@ -216,7 +216,7 @@ class WebSocketShard extends EventEmitter {
this.once(ShardEvents.INVALID_SESSION, onInvalidOrDestroyed);
this.once(ShardEvents.DESTROYED, onInvalidOrDestroyed);
if (this.connection && this.connection.readyState === WebSocket.OPEN) {
if (this.connection?.readyState === WebSocket.OPEN) {
this.debug('An open connection was found, attempting an immediate identify.');
this.identify();
return;
@@ -306,7 +306,7 @@ class WebSocketShard extends EventEmitter {
* @private
*/
onError(event) {
const error = event && event.error ? event.error : event;
const error = event?.error ?? event;
if (!error) return;
/**
@@ -345,7 +345,7 @@ class WebSocketShard extends EventEmitter {
this.debug(`[CLOSE]
Event Code: ${event.code}
Clean : ${event.wasClean}
Reason : ${event.reason || 'No reason received'}`);
Reason : ${event.reason ?? 'No reason received'}`);
this.setHeartbeatTimer(-1);
this.setHelloTimeout(-1);
@@ -648,7 +648,7 @@ class WebSocketShard extends EventEmitter {
* @private
*/
_send(data) {
if (!this.connection || this.connection.readyState !== WebSocket.OPEN) {
if (this.connection?.readyState !== WebSocket.OPEN) {
this.debug(`Tried to send packet '${JSON.stringify(data)}' but no WebSocket is available!`);
this.destroy({ closeCode: 4000 });
return;

View File

@@ -8,7 +8,7 @@ module.exports = (client, { d: data }) => {
if (channel && !Number.isNaN(time.getTime())) {
// Discord sends null for last_pin_timestamp if the last pinned message was removed
channel.lastPinTimestamp = time.getTime() || null;
channel.lastPinTimestamp = time.getTime() ?? null;
/**
* Emitted whenever the pins of a channel are updated. Due to the nature of the WebSocket event,