mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
refactor: removed code and split options (#5918)
Co-authored-by: Jan <66554238+vaporox@users.noreply.github.com> BREAKING CHANGE: Removed `APIMessage#split` BREAKING CHANGE: Removed `MessageEditOptions#code` BREAKING CHANGE: Removed `BaseMessageOptions#code` BREAKING CHANGE: Removed `BaseMessageOptions#split`
This commit is contained in:
@@ -104,7 +104,7 @@ class APIMessage {
|
||||
|
||||
/**
|
||||
* Makes the content of this message.
|
||||
* @returns {?(string|string[])}
|
||||
* @returns {?string}
|
||||
*/
|
||||
makeContent() {
|
||||
let content;
|
||||
@@ -114,27 +114,6 @@ class APIMessage {
|
||||
content = Util.verifyString(this.options.content, RangeError, 'MESSAGE_CONTENT_TYPE', false);
|
||||
}
|
||||
|
||||
if (typeof content !== 'string') return content;
|
||||
|
||||
const isSplit = typeof this.options.split !== 'undefined' && this.options.split !== false;
|
||||
const isCode = typeof this.options.code !== 'undefined' && this.options.code !== false;
|
||||
const splitOptions = isSplit ? { ...this.options.split } : undefined;
|
||||
|
||||
if (content) {
|
||||
if (isCode) {
|
||||
const codeName = typeof this.options.code === 'string' ? this.options.code : '';
|
||||
content = `\`\`\`${codeName}\n${Util.cleanCodeBlockContent(content)}\n\`\`\``;
|
||||
if (isSplit) {
|
||||
splitOptions.prepend = `${splitOptions.prepend || ''}\`\`\`${codeName}\n`;
|
||||
splitOptions.append = `\n\`\`\`${splitOptions.append || ''}`;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSplit) {
|
||||
content = Util.splitMessage(content, splitOptions);
|
||||
}
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
@@ -232,37 +211,6 @@ class APIMessage {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts this APIMessage into an array of APIMessages for each split content
|
||||
* @returns {APIMessage[]}
|
||||
*/
|
||||
split() {
|
||||
if (!this.data) this.resolveData();
|
||||
|
||||
if (!Array.isArray(this.data.content)) return [this];
|
||||
|
||||
const apiMessages = [];
|
||||
|
||||
for (let i = 0; i < this.data.content.length; i++) {
|
||||
let data;
|
||||
let opt;
|
||||
|
||||
if (i === this.data.content.length - 1) {
|
||||
data = { ...this.data, content: this.data.content[i] };
|
||||
opt = { ...this.options, content: this.data.content[i] };
|
||||
} else {
|
||||
data = { content: this.data.content[i], tts: this.data.tts, allowed_mentions: this.options.allowedMentions };
|
||||
opt = { content: this.data.content[i], tts: this.data.tts, allowedMentions: this.options.allowedMentions };
|
||||
}
|
||||
|
||||
const apiMessage = new APIMessage(this.target, opt);
|
||||
apiMessage.data = data;
|
||||
apiMessages.push(apiMessage);
|
||||
}
|
||||
|
||||
return apiMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a single file into an object sendable to the API.
|
||||
* @param {BufferResolvable|Stream|FileOptions|MessageAttachment} fileLike Something that could be resolved to a file
|
||||
|
||||
@@ -554,7 +554,6 @@ class Message extends Base {
|
||||
* @typedef {Object} MessageEditOptions
|
||||
* @property {?string} [content] Content to be edited
|
||||
* @property {MessageEmbed[]|APIEmbed[]} [embeds] Embeds to be added/edited
|
||||
* @property {string|boolean} [code] Language for optional codeblock formatting to apply
|
||||
* @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content
|
||||
* @property {MessageFlags} [flags] Which flags to set for the message. Only `SUPPRESS_EMBEDS` can be edited.
|
||||
* @property {MessageAttachment[]} [attachments] An array of attachments to keep,
|
||||
|
||||
@@ -166,10 +166,6 @@ class Webhook {
|
||||
apiMessage = APIMessage.create(this, options).resolveData();
|
||||
}
|
||||
|
||||
if (Array.isArray(apiMessage.data.content)) {
|
||||
return Promise.all(apiMessage.split().map(this.send.bind(this)));
|
||||
}
|
||||
|
||||
const { data, files } = await apiMessage.resolveFiles();
|
||||
return this.client.api
|
||||
.webhooks(this.id, this.token)
|
||||
|
||||
@@ -62,9 +62,6 @@ class TextBasedChannel {
|
||||
* @property {MessageMentionOptions} [allowedMentions] Which mentions should be parsed from the message content
|
||||
* (see [here](https://discord.com/developers/docs/resources/channel#allowed-mentions-object) for more details)
|
||||
* @property {FileOptions[]|BufferResolvable[]|MessageAttachment[]} [files] Files to send with the message
|
||||
* @property {string|boolean} [code] Language for optional codeblock formatting to apply
|
||||
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
|
||||
* it exceeds the character limit. If an object is provided, these are the options for splitting the message
|
||||
* @property {MessageActionRow[]|MessageActionRowOptions[]|MessageActionRowComponentResolvable[][]} [components]
|
||||
* Action rows containing interactive components for the message (buttons, select menus)
|
||||
*/
|
||||
@@ -98,16 +95,6 @@ class TextBasedChannel {
|
||||
* @property {string} [name='file.jpg'] Filename of the attachment
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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(s) 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* Options for sending a message with a reply.
|
||||
* @typedef {Object} ReplyOptions
|
||||
@@ -177,10 +164,6 @@ class TextBasedChannel {
|
||||
apiMessage = APIMessage.create(this, options).resolveData();
|
||||
}
|
||||
|
||||
if (Array.isArray(apiMessage.data.content)) {
|
||||
return Promise.all(apiMessage.split().map(this.send.bind(this)));
|
||||
}
|
||||
|
||||
const { data, files } = await apiMessage.resolveFiles();
|
||||
return this.client.api.channels[this.id].messages
|
||||
.post({ data, files })
|
||||
|
||||
Reference in New Issue
Block a user