discord.js
Advanced tools
Comparing version 2.2.2 to 2.3.0
160
index.js
@@ -12,2 +12,15 @@ var request = require( "superagent" ); | ||
exports.Endpoints = Endpoints; | ||
exports.Server = Server; | ||
exports.Message = Message; | ||
exports.User = User; | ||
exports.Channel = Channel; | ||
exports.List = List; | ||
exports.Invite = Invite; | ||
exports.PMChannel = PMChannel; | ||
exports.isUserID = function( id ) { | ||
return ( ( id + "" ).length === 17 && !isNaN( id ) ); | ||
} | ||
exports.Client = function( options ) { | ||
@@ -29,3 +42,3 @@ | ||
if ( !this.ready ) { //if we're not even loaded yet, don't try doing anything because it always ends badly! | ||
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; | ||
@@ -51,32 +64,73 @@ } | ||
exports.Client.prototype.cacheServer = function( id, cb, members ) { | ||
var self = this; | ||
var serverInput = {}; | ||
if ( this.serverList.filter( "id", id ).length > 0 ) { | ||
return; | ||
if ( typeof id === 'string' || id instanceof String ) { | ||
//actually an ID | ||
if ( this.serverList.filter( "id", id ).length > 0 ) { | ||
return; | ||
} | ||
request | ||
.get( Endpoints.SERVERS + "/" + id ) | ||
.set( "authorization", self.token ) | ||
.end( function( err, res ) { | ||
if ( err ) { | ||
throw err; | ||
} | ||
var dat = res.body; | ||
makeServer( dat ); | ||
} ); | ||
} else { | ||
// got objects because SPEEEDDDD | ||
if ( this.serverList.filter( "id", id.id ).length > 0 ) { | ||
return; | ||
} | ||
serverInput = id; | ||
id = id.id; | ||
makeServer( serverInput ); | ||
} | ||
var self = this; | ||
function channelsFromHTTP() { | ||
request | ||
.get( Endpoints.SERVERS + "/" + id + "/channels" ) | ||
.set( "authorization", self.token ) | ||
.end( function( err, res ) { | ||
if ( err ) | ||
throw err; | ||
request | ||
.get( Endpoints.SERVERS + "/" + id ) | ||
.set( "authorization", this.token ) | ||
.end( function( err, res ) { | ||
var dat = res.body; | ||
var server = new Server( dat.region, dat.owner_id, dat.name, dat.roles[ 0 ].id, members || dat.members ); | ||
cacheChannels( res.body ); | ||
} ); | ||
} | ||
request | ||
.get( Endpoints.SERVERS + "/" + id + "/channels" ) | ||
.set( "authorization", self.token ) | ||
.end( function( err, res ) { | ||
var server; | ||
var channelList = res.body; | ||
for ( channel of channelList ) { | ||
server.channels.add( new Channel( channel, server ) ); | ||
} | ||
function makeServer( dat ) { | ||
server = new Server( dat.region, dat.owner_id, dat.name, id, serverInput.members || dat.members, dat.icon, dat.afk_timeout, dat.afk_channel_id ); | ||
if ( dat.channels ) | ||
cacheChannels(dat.channels); | ||
else | ||
channelsFromHTTP(); | ||
} | ||
self.serverList.add( server ); | ||
function cacheChannels( dat ) { | ||
cb( server ); | ||
} ); | ||
} ); | ||
var channelList = dat; | ||
for ( channel of channelList ) { | ||
server.channels.add( new Channel( channel, server ) ); | ||
} | ||
self.serverList.add( server ); | ||
cb( server ); | ||
} | ||
} | ||
@@ -97,3 +151,3 @@ | ||
.end( function( err, res ) { | ||
if ( !res.ok ) { | ||
if ( err ) { | ||
client.triggerEvent( "disconnected", [ { | ||
@@ -112,2 +166,14 @@ reason: "failed to log in", | ||
exports.Client.prototype.reply = function() { | ||
if ( arguments[ 1 ] instanceof Array ) { | ||
arguments[ 1 ] = arguments[ 1 ].join( "\n" ); | ||
} | ||
arguments[ 1 ] = arguments[ 0 ].author.mention() + ", " + arguments[ 1 ]; | ||
this.sendMessage.apply( this, arguments ); | ||
} | ||
exports.Client.prototype.connectWebsocket = function( cb ) { | ||
@@ -150,11 +216,3 @@ | ||
var sID = ""; | ||
for ( role of _server.roles ) { | ||
if ( role.name === "@everyone" ) { | ||
sID = role.id; | ||
break; | ||
} | ||
} | ||
client.cacheServer( sID, function( server ) { | ||
client.cacheServer( _server, function( server ) { | ||
cached++; | ||
@@ -165,3 +223,3 @@ if ( cached >= toCache ) { | ||
} | ||
}, _server.members ); | ||
} ); | ||
} | ||
@@ -212,5 +270,5 @@ | ||
if ( !client.serverList.filter( "id", dat.d.id, true ) ) { | ||
client.cacheServer( dat.d.id, function( server ) { | ||
client.cacheServer( dat.d, function( server ) { | ||
client.triggerEvent( "serverJoin", [ server ] ); | ||
}, dat.d.members ); | ||
}); | ||
} | ||
@@ -303,3 +361,3 @@ | ||
.end( function( err, res ) { | ||
if ( !res.ok ) { | ||
if ( err ) { | ||
cb( err ); | ||
@@ -325,3 +383,3 @@ } else { | ||
.end( function( err, res ) { | ||
if ( !res.ok ) { | ||
if ( err ) { | ||
cb( err ); | ||
@@ -355,3 +413,3 @@ } else { | ||
.end( function( err, res ) { | ||
if ( !res.ok ) { | ||
if ( err ) { | ||
cb( err ); | ||
@@ -376,3 +434,3 @@ } else { | ||
.end( function( err, res ) { | ||
if ( !res.ok ) { | ||
if ( err ) { | ||
cb( err ); | ||
@@ -391,2 +449,6 @@ } else { | ||
if ( message instanceof Array ) { | ||
message = message.join( "\n" ); | ||
} | ||
var thisLoopId = Math.floor( Math.random() * 1000 ); | ||
@@ -424,3 +486,3 @@ | ||
_mentions = []; | ||
var mentionsArray = message.match( /<[^>]*>/g ) || []; | ||
var mentionsArray = message.match( /<@[^>]*>/g ) || []; | ||
for ( mention of mentionsArray ) { | ||
@@ -467,3 +529,3 @@ _mentions.push( mention.substring( 2, mention.length - 1 ) ); | ||
exports.Client.prototype.deleteMessage = function( message ) { | ||
exports.Client.prototype.deleteMessage = function( message, cb ) { | ||
@@ -478,3 +540,3 @@ if ( !message ) | ||
.set( "authorization", client.token ) | ||
.end( function( err, res ) {} ); | ||
.end( cb ); | ||
} | ||
@@ -486,2 +548,8 @@ | ||
if ( !channel ) { | ||
channel = this.PMList.filter( "id", id, true ); | ||
} | ||
return channel; | ||
@@ -499,3 +567,3 @@ } | ||
if ( !res.ok ) { | ||
if ( err ) { | ||
cb( err ); | ||
@@ -527,3 +595,3 @@ return; | ||
.end( function( err, res ) { | ||
if ( !res.ok ) { | ||
if ( err ) { | ||
cb( err ); | ||
@@ -546,3 +614,3 @@ } else { | ||
.end( function( err, res ) { | ||
if ( !res.ok ) { | ||
if ( err ) { | ||
cb( err ); | ||
@@ -569,3 +637,3 @@ } else { | ||
.end( function( err, res ) { | ||
if ( !res.ok ) { | ||
if ( err ) { | ||
cb( err ); | ||
@@ -572,0 +640,0 @@ } else { |
var User = require( "./user.js" ).User; | ||
var List = require( "./list.js" ).List; | ||
var PMChannel = require( "./PMChannel.js" ).PMChannel; | ||
@@ -30,4 +31,8 @@ exports.Message = function( time, author, content, channel, id, mentions, everyoneMentioned ) { | ||
exports.Message.prototype.isPM = function() { | ||
return ( this.channel instanceof PMChannel ); | ||
} | ||
exports.Message.prototype.isMentioned = function( user ) { | ||
return ( this.mentions.filter( "id", user.id ).length > 0 ); | ||
} |
var User = require( "./user.js" ).User; | ||
var List = require( "./list.js" ).List; | ||
exports.Server = function( region, ownerID, name, id, members ) { | ||
exports.Server = function( region, ownerID, name, id, members, icon, afkTimeout, afkChannelId ) { | ||
@@ -11,2 +11,5 @@ this.region = region; | ||
this.channels = new List( "id" ); | ||
this.icon = icon; | ||
this.afkTimeout = afkTimeout; | ||
this.afkChannelId = afkChannelId; | ||
@@ -17,5 +20,20 @@ for ( x in members ) { | ||
} | ||
} | ||
exports.Server.prototype.getIconURL = function(){ | ||
if(!this.icon) | ||
return false; | ||
return "https://discordapp.com/api/guilds/"+this.id+"/icons/"+this.icon+".jpg"; | ||
} | ||
exports.Server.prototype.getAFKChannel = function(){ | ||
if(!this.afkChannelId) | ||
return false; | ||
return this.channels.filter("id", this.afkChannelId, true); | ||
} | ||
exports.Server.prototype.getDefaultChannel = function() { | ||
@@ -22,0 +40,0 @@ |
@@ -17,2 +17,8 @@ exports.User = function(username, id, discriminator, avatar){ | ||
exports.User.prototype.getAvatarURL = function(){ | ||
if(!this.avatar) | ||
return false; | ||
return "https://discordapp.com/api/users/" + this.id + "/avatars/" + this.avatar + ".jpg"; | ||
} | ||
exports.User.prototype.mention = function(){ | ||
@@ -19,0 +25,0 @@ return "<@"+this.id+">"; |
{ | ||
"name": "discord.js", | ||
"version": "2.2.2", | ||
"version": "2.3.0", | ||
"description": "A way to interface with the Discord API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55261
24
1186
1