mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
make login sane (#735)
This commit is contained in:
@@ -32,6 +32,10 @@ class ClientManager {
|
|||||||
this.client.rest.methods.getGateway().then(gateway => {
|
this.client.rest.methods.getGateway().then(gateway => {
|
||||||
this.client.emit(Constants.Events.DEBUG, `Using gateway ${gateway}`);
|
this.client.emit(Constants.Events.DEBUG, `Using gateway ${gateway}`);
|
||||||
this.client.ws.connect(gateway);
|
this.client.ws.connect(gateway);
|
||||||
|
this.client.ws.once('close', event => {
|
||||||
|
if (event.code === 4004) reject(new Error(Constants.Errors.BAD_LOGIN));
|
||||||
|
if (event.code === 4010) reject(new Error(Constants.Errors.INVALID_SHARD));
|
||||||
|
});
|
||||||
this.client.once(Constants.Events.READY, () => {
|
this.client.once(Constants.Events.READY, () => {
|
||||||
resolve(token);
|
resolve(token);
|
||||||
this.client.clearTimeout(timeout);
|
this.client.clearTimeout(timeout);
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const Constants = require('../../util/Constants');
|
const Constants = require('../../util/Constants');
|
||||||
const zlib = require('zlib');
|
const zlib = require('zlib');
|
||||||
const PacketManager = require('./packets/WebSocketPacketManager');
|
const PacketManager = require('./packets/WebSocketPacketManager');
|
||||||
@@ -7,8 +8,9 @@ const PacketManager = require('./packets/WebSocketPacketManager');
|
|||||||
* The WebSocket Manager of the Client
|
* The WebSocket Manager of the Client
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
class WebSocketManager {
|
class WebSocketManager extends EventEmitter {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
|
super();
|
||||||
/**
|
/**
|
||||||
* The Client that instantiated this WebSocketManager
|
* The Client that instantiated this WebSocketManager
|
||||||
* @type {Client}
|
* @type {Client}
|
||||||
@@ -164,12 +166,14 @@ class WebSocketManager {
|
|||||||
* @param {Object} event The received websocket data
|
* @param {Object} event The received websocket data
|
||||||
*/
|
*/
|
||||||
eventClose(event) {
|
eventClose(event) {
|
||||||
|
this.emit('close', event);
|
||||||
/**
|
/**
|
||||||
* Emitted whenever the client websocket is disconnected
|
* Emitted whenever the client websocket is disconnected
|
||||||
* @event Client#disconnect
|
* @event Client#disconnect
|
||||||
*/
|
*/
|
||||||
if (!this.reconnecting) this.client.emit(Constants.Events.DISCONNECT);
|
if (!this.reconnecting) this.client.emit(Constants.Events.DISCONNECT);
|
||||||
if (event.code === 4004) throw new Error(Constants.Errors.BAD_LOGIN);
|
if (event.code === 4004) return;
|
||||||
|
if (event.code === 4010) return;
|
||||||
if (!this.reconnecting && event.code !== 1000) this.tryReconnect();
|
if (!this.reconnecting && event.code !== 1000) this.tryReconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ exports.Errors = {
|
|||||||
NOT_A_PERMISSION: 'Invalid permission string or number.',
|
NOT_A_PERMISSION: 'Invalid permission string or number.',
|
||||||
INVALID_RATE_LIMIT_METHOD: 'Unknown rate limiting method.',
|
INVALID_RATE_LIMIT_METHOD: 'Unknown rate limiting method.',
|
||||||
BAD_LOGIN: 'Incorrect login details were provided.',
|
BAD_LOGIN: 'Incorrect login details were provided.',
|
||||||
|
INVALID_SHARD: 'Invalid shard settings were provided',
|
||||||
};
|
};
|
||||||
|
|
||||||
const API = `https://discordapp.com/api/v${exports.DefaultOptions.protocol_version}`;
|
const API = `https://discordapp.com/api/v${exports.DefaultOptions.protocol_version}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user