Skip to content

Commit

Permalink
add option for guilds per shard, and fix type (#1053)
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek authored and Gawdl3y committed Dec 31, 2016
1 parent 2156ce1 commit 2b25641
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/util/FetchRecommendedShards.js
Expand Up @@ -3,17 +3,18 @@ const botGateway = require('./Constants').Endpoints.botGateway;

/**
* Gets the recommended shard count from Discord
* @param {number} token Discord auth token
* @param {string} token Discord auth token
* @param {number} [guildsPerShard=1000] Number of guilds per shard
* @returns {Promise<number>} the recommended number of shards
*/
module.exports = function fetchRecommendedShards(token) {
module.exports = function fetchRecommendedShards(token, guildsPerShard = 1000) {
return new Promise((resolve, reject) => {
if (!token) throw new Error('A token must be provided.');
superagent.get(botGateway)
.set('Authorization', `Bot ${token.replace(/^Bot\s*/i, '')}`)
.end((err, res) => {
if (err) reject(err);
resolve(res.body.shards);
resolve(res.body.shards * (1000 / guildsPerShard));
});
});
};

1 comment on commit 2b25641

@gavwin
Copy link
Contributor

@gavwin gavwin commented on 2b25641 May 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very useful

Please sign in to comment.