mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
fix(APIRequest): group reaction requests into one route per channel (#4017)
* fix(APIRequest): group all reactions into the same route per channel * refactor(APIRequest): make route a const
This commit is contained in:
@@ -15,13 +15,17 @@ class APIRequest {
|
||||
}
|
||||
|
||||
getRoute(url) {
|
||||
let route = url.split('?')[0];
|
||||
if (route.includes('/channels/') || route.includes('/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);
|
||||
const route = url.split('?')[0].split('/');
|
||||
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 route;
|
||||
return routeBucket.join('/');
|
||||
}
|
||||
|
||||
getAuth() {
|
||||
|
||||
Reference in New Issue
Block a user