Skip to content

Commit

Permalink
refactor(Util)!: rename fetchRecommendedShards (#8298)
Browse files Browse the repository at this point in the history
  • Loading branch information
mainleau committed Jul 17, 2022
1 parent b7d4e55 commit cafde77
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/discord.js/src/sharding/ShardingManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { setTimeout: sleep } = require('node:timers/promises');
const { Collection } = require('@discordjs/collection');
const Shard = require('./Shard');
const { Error, TypeError, RangeError, ErrorCodes } = require('../errors');
const { mergeDefault, fetchRecommendedShards } = require('../util/Util');
const { mergeDefault, fetchRecommendedShardCount } = require('../util/Util');

/**
* This is a utility class that makes multi-process sharding of a bot an easy and painless experience.
Expand Down Expand Up @@ -187,7 +187,7 @@ class ShardingManager extends EventEmitter {
async spawn({ amount = this.totalShards, delay = 5500, timeout = 30_000 } = {}) {
// Obtain/verify the number of shards to spawn
if (amount === 'auto') {
amount = await fetchRecommendedShards(this.token);
amount = await fetchRecommendedShardCount(this.token);
} else {
if (typeof amount !== 'number' || isNaN(amount)) {
throw new TypeError(ErrorCodes.ClientInvalidOption, 'Amount of shards', 'a number.');
Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/src/util/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,18 @@ function escapeSpoiler(text) {
}

/**
* @typedef {Object} FetchRecommendedShardsOptions
* @typedef {Object} FetchRecommendedShardCountOptions
* @property {number} [guildsPerShard=1000] Number of guilds assigned per shard
* @property {number} [multipleOf=1] The multiple the shard count should round up to. (16 for large bot sharding)
*/

/**
* Gets the recommended shard count from Discord.
* @param {string} token Discord auth token
* @param {FetchRecommendedShardsOptions} [options] Options for fetching the recommended shard count
* @param {FetchRecommendedShardCountOptions} [options] Options for fetching the recommended shard count
* @returns {Promise<number>} The recommended number of shards
*/
async function fetchRecommendedShards(token, { guildsPerShard = 1_000, multipleOf = 1 } = {}) {
async function fetchRecommendedShardCount(token, { guildsPerShard = 1_000, multipleOf = 1 } = {}) {
if (!token) throw new DiscordError(ErrorCodes.TokenMissing);
const response = await fetch(RouteBases.api + Routes.gatewayBot(), {
method: 'GET',
Expand Down Expand Up @@ -555,7 +555,7 @@ module.exports = {
escapeUnderline,
escapeStrikethrough,
escapeSpoiler,
fetchRecommendedShards,
fetchRecommendedShardCount,
parseEmoji,
resolvePartialEmoji,
mergeDefault,
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ export class ShardingManager extends EventEmitter {
public once(event: 'shardCreate', listener: (shard: Shard) => Awaitable<void>): this;
}

export interface FetchRecommendedShardsOptions {
export interface FetchRecommendedShardCountOptions {
guildsPerShard?: number;
multipleOf?: number;
}
Expand Down Expand Up @@ -2640,7 +2640,7 @@ export function escapeUnderline(text: string): string;
export function escapeStrikethrough(text: string): string;
export function escapeSpoiler(text: string): string;
export function cleanCodeBlockContent(text: string): string;
export function fetchRecommendedShards(token: string, options?: FetchRecommendedShardsOptions): Promise<number>;
export function fetchRecommendedShardCount(token: string, options?: FetchRecommendedShardCountOptions): Promise<number>;
export function flatten(obj: unknown, ...props: Record<string, boolean | string>[]): unknown;
export function makeError(obj: MakeErrorOptions): Error;
export function makePlainError(err: Error): MakeErrorOptions;
Expand Down

0 comments on commit cafde77

Please sign in to comment.