mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
Moved to the internals to declutter main class
This commit is contained in:
@@ -11,6 +11,8 @@ Commands[ "info" ] = {
|
|||||||
var verbose = hasFlag( params, "verbose" ) || hasFlag( params, "v" );
|
var verbose = hasFlag( params, "verbose" ) || hasFlag( params, "v" );
|
||||||
var user = getUser( message, params );
|
var user = getUser( message, params );
|
||||||
|
|
||||||
|
console.log("INFO", params);
|
||||||
|
|
||||||
bot.reply( message, [
|
bot.reply( message, [
|
||||||
"here's some info on " + user.mention() + ":",
|
"here's some info on " + user.mention() + ":",
|
||||||
"In channel **#" + message.channel.name + "**" + ( verbose ? " - ID *" + message.channel.id + "*" : "" ), ( message.isPM() ?
|
"In channel **#" + message.channel.name + "**" + ( verbose ? " - ID *" + message.channel.id + "*" : "" ), ( message.isPM() ?
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ hydrabot.on( "disconnected", function( obj ) {
|
|||||||
hydrabot.on( "message", function( message ) {
|
hydrabot.on( "message", function( message ) {
|
||||||
|
|
||||||
// if the message doesn't begin with a valid command prefix exit
|
// if the message doesn't begin with a valid command prefix exit
|
||||||
|
|
||||||
if ( commandPrefixes.indexOf( message.content.charAt( 0 ) ) == -1 )
|
if ( commandPrefixes.indexOf( message.content.charAt( 0 ) ) == -1 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
734
index.js
734
index.js
@@ -8,6 +8,7 @@ var List = require( "./lib/list.js" ).List;
|
|||||||
var Invite = require( "./lib/invite.js" ).Invite;
|
var Invite = require( "./lib/invite.js" ).Invite;
|
||||||
var PMChannel = require( "./lib/PMChannel.js" ).PMChannel;
|
var PMChannel = require( "./lib/PMChannel.js" ).PMChannel;
|
||||||
var WebSocket = require( 'ws' );
|
var WebSocket = require( 'ws' );
|
||||||
|
var Internal = require( "./lib/internal.js" ).Internal;
|
||||||
|
|
||||||
exports.Endpoints = Endpoints;
|
exports.Endpoints = Endpoints;
|
||||||
exports.Server = Server;
|
exports.Server = Server;
|
||||||
@@ -33,6 +34,45 @@ exports.Client = function( options ) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.getServers = function() {
|
||||||
|
return this.serverList;
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.getChannels = function() {
|
||||||
|
return this.serverList.concatSublists( "channels", "id" );
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.getServer = function( id ) {
|
||||||
|
return this.getServers().filter( "id", id, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.getChannel = function( id ) {
|
||||||
|
return this.getChannels().filter( "id", id, true );
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.triggerEvent = function( event, args ) {
|
||||||
|
|
||||||
|
if ( !this.ready && event !== "raw" && event !== "disconnected" ) { //if we're not even loaded yet, don't try doing anything because it always ends badly!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(this.events[event]);
|
||||||
|
if ( this.events[ event ] ) {
|
||||||
|
this.events[ event ].apply( this, args );
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.on = function( name, fn ) {
|
||||||
|
this.events[ name ] = fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.off = function( name ) {
|
||||||
|
this.events[ name ] = function() {};
|
||||||
|
}
|
||||||
|
|
||||||
exports.Client.prototype.cacheServer = function( id, cb, members ) {
|
exports.Client.prototype.cacheServer = function( id, cb, members ) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var serverInput = {};
|
var serverInput = {};
|
||||||
@@ -44,20 +84,11 @@ exports.Client.prototype.cacheServer = function( id, cb, members ) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
request
|
Internal.XHR.getServer(self.token, id, function(err, data){
|
||||||
.get( Endpoints.SERVERS + "/" + id )
|
if(!err){
|
||||||
.set( "authorization", self.token )
|
makeServer( data );
|
||||||
.end( function( err, res ) {
|
}
|
||||||
|
})
|
||||||
if ( err ) {
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
var dat = res.body;
|
|
||||||
|
|
||||||
makeServer( dat );
|
|
||||||
|
|
||||||
} );
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// got objects because SPEEEDDDD
|
// got objects because SPEEEDDDD
|
||||||
@@ -72,15 +103,10 @@ exports.Client.prototype.cacheServer = function( id, cb, members ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function channelsFromHTTP() {
|
function channelsFromHTTP() {
|
||||||
request
|
Internal.XHR.getChannel(self.token, id, function(err){
|
||||||
.get( Endpoints.SERVERS + "/" + id + "/channels" )
|
if(!err)
|
||||||
.set( "authorization", self.token )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
if ( err )
|
|
||||||
throw err;
|
|
||||||
|
|
||||||
cacheChannels( res.body );
|
cacheChannels( res.body );
|
||||||
} );
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var server;
|
var server;
|
||||||
@@ -109,29 +135,22 @@ exports.Client.prototype.cacheServer = function( id, cb, members ) {
|
|||||||
|
|
||||||
exports.Client.prototype.login = function( email, password ) {
|
exports.Client.prototype.login = function( email, password ) {
|
||||||
|
|
||||||
var client = this;
|
var self = this;
|
||||||
|
|
||||||
var details = {
|
Internal.XHR.login( email, password, function( err, token ) {
|
||||||
email: email,
|
|
||||||
password: password
|
|
||||||
};
|
|
||||||
|
|
||||||
request
|
if ( err ) {
|
||||||
.post( Endpoints.LOGIN )
|
self.triggerEvent( "disconnected", [ {
|
||||||
.send( details )
|
reason: "failed to log in",
|
||||||
.end( function( err, res ) {
|
error: err
|
||||||
if ( err ) {
|
} ] );
|
||||||
client.triggerEvent( "disconnected", [ {
|
} else {
|
||||||
reason: "failed to log in",
|
self.token = token;
|
||||||
error: err
|
self.loggedIn = true;
|
||||||
} ] );
|
self.connectWebsocket();
|
||||||
} else {
|
}
|
||||||
client.token = res.body.token;
|
|
||||||
client.loggedIn = true;
|
|
||||||
client.connectWebsocket();
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
|
|
||||||
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.reply = function() {
|
exports.Client.prototype.reply = function() {
|
||||||
@@ -148,18 +167,18 @@ exports.Client.prototype.reply = function() {
|
|||||||
|
|
||||||
exports.Client.prototype.connectWebsocket = function( cb ) {
|
exports.Client.prototype.connectWebsocket = function( cb ) {
|
||||||
|
|
||||||
var client = this;
|
var self = this;
|
||||||
|
|
||||||
this.websocket = new WebSocket( Endpoints.WEBSOCKET_HUB );
|
this.websocket = new WebSocket( Endpoints.WEBSOCKET_HUB );
|
||||||
this.websocket.onclose = function( e ) {
|
this.websocket.onclose = function( e ) {
|
||||||
client.triggerEvent( "disconnected", [ {
|
self.triggerEvent( "disconnected", [ {
|
||||||
reason: "websocket disconnected",
|
reason: "websocket disconnected",
|
||||||
error: e
|
error: e
|
||||||
} ] );
|
} ] );
|
||||||
};
|
};
|
||||||
this.websocket.onmessage = function( e ) {
|
this.websocket.onmessage = function( e ) {
|
||||||
|
|
||||||
client.triggerEvent( "raw", [ e ] );
|
self.triggerEvent( "raw", [ e ] );
|
||||||
|
|
||||||
var dat = JSON.parse( e.data );
|
var dat = JSON.parse( e.data );
|
||||||
switch ( dat.op ) {
|
switch ( dat.op ) {
|
||||||
@@ -169,12 +188,12 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
|
|
||||||
var data = dat.d;
|
var data = dat.d;
|
||||||
|
|
||||||
self = this;
|
webself = this;
|
||||||
setInterval( function() {
|
setInterval( function() {
|
||||||
self.keepAlive.apply( self );
|
webself.keepAlive.apply( self );
|
||||||
}, data.heartbeat_interval );
|
}, data.heartbeat_interval );
|
||||||
|
|
||||||
client.user = new User( data.user );
|
self.user = new User( data.user );
|
||||||
|
|
||||||
var _servers = data.guilds,
|
var _servers = data.guilds,
|
||||||
servers = [];
|
servers = [];
|
||||||
@@ -185,65 +204,64 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
for ( x in _servers ) {
|
for ( x in _servers ) {
|
||||||
_server = _servers[ x ];
|
_server = _servers[ x ];
|
||||||
|
|
||||||
client.cacheServer( _server, function( server ) {
|
self.cacheServer( _server, function( server ) {
|
||||||
cached++;
|
cached++;
|
||||||
if ( cached >= toCache ) {
|
if ( cached >= toCache ) {
|
||||||
client.ready = true;
|
self.ready = true;
|
||||||
client.triggerEvent( "ready" );
|
self.triggerEvent( "ready" );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( x in data.private_channels ) {
|
for ( x in data.private_channels ) {
|
||||||
client.PMList.add( new PMChannel( data.private_channels[ x ].recipient, data.private_channels[ x ].id ) );
|
self.PMList.add( new PMChannel( data.private_channels[ x ].recipient, data.private_channels[ x ].id ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ( dat.t === "MESSAGE_CREATE" ) {
|
} else if ( dat.t === "MESSAGE_CREATE" ) {
|
||||||
var data = dat.d;
|
var data = dat.d;
|
||||||
|
|
||||||
var channel = client.channelFromId( data.channel_id );
|
var channel = self.getChannel( data.channel_id );
|
||||||
|
|
||||||
var message = new Message( data, channel );
|
var message = new Message( data, channel );
|
||||||
|
|
||||||
client.triggerEvent( "message", [ message ] );
|
self.triggerEvent( "message", [ message ] );
|
||||||
|
|
||||||
} else if ( dat.t === "PRESENCE_UPDATE" ) {
|
} else if ( dat.t === "PRESENCE_UPDATE" ) {
|
||||||
|
|
||||||
var data = dat.d;
|
var data = dat.d;
|
||||||
|
|
||||||
client.triggerEvent( "presence", [ new User( data.user ), data.status, client.serverList.filter( "id", data.guild_id, true ) ] );
|
self.triggerEvent( "presence", [ new User( data.user ), data.status, self.serverList.filter( "id", data.guild_id, true ) ] );
|
||||||
|
|
||||||
} else if ( dat.t === "GUILD_DELETE" ) {
|
} else if ( dat.t === "GUILD_DELETE" ) {
|
||||||
|
|
||||||
var deletedServer = client.serverList.filter( "id", dat.d.id, true );
|
var deletedServer = self.serverList.filter( "id", dat.d.id, true );
|
||||||
|
|
||||||
if ( deletedServer ) {
|
if ( deletedServer ) {
|
||||||
client.triggerEvent( "serverDelete", [ deletedServer ] );
|
self.triggerEvent( "serverDelete", [ deletedServer ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ( dat.t === "CHANNEL_DELETE" ) {
|
} else if ( dat.t === "CHANNEL_DELETE" ) {
|
||||||
|
|
||||||
var delServer = client.serverList.filter( "id", dat.d.guild_id, true );
|
var delServer = self.serverList.filter( "id", dat.d.guild_id, true );
|
||||||
|
|
||||||
if ( delServer ) {
|
if ( delServer ) {
|
||||||
var channel = delServer.channels.filter( "id", dat.d.id, true );
|
var channel = delServer.channels.filter( "id", dat.d.id, true );
|
||||||
|
|
||||||
if ( channel ) {
|
if ( channel ) {
|
||||||
client.triggerEvent( "channelDelete", [ channel ] );
|
self.triggerEvent( "channelDelete", [ channel ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ( dat.t === "GUILD_CREATE" ) {
|
} else if ( dat.t === "GUILD_CREATE" ) {
|
||||||
|
|
||||||
if ( !client.serverList.filter( "id", dat.d.id, true ) ) {
|
if ( !self.serverList.filter( "id", dat.d.id, true ) ) {
|
||||||
client.cacheServer( dat.d, function( server ) {
|
self.cacheServer( dat.d, function( server ) {
|
||||||
client.triggerEvent( "serverJoin", [ server ] );
|
self.triggerEvent( "serverJoin", [ server ] );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ( dat.t === "CHANNEL_CREATE" ) {
|
} else if ( dat.t === "CHANNEL_CREATE" ) {
|
||||||
|
|
||||||
var srv = client.serverList.filter( "id", dat.d.guild_id, true );
|
var srv = self.serverList.filter( "id", dat.d.guild_id, true );
|
||||||
|
|
||||||
if ( srv ) {
|
if ( srv ) {
|
||||||
|
|
||||||
@@ -252,7 +270,7 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
var chann = new Channel( dat.d, srv );
|
var chann = new Channel( dat.d, srv );
|
||||||
|
|
||||||
srv.channels.add( new Channel( dat.d, srv ) );
|
srv.channels.add( new Channel( dat.d, srv ) );
|
||||||
client.triggerEvent( "channelCreate", [ chann ] );
|
self.triggerEvent( "channelCreate", [ chann ] );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,85 +301,76 @@ exports.Client.prototype.connectWebsocket = function( cb ) {
|
|||||||
var connDat = {
|
var connDat = {
|
||||||
op: 2,
|
op: 2,
|
||||||
d: {
|
d: {
|
||||||
token: client.token,
|
token: self.token,
|
||||||
v: 2
|
v: 2
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
connDat.d.properties = {
|
connDat.d.properties = Internal.WebSocket.properties;
|
||||||
"$os": "discord.js",
|
|
||||||
"$browser": "discord.js",
|
|
||||||
"$device": "discord.js",
|
|
||||||
"$referrer": "",
|
|
||||||
"$referring_domain": ""
|
|
||||||
};
|
|
||||||
|
|
||||||
this.sendPacket( connDat );
|
this.sendPacket( connDat );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.logout = function() {
|
exports.Client.prototype.logout = function( callback ) {
|
||||||
|
|
||||||
var client = this;
|
var self = this;
|
||||||
|
|
||||||
request
|
Internal.XHR.logout( self.token, function( err ) {
|
||||||
.post( Endpoints.LOGOUT )
|
callback( err ); //if there isn't an error it'll be null anyway so...
|
||||||
.end( function() {
|
self.loggedIn = Boolean( err );
|
||||||
client.loggedIn = false;
|
} );
|
||||||
} );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.createServer = function( _name, _region, cb ) {
|
exports.Client.prototype.createServer = function( name, region, cb ) {
|
||||||
|
|
||||||
var client = this;
|
var self = this;
|
||||||
|
|
||||||
var details = {
|
Internal.XHR.createServer( self.token, name, region, function( err, data ) {
|
||||||
name: _name,
|
|
||||||
region: _region
|
|
||||||
};
|
|
||||||
|
|
||||||
request
|
if ( err ) {
|
||||||
.post( Endpoints.SERVERS )
|
cb( err );
|
||||||
.set( "authorization", client.token )
|
} else {
|
||||||
.send( details )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
if ( err ) {
|
|
||||||
cb( err );
|
|
||||||
} else {
|
|
||||||
client.cacheServer( res.body.id, function( server ) {
|
|
||||||
|
|
||||||
cb( null, server );
|
self.cacheServer( data, function( server ) {
|
||||||
|
cb( null, server );
|
||||||
|
} );
|
||||||
|
|
||||||
} );
|
}
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.leaveServer = function( server, cb ) {
|
exports.Client.prototype.leaveServer = function( server, callback ) {
|
||||||
|
|
||||||
var client = this;
|
var self = this;
|
||||||
|
|
||||||
request
|
// callback is not necessary for this function
|
||||||
.del( Endpoints.SERVERS + "/" + server.id )
|
callback = callback || function() {};
|
||||||
.set( "authorization", client.token )
|
|
||||||
.end( function( err, res ) {
|
Internal.XHR.leaveServer( self.token, server.id, function( err ) {
|
||||||
if ( err ) {
|
|
||||||
cb( err );
|
if ( err ) {
|
||||||
} else {
|
callback( err );
|
||||||
client.serverList.removeElement( server );
|
} else {
|
||||||
cb( null );
|
self.serverList.removeElement( server );
|
||||||
}
|
callback( null );
|
||||||
} );
|
}
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.createInvite = function( channel, options, cb ) {
|
exports.Client.prototype.createInvite = function( channel, options, callback ) {
|
||||||
|
|
||||||
var client = this;
|
var self = this;
|
||||||
var options = options || {};
|
var options = options || {};
|
||||||
|
|
||||||
|
// callback is not necessary for this function
|
||||||
|
callback = callback || function() {};
|
||||||
|
|
||||||
if ( channel instanceof Server ) {
|
if ( channel instanceof Server ) {
|
||||||
channel = channel.getDefaultChannel();
|
channel = channel.getDefaultChannel();
|
||||||
}
|
}
|
||||||
@@ -371,308 +380,215 @@ exports.Client.prototype.createInvite = function( channel, options, cb ) {
|
|||||||
options.temporary = options.temporary || false;
|
options.temporary = options.temporary || false;
|
||||||
options.xkcdpass = options.xkcd || false;
|
options.xkcdpass = options.xkcd || false;
|
||||||
|
|
||||||
request
|
Internal.XHR.createInvite( self.token, channel.id, options, function( err, data ) {
|
||||||
.post( Endpoints.CHANNELS + "/" + channel.id + "/invites" )
|
|
||||||
.set( "authorization", client.token )
|
|
||||||
.send( options )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
if ( err ) {
|
|
||||||
cb( err );
|
|
||||||
} else {
|
|
||||||
cb( false, new Invite( res.body ) );
|
|
||||||
}
|
|
||||||
} )
|
|
||||||
|
|
||||||
}
|
if ( err ) {
|
||||||
|
callback( err );
|
||||||
exports.Client.prototype.startPM = function( user, message, cb, _mentions, options ) {
|
} else {
|
||||||
|
callback( null, new Invite( data ) );
|
||||||
var client = this;
|
|
||||||
|
|
||||||
cb = cb || function() {};
|
|
||||||
|
|
||||||
request
|
|
||||||
.post( Endpoints.USERS + "/" + client.user.id + "/channels" )
|
|
||||||
.set( "authorization", client.token )
|
|
||||||
.send( {
|
|
||||||
recipient_id: user.id
|
|
||||||
} )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
if ( err ) {
|
|
||||||
cb( err );
|
|
||||||
} else {
|
|
||||||
client.PMList.add( new PMChannel( res.body.recipient, res.body.id ) );
|
|
||||||
client.sendMessage( user, message, cb, _mentions, options );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Client.prototype.editMessage = function( originalMessage, newContent, cb, _mentions ){
|
|
||||||
|
|
||||||
if ( _mentions === false ) {
|
|
||||||
//mentions is false, explicitly don't want to mention someone
|
|
||||||
_mentions = [];
|
|
||||||
} else if ( _mentions === true || _mentions === "auto" || _mentions == null || _mentions == undefined ) {
|
|
||||||
//want to auto sort mentions
|
|
||||||
_mentions = [];
|
|
||||||
var mentionsArray = message.match( /<@[^>]*>/g ) || [];
|
|
||||||
for ( mention of mentionsArray ) {
|
|
||||||
_mentions.push( mention.substring( 2, mention.length - 1 ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if ( _mentions instanceof Array ) {
|
} );
|
||||||
//specific mentions
|
|
||||||
for ( mention in _mentions ) {
|
|
||||||
_mentions[ mention ] = _mentions[ mention ].id;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
request
|
|
||||||
.patch( Endpoints.CHANNELS + "/" + originalMessage.channel.id + "/messages/" + originalMessage.id )
|
|
||||||
.set( "authorization", client.token )
|
|
||||||
.send( {} )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
|
|
||||||
if ( err ) {
|
|
||||||
cb( err );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg = new Message( res.body, client.channelFromId( res.body.channel_id ) );
|
|
||||||
if ( options.selfDestruct ) {
|
|
||||||
setTimeout( function() {
|
|
||||||
client.deleteMessage( msg );
|
|
||||||
}, options.selfDestruct );
|
|
||||||
}
|
|
||||||
cb( null, msg );
|
|
||||||
} );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.sendMessage = function( channel, message, cb, _mentions, options ) {
|
exports.Client.prototype.startPM = function( user, callback ) {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
callback = callback || function() {};
|
||||||
|
|
||||||
|
Internal.XHR.startPM( self.token, self.user.id, user.id, function( err, data ) {
|
||||||
|
|
||||||
|
if ( err ) {
|
||||||
|
callback( err );
|
||||||
|
} else {
|
||||||
|
var channel = new PMChannel( data.recipient, data.id );
|
||||||
|
self.PMList.add( channel );
|
||||||
|
callback( null, channel );
|
||||||
|
}
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.sendMessage = function( destination, toSend, callback, options ) {
|
||||||
|
|
||||||
options = options || {};
|
options = options || {};
|
||||||
|
callback = callback || function() {};
|
||||||
|
|
||||||
if ( message instanceof Array ) {
|
var channel_id, message, mentions, self = this;
|
||||||
message = message.join( "\n" );
|
|
||||||
|
channel_id = resolveChannel( destination, self );
|
||||||
|
message = resolveMessage( toSend );
|
||||||
|
mentions = resolveMentions( message, options.mention );
|
||||||
|
|
||||||
|
if ( channel_id ) {
|
||||||
|
sendMessage();
|
||||||
|
} else {
|
||||||
|
//a channel is being sorted
|
||||||
}
|
}
|
||||||
|
|
||||||
var thisLoopId = Math.floor( Math.random() * 1000 );
|
function sendMessage() {
|
||||||
|
Internal.XHR.sendMessage( self.token, channel_id, {
|
||||||
|
content: message,
|
||||||
|
mentions: mentions
|
||||||
|
}, function( err, data ) {
|
||||||
|
if ( err ) {
|
||||||
|
callback( err );
|
||||||
|
} else {
|
||||||
|
var msg = new Message( data, self.channelFromId( data.channel_id ) );
|
||||||
|
if ( options.selfDestruct ) {
|
||||||
|
setTimeout( function() {
|
||||||
|
self.deleteMessage( msg );
|
||||||
|
}, options.selfDestruct );
|
||||||
|
}
|
||||||
|
callback( null, msg );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
if ( channel instanceof User ) {
|
function setChannId( id ) {
|
||||||
if ( !this.PMList.deepFilter( [ "user", "id" ], channel.id, true ) ) {
|
channel_id = id;
|
||||||
//user does not exist! omgomgomg
|
}
|
||||||
this.startPM( channel, message, cb, _mentions, options, true );
|
|
||||||
return;
|
function resolveChannel( destination, self ) {
|
||||||
|
var channel_id = false;
|
||||||
|
if ( destination instanceof Server ) {
|
||||||
|
channel_id = destination.getDefaultChannel().id;
|
||||||
|
} else if ( destination instanceof Channel ) {
|
||||||
|
channel_id = destination.id;
|
||||||
|
} else if ( destination instanceof PMChannel ) {
|
||||||
|
channel_id = destination.id;
|
||||||
|
} else if ( destination instanceof Message ) {
|
||||||
|
channel_id = destination.channel.id;
|
||||||
|
} else if ( destination instanceof User ) {
|
||||||
|
var destId = self.PMList.deepFilter( [ "user", "id" ], destination.id, true );
|
||||||
|
if ( destId ) {
|
||||||
|
channel_id = destId;
|
||||||
|
} else {
|
||||||
|
//start a PM and then get that use that
|
||||||
|
self.startPM( destination, function( err, channel ) {
|
||||||
|
if ( err ) {
|
||||||
|
callback( err );
|
||||||
|
} else {
|
||||||
|
setChannId( channel.id );
|
||||||
|
sendMessage();
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
channel.id = this.PMList.deepFilter( [ "user", "id" ], channel.id, true ).id;
|
channel_id = destination;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return channel_id;
|
||||||
|
|
||||||
if ( channel instanceof Message ) { //if the channel is actually a message, get the channel
|
function resolveMessage( toSend ) {
|
||||||
channel = channel.channel;
|
var message;
|
||||||
|
if ( typeof toSend === "string" || toSend instanceof String )
|
||||||
|
message = toSend;
|
||||||
|
else if ( toSend instanceof Array )
|
||||||
|
message = toSend.join( "\n" );
|
||||||
|
else if ( toSend instanceof Message )
|
||||||
|
message = toSend.content;
|
||||||
|
else
|
||||||
|
message = toSend;
|
||||||
|
return message.substring( 0, 2000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( typeof channel === 'string' || channel instanceof String || !isNaN( channel ) ) {
|
function resolveMentions( message, mentionsOpt ) {
|
||||||
//Channel is an ID
|
var mentions = [];
|
||||||
var chanId = channel;
|
if ( mentionsOpt === false ) {} else if ( mentionsOpt || mentionsOpt === "auto" || mentionsOpt == null || mentionsOpt == undefined ) {
|
||||||
channel = {
|
for ( mention of( message.match( /<@[^>]*>/g ) || [] ) ) {
|
||||||
id: chanId
|
mentions.push( mention.substring( 2, mention.length - 1 ) );
|
||||||
|
}
|
||||||
|
} else if ( mentionsOpt instanceof Array ) {
|
||||||
|
for ( mention of mentionsOpt ) {
|
||||||
|
if ( mention instanceof User ) {
|
||||||
|
mentions.push( mention.id );
|
||||||
|
} else {
|
||||||
|
mentions.push( mention );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return mentions;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var cb = cb || function() {};
|
exports.Client.prototype.deleteMessage = function( message, callback ) {
|
||||||
|
callback = callback || function() {};
|
||||||
|
|
||||||
_mentions = createMentions(_mentions, message);
|
var self = this;
|
||||||
|
|
||||||
var client = this;
|
Internal.XHR.deleteMessage( self.token, message.channel.id, message.id, callback );
|
||||||
var details = {
|
}
|
||||||
content: message.substring( 0, 2000 ),
|
|
||||||
mentions: _mentions || []
|
|
||||||
};
|
|
||||||
|
|
||||||
request
|
exports.Client.prototype.getChannelLogs = function( channel, amount, callback ) {
|
||||||
.post( Endpoints.CHANNELS + "/" + channel.id + "/messages" )
|
var self = this;
|
||||||
.set( "authorization", client.token )
|
|
||||||
.send( details )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
|
|
||||||
if ( err ) {
|
Internal.XHR.getChannelLogs( self.token, message.channel.id, ( amount || 50 ), function( err, data ) {
|
||||||
cb( err );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var msg = new Message( res.body, client.channelFromId( res.body.channel_id ) );
|
var logs = new List( "id" );
|
||||||
if ( options.selfDestruct ) {
|
for ( message of data ) {
|
||||||
setTimeout( function() {
|
logs.add( new Message( message, channel ) );
|
||||||
client.deleteMessage( msg );
|
}
|
||||||
}, options.selfDestruct );
|
callback( null, logs );
|
||||||
}
|
|
||||||
cb( null, msg );
|
} );
|
||||||
} );
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.createChannel = function( server, name, type, callback ) {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
Internal.XHR.createChannel( self.token, server.id, name, type, function( err, data ) {
|
||||||
|
|
||||||
|
if ( err ) {
|
||||||
|
callback( err );
|
||||||
|
} else {
|
||||||
|
var chann = new Channel( data, server );
|
||||||
|
server.channels.add( chann );
|
||||||
|
callback( null, chann );
|
||||||
|
}
|
||||||
|
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.deleteChannel = function( channel, callback ) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
Internal.XHR.deleteChannel( self.token, channel.id, function( err ) {
|
||||||
|
|
||||||
|
channel.server.channels.removeElement( channel );
|
||||||
|
self.triggerEvent( "channelDelete", [ channel ] );
|
||||||
|
callback( null );
|
||||||
|
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Client.prototype.deleteServer = function( server, callback ) {
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
Internal.XHR.deleteServer( self.token, server.id, function( err ) {
|
||||||
|
|
||||||
|
self.serverList.removeElement( server );
|
||||||
|
self.triggerEvent( "serverDelete", [ server ] );
|
||||||
|
callback( null );
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.deleteMessage = function( message, cb ) {
|
/**
|
||||||
|
UTILS
|
||||||
if ( !message )
|
UTILS
|
||||||
return false;
|
UTILS
|
||||||
|
did I mention UTILS?
|
||||||
var client = this;
|
|
||||||
|
|
||||||
request
|
|
||||||
.del( Endpoints.CHANNELS + "/" + message.channel.id + "/messages/" + message.id )
|
|
||||||
.set( "authorization", client.token )
|
|
||||||
.end( cb );
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Client.prototype.getChannelLogs = function( channel, amount, cb ) {
|
|
||||||
amount = amount || 0;
|
|
||||||
var client = this;
|
|
||||||
|
|
||||||
request
|
|
||||||
.get( Endpoints.CHANNELS + "/" + channel.id + "/messages?limit=" + amount )
|
|
||||||
.set( "authorization", client.token )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
|
|
||||||
if ( err ) {
|
|
||||||
cb( err );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var datList = new List( "id" );
|
|
||||||
|
|
||||||
for ( item of res.body ) {
|
|
||||||
datList.add( new Message( item, channel ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
cb( null, datList );
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Client.prototype.createChannel = function( server, serverName, serverType, cb ) {
|
|
||||||
|
|
||||||
var client = this;
|
|
||||||
|
|
||||||
request
|
|
||||||
.post( Endpoints.SERVERS + "/" + server.id + "/channels" )
|
|
||||||
.set( "authorization", client.token )
|
|
||||||
.send( {
|
|
||||||
name: serverName,
|
|
||||||
type: serverType
|
|
||||||
} )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
if ( err ) {
|
|
||||||
cb( err );
|
|
||||||
} else {
|
|
||||||
var chann = new Channel( res.body, server );
|
|
||||||
client.serverList.filter( "id", server.id, true ).channels.add( chann );
|
|
||||||
cb( null, chann );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Client.prototype.deleteChannel = function( channel, cb ) {
|
|
||||||
|
|
||||||
var client = this;
|
|
||||||
|
|
||||||
request
|
|
||||||
.del( Endpoints.CHANNELS + "/" + channel.id )
|
|
||||||
.set( "authorization", client.token )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
if ( err ) {
|
|
||||||
cb( err );
|
|
||||||
} else {
|
|
||||||
|
|
||||||
client.serverList.filter( "id", channel.server.id, true ).channels.removeElement( channel );
|
|
||||||
|
|
||||||
client.triggerEvent( "channelDelete", [ channel ] );
|
|
||||||
|
|
||||||
cb( null );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Client.prototype.deleteServer = function( server, cb ) {
|
|
||||||
|
|
||||||
var client = this;
|
|
||||||
|
|
||||||
request
|
|
||||||
.del( Endpoints.SERVERS + "/" + server.id )
|
|
||||||
.set( "authorization", client.token )
|
|
||||||
.end( function( err, res ) {
|
|
||||||
if ( err ) {
|
|
||||||
cb( err );
|
|
||||||
} else {
|
|
||||||
|
|
||||||
client.serverList.removeElement( server );
|
|
||||||
|
|
||||||
client.triggerEvent( "serverDelete", [ server ] );
|
|
||||||
|
|
||||||
cb( null );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
##############################################
|
|
||||||
UTILS
|
|
||||||
##############################################
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.isUserID = function( id ) {
|
|
||||||
return ( ( id + "" ).length === 17 && !isNaN( id ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Client.prototype.channelFromId = function( id ) {
|
|
||||||
var channelList = this.serverList.concatSublists( "channels", "id" );
|
|
||||||
var channel = channelList.filter( "id", id, true );
|
|
||||||
|
|
||||||
if ( !channel ) {
|
|
||||||
|
|
||||||
channel = this.PMList.filter( "id", id, true );
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Client.prototype.getServers = function() {
|
exports.Client.prototype.getServers = function() {
|
||||||
return this.serverList;
|
return this.serverList;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.getChannels = function() {
|
exports.Client.prototype.getChannels = function() {
|
||||||
@@ -695,50 +611,6 @@ exports.Client.prototype.getUser = function( id ) {
|
|||||||
return this.getUsers().filter( "id", id, true );
|
return this.getUsers().filter( "id", id, true );
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Client.prototype.triggerEvent = function( event, args ) {
|
exports.isUserID = function( id ) {
|
||||||
|
return ( ( id + "" ).length === 17 && !isNaN( id ) );
|
||||||
if ( !this.ready && event !== "raw" && event !== "disconnected" ) { //if we're not even loaded yet, don't try doing anything because it always ends badly!
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( this.events[ event ] ) {
|
|
||||||
this.events[ event ].apply( this, args );
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Client.prototype.on = function( name, fn ) {
|
|
||||||
this.events[ name ] = fn;
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.Client.prototype.off = function( name ) {
|
|
||||||
this.events[ name ] = function() {};
|
|
||||||
}
|
|
||||||
|
|
||||||
function createMentions(_mentions, message){
|
|
||||||
|
|
||||||
if ( _mentions === false ) {
|
|
||||||
//mentions is false, explicitly don't want to mention someone
|
|
||||||
return [];
|
|
||||||
} else if ( _mentions === true || _mentions === "auto" || _mentions == null || _mentions == undefined ) {
|
|
||||||
//want to auto sort mentions
|
|
||||||
_mentions = [];
|
|
||||||
var mentionsArray = message.match( /<@[^>]*>/g ) || [];
|
|
||||||
for ( mention of mentionsArray ) {
|
|
||||||
_mentions.push( mention.substring( 2, mention.length - 1 ) );
|
|
||||||
}
|
|
||||||
return mentionsArray;
|
|
||||||
|
|
||||||
} else if ( _mentions instanceof Array ) {
|
|
||||||
//specific mentions
|
|
||||||
for ( mention in _mentions ) {
|
|
||||||
_mentions[ mention ] = _mentions[ mention ].id;
|
|
||||||
}
|
|
||||||
return _mentions;
|
|
||||||
} else {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|||||||
213
lib/internal.js
Normal file
213
lib/internal.js
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
var request = require( "superagent" );
|
||||||
|
var Endpoints = require( "./endpoints.js" );
|
||||||
|
|
||||||
|
var Internal = {};
|
||||||
|
|
||||||
|
Internal.XHR = {};
|
||||||
|
Internal.WebSocket = {};
|
||||||
|
|
||||||
|
Internal.WebSocket.properties = {
|
||||||
|
"$os": "discord.js",
|
||||||
|
"$browser": "discord.js",
|
||||||
|
"$device": "discord.js",
|
||||||
|
"$referrer": "",
|
||||||
|
"$referring_domain": ""
|
||||||
|
};
|
||||||
|
|
||||||
|
Internal.XHR.login = function( email, password, callback ) {
|
||||||
|
|
||||||
|
request
|
||||||
|
.post( Endpoints.LOGIN )
|
||||||
|
.send( {
|
||||||
|
email: email,
|
||||||
|
password: password
|
||||||
|
} )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
if ( err ) {
|
||||||
|
callback( err );
|
||||||
|
} else {
|
||||||
|
callback( null, res.body.token );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.logout = function( token, callback ) {
|
||||||
|
|
||||||
|
request
|
||||||
|
.post( Endpoints.LOGOUT )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
|
||||||
|
err ? callback( err ) : callback( null );
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.createServer = function( token, name, region, callback ) {
|
||||||
|
|
||||||
|
request
|
||||||
|
.post( Endpoints.SERVERS )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.send( {
|
||||||
|
name: name,
|
||||||
|
region: region
|
||||||
|
} )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
if ( err ) {
|
||||||
|
callback( err );
|
||||||
|
} else {
|
||||||
|
callback( null, res.body );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.leaveServer = function( token, serverId, callback ) {
|
||||||
|
|
||||||
|
request
|
||||||
|
.del( Endpoints.SERVERS + "/" + serverId )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
|
||||||
|
err ? callback( err ) : callback( null );
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.createInvite = function( token, channelId, options, callback ) {
|
||||||
|
request
|
||||||
|
.post( Endpoints.CHANNELS + "/" + channelId + "/invites" )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.send( options )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
if ( err ) {
|
||||||
|
cb( err );
|
||||||
|
} else {
|
||||||
|
cb( null, res.body );
|
||||||
|
}
|
||||||
|
} )
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.startPM = function( token, selfID, userID, callback ) {
|
||||||
|
|
||||||
|
request
|
||||||
|
.post( Endpoints.USERS + "/" + selfID + "/channels" )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.send( {
|
||||||
|
recipient_id: userID
|
||||||
|
} )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
if ( err ) {
|
||||||
|
callback( err );
|
||||||
|
} else {
|
||||||
|
callback( null, res.body );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.sendMessage = function( token, channelID, messageParameters, callback ) {
|
||||||
|
request
|
||||||
|
.post( Endpoints.CHANNELS + "/" + channelID + "/messages" )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.send( messageParameters )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
|
||||||
|
if ( err ) {
|
||||||
|
callback( err );
|
||||||
|
} else {
|
||||||
|
callback( null, res.body );
|
||||||
|
}
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.deleteMessage = function( token, channelID, messageID, callback ) {
|
||||||
|
request
|
||||||
|
.del( Endpoints.CHANNELS + "/" + channelID + "/messages/" + messageID )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.end( function( err ) {
|
||||||
|
err ? callback( err ) : callback( null );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.getChannelLogs = function( token, channelID, amount, callback ) {
|
||||||
|
request
|
||||||
|
.get( Endpoints.CHANNELS + "/" + channelID + "/messages?limit=" + amount )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
|
||||||
|
if ( err ) {
|
||||||
|
cb( err );
|
||||||
|
} else {
|
||||||
|
cb( null, res.body );
|
||||||
|
}
|
||||||
|
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.createChannel = function( token, serverID, name, type, callback ) {
|
||||||
|
request
|
||||||
|
.post( Endpoints.SERVERS + "/" + serverID + "/channels" )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.send( {
|
||||||
|
name: name,
|
||||||
|
type: type
|
||||||
|
} )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
if ( err ) {
|
||||||
|
cb( err );
|
||||||
|
} else {
|
||||||
|
cb( null, res.body );
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.deleteChannel = function( token, channelID, callback ) {
|
||||||
|
|
||||||
|
request
|
||||||
|
.del( Endpoints.CHANNELS + "/" + channelID )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.end( function( err ) {
|
||||||
|
err ? callback( err ) : callback( null );
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
Internal.XHR.deleteServer = function( token, serverID, callback ) {
|
||||||
|
request
|
||||||
|
.del( Endpoints.SERVERS + "/" + serverID )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.end( function( err ) {
|
||||||
|
err ? callback( err ) : callback( null );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.getChannels = function( token, serverID, callback ) {
|
||||||
|
request
|
||||||
|
.get( Endpoints.SERVERS + "/" + serverID + "/channels" )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.end( function( err ) {
|
||||||
|
err ? callback( err ) : callback( null );
|
||||||
|
} );
|
||||||
|
}
|
||||||
|
|
||||||
|
Internal.XHR.getServer = function( token, serverID, callback ) {
|
||||||
|
|
||||||
|
request
|
||||||
|
.get( Endpoints.SERVERS + "/" + serverID )
|
||||||
|
.set( "authorization", token )
|
||||||
|
.end( function( err, res ) {
|
||||||
|
|
||||||
|
if ( err ) {
|
||||||
|
cb( err );
|
||||||
|
} else {
|
||||||
|
cb( null, res.body );
|
||||||
|
}
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Internal = Internal;
|
||||||
Reference in New Issue
Block a user