From 4dcc8a2353c36d2655a9c89dd0a2e9c8235da14a Mon Sep 17 00:00:00 2001 From: John Marlo Date: Fri, 1 Apr 2022 23:06:22 +0800 Subject: [PATCH 1/2] Update webembeds check content, if it too long remove hidden characters.. --- src/structures/MessagePayload.js | 46 +++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/structures/MessagePayload.js b/src/structures/MessagePayload.js index b9b8da4..3b09239 100644 --- a/src/structures/MessagePayload.js +++ b/src/structures/MessagePayload.js @@ -188,36 +188,56 @@ class MessagePayload { } else { this.options.attachments = attachments; } - + if (this.options.embeds) { if (!Array.isArray(this.options.embeds)) { this.options.embeds = [this.options.embeds]; } - const webembeds = this.options.embeds.filter( - (e) => !(e instanceof MessageEmbed), - ); - this.options.embeds = this.options.embeds.filter(e => e instanceof MessageEmbed); + let webembeds = this.options.embeds.filter(e => (e instanceof WebEmbed) && Boolean(e.hidden) === true); + let webembeds_ = this.options.embeds.filter(e => (e instanceof WebEmbed) && Boolean(e.hidden) === false); + this.options.embeds = this.options.embeds.filter(e => !(e instanceof WebEmbed)); + let hidden = false; + + if (webembeds.length > 0) { + content = "\n"; + + while (webembeds_.length) { + const embed = webembeds_.shift(); + const data = await embed.toMessage(); + content +=`\n${data}` + + await new Promise(resolve => setTimeout(resolve, 1000)) + } + } if (webembeds.length > 0) { // add hidden embed link content += `\n${WebEmbed.hiddenEmbed} \n`; - if (webembeds.length > 1) { - console.warn('Multiple webembeds are not supported, only the first one will be sent'); + hidden = true; + + while (webembeds.length) { + const embed = webembeds.shift(); + const data = await embed.toMessage(); + content +=`\n${data}` + + await new Promise(resolve => setTimeout(resolve, 1000)) } - const embed = webembeds[0]; - const data = await embed.toMessage(); - content += `\n${data}`; } + // Check content if (content.length > 2000) { - console.warn(`[WARN] Content is longer than 2000 characters.`); + console.warn(`[WARN] Content length is ${content.length} characters. This exceeds Discord's 2000 character limit.`); } - if (content.length > 4000) { // Max length if user has nitro boost + if (hidden && content.length > 2000) { // Max length if user has nitro boost + content = content.replace(`\n${WebEmbed.hiddenEmbed} \n`, ""); // Remove hidden character + console.warn(`[WARN] Removing hidden character to make content fit. Your content length now is ${content.length} characters long.`); + } + if (content.length > 4000) { // Recheck the content length throw new RangeError('MESSAGE_EMBED_LINK_LENGTH'); } } - + this.data = { content, tts, From dde279db22f71c5a862f29a468d4674676776fbd Mon Sep 17 00:00:00 2001 From: John Marlo Date: Fri, 1 Apr 2022 23:13:54 +0800 Subject: [PATCH 2/2] bug? --- src/structures/MessagePayload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/MessagePayload.js b/src/structures/MessagePayload.js index 3b09239..a9aa490 100644 --- a/src/structures/MessagePayload.js +++ b/src/structures/MessagePayload.js @@ -200,7 +200,7 @@ class MessagePayload { let hidden = false; if (webembeds.length > 0) { - content = "\n"; + content += "\n"; while (webembeds_.length) { const embed = webembeds_.shift();