mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 12:03:31 +01:00
Clean up some stuff
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -20,93 +20,152 @@ class Client extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The options the client was instantiated with
|
||||||
|
* @type {ClientOptions}
|
||||||
|
*/
|
||||||
this.options = mergeDefault(Constants.DefaultOptions, options);
|
this.options = mergeDefault(Constants.DefaultOptions, options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The REST manager of the client
|
* The REST manager of the client
|
||||||
* @type {RESTManager}
|
* @type {RESTManager}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.rest = new RESTManager(this);
|
this.rest = new RESTManager(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The data manager of the Client
|
* The data manager of the Client
|
||||||
* @type {ClientDataManager}
|
* @type {ClientDataManager}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.dataManager = new ClientDataManager(this);
|
this.dataManager = new ClientDataManager(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The manager of the Client
|
* The manager of the Client
|
||||||
* @type {ClientManager}
|
* @type {ClientManager}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.manager = new ClientManager(this);
|
this.manager = new ClientManager(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The WebSocket Manager of the Client
|
* The WebSocket Manager of the Client
|
||||||
* @type {WebSocketManager}
|
* @type {WebSocketManager}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.ws = new WebSocketManager(this);
|
this.ws = new WebSocketManager(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Data Resolver of the Client
|
* The Data Resolver of the Client
|
||||||
* @type {ClientDataResolver}
|
* @type {ClientDataResolver}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.resolver = new ClientDataResolver(this);
|
this.resolver = new ClientDataResolver(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Action Manager of the Client
|
* The Action Manager of the Client
|
||||||
* @type {ActionsManager}
|
* @type {ActionsManager}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.actions = new ActionsManager(this);
|
this.actions = new ActionsManager(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Voice Manager of the Client
|
* The Voice Manager of the Client
|
||||||
* @type {ClientVoiceManager}
|
* @type {ClientVoiceManager}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.voice = new ClientVoiceManager(this);
|
this.voice = new ClientVoiceManager(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Collection of the Client's stored users
|
* A Collection of the Client's stored users
|
||||||
* @type {Collection<string, User>}
|
* @type {Collection<string, User>}
|
||||||
*/
|
*/
|
||||||
this.users = new Collection();
|
this.users = new Collection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Collection of the Client's stored guilds
|
* A Collection of the Client's stored guilds
|
||||||
* @type {Collection<string, Guild>}
|
* @type {Collection<string, Guild>}
|
||||||
*/
|
*/
|
||||||
this.guilds = new Collection();
|
this.guilds = new Collection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Collection of the Client's stored channels
|
* A Collection of the Client's stored channels
|
||||||
* @type {Collection<string, Channel>}
|
* @type {Collection<string, Channel>}
|
||||||
*/
|
*/
|
||||||
this.channels = new Collection();
|
this.channels = new Collection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The authorization token for the logged in user/bot.
|
* The authorization token for the logged in user/bot.
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.token = null;
|
this.token = null;
|
||||||
/**
|
|
||||||
* The ClientUser representing the logged in Client
|
|
||||||
* @type {?ClientUser}
|
|
||||||
*/
|
|
||||||
this.user = null;
|
|
||||||
/**
|
/**
|
||||||
* The email, if there is one, for the logged in Client
|
* The email, if there is one, for the logged in Client
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.email = null;
|
this.email = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The password, if there is one, for the logged in Client
|
* The password, if there is one, for the logged in Client
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.password = null;
|
this.password = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The ClientUser representing the logged in Client
|
||||||
|
* @type {?ClientUser}
|
||||||
|
*/
|
||||||
|
this.user = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The date at which the Client was regarded as being in the `READY` state.
|
* The date at which the Client was regarded as being in the `READY` state.
|
||||||
* @type {?Date}
|
* @type {?Date}
|
||||||
*/
|
*/
|
||||||
this.readyTime = null;
|
this.readyTime = null;
|
||||||
|
|
||||||
this._timeouts = new Set();
|
this._timeouts = new Set();
|
||||||
this._intervals = new Set();
|
this._intervals = new Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The status for the logged in Client.
|
||||||
|
* @readonly
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
get status() {
|
||||||
|
return this.ws.status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The uptime for the logged in Client.
|
||||||
|
* @readonly
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
get uptime() {
|
||||||
|
return this.readyTime ? Date.now() - this.readyTime : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a Collection, mapping Guild ID to Voice Connections.
|
||||||
|
* @readonly
|
||||||
|
* @type {Collection<string, VoiceConnection>}
|
||||||
|
*/
|
||||||
|
get voiceConnections() {
|
||||||
|
return this.voice.connections;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The emojis that the client can use. Mapped by emoji ID.
|
||||||
|
* @type {Collection<string, Emoji>}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
get emojis() {
|
||||||
|
const emojis = new Collection();
|
||||||
|
this.guilds.map(g => g.emojis.map(e => emojis.set(e.id, e)));
|
||||||
|
return emojis;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Logs the client in. If successful, resolves with the account's token. <warn>If you're making a bot, it's
|
* Logs the client in. If successful, resolves with the account's token. <warn>If you're making a bot, it's
|
||||||
* much better to use a bot account rather than a user account.
|
* much better to use a bot account rather than a user account.
|
||||||
@@ -184,44 +243,6 @@ class Client extends EventEmitter {
|
|||||||
return this.rest.methods.getInvite(code);
|
return this.rest.methods.getInvite(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a Collection, mapping Guild ID to Voice Connections.
|
|
||||||
* @readonly
|
|
||||||
* @type {Collection<string, VoiceConnection>}
|
|
||||||
*/
|
|
||||||
get voiceConnections() {
|
|
||||||
return this.voice.connections;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The uptime for the logged in Client.
|
|
||||||
* @readonly
|
|
||||||
* @type {?number}
|
|
||||||
*/
|
|
||||||
get uptime() {
|
|
||||||
return this.readyTime ? Date.now() - this.readyTime : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The emojis that the client can use. Mapped by emoji ID.
|
|
||||||
* @type {Collection<string, Emoji>}
|
|
||||||
* @readonly
|
|
||||||
*/
|
|
||||||
get emojis() {
|
|
||||||
const emojis = new Collection();
|
|
||||||
this.guilds.map(g => g.emojis.map(e => emojis.set(e.id, e)));
|
|
||||||
return emojis;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The status for the logged in Client.
|
|
||||||
* @readonly
|
|
||||||
* @type {?number}
|
|
||||||
*/
|
|
||||||
get status() {
|
|
||||||
return this.ws.status;
|
|
||||||
}
|
|
||||||
|
|
||||||
setTimeout(fn, ...params) {
|
setTimeout(fn, ...params) {
|
||||||
const timeout = setTimeout(() => {
|
const timeout = setTimeout(() => {
|
||||||
fn();
|
fn();
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class ClientManager {
|
|||||||
* @type {Client}
|
* @type {Client}
|
||||||
*/
|
*/
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The heartbeat interval, null if not yet set
|
* The heartbeat interval, null if not yet set
|
||||||
* @type {?number}
|
* @type {?number}
|
||||||
|
|||||||
@@ -13,9 +13,15 @@ class RESTMethods {
|
|||||||
this.rest = restManager;
|
this.rest = restManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loginToken(token) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.rest.client.manager.connectToWebSocket(token, resolve, reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
loginEmailPassword(email, password) {
|
loginEmailPassword(email, password) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.client.emit('debug', 'Client launched using email and password - should use token instead');
|
this.rest.client.emit('warn', 'Client launched using email and password - should use token instead');
|
||||||
this.rest.client.email = email;
|
this.rest.client.email = email;
|
||||||
this.rest.client.password = password;
|
this.rest.client.password = password;
|
||||||
this.rest.makeRequest('post', Constants.Endpoints.login, false, { email, password })
|
this.rest.makeRequest('post', Constants.Endpoints.login, false, { email, password })
|
||||||
@@ -26,12 +32,6 @@ class RESTMethods {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loginToken(token) {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
this.rest.client.manager.connectToWebSocket(token, resolve, reject);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
logout() {
|
logout() {
|
||||||
return this.rest.makeRequest('post', Constants.Endpoints.logout, true);
|
return this.rest.makeRequest('post', Constants.Endpoints.logout, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
const RequestHandler = require('./RequestHandler');
|
const RequestHandler = require('./RequestHandler');
|
||||||
|
|
||||||
class BurstRequestHandler extends RequestHandler {
|
class BurstRequestHandler extends RequestHandler {
|
||||||
|
|
||||||
constructor(restManager, endpoint) {
|
constructor(restManager, endpoint) {
|
||||||
super(restManager, endpoint);
|
super(restManager, endpoint);
|
||||||
this.requestRemaining = 1;
|
this.requestRemaining = 1;
|
||||||
@@ -58,7 +57,6 @@ class BurstRequestHandler extends RequestHandler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
handle() {
|
handle() {
|
||||||
super.handle();
|
super.handle();
|
||||||
if (this.requestRemaining < 1 || this.queue.length === 0 || this.globalLimit) return;
|
if (this.requestRemaining < 1 || this.queue.length === 0 || this.globalLimit) return;
|
||||||
@@ -67,7 +65,6 @@ class BurstRequestHandler extends RequestHandler {
|
|||||||
this.requestRemaining--;
|
this.requestRemaining--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = BurstRequestHandler;
|
module.exports = BurstRequestHandler;
|
||||||
|
|||||||
@@ -14,36 +14,43 @@ class WebSocketManager {
|
|||||||
* @type {Client}
|
* @type {Client}
|
||||||
*/
|
*/
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A WebSocket Packet manager, it handles all the messages
|
* A WebSocket Packet manager, it handles all the messages
|
||||||
* @type {PacketManager}
|
* @type {PacketManager}
|
||||||
*/
|
*/
|
||||||
this.packetManager = new PacketManager(this);
|
this.packetManager = new PacketManager(this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The status of the WebSocketManager, a type of Constants.Status. It defaults to IDLE.
|
* The status of the WebSocketManager, a type of Constants.Status. It defaults to IDLE.
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.status = Constants.Status.IDLE;
|
this.status = Constants.Status.IDLE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The session ID of the connection, null if not yet available.
|
* The session ID of the connection, null if not yet available.
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.sessionID = null;
|
this.sessionID = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The packet count of the client, null if not yet available.
|
* The packet count of the client, null if not yet available.
|
||||||
* @type {?number}
|
* @type {?number}
|
||||||
*/
|
*/
|
||||||
this.sequence = -1;
|
this.sequence = -1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The gateway address for this WebSocket connection, null if not yet available.
|
* The gateway address for this WebSocket connection, null if not yet available.
|
||||||
* @type {?string}
|
* @type {?string}
|
||||||
*/
|
*/
|
||||||
this.gateway = null;
|
this.gateway = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether READY was emitted normally (all packets received) or not
|
* Whether READY was emitted normally (all packets received) or not
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
this.normalReady = false;
|
this.normalReady = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The WebSocket connection to the gateway
|
* The WebSocket connection to the gateway
|
||||||
* @type {?WebSocket}
|
* @type {?WebSocket}
|
||||||
@@ -197,9 +204,7 @@ class WebSocketManager {
|
|||||||
* @event Client#error
|
* @event Client#error
|
||||||
* @param {Error} error The encountered error
|
* @param {Error} error The encountered error
|
||||||
*/
|
*/
|
||||||
if (this.client.listenerCount('error') > 0) {
|
if (this.client.listenerCount('error') > 0) this.client.emit('error', err);
|
||||||
this.client.emit('error', err);
|
|
||||||
}
|
|
||||||
this.tryReconnect();
|
this.tryReconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,11 +15,13 @@ class Shard {
|
|||||||
* @type {ShardingManager}
|
* @type {ShardingManager}
|
||||||
*/
|
*/
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The shard ID
|
* The shard ID
|
||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The process of the shard
|
* The process of the shard
|
||||||
* @type {ChildProcess}
|
* @type {ChildProcess}
|
||||||
|
|||||||
Reference in New Issue
Block a user