mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
@@ -240,7 +240,7 @@ Commands[ "avatar" ] = {
|
|||||||
oplevel: 0,
|
oplevel: 0,
|
||||||
fn: function( bot, params, message ) {
|
fn: function( bot, params, message ) {
|
||||||
|
|
||||||
var user = getUser( message, params );
|
var user = getUser( message, params, bot );
|
||||||
|
|
||||||
if ( !user.avatar ) {
|
if ( !user.avatar ) {
|
||||||
bot.sendMessage( message.channel, user.mention() + " does not have an avatar!" );
|
bot.sendMessage( message.channel, user.mention() + " does not have an avatar!" );
|
||||||
@@ -442,11 +442,15 @@ function setAuthLevel( user, level ) {
|
|||||||
Authority.setLevel( user, level );
|
Authority.setLevel( user, level );
|
||||||
}
|
}
|
||||||
|
|
||||||
function getUser( message, params ) {
|
function getUser( message, params, bot ) {
|
||||||
var usr = false;
|
var usr = false;
|
||||||
if ( !message.isPM() ) {
|
if ( !message.isPM() ) {
|
||||||
var wantedUser = getKey( params, "user", false ) || getKey( params, "u", false );
|
var wantedUser = getKey( params, "user", false ) || getKey( params, "u", false );
|
||||||
if ( wantedUser ) {
|
if ( wantedUser ) {
|
||||||
|
if(bot){
|
||||||
|
console.log(bot.getUsers().length());
|
||||||
|
return bot.getUsers().filter("username", wantedUser);
|
||||||
|
}
|
||||||
usr = message.channel.server.members.filter( Discord.isUserID( wantedUser ) ? "id" : "username", wantedUser, true );
|
usr = message.channel.server.members.filter( Discord.isUserID( wantedUser ) ? "id" : "username", wantedUser, true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ var hydrabot = new Discord.Client();
|
|||||||
var commandPrefixes = [ "$", "£", "`" ];
|
var commandPrefixes = [ "$", "£", "`" ];
|
||||||
|
|
||||||
// Log the client in using the auth details in config.json
|
// Log the client in using the auth details in config.json
|
||||||
|
|
||||||
|
hydrabot.on("debug", function(m){
|
||||||
|
console.log("debug", m);
|
||||||
|
})
|
||||||
|
|
||||||
console.time("hydrabotbenchmark");
|
console.time("hydrabotbenchmark");
|
||||||
hydrabot.login( BotConfig.email, BotConfig.password );
|
hydrabot.login( BotConfig.email, BotConfig.password );
|
||||||
|
|
||||||
|
|||||||
40
index.js
40
index.js
@@ -11,7 +11,11 @@ var WebSocket = require( 'ws' );
|
|||||||
var Internal = require( "./lib/internal.js" ).Internal;
|
var Internal = require( "./lib/internal.js" ).Internal;
|
||||||
var TokenManager = require( "./lib/TokenManager.js" ).TokenManager;
|
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.
|
* 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 ) {
|
exports.Client.prototype.login = function( email, password, callback, noCache ) {
|
||||||
|
|
||||||
|
globalLoginTime = Date.now();
|
||||||
|
|
||||||
|
this.debug("login called at " + globalLoginTime);
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
callback = callback || function() {};
|
callback = callback || function() {};
|
||||||
|
|
||||||
@@ -272,8 +280,15 @@ exports.Client.prototype.login = function( email, password, callback, noCache )
|
|||||||
self.connectWebsocket();
|
self.connectWebsocket();
|
||||||
|
|
||||||
if ( this.tokenManager.exists( email ) && !noCache ) {
|
if ( this.tokenManager.exists( email ) && !noCache ) {
|
||||||
done( this.tokenManager.getToken( email, password ) );
|
|
||||||
return;
|
var token = this.tokenManager.getToken( email, password );
|
||||||
|
if(!token.match(/[^\w.-]+/g)){
|
||||||
|
done( this.tokenManager.getToken( email, password ) );
|
||||||
|
self.debug("loaded token from caches in "+tp(globalLoginTime));
|
||||||
|
return;
|
||||||
|
}else{
|
||||||
|
self.debug("error getting token from caches, using default auth");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var time = Date.now();
|
var time = Date.now();
|
||||||
@@ -284,16 +299,19 @@ exports.Client.prototype.login = function( email, password, callback, noCache )
|
|||||||
error: err
|
error: err
|
||||||
} ] );
|
} ] );
|
||||||
self.websocket.close();
|
self.websocket.close();
|
||||||
|
self.debug("failed to login in "+tp(globalLoginTime));
|
||||||
} else {
|
} else {
|
||||||
if ( !noCache ) {
|
if ( !noCache ) {
|
||||||
self.tokenManager.addToken( email, token, password );
|
self.tokenManager.addToken( email, token, password );
|
||||||
}
|
}
|
||||||
|
self.debug("loaded token from auth servers in "+tp(globalLoginTime));
|
||||||
done( token );
|
done( token );
|
||||||
}
|
}
|
||||||
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
function done( token ) {
|
function done( token ) {
|
||||||
|
self.debug("using token " + token);
|
||||||
self.token = token;
|
self.token = token;
|
||||||
self.websocket.sendData();
|
self.websocket.sendData();
|
||||||
self.loggedIn = true;
|
self.loggedIn = true;
|
||||||
@@ -349,11 +367,9 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
case 0:
|
case 0:
|
||||||
if ( dat.t === "READY" ) {
|
if ( dat.t === "READY" ) {
|
||||||
|
|
||||||
var data = dat.d;
|
self.debug("got ready packet");
|
||||||
|
|
||||||
setInterval( function() {
|
var data = dat.d;
|
||||||
webself.keepAlive.apply( webself );
|
|
||||||
}, data.heartbeat_interval );
|
|
||||||
|
|
||||||
self.user = new User( data.user );
|
self.user = new User( data.user );
|
||||||
|
|
||||||
@@ -375,10 +391,15 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
if ( cached === toCache ) {
|
if ( cached === toCache ) {
|
||||||
self.ready = true;
|
self.ready = true;
|
||||||
self.triggerEvent( "ready" );
|
self.triggerEvent( "ready" );
|
||||||
|
self.debug("ready triggered");
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setInterval( function() {
|
||||||
|
webself.keepAlive.apply( webself );
|
||||||
|
}, data.heartbeat_interval );
|
||||||
|
|
||||||
} else if ( dat.t === "MESSAGE_CREATE" ) {
|
} else if ( dat.t === "MESSAGE_CREATE" ) {
|
||||||
var data = dat.d;
|
var data = dat.d;
|
||||||
|
|
||||||
@@ -516,6 +537,7 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
}
|
}
|
||||||
this.websocket.onopen = function() {
|
this.websocket.onopen = function() {
|
||||||
|
|
||||||
|
self.debug("websocket conn open");
|
||||||
this.sendData( "onopen" );
|
this.sendData( "onopen" );
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -536,6 +558,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.
|
* Logs the current Client out of Discord and closes any connections.
|
||||||
* @param {Function} callback Called after a response is obtained.
|
* @param {Function} callback Called after a response is obtained.
|
||||||
|
|||||||
@@ -14,11 +14,7 @@ exports.TokenManager = function( folder, file ) {
|
|||||||
var fd = fs.openSync( self.path, "wx" );
|
var fd = fs.openSync( self.path, "wx" );
|
||||||
self.writeTokens();
|
self.writeTokens();
|
||||||
} catch ( e ) {
|
} catch ( e ) {
|
||||||
if ( e.errno !== -4075 ) {
|
self.readTokens();
|
||||||
throw e;
|
|
||||||
} else {
|
|
||||||
self.readTokens();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js",
|
"name": "discord.js",
|
||||||
"version": "2.6.1",
|
"version": "2.6.2",
|
||||||
"description": "A way to interface with the Discord API",
|
"description": "A way to interface with the Discord API",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user