mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 16:43:31 +01:00
crappy ratelimiting it doesnt work but its here ok
This commit is contained in:
43
src/client/rest/APIRequest.js
Normal file
43
src/client/rest/APIRequest.js
Normal file
@@ -0,0 +1,43 @@
|
||||
const request = require('superagent');
|
||||
const Constants = require('../../util/Constants');
|
||||
|
||||
class APIRequest {
|
||||
constructor(rest, method, url, auth, data, file) {
|
||||
this.rest = rest;
|
||||
this.method = method;
|
||||
this.url = url;
|
||||
this.auth = auth;
|
||||
this.data = data;
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
getBucketName() {
|
||||
return `${this.method} ${this.url}`;
|
||||
}
|
||||
|
||||
getAuth() {
|
||||
if (this.rest.client.store.token && this.rest.client.store.user && this.rest.client.store.user.bot) {
|
||||
return `Bot ${this.rest.client.store.token}`;
|
||||
} else if (this.rest.client.store.token) {
|
||||
return this.rest.client.store.token;
|
||||
}
|
||||
throw Constants.Errors.NO_TOKEN;
|
||||
}
|
||||
|
||||
gen() {
|
||||
const apiRequest = request[this.method](this.url);
|
||||
if (this.auth) {
|
||||
apiRequest.set('authorization', this.getAuth());
|
||||
}
|
||||
if (this.data) {
|
||||
apiRequest.send(this.data);
|
||||
}
|
||||
if (this.file) {
|
||||
apiRequest.attach('file', this.file.file, this.file.name);
|
||||
}
|
||||
apiRequest.set('User-Agent', this.rest.userAgentManager.userAgent);
|
||||
return apiRequest;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = APIRequest;
|
||||
Reference in New Issue
Block a user