Move protocol version to a constant, and reorganise constants a bit

This commit is contained in:
Schuyler Cebulskie
2016-09-30 02:45:16 -04:00
parent cda31dd224
commit 543e814f8e
3 changed files with 24 additions and 26 deletions

File diff suppressed because one or more lines are too long

View File

@@ -40,7 +40,7 @@ class RESTMethods {
return new Promise((resolve, reject) => {
this.rest.makeRequest('get', Constants.Endpoints.gateway, true)
.then(res => {
this.rest.client.ws.gateway = `${res.url}/?encoding=json&v=${this.rest.client.options.protocolVersion}`;
this.rest.client.ws.gateway = `${res.url}/?encoding=json&v=${Constants.PROTOCOL_VERSION}`;
resolve(this.rest.client.ws.gateway);
})
.catch(reject);

View File

@@ -1,3 +1,5 @@
exports.Package = require('../../package.json');
/**
* Options for a Client.
* @typedef {Object} ClientOptions
@@ -10,7 +12,8 @@
* (in seconds, 0 for forever)
* @property {number} [messageSweepInterval=0] How frequently to remove messages from the cache that are older than
* the max message lifetime (in seconds, 0 for never)
* @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup
* @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as
* upon joining a guild
* @property {boolean} [disableEveryone=false] Default value for MessageOptions.disableEveryone
* @property {number} [restWsBridgeTimeout=5000] Maximum time permitted between REST responses and their
* corresponding websocket events
@@ -26,7 +29,6 @@ exports.DefaultOptions = {
fetchAllMembers: false,
disableEveryone: false,
restWsBridgeTimeout: 5000,
protocolVersion: 6,
/**
* Websocket options. These are left as snake_case to match the API.
@@ -47,23 +49,6 @@ exports.DefaultOptions = {
},
};
exports.Status = {
READY: 0,
CONNECTING: 1,
RECONNECTING: 2,
IDLE: 3,
NEARLY: 4,
};
exports.ChannelTypes = {
text: 0,
DM: 1,
voice: 2,
groupDM: 3,
};
exports.Package = require('../../package.json');
exports.Errors = {
NO_TOKEN: 'Request to use token, but token was unavailable to the client.',
NO_BOT_ACCOUNT: 'You ideally should be using a bot account!',
@@ -75,10 +60,10 @@ exports.Errors = {
INVALID_SHARD: 'Invalid shard settings were provided.',
};
const API = `https://discordapp.com/api/v${exports.DefaultOptions.protocolVersion}`;
const PROTOCOL_VERSION = exports.PROTOCOL_VERSION = 6;
const API = exports.API = `https://discordapp.com/api/v${PROTOCOL_VERSION}`;
const Endpoints = exports.Endpoints = {
// general endpoints
// general
login: `${API}/auth/login`,
logout: `${API}/auth/logout`,
gateway: `${API}/gateway`,
@@ -120,6 +105,21 @@ const Endpoints = exports.Endpoints = {
channelMessage: (channelID, messageID) => `${Endpoints.channelMessages(channelID)}/${messageID}`,
};
exports.Status = {
READY: 0,
CONNECTING: 1,
RECONNECTING: 2,
IDLE: 3,
NEARLY: 4,
};
exports.ChannelTypes = {
text: 0,
DM: 1,
voice: 2,
groupDM: 3,
};
exports.OPCodes = {
DISPATCH: 0,
HEARTBEAT: 1,
@@ -248,7 +248,5 @@ const PermissionFlags = exports.PermissionFlags = {
let _ALL_PERMISSIONS = 0;
for (const key in PermissionFlags) _ALL_PERMISSIONS |= PermissionFlags[key];
exports.ALL_PERMISSIONS = _ALL_PERMISSIONS;
exports.DEFAULT_PERMISSIONS = 104324097;