From 34f71eaba1c17bc3b9dea4392ead7179bd0bdadc Mon Sep 17 00:00:00 2001 From: abalabahaha Date: Fri, 29 Jul 2016 08:06:41 +0900 Subject: [PATCH] Properly reference server IDs when ratelimiting --- lib/Client/InternalClient.js | 10 +++++----- src/Client/InternalClient.js | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Client/InternalClient.js b/lib/Client/InternalClient.js index 06d54c61f..b804f3811 100644 --- a/lib/Client/InternalClient.js +++ b/lib/Client/InternalClient.js @@ -131,14 +131,14 @@ var InternalClient = (function () { var buckets = []; var match = url.match(/\/channels\/([0-9]+)\/messages(\/[0-9]+)?$/); if (match) { - if (method === "del" && (match[1] = this.channels.get("id", match[1]))) { - buckets = ["dmsg:" + (match[1].server ? match[1].server.id : undefined)]; + if (method === "del" && (match[1] = this.channels.get("id", match[1]) || this.private_channels.get("id", match[1]))) { + buckets = ["dmsg:" + (match[1].server || {}).id]; } else if (this.user.bot) { if (method === "post" || method === "patch") { if (this.private_channels.get("id", match[1])) { buckets = ["bot:msg:dm", "bot:msg:global"]; } else if (match[1] = this.channels.get("id", match[1])) { - buckets = ["bot:msg:guild:" + match[1].id, "bot:msg:global"]; + buckets = ["bot:msg:guild:" + match[1].server.id, "bot:msg:global"]; } } } else { @@ -157,6 +157,7 @@ var InternalClient = (function () { var self = this; var actualCall = function actualCall() { + var startTime = Date.now(); var ret = _superagent2["default"][method](url); if (useAuth) { ret.set("authorization", self.token); @@ -177,7 +178,7 @@ var InternalClient = (function () { ret.end(function (error, data) { if (error) { if (data.status === 429) { - self.client.emit("debug", "Encountered 429 at " + url); + self.client.emit("debug", "Encountered 429 at " + url + " | " + self.client.options.shard + " | Buckets" + buckets + " | " + (Date.now() - startTime) + "ms latency"); } reject(error); } else { @@ -252,7 +253,6 @@ var InternalClient = (function () { this.buckets = { "bot:msg:dm": new _UtilBucket2["default"](5, 5000), "bot:msg:global": new _UtilBucket2["default"](50, 10000), - "dmsg:undefined": new _UtilBucket2["default"](5, 1000), "msg": new _UtilBucket2["default"](10, 10000), "username": new _UtilBucket2["default"](2, 3600000) }; diff --git a/src/Client/InternalClient.js b/src/Client/InternalClient.js index 66f0f4206..70fe6ffad 100755 --- a/src/Client/InternalClient.js +++ b/src/Client/InternalClient.js @@ -61,14 +61,14 @@ export default class InternalClient { var buckets = []; var match = url.match(/\/channels\/([0-9]+)\/messages(\/[0-9]+)?$/); if(match) { - if(method === "del" && (match[1] = this.channels.get("id", match[1]))) { - buckets = ["dmsg:" + (match[1].server ? match[1].server.id : undefined)]; + if(method === "del" && (match[1] = this.channels.get("id", match[1]) || this.private_channels.get("id", match[1]))) { + buckets = ["dmsg:" + (match[1].server || {}).id]; } else if(this.user.bot) { if(method === "post" || method === "patch") { if(this.private_channels.get("id", match[1])) { buckets = ["bot:msg:dm", "bot:msg:global"]; } else if((match[1] = this.channels.get("id", match[1]))) { - buckets = ["bot:msg:guild:" + match[1].id, "bot:msg:global"]; + buckets = ["bot:msg:guild:" + match[1].server.id, "bot:msg:global"]; } } } else { @@ -87,6 +87,7 @@ export default class InternalClient { var self = this; var actualCall = function() { + var startTime = Date.now(); var ret = request[method](url); if (useAuth) { ret.set("authorization", self.token); @@ -107,7 +108,7 @@ export default class InternalClient { ret.end((error, data) => { if (error) { if(data.status === 429) { - self.client.emit("debug", "Encountered 429 at " + url); + self.client.emit("debug", "Encountered 429 at " + url + " | " + self.client.options.shard + " | Buckets" + buckets + " | " + (Date.now() - startTime) + "ms latency"); } reject(error); } else { @@ -169,7 +170,6 @@ export default class InternalClient { this.buckets = { "bot:msg:dm": new Bucket(5, 5000), "bot:msg:global": new Bucket(50, 10000), - "dmsg:undefined": new Bucket(5, 1000), "msg": new Bucket(10, 10000), "username": new Bucket(2, 3600000) };