mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
refactor: make use of destructuring for Constants (#1942)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
const Constants = require('../util/Constants');
|
||||
const { Events, Status } = require('../util/Constants');
|
||||
const { Error } = require('../errors');
|
||||
|
||||
/**
|
||||
@@ -25,7 +25,7 @@ class ClientManager {
|
||||
* @type {number}
|
||||
*/
|
||||
get status() {
|
||||
return this.connection ? this.connection.status : Constants.Status.IDLE;
|
||||
return this.connection ? this.connection.status : Status.IDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -35,19 +35,19 @@ class ClientManager {
|
||||
* @param {Function} reject Function to run when connection fails
|
||||
*/
|
||||
connectToWebSocket(token, resolve, reject) {
|
||||
this.client.emit(Constants.Events.DEBUG, `Authenticated using token ${token}`);
|
||||
this.client.emit(Events.DEBUG, `Authenticated using token ${token}`);
|
||||
this.client.token = token;
|
||||
const timeout = this.client.setTimeout(() => reject(new Error('TOKEN_INVALID')), 1000 * 300);
|
||||
this.client.api.gateway.get().then(res => {
|
||||
const gateway = `${res.url}/`;
|
||||
this.client.emit(Constants.Events.DEBUG, `Using gateway ${gateway}`);
|
||||
this.client.emit(Events.DEBUG, `Using gateway ${gateway}`);
|
||||
this.client.ws.connect(gateway);
|
||||
this.client.ws.connection.once('close', event => {
|
||||
if (event.code === 4004) reject(new Error('TOKEN_INVALID'));
|
||||
if (event.code === 4010) reject(new Error('SHARDING_INVALID'));
|
||||
if (event.code === 4011) reject(new Error('SHARDING_REQUIRED'));
|
||||
});
|
||||
this.client.once(Constants.Events.READY, () => {
|
||||
this.client.once(Events.READY, () => {
|
||||
resolve(token);
|
||||
this.client.clearTimeout(timeout);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user