summaryrefslogtreecommitdiff
path: root/node_modules/discord.js/src/rest/APIRouter.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/discord.js/src/rest/APIRouter.js')
-rw-r--r--node_modules/discord.js/src/rest/APIRouter.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/rest/APIRouter.js b/node_modules/discord.js/src/rest/APIRouter.js
new file mode 100644
index 0000000..e85c739
--- /dev/null
+++ b/node_modules/discord.js/src/rest/APIRouter.js
@@ -0,0 +1,53 @@
+'use strict';
+
+const noop = () => {}; // eslint-disable-line no-empty-function
+const methods = ['get', 'post', 'delete', 'patch', 'put'];
+const reflectors = [
+ 'toString',
+ 'valueOf',
+ 'inspect',
+ 'constructor',
+ Symbol.toPrimitive,
+ Symbol.for('nodejs.util.inspect.custom'),
+];
+
+function buildRoute(manager) {
+ const route = [''];
+ const handler = {
+ 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: routeBucket.join('/'),
+ },
+ options,
+ ),
+ );
+ }
+ route.push(name);
+ return new Proxy(noop, handler);
+ },
+ apply(target, _, args) {
+ route.push(...args.filter(x => x != null)); // eslint-disable-line eqeqeq
+ return new Proxy(noop, handler);
+ },
+ };
+ return new Proxy(noop, handler);
+}
+
+module.exports = buildRoute;