Add getRecommendedShards and automatic shard count in ShardingManager (#796)

* draft stuff

fix docstring for Client#token

Reorganise resolver

make env better for shards, clean up docs

Fix Gus' log messages

7

meh just gateway/bot not v7 :(

final changes, ready for mergin!

build docs

make default totalShards 'auto', fix docs for totalShards type

clean up docs more

run docs

* make consistancy real

* Update and rename getRecommendedShards.js to GetRecommendedShards.js

* Update GetRecommendedShards.js

* Update index.js

* Update RESTMethods.js

* Update Shard.js

* Update GetRecommendedShards.js

* Update ShardingManager.js

* run docs
This commit is contained in:
Gus Caplan
2016-10-13 22:26:10 -05:00
committed by Schuyler Cebulskie
parent 492f706035
commit 853a3dfa04
8 changed files with 90 additions and 26 deletions

View File

@@ -72,6 +72,7 @@ const Endpoints = exports.Endpoints = {
login: `${API}/auth/login`,
logout: `${API}/auth/logout`,
gateway: `${API}/gateway`,
botGateway: `${API}/gateway/bot`,
invite: (id) => `${API}/invite/${id}`,
inviteLink: (id) => `https://discord.gg/${id}`,
CDN: 'https://cdn.discordapp.com',

View File

@@ -0,0 +1,19 @@
const superagent = require('superagent');
const botGateway = require('./Constants').Endpoints.botGateway;
/**
* Gets the recommended shard count from Discord
* @param {number} token Discord auth token
* @returns {Promise<number>} the recommended number of shards
*/
module.exports = function getRecommendedShards(token) {
return new Promise((resolve, reject) => {
if (!token) reject(new Error('A token must be provided.'));
superagent.get(botGateway)
.set('Authorization', `Bot ${token.replace('Bot ', '')}`)
.end((err, res) => {
if (err) reject(err);
resolve(res.body.shards);
});
});
};