diff --git a/src/client/rest/APIRequest.js b/src/client/rest/APIRequest.js index 67491900d..40eb0aba8 100644 --- a/src/client/rest/APIRequest.js +++ b/src/client/rest/APIRequest.js @@ -4,7 +4,7 @@ const Constants = require('../../util/Constants'); function getRoute(url) { let route = url.split('?')[0]; if (route.includes('/channels/') || route.includes('/guilds/')) { - const startInd = ~route.indexOf('/channels/') ? route.indexOf('/channels/') : route.indexOf('/guilds/'); + const startInd = route.includes('/channels/') ? route.indexOf('/channels/') : route.indexOf('/guilds/'); const majorID = route.substring(startInd).split('/')[2]; route = route.replace(/(\d{8,})/g, ':id').replace(':id', majorID); } @@ -37,11 +37,7 @@ class APIRequest { if (this.file && this.file.file) { apiRequest.attach('file', this.file.file, this.file.name); this.data = this.data || {}; - for (const key in this.data) { - if (this.data[key]) { - apiRequest.field(key, this.data[key]); - } - } + for (const key in this.data) if (this.data[key]) apiRequest.field(key, this.data[key]); } else if (this.data) { apiRequest.send(this.data); } diff --git a/src/client/websocket/WebSocketManager.js b/src/client/websocket/WebSocketManager.js index 462e77c3b..04772cf41 100644 --- a/src/client/websocket/WebSocketManager.js +++ b/src/client/websocket/WebSocketManager.js @@ -105,7 +105,11 @@ class WebSocketManager extends EventEmitter { this.ws.onclose = this.eventClose.bind(this); this.ws.onerror = this.eventError.bind(this); this._queue = []; - this._remaining = 3; + this._remaining = 120; + this.client.setInterval(() => { + this._remaining = 120; + this._remainingReset = Date.now(); + }, 60e3); } connect(gateway) { @@ -147,17 +151,15 @@ class WebSocketManager extends EventEmitter { doQueue() { const item = this._queue[0]; - if (this.ws.readyState === WebSocket.OPEN && item) { - if (this._remaining === 0) { - this.client.setTimeout(this.doQueue.bind(this), 1000); - return; - } - this._remaining--; - this._send(item); - this._queue.shift(); - this.doQueue(); - this.client.setTimeout(() => this._remaining++, 1000); + if (!(this.ws.readyState === WebSocket.OPEN && item)) return; + if (this.remaining === 0) { + this.client.setTimeout(this.doQueue.bind(this), Date.now() - this.remainingReset); + return; } + this._remaining--; + this._send(item); + this._queue.shift(); + this.doQueue(); } /** diff --git a/src/structures/Webhook.js b/src/structures/Webhook.js index 56f9046b5..96984ffe0 100644 --- a/src/structures/Webhook.js +++ b/src/structures/Webhook.js @@ -102,7 +102,7 @@ class Webhook { * 'color': '#F0F', * 'footer_icon': 'http://snek.s3.amazonaws.com/topSnek.png', * 'footer': 'Powered by sneks', - * 'ts': new Date().getTime() / 1000 + * 'ts': Date.now() / 1000 * }] * }).catch(console.error); */