mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
added debugging
This commit is contained in:
@@ -24,6 +24,11 @@ var hydrabot = new Discord.Client();
|
||||
var commandPrefixes = [ "$", "£", "`" ];
|
||||
|
||||
// Log the client in using the auth details in config.json
|
||||
|
||||
hydrabot.on("debug", function(m){
|
||||
console.log("debug", m);
|
||||
})
|
||||
|
||||
console.time("hydrabotbenchmark");
|
||||
hydrabot.login( BotConfig.email, BotConfig.password );
|
||||
|
||||
|
||||
29
index.js
29
index.js
@@ -11,7 +11,11 @@ var WebSocket = require( 'ws' );
|
||||
var Internal = require( "./lib/internal.js" ).Internal;
|
||||
var TokenManager = require( "./lib/TokenManager.js" ).TokenManager;
|
||||
|
||||
var serverCreateRequests = [];
|
||||
var serverCreateRequests = []. globalLoginTime = Date.now();
|
||||
|
||||
function tp(time){
|
||||
return Date.now() - time;
|
||||
}
|
||||
|
||||
/**
|
||||
* The wrapper module for the Discord Client, also provides some helpful objects.
|
||||
@@ -262,6 +266,10 @@ exports.Client.prototype.cacheServer = function( id, cb, members ) {
|
||||
*/
|
||||
exports.Client.prototype.login = function( email, password, callback, noCache ) {
|
||||
|
||||
globalLoginTime = Date.now();
|
||||
|
||||
this.debug("login called at " + globalLoginTime);
|
||||
|
||||
var self = this;
|
||||
callback = callback || function() {};
|
||||
|
||||
@@ -273,6 +281,7 @@ exports.Client.prototype.login = function( email, password, callback, noCache )
|
||||
|
||||
if ( this.tokenManager.exists( email ) && !noCache ) {
|
||||
done( this.tokenManager.getToken( email, password ) );
|
||||
self.debug("loaded token from caches in "+tp(globalLoginTime));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -284,10 +293,12 @@ exports.Client.prototype.login = function( email, password, callback, noCache )
|
||||
error: err
|
||||
} ] );
|
||||
self.websocket.close();
|
||||
self.debug("failed to login in "+tp(globalLoginTime));
|
||||
} else {
|
||||
if ( !noCache ) {
|
||||
self.tokenManager.addToken( email, token, password );
|
||||
}
|
||||
self.debug("loaded token from auth servers in "+tp(globalLoginTime));
|
||||
done( token );
|
||||
}
|
||||
|
||||
@@ -349,11 +360,9 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
||||
case 0:
|
||||
if ( dat.t === "READY" ) {
|
||||
|
||||
var data = dat.d;
|
||||
self.debug("got ready packet");
|
||||
|
||||
setInterval( function() {
|
||||
webself.keepAlive.apply( webself );
|
||||
}, data.heartbeat_interval );
|
||||
var data = dat.d;
|
||||
|
||||
self.user = new User( data.user );
|
||||
|
||||
@@ -375,10 +384,15 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
||||
if ( cached === toCache ) {
|
||||
self.ready = true;
|
||||
self.triggerEvent( "ready" );
|
||||
self.debug("ready triggered");
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
setInterval( function() {
|
||||
webself.keepAlive.apply( webself );
|
||||
}, data.heartbeat_interval );
|
||||
|
||||
} else if ( dat.t === "MESSAGE_CREATE" ) {
|
||||
var data = dat.d;
|
||||
|
||||
@@ -516,6 +530,7 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
||||
}
|
||||
this.websocket.onopen = function() {
|
||||
|
||||
self.debug("websocket conn open");
|
||||
this.sendData( "onopen" );
|
||||
|
||||
}
|
||||
@@ -536,6 +551,10 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
||||
}
|
||||
}
|
||||
|
||||
exports.Client.prototype.debug = function(msg){
|
||||
this.triggerEvent("debug", ["[SL "+ tp(globalLoginTime) +"] " + msg]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs the current Client out of Discord and closes any connections.
|
||||
* @param {Function} callback Called after a response is obtained.
|
||||
|
||||
Reference in New Issue
Block a user