fix(rate-limits): reactions buckets need to be shared with sub-… (#3439)

This commit is contained in:
bdistin
2019-09-10 10:29:44 -05:00
committed by Crawl
parent 8dec251d3c
commit 278f185b64

View File

@@ -13,13 +13,18 @@ function buildRoute(manager) {
get(target, name) {
if (reflectors.includes(name)) return () => route.join('/');
if (methods.includes(name)) {
const routeBucket = [];
for (let i = 0; i < route.length; i++) {
// Reactions routes and sub-routes all share the same bucket
if (route[i - 1] === 'reactions') break;
// Literal IDs should only be taken account if they are the Major ID (the Channel/Guild ID)
if (/\d{16,19}/g.test(route[i]) && !/channels|guilds/.test(route[i - 1])) routeBucket.push(':id');
// All other parts of the route should be considered as part of the bucket identifier
else routeBucket.push(route[i]);
}
return options => manager.request(name, route.join('/'), Object.assign({
versioned: manager.versioned,
route: route.map((r, i) => {
if (/\d{16,19}/g.test(r)) return /channels|guilds/.test(route[i - 1]) ? r : ':id';
if (route[i - 1] === 'reactions') return ':reaction';
return r;
}).join('/'),
route: routeBucket.join('/'),
}, options));
}
route.push(name);