Properly reference server IDs when ratelimiting

This commit is contained in:
abalabahaha
2016-07-29 08:06:41 +09:00
parent 95db1d611b
commit 34f71eaba1
2 changed files with 10 additions and 10 deletions

View File

@@ -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)
};