refactor: make use of destructuring for Constants (#1942)

This commit is contained in:
SpaceEEC
2017-09-16 20:31:36 +02:00
committed by Crawl
parent 25ece1882b
commit ec4c98704f
66 changed files with 262 additions and 262 deletions

View File

@@ -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);
});