From b35763a0c94a764fe078f14b0d7307efc8c05c01 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Thu, 13 Aug 2015 21:46:47 +0100 Subject: [PATCH 1/5] 2.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 17aa6f7fd..8a3049b08 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "discord.js", - "version": "2.1.1", + "version": "2.2.0", "description": "A way to interface with the Discord API", "main": "index.js", "scripts": { From a7e9fcc2cd99a9e956cec662454a72cea9baf548 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Thu, 13 Aug 2015 22:45:16 +0100 Subject: [PATCH 2/5] getChannelLogs now returns actual error instead of empty List --- index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6518b1811..055c10dd6 100644 --- a/index.js +++ b/index.js @@ -462,8 +462,8 @@ exports.Client.prototype.getChannelLogs = function( channel, amount, cb ) { .set( "authorization", client.token ) .end( function( err, res ) { - if ( err ) { - cb( new List( "id" ) ); + if ( !res.ok ) { + cb( err ); return; } @@ -473,7 +473,7 @@ exports.Client.prototype.getChannelLogs = function( channel, amount, cb ) { datList.add( new Message( item, channel ) ); } - cb( datList ); + cb( null, datList ); } ); } From e1ada38234d7ce948e26a8346cdb45753a00de45 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Thu, 13 Aug 2015 23:17:20 +0100 Subject: [PATCH 3/5] sendMessage now also takes a Message instead of a Channel if wanted To help reduce verbosity --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 055c10dd6..adeac2579 100644 --- a/index.js +++ b/index.js @@ -383,6 +383,10 @@ exports.Client.prototype.sendMessage = function( channel, message, cb, _mentions } } + if( channel instanceof Message ){ + channel = channel.channel; + } + var cb = cb || function() {}; if ( _mentions === false ) { From 6589814789621734c0ebb0b3a087b9daf960f5df Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Thu, 13 Aug 2015 23:23:07 +0100 Subject: [PATCH 4/5] Beautify and sendMessage also takes channel IDs --- index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index adeac2579..91919648a 100644 --- a/index.js +++ b/index.js @@ -210,7 +210,7 @@ exports.Client.prototype.connectWebsocket = function( cb ) { if ( !srv.channels.filter( "id", dat.d.d, true ) ) { - var chann = new Channel(dat.d, srv); + var chann = new Channel( dat.d, srv ); srv.channels.add( new Channel( dat.d, srv ) ); client.triggerEvent( "channelCreate", [ chann ] ); @@ -383,10 +383,18 @@ exports.Client.prototype.sendMessage = function( channel, message, cb, _mentions } } - if( channel instanceof Message ){ + if ( channel instanceof Message ) { //if the channel is actually a message, get the channel channel = channel.channel; } + if ( typeof channel === 'string' || channel instanceof String || !isNaN( channel ) ) { + //Channel is an ID + var chanId = channel; + channel = { + id : chanId + } + } + var cb = cb || function() {}; if ( _mentions === false ) { From d3ae0ccb8ca7a9d68da174821586d1fdf0811b36 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Thu, 13 Aug 2015 23:28:30 +0100 Subject: [PATCH 5/5] Events are only received when the Client is ready for it Without this, any messages received during startup could cause crashes --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 91919648a..cf4c2abbc 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ exports.Client = function( options ) { this.websocket = null; this.events = {}; this.user = null; - + this.ready = false; this.serverList = new List( "id" ); this.PMList = new List( "id" ); @@ -25,6 +25,10 @@ exports.Client = function( options ) { exports.Client.prototype.triggerEvent = function( event, args ) { + if ( !this.ready ) { //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 { @@ -149,6 +153,7 @@ exports.Client.prototype.connectWebsocket = function( cb ) { client.cacheServer( sID, function( server ) { cached++; if ( cached >= toCache ) { + client.ready = true; client.triggerEvent( "ready" ); } }, _server.members ); @@ -391,7 +396,7 @@ exports.Client.prototype.sendMessage = function( channel, message, cb, _mentions //Channel is an ID var chanId = channel; channel = { - id : chanId + id: chanId } }