From b0fb50622147a60c3d2f03062bf52bb466d8a0e3 Mon Sep 17 00:00:00 2001 From: hydrabolt Date: Sat, 15 Aug 2015 14:02:42 +0100 Subject: [PATCH] Now includes getter functions to limit the amount of filters required --- index.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index e683d1ad9..b2422757e 100644 --- a/index.js +++ b/index.js @@ -25,6 +25,7 @@ exports.isUserID = function( id ) { exports.Client = function( options ) { this.options = options || {}; + this.options.maxmessage = 5000; this.token = ""; this.loggedIn = false; this.websocket = null; @@ -36,6 +37,23 @@ 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! @@ -113,7 +131,7 @@ exports.Client.prototype.cacheServer = function( id, cb, members ) { 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); + cacheChannels( dat.channels ); else channelsFromHTTP(); } @@ -263,7 +281,7 @@ exports.Client.prototype.connectWebsocket = function( cb ) { if ( !client.serverList.filter( "id", dat.d.id, true ) ) { client.cacheServer( dat.d, function( server ) { client.triggerEvent( "serverJoin", [ server ] ); - }); + } ); } } else if ( dat.t === "CHANNEL_CREATE" ) { @@ -414,7 +432,7 @@ exports.Client.prototype.startPM = function( user, message, cb, _mentions, optio var client = this; - cb = cb || function(){}; + cb = cb || function() {}; request .post( Endpoints.USERS + "/" + client.user.id + "/channels" )