From e1af92f9d104ba7101372af29e112a622b4b66ce Mon Sep 17 00:00:00 2001 From: Cynthia Foxwell Date: Tue, 17 Jan 2023 12:25:05 -0700 Subject: [PATCH] fedimbed: spoiler cw'd media --- src/modules/fedimbed.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index 18cbdce..8c5fc09 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -8,7 +8,8 @@ const {parseHtmlEntities, getUploadLimit} = require("../lib/utils.js"); const FRIENDLY_USERAGENT = "HiddenPhox/fedimbed (https://gitdab.com/Cynosphere/HiddenPhox)"; -const URLS_REGEX = /(?:\s|^)(\|\|\s*)?(https?:\/\/[^\s<]+[^<.,:;"'\]\s])(\s+\|\|)?/g; +const URLS_REGEX = + /(?:\s|^)(\|\|\s*)?(https?:\/\/[^\s<]+[^<.,:;"'\]\s])(\s+\|\|)?/g; const SPOILER_REGEX = /^\|\|([\s\S]+?)\|\|/; const PATH_REGEX = { @@ -468,7 +469,7 @@ async function processUrl(msg, url, spoiler = false) { files.push({ name: - attachment.type.indexOf("/") > -1 + (cw != "" || spoiler ? "SPOILER_" : "") + attachment.type.indexOf("/") > -1 ? attachment.type.replace("/", ".") : attachment.type + "." + @@ -500,7 +501,7 @@ async function processUrl(msg, url, spoiler = false) { files.push({ name: - attachment.type.indexOf("/") > -1 + (cw != "" || spoiler ? "SPOILER_" : "") + attachment.type.indexOf("/") > -1 ? attachment.type .replace("/", ".") .replace("mpeg", "mp3") @@ -524,9 +525,12 @@ async function processUrl(msg, url, spoiler = false) { await msg.channel .createMessage({ content: - cw && (images.length > 0 || videos.length > 0 || audios.length > 0) + cw != "" && + (images.length > 0 || videos.length > 0 || audios.length > 0) ? `:warning: ${cw} || ${url} ||` - : spoiler ? `|| ${url} ||` : "", + : spoiler + ? `|| ${url} ||` + : "", embeds, files, allowedMentions: { @@ -567,7 +571,11 @@ events.add("messageCreate", "fedimbed", async function (msg) { const urls = msg.content.match(URLS_REGEX); for (let url of urls) { const hasSpoiler = SPOILER_REGEX.test(url); - url = url.replace(/\|/g,"").trim().replace("@\u200b", "@").replace("@%E2%80%8B", "@"); + url = url + .replace(/\|/g, "") + .trim() + .replace("@\u200b", "@") + .replace("@%E2%80%8B", "@"); for (const service of Object.keys(PATH_REGEX)) { const regex = PATH_REGEX[service]; const urlObj = new URL(url);