mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-20 21:43:33 +01:00
Switched to VSCode, reformatted
This commit is contained in:
13
index.js
13
index.js
@@ -11,7 +11,8 @@ var WebSocket = require( 'ws' );
|
||||
var Internal = require("./lib/internal.js").Internal;
|
||||
var TokenManager = require("./lib/TokenManager.js").TokenManager;
|
||||
|
||||
var serverCreateRequests = [], globalLoginTime = Date.now();
|
||||
var serverCreateRequests = [],
|
||||
globalLoginTime = Date.now();
|
||||
|
||||
function tp(time) {
|
||||
return Date.now() - time;
|
||||
@@ -42,15 +43,14 @@ exports.PMChannel = PMChannel;
|
||||
* @param {Number} [options.maxmessage=5000] The maximum amount of messages to be stored per channel.
|
||||
*/
|
||||
|
||||
exports.Client = function( options ) {
|
||||
exports.Client = function (shouldUseTokenManager) {
|
||||
|
||||
/**
|
||||
* Contains the options of the client
|
||||
* @attribute options
|
||||
* @type {Object}
|
||||
*/
|
||||
this.options = options || {};
|
||||
this.options.maxmessage = 5000;
|
||||
if (shouldUseTokenManager)
|
||||
this.tokenManager = new TokenManager("./", "tokencache.json");
|
||||
/**
|
||||
* Contains the token used to authorise HTTP requests and WebSocket connection. Received when login was successful.
|
||||
@@ -250,7 +250,7 @@ exports.Client.prototype.cacheServer = function( id, cb, members ) {
|
||||
function cacheChannels(dat) {
|
||||
|
||||
var channelList = dat;
|
||||
for ( channel of channelList ) {
|
||||
for (var channel of channelList) {
|
||||
server.channels.add(new Channel(channel, server));
|
||||
}
|
||||
self.serverList.add(server);
|
||||
@@ -288,6 +288,7 @@ exports.Client.prototype.login = function( email, password, callback, noCache )
|
||||
|
||||
self.connectWebsocket();
|
||||
|
||||
if (this.tokenManager) {
|
||||
if (this.tokenManager.exists(email) && !noCache) {
|
||||
|
||||
var token = this.tokenManager.getToken(email, password);
|
||||
@@ -299,7 +300,7 @@ exports.Client.prototype.login = function( email, password, callback, noCache )
|
||||
self.debug("error getting token from caches, using default auth");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
var time = Date.now();
|
||||
Internal.XHR.login(email, password, function (err, token) {
|
||||
if (err) {
|
||||
|
||||
Reference in New Issue
Block a user