fedimbed: spoiler support
This commit is contained in:
parent
105b0ade06
commit
d98dc9b925
1 changed files with 7 additions and 5 deletions
|
@ -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|^)(https?:\/\/[^\s<]+[^<.,:;"'\]\s])/g;
|
||||
const URLS_REGEX = /(?:\s|^)(\|\|\s+)(https?:\/\/[^\s<]+[^<.,:;"'\]\s])(\s+\|\|)/g;
|
||||
const SPOILER_REGEX = /^\|\|([\s\S]+?)\|\|/;
|
||||
|
||||
const PATH_REGEX = {
|
||||
mastodon: /^\/@(.+?)\/(\d+)\/?/,
|
||||
|
@ -61,7 +62,7 @@ async function resolvePlatform(url) {
|
|||
return nodeinfo.software.name;
|
||||
}
|
||||
|
||||
async function processUrl(msg, url) {
|
||||
async function processUrl(msg, url, spoiler = false) {
|
||||
let urlObj = new URL(url);
|
||||
let platform = await resolvePlatform(url);
|
||||
let color = PLATFORM_COLORS[platform];
|
||||
|
@ -519,7 +520,7 @@ async function processUrl(msg, url) {
|
|||
content:
|
||||
cw && (images.length > 0 || videos.length > 0 || audios.length > 0)
|
||||
? `:warning: ${cw} || ${url} ||`
|
||||
: "",
|
||||
: spoiler ? `|| ${url} ||` : "",
|
||||
embeds,
|
||||
files,
|
||||
allowedMentions: {
|
||||
|
@ -555,7 +556,8 @@ events.add("messageCreate", "fedimbed", async function (msg) {
|
|||
if (URLS_REGEX.test(msg.content)) {
|
||||
const urls = msg.content.match(URLS_REGEX);
|
||||
for (let url of urls) {
|
||||
url = url.trim().replace("@\u200b", "@").replace("@%E2%80%8B", "@");
|
||||
const hasSpoiler = url.test(SPOILER_REGEX);
|
||||
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);
|
||||
|
@ -564,7 +566,7 @@ events.add("messageCreate", "fedimbed", async function (msg) {
|
|||
"fedimbed",
|
||||
`Hit "${service}" for "${url}", processing now.`
|
||||
);
|
||||
await processUrl(msg, url).catch((err) => {
|
||||
await processUrl(msg, url, hasSpoiler).catch((err) => {
|
||||
logger.error("fedimbed", `Error processing "${url}": ${err}`);
|
||||
});
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue