fedimbed: minimal mode

This commit is contained in:
Cynthia Foxwell 2025-05-06 20:47:47 -06:00
parent 79da0933cf
commit 37c09e1944
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk

View file

@ -480,7 +480,7 @@ async function blueskyQuoteEmbed(quote) {
return {components, adult, hidden, spoiler, tags}; return {components, adult, hidden, spoiler, tags};
} }
async function bluesky(msg, url, spoiler = false) { async function bluesky(msg, url, spoiler = false, minimal = false) {
const quoteOnly = await hasFlag(msg.guildID, "bskyQuoteOnly"); const quoteOnly = await hasFlag(msg.guildID, "bskyQuoteOnly");
if (url.includes("bsky.brid.gy")) url = url.replace("bsky.brid.gy/r/https://", ""); if (url.includes("bsky.brid.gy")) url = url.replace("bsky.brid.gy/r/https://", "");
@ -637,7 +637,7 @@ async function bluesky(msg, url, spoiler = false) {
const warningText = { const warningText = {
type: 10, type: 10,
content: `## ${warnings.join("\n## ")}`, content: minimal ? `${warnings.join("\n")}` : `## ${warnings.join("\n## ")}`,
}; };
const container = { const container = {
@ -650,7 +650,7 @@ async function bluesky(msg, url, spoiler = false) {
let context = ""; let context = "";
if (data.thread.parent) { if (data.thread.parent) {
const reply = data.thread.parent.post; const reply = data.thread.parent.post;
context = `-# ${Icons.fedimbed.reply} Replying to: [${reply.author.displayName} (@${ context = `-# ${Icons.fedimbed.reply} ${minimal ? "" : "Replying to: "}[${reply.author.displayName} (@${
reply.author.handle reply.author.handle
})](https://bsky.app/profile/${reply.author.did}/post/${reply.uri.substring(reply.uri.lastIndexOf("/") + 1)})`; })](https://bsky.app/profile/${reply.author.did}/post/${reply.uri.substring(reply.uri.lastIndexOf("/") + 1)})`;
} }
@ -661,19 +661,23 @@ async function bluesky(msg, url, spoiler = false) {
} }
content = content.replaceAll("`", "\u02cb").replaceAll("*", "\u2217").replaceAll("||", "|\u200b|"); content = content.replaceAll("`", "\u02cb").replaceAll("*", "\u2217").replaceAll("||", "|\u200b|");
const contentComponent = {
type: 10,
content: minimal
? `### [${post.author.displayName} (@${post.author.handle})](${url})`
: `## ${post.author.displayName}\n-# [@${post.author.handle}](https://bsky.app/profile/${post.author.did})\n${content}`,
};
const header = [ const header = [
context && { context && {
type: 10, type: 10,
content: context, content: context,
}, },
{ minimal
? contentComponent
: {
type: 9, type: 9,
components: [ components: [contentComponent],
{
type: 10,
content: `## ${post.author.displayName}\n-# [@${post.author.handle}](https://bsky.app/profile/${post.author.did})\n${content}`,
},
],
accessory: { accessory: {
type: 11, type: 11,
media: { media: {
@ -684,7 +688,14 @@ async function bluesky(msg, url, spoiler = false) {
].filter((x) => !!x); ].filter((x) => !!x);
container.components.push(...header); container.components.push(...header);
const footer = { const footer = minimal
? {
type: 10,
content: `${Icons.fedimbed.bluesky} Bluesky \u2022 <t:${Math.floor(
new Date(post.record.createdAt).getTime() / 1000
)}:F>`,
}
: {
type: 9, type: 9,
components: [ components: [
{ {
@ -936,7 +947,7 @@ function getStatsMasto(post) {
return stats.join("\u3000"); return stats.join("\u3000");
} }
async function processUrl(msg, url, spoiler = false, command = false, inQuote = false) { async function processUrl(msg, url, spoiler = false, command = false, inQuote = false, minimal = false) {
let canFedi = await hasFlag(msg.guildID, "fedimbed"); let canFedi = await hasFlag(msg.guildID, "fedimbed");
let canBsky = await hasFlag(msg.guildID, "bskyEmbeds"); let canBsky = await hasFlag(msg.guildID, "bskyEmbeds");
let canTwitter = await hasFlag(msg.guildID, "twitterEmbeds"); let canTwitter = await hasFlag(msg.guildID, "twitterEmbeds");
@ -959,7 +970,7 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
if (BSKY_DOMAINS.includes(urlObj.hostname.toLowerCase())) { if (BSKY_DOMAINS.includes(urlObj.hostname.toLowerCase())) {
if (canBsky) { if (canBsky) {
return await bluesky(msg, url, spoiler); return await bluesky(msg, url, spoiler, minimal);
} else { } else {
return {}; return {};
} }
@ -1303,7 +1314,7 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
!inQuote ? "" : `<small>\u2198 Quoting <a href="${quoteUrl}">$1</a></small>` !inQuote ? "" : `<small>\u2198 Quoting <a href="${quoteUrl}">$1</a></small>`
); );
if (!inQuote) quoteRes = await processUrl(msg, quoteUrl, spoiler, command, true); if (!inQuote) quoteRes = await processUrl(msg, quoteUrl, spoiler, command, true, minimal);
} }
content = content content = content
@ -1384,9 +1395,11 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
spoiler, spoiler,
}; };
let headerContent = `${author.name ? `## ${author.name}\n` : ""}-# [${author.handle}](${author.url})`; let headerContent = minimal
? `### [${author.name ? `${author.name} (${author.handle})` : author.handle}](${realUrl})`
: `${author.name ? `## ${author.name}\n` : ""}-# [${author.handle}](${author.url})`;
if (title) headerContent += "\n### " + title; if (title) headerContent += minimal ? "\n**__" + title + "__**" : "\n### " + title;
MAX_LENGTH -= headerContent.length + 1; MAX_LENGTH -= headerContent.length + 1;
@ -1400,19 +1413,25 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
} }
headerContent += "\n" + desc.trim(); headerContent += "\n" + desc.trim();
const contentComponent = {
type: 10,
content: headerContent,
};
if (minimal && context) {
context = context.replace("Replying to: ", "");
}
const header = [ const header = [
context && { context && {
type: 10, type: 10,
content: context, content: context,
}, },
{ minimal
? contentComponent
: {
type: 9, type: 9,
components: [ components: [contentComponent],
{
type: 10,
content: headerContent,
},
],
accessory: { accessory: {
type: 11, type: 11,
media: { media: {
@ -1445,7 +1464,14 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
} }
const footerIcon = PLATFORM_ICONS[platformName.toLowerCase()]; const footerIcon = PLATFORM_ICONS[platformName.toLowerCase()];
const footer = { const footer = minimal
? {
type: 10,
content: `${footerIcon ? footerIcon + " " : ""}${platformName} \u2022 <t:${Math.floor(
new Date(timestamp).getTime() / 1000
)}:F>`,
}
: {
type: 9, type: 9,
components: [ components: [
{ {
@ -1525,7 +1551,8 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
const quoteComponents = quoteRes.response.components[0].components; const quoteComponents = quoteRes.response.components[0].components;
const quoteContext = `-# ${Icons.fedimbed.quote} Quoted Post`; const quoteContext = `-# ${Icons.fedimbed.quote} Quoted Post`;
if (quoteComponents[0].type == 10) { if (quoteComponents[0].type == 10) {
quoteComponents[0].content = quoteContext + "\n" + quoteComponents[0].content; quoteComponents[0].content =
(minimal ? Icons.fedimbed.quote + " " : quoteContext + "\n") + quoteComponents[0].content;
} else { } else {
quoteComponents.splice(0, 0, {type: 10, content: quoteContext}); quoteComponents.splice(0, 0, {type: 10, content: quoteContext});
} }
@ -1611,10 +1638,18 @@ fedimbedCommand.options.spoiler = {
required: false, required: false,
default: false, default: false,
}; };
fedimbedCommand.options.minimal = {
name: "minimal",
type: ApplicationCommandOptionTypes.BOOLEAN,
description: "Remove stats, avatars and other visual noise",
required: false,
default: false,
};
fedimbedCommand.permissions = Permissions.embedLinks | Permissions.attachFiles; fedimbedCommand.permissions = Permissions.embedLinks | Permissions.attachFiles;
fedimbedCommand.callback = async function (interaction) { fedimbedCommand.callback = async function (interaction) {
let url = this.getOption(interaction, "url"); let url = this.getOption(interaction, "url");
const spoiler = this.getOption(interaction, "spoiler"); const spoiler = this.getOption(interaction, "spoiler");
const minimal = this.getOption(interaction, "minimal");
url = url url = url
.replace(/\|/g, "") .replace(/\|/g, "")
@ -1644,7 +1679,7 @@ fedimbedCommand.callback = async function (interaction) {
if (hasService || BSKY_DOMAINS.includes(urlObj.hostname.toLowerCase())) { if (hasService || BSKY_DOMAINS.includes(urlObj.hostname.toLowerCase())) {
try { try {
const {response} = await processUrl(interaction, url, spoiler, true); const {response} = await processUrl(interaction, url, spoiler, true, false, minimal);
if (!response) if (!response)
return { return {