diff --git a/lib/index.js b/lib/index.js index 96ed7446..d5188304 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1628,6 +1628,14 @@ function getOfflineUsers(client, servArr, callback) { setTimeout( getOfflineUsers, 0, client, servArr, callback ); } +function checkForAllServers(client, ready, message) { + var all = Object.keys(client.servers).every(function(s) { + return !client.servers[s].unavailable; + }); + if (all || ready[0]) return client.emit('ready', message); + setTimeout(checkForAllServers, 0, client, ready, message); +} + /* - Functions - Websocket Handling - */ function handleWSOpen(opts) { var ident = { @@ -1699,25 +1707,9 @@ function handleWSMessage(opts, data, flags) { }); return (function() { - var ready = false; - var t = setTimeout(function() { - ready = true; - client.emit('ready', message); - }, 3500); - checkForAllServers(); - - function checkForAllServers() { - if (ready) return; - if ( - Object.keys(client.servers).every(function(s) { - return !client.servers[s].unavailable; - }) - ) { - clearTimeout(t); - return client.emit('ready', message); - } - setTimeout(checkForAllServers, 0); - } + var ready = [false]; + setTimeout(function() { ready[0] = true; }, 3500); + checkForAllServers(client, ready, message); })(); case "MESSAGE_CREATE": client.emit('message', _data.author.username, _data.author.id, _data.channel_id, _data.content, message); @@ -2692,12 +2684,12 @@ function Websocket(url, opts) { API: API, ME: ME, - NOTE: function(userID) { + NOTE: function(userID) { return ME + "/notes/" + userID; }, - LOGIN: API + "/auth/login", + LOGIN: API + "/auth/login", OAUTH: API + "/oauth2/applications/@me", - GATEWAY: API + "/gateway", + GATEWAY: API + "/gateway", SETTINGS: ME + "/settings", SERVERS: function(serverID) {