diff --git a/packages/discord.js/src/util/Util.js b/packages/discord.js/src/util/Util.js index 98771b655..2572c67f1 100644 --- a/packages/discord.js/src/util/Util.js +++ b/packages/discord.js/src/util/Util.js @@ -52,51 +52,6 @@ class Util extends null { return out; } - /** - * Options for splitting a message. - * @typedef {Object} SplitOptions - * @property {number} [maxLength=2000] Maximum character length per message piece - * @property {string|string[]|RegExp|RegExp[]} [char='\n'] Character(s) or Regex(es) to split the message with, - * an array can be used to split multiple times - * @property {string} [prepend=''] Text to prepend to every piece except the first - * @property {string} [append=''] Text to append to every piece except the last - */ - - /** - * Splits a string into multiple chunks at a designated character that do not exceed a specific length. - * @param {string} text Content to split - * @param {SplitOptions} [options] Options controlling the behavior of the split - * @returns {string[]} - */ - static splitMessage(text, { maxLength = 2_000, char = '\n', prepend = '', append = '' } = {}) { - text = Util.verifyString(text); - if (text.length <= maxLength) return [text]; - let splitText = [text]; - if (Array.isArray(char)) { - while (char.length > 0 && splitText.some(elem => elem.length > maxLength)) { - const currentChar = char.shift(); - if (currentChar instanceof RegExp) { - splitText = splitText.flatMap(chunk => chunk.match(currentChar)); - } else { - splitText = splitText.flatMap(chunk => chunk.split(currentChar)); - } - } - } else { - splitText = text.split(char); - } - if (splitText.some(elem => elem.length > maxLength)) throw new RangeError('SPLIT_MAX_LEN'); - const messages = []; - let msg = ''; - for (const chunk of splitText) { - if (msg && (msg + char + chunk + append).length > maxLength) { - messages.push(msg + append); - msg = prepend; - } - msg += (msg && msg !== prepend ? char : '') + chunk; - } - return messages.concat(msg).filter(m => m); - } - /** * Options used to escape markdown. * @typedef {Object} EscapeMarkdownOptions diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 5dcd2cf73..8a5ef2e2e 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -2558,7 +2558,6 @@ export class Util extends null { route: string, reason?: string, ): Promise<{ id: Snowflake; position: number }[]>; - public static splitMessage(text: string, options?: SplitOptions): string[]; public static resolveAutoArchiveMaxLimit(guild: Guild): number; } @@ -5091,13 +5090,6 @@ export interface ShardingManagerOptions { export { Snowflake }; -export interface SplitOptions { - maxLength?: number; - char?: string | string[] | RegExp | RegExp[]; - prepend?: string; - append?: string; -} - export type StageInstanceResolvable = StageInstance | Snowflake; export interface StartThreadOptions {