refactor(Util)!: rename fetchRecommendedShards (#8298)

This commit is contained in:
Lo
2022-07-17 21:17:49 +02:00
committed by GitHub
parent b7d4e55419
commit cafde77d73
3 changed files with 8 additions and 8 deletions

View File

@@ -8,7 +8,7 @@ const { setTimeout: sleep } = require('node:timers/promises');
const { Collection } = require('@discordjs/collection'); const { Collection } = require('@discordjs/collection');
const Shard = require('./Shard'); const Shard = require('./Shard');
const { Error, TypeError, RangeError, ErrorCodes } = require('../errors'); 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. * This is a utility class that makes multi-process sharding of a bot an easy and painless experience.
@@ -187,7 +187,7 @@ class ShardingManager extends EventEmitter {
async spawn({ amount = this.totalShards, delay = 5500, timeout = 30_000 } = {}) { async spawn({ amount = this.totalShards, delay = 5500, timeout = 30_000 } = {}) {
// Obtain/verify the number of shards to spawn // Obtain/verify the number of shards to spawn
if (amount === 'auto') { if (amount === 'auto') {
amount = await fetchRecommendedShards(this.token); amount = await fetchRecommendedShardCount(this.token);
} else { } else {
if (typeof amount !== 'number' || isNaN(amount)) { if (typeof amount !== 'number' || isNaN(amount)) {
throw new TypeError(ErrorCodes.ClientInvalidOption, 'Amount of shards', 'a number.'); throw new TypeError(ErrorCodes.ClientInvalidOption, 'Amount of shards', 'a number.');

View File

@@ -211,7 +211,7 @@ function escapeSpoiler(text) {
} }
/** /**
* @typedef {Object} FetchRecommendedShardsOptions * @typedef {Object} FetchRecommendedShardCountOptions
* @property {number} [guildsPerShard=1000] Number of guilds assigned per shard * @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) * @property {number} [multipleOf=1] The multiple the shard count should round up to. (16 for large bot sharding)
*/ */
@@ -219,10 +219,10 @@ function escapeSpoiler(text) {
/** /**
* Gets the recommended shard count from Discord. * Gets the recommended shard count from Discord.
* @param {string} token Discord auth token * @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 * @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); if (!token) throw new DiscordError(ErrorCodes.TokenMissing);
const response = await fetch(RouteBases.api + Routes.gatewayBot(), { const response = await fetch(RouteBases.api + Routes.gatewayBot(), {
method: 'GET', method: 'GET',
@@ -555,7 +555,7 @@ module.exports = {
escapeUnderline, escapeUnderline,
escapeStrikethrough, escapeStrikethrough,
escapeSpoiler, escapeSpoiler,
fetchRecommendedShards, fetchRecommendedShardCount,
parseEmoji, parseEmoji,
resolvePartialEmoji, resolvePartialEmoji,
mergeDefault, mergeDefault,

View File

@@ -2290,7 +2290,7 @@ export class ShardingManager extends EventEmitter {
public once(event: 'shardCreate', listener: (shard: Shard) => Awaitable<void>): this; public once(event: 'shardCreate', listener: (shard: Shard) => Awaitable<void>): this;
} }
export interface FetchRecommendedShardsOptions { export interface FetchRecommendedShardCountOptions {
guildsPerShard?: number; guildsPerShard?: number;
multipleOf?: number; multipleOf?: number;
} }
@@ -2640,7 +2640,7 @@ export function escapeUnderline(text: string): string;
export function escapeStrikethrough(text: string): string; export function escapeStrikethrough(text: string): string;
export function escapeSpoiler(text: string): string; export function escapeSpoiler(text: string): string;
export function cleanCodeBlockContent(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 flatten(obj: unknown, ...props: Record<string, boolean | string>[]): unknown;
export function makeError(obj: MakeErrorOptions): Error; export function makeError(obj: MakeErrorOptions): Error;
export function makePlainError(err: Error): MakeErrorOptions; export function makePlainError(err: Error): MakeErrorOptions;