Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add super properties and context properties #1314

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/client/rest/APIRequest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const request = require('superagent');
const Constants = require('../../util/Constants');
const os = require('os');
const version = require('../../../package').version;

class APIRequest {
constructor(rest, method, url, auth, data, files) {
Expand Down Expand Up @@ -31,9 +33,30 @@ class APIRequest {
throw new Error(Constants.Errors.NO_TOKEN);
}

getCtx(ctx) {
return new Buffer(JSON.stringify({
location: ctx,
})).toString('base64'));
}

getSuper() {
const super = {
os: os.type(),
browser: 'DiscordJS',
client_version: version,
os_version: os.release(),
};
if (super.os === 'Windows_NT') super.os = 'Windows';
return new Buffer(JSON.stringify(super)).toString('base64'));
}

gen() {
const apiRequest = request[this.method](this.url);
if (this.auth) apiRequest.set('authorization', this.getAuth());
if (!this.getAuth().startsWith('Bot')) {
apiRequest.set('x-super-properties', this.getSuper());
if (this.ctx) apiRequest.set('x-context-properties', this.getCtx(this.ctx));
}
if (this.files) {
for (const file of this.files) if (file && file.file) apiRequest.attach(file.name, file.file, file.name);
this.data = this.data || {};
Expand Down