@antibot/interactions
Version:
## 🗡️ An interactions library made for Discord interactions
109 lines • 3.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RequestManager = void 0;
const cross_fetch_1 = __importDefault(require("cross-fetch"));
const typings_1 = require("./typings");
class RequestManager {
publicKey;
token;
api;
debug;
constructor(publicKey, token, api, debug) {
this.publicKey = publicKey;
this.token = token;
this.api = api;
this.debug = debug;
this.publicKey = publicKey;
this.token = token;
this.api = api;
this.debug = debug;
}
async GET(opts) {
(await this.request({
publicKey: opts.publicKey,
options: {
method: typings_1.METHOD.GET,
endpoint: opts.route,
contentType: opts.contentType,
},
data: opts.data,
}));
}
async POST(opts) {
(await this.request({
publicKey: opts.publicKey,
options: {
method: typings_1.METHOD.POST,
endpoint: opts.route,
contentType: opts.contentType,
},
data: opts.data,
}));
}
async PUT(opts) {
(await this.request({
publicKey: opts.publicKey,
options: {
method: typings_1.METHOD.PUT,
endpoint: opts.route,
contentType: opts.contentType,
},
data: opts.data,
}));
}
async PATCH(opts) {
(await this.request({
publicKey: opts.publicKey,
options: {
method: typings_1.METHOD.PATCH,
endpoint: opts.route,
contentType: opts.contentType,
},
data: opts.data,
}));
}
async DELETE(opts) {
(await this.request({
publicKey: opts.publicKey,
options: {
method: typings_1.METHOD.DELETE,
endpoint: opts.route,
contentType: opts.contentType,
},
data: opts.data,
}));
}
async request(opts) {
let request = {
method: opts.options.method,
headers: {
'Content-Type': opts.options.contentType,
'User-Agent': '@antibot/interactions',
Authorization: '',
},
body: JSON.stringify(opts.data),
};
request.headers.Authorization = opts.publicKey
? `Bearer ${this.publicKey}`
: `Bot ${this.token}`;
return new Promise(async (resolve, reject) => {
return await (0, cross_fetch_1.default)(this.api + opts.options.endpoint, request).then((x) => {
x.json()
.then((res) => {
if (this.debug) {
console.log(res);
}
return resolve(res);
})
.catch(() => {
resolve(null);
});
});
});
}
}
exports.RequestManager = RequestManager;
//# sourceMappingURL=RequestManager.js.map