fedimbed: spoiler cw'd media

This commit is contained in:
Cynthia Foxwell 2023-01-17 12:25:05 -07:00
parent a3f782e941
commit e1af92f9d1

View file

@ -8,7 +8,8 @@ const {parseHtmlEntities, getUploadLimit} = require("../lib/utils.js");
const FRIENDLY_USERAGENT = const FRIENDLY_USERAGENT =
"HiddenPhox/fedimbed (https://gitdab.com/Cynosphere/HiddenPhox)"; "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 SPOILER_REGEX = /^\|\|([\s\S]+?)\|\|/;
const PATH_REGEX = { const PATH_REGEX = {
@ -468,7 +469,7 @@ async function processUrl(msg, url, spoiler = false) {
files.push({ files.push({
name: name:
attachment.type.indexOf("/") > -1 (cw != "" || spoiler ? "SPOILER_" : "") + attachment.type.indexOf("/") > -1
? attachment.type.replace("/", ".") ? attachment.type.replace("/", ".")
: attachment.type + : attachment.type +
"." + "." +
@ -500,7 +501,7 @@ async function processUrl(msg, url, spoiler = false) {
files.push({ files.push({
name: name:
attachment.type.indexOf("/") > -1 (cw != "" || spoiler ? "SPOILER_" : "") + attachment.type.indexOf("/") > -1
? attachment.type ? attachment.type
.replace("/", ".") .replace("/", ".")
.replace("mpeg", "mp3") .replace("mpeg", "mp3")
@ -524,9 +525,12 @@ async function processUrl(msg, url, spoiler = false) {
await msg.channel await msg.channel
.createMessage({ .createMessage({
content: content:
cw && (images.length > 0 || videos.length > 0 || audios.length > 0) cw != "" &&
(images.length > 0 || videos.length > 0 || audios.length > 0)
? `:warning: ${cw} || ${url} ||` ? `:warning: ${cw} || ${url} ||`
: spoiler ? `|| ${url} ||` : "", : spoiler
? `|| ${url} ||`
: "",
embeds, embeds,
files, files,
allowedMentions: { allowedMentions: {
@ -567,7 +571,11 @@ events.add("messageCreate", "fedimbed", async function (msg) {
const urls = msg.content.match(URLS_REGEX); const urls = msg.content.match(URLS_REGEX);
for (let url of urls) { for (let url of urls) {
const hasSpoiler = SPOILER_REGEX.test(url); 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)) { for (const service of Object.keys(PATH_REGEX)) {
const regex = PATH_REGEX[service]; const regex = PATH_REGEX[service];
const urlObj = new URL(url); const urlObj = new URL(url);