fedimbed: minimal mode
This commit is contained in:
		
							parent
							
								
									79da0933cf
								
							
						
					
					
						commit
						37c09e1944
					
				
					 1 changed files with 103 additions and 68 deletions
				
			
		| 
						 | 
				
			
			@ -480,7 +480,7 @@ async function blueskyQuoteEmbed(quote) {
 | 
			
		|||
  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");
 | 
			
		||||
 | 
			
		||||
  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 = {
 | 
			
		||||
    type: 10,
 | 
			
		||||
    content: `## ${warnings.join("\n## ")}`,
 | 
			
		||||
    content: minimal ? `${warnings.join("\n")}` : `## ${warnings.join("\n## ")}`,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const container = {
 | 
			
		||||
| 
						 | 
				
			
			@ -650,7 +650,7 @@ async function bluesky(msg, url, spoiler = false) {
 | 
			
		|||
  let context = "";
 | 
			
		||||
  if (data.thread.parent) {
 | 
			
		||||
    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
 | 
			
		||||
    })](https://bsky.app/profile/${reply.author.did}/post/${reply.uri.substring(reply.uri.lastIndexOf("/") + 1)})`;
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -661,46 +661,57 @@ async function bluesky(msg, url, spoiler = false) {
 | 
			
		|||
  }
 | 
			
		||||
  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 = [
 | 
			
		||||
    context && {
 | 
			
		||||
      type: 10,
 | 
			
		||||
      content: context,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      type: 9,
 | 
			
		||||
      components: [
 | 
			
		||||
        {
 | 
			
		||||
          type: 10,
 | 
			
		||||
          content: `## ${post.author.displayName}\n-# [@${post.author.handle}](https://bsky.app/profile/${post.author.did})\n${content}`,
 | 
			
		||||
    minimal
 | 
			
		||||
      ? contentComponent
 | 
			
		||||
      : {
 | 
			
		||||
          type: 9,
 | 
			
		||||
          components: [contentComponent],
 | 
			
		||||
          accessory: {
 | 
			
		||||
            type: 11,
 | 
			
		||||
            media: {
 | 
			
		||||
              url: post.author.avatar,
 | 
			
		||||
            },
 | 
			
		||||
          },
 | 
			
		||||
        },
 | 
			
		||||
      ],
 | 
			
		||||
      accessory: {
 | 
			
		||||
        type: 11,
 | 
			
		||||
        media: {
 | 
			
		||||
          url: post.author.avatar,
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  ].filter((x) => !!x);
 | 
			
		||||
  container.components.push(...header);
 | 
			
		||||
 | 
			
		||||
  const footer = {
 | 
			
		||||
    type: 9,
 | 
			
		||||
    components: [
 | 
			
		||||
      {
 | 
			
		||||
  const footer = minimal
 | 
			
		||||
    ? {
 | 
			
		||||
        type: 10,
 | 
			
		||||
        content: `### -# ${getStatsBluesky(post)}\n${Icons.fedimbed.bluesky} Bluesky \u2022 <t:${Math.floor(
 | 
			
		||||
        content: `${Icons.fedimbed.bluesky} Bluesky \u2022 <t:${Math.floor(
 | 
			
		||||
          new Date(post.record.createdAt).getTime() / 1000
 | 
			
		||||
        )}:F>`,
 | 
			
		||||
      },
 | 
			
		||||
    ],
 | 
			
		||||
    accessory: {
 | 
			
		||||
      type: 2,
 | 
			
		||||
      style: 5,
 | 
			
		||||
      label: "View Post",
 | 
			
		||||
      url,
 | 
			
		||||
    },
 | 
			
		||||
  };
 | 
			
		||||
      }
 | 
			
		||||
    : {
 | 
			
		||||
        type: 9,
 | 
			
		||||
        components: [
 | 
			
		||||
          {
 | 
			
		||||
            type: 10,
 | 
			
		||||
            content: `### -# ${getStatsBluesky(post)}\n${Icons.fedimbed.bluesky} Bluesky \u2022 <t:${Math.floor(
 | 
			
		||||
              new Date(post.record.createdAt).getTime() / 1000
 | 
			
		||||
            )}:F>`,
 | 
			
		||||
          },
 | 
			
		||||
        ],
 | 
			
		||||
        accessory: {
 | 
			
		||||
          type: 2,
 | 
			
		||||
          style: 5,
 | 
			
		||||
          label: "View Post",
 | 
			
		||||
          url,
 | 
			
		||||
        },
 | 
			
		||||
      };
 | 
			
		||||
 | 
			
		||||
  if (images.length > 0) {
 | 
			
		||||
    container.components.push({
 | 
			
		||||
| 
						 | 
				
			
			@ -936,7 +947,7 @@ function getStatsMasto(post) {
 | 
			
		|||
  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 canBsky = await hasFlag(msg.guildID, "bskyEmbeds");
 | 
			
		||||
  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 (canBsky) {
 | 
			
		||||
      return await bluesky(msg, url, spoiler);
 | 
			
		||||
      return await bluesky(msg, url, spoiler, minimal);
 | 
			
		||||
    } else {
 | 
			
		||||
      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>`
 | 
			
		||||
      );
 | 
			
		||||
 | 
			
		||||
      if (!inQuote) quoteRes = await processUrl(msg, quoteUrl, spoiler, command, true);
 | 
			
		||||
      if (!inQuote) quoteRes = await processUrl(msg, quoteUrl, spoiler, command, true, minimal);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    content = content
 | 
			
		||||
| 
						 | 
				
			
			@ -1384,9 +1395,11 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
			
		|||
    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;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1400,26 +1413,32 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
			
		|||
  }
 | 
			
		||||
  headerContent += "\n" + desc.trim();
 | 
			
		||||
 | 
			
		||||
  const contentComponent = {
 | 
			
		||||
    type: 10,
 | 
			
		||||
    content: headerContent,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  if (minimal && context) {
 | 
			
		||||
    context = context.replace("Replying to: ", "");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const header = [
 | 
			
		||||
    context && {
 | 
			
		||||
      type: 10,
 | 
			
		||||
      content: context,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      type: 9,
 | 
			
		||||
      components: [
 | 
			
		||||
        {
 | 
			
		||||
          type: 10,
 | 
			
		||||
          content: headerContent,
 | 
			
		||||
    minimal
 | 
			
		||||
      ? contentComponent
 | 
			
		||||
      : {
 | 
			
		||||
          type: 9,
 | 
			
		||||
          components: [contentComponent],
 | 
			
		||||
          accessory: {
 | 
			
		||||
            type: 11,
 | 
			
		||||
            media: {
 | 
			
		||||
              url: author.avatar,
 | 
			
		||||
            },
 | 
			
		||||
          },
 | 
			
		||||
        },
 | 
			
		||||
      ],
 | 
			
		||||
      accessory: {
 | 
			
		||||
        type: 11,
 | 
			
		||||
        media: {
 | 
			
		||||
          url: author.avatar,
 | 
			
		||||
        },
 | 
			
		||||
      },
 | 
			
		||||
    },
 | 
			
		||||
  ].filter((x) => !!x);
 | 
			
		||||
  container.components.push(...header);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1445,23 +1464,30 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  const footerIcon = PLATFORM_ICONS[platformName.toLowerCase()];
 | 
			
		||||
  const footer = {
 | 
			
		||||
    type: 9,
 | 
			
		||||
    components: [
 | 
			
		||||
      {
 | 
			
		||||
  const footer = minimal
 | 
			
		||||
    ? {
 | 
			
		||||
        type: 10,
 | 
			
		||||
        content: `${stats.length > 0 ? "### -# " + stats + "\n" : ""}${
 | 
			
		||||
          footerIcon ? footerIcon + " " : ""
 | 
			
		||||
        }${platformName} \u2022 <t:${Math.floor(new Date(timestamp).getTime() / 1000)}:F>`,
 | 
			
		||||
      },
 | 
			
		||||
    ],
 | 
			
		||||
    accessory: {
 | 
			
		||||
      type: 2,
 | 
			
		||||
      style: 5,
 | 
			
		||||
      label: "View Post",
 | 
			
		||||
      url: realUrl,
 | 
			
		||||
    },
 | 
			
		||||
  };
 | 
			
		||||
        content: `${footerIcon ? footerIcon + " " : ""}${platformName} \u2022 <t:${Math.floor(
 | 
			
		||||
          new Date(timestamp).getTime() / 1000
 | 
			
		||||
        )}:F>`,
 | 
			
		||||
      }
 | 
			
		||||
    : {
 | 
			
		||||
        type: 9,
 | 
			
		||||
        components: [
 | 
			
		||||
          {
 | 
			
		||||
            type: 10,
 | 
			
		||||
            content: `${stats.length > 0 ? "### -# " + stats + "\n" : ""}${
 | 
			
		||||
              footerIcon ? footerIcon + " " : ""
 | 
			
		||||
            }${platformName} \u2022 <t:${Math.floor(new Date(timestamp).getTime() / 1000)}:F>`,
 | 
			
		||||
          },
 | 
			
		||||
        ],
 | 
			
		||||
        accessory: {
 | 
			
		||||
          type: 2,
 | 
			
		||||
          style: 5,
 | 
			
		||||
          label: "View Post",
 | 
			
		||||
          url: realUrl,
 | 
			
		||||
        },
 | 
			
		||||
      };
 | 
			
		||||
  if (images.length > 0) {
 | 
			
		||||
    const overMax = images.length + videos.length > 40;
 | 
			
		||||
    if (images.length > 10) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1525,7 +1551,8 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
			
		|||
    const quoteComponents = quoteRes.response.components[0].components;
 | 
			
		||||
    const quoteContext = `-# ${Icons.fedimbed.quote} Quoted Post`;
 | 
			
		||||
    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 {
 | 
			
		||||
      quoteComponents.splice(0, 0, {type: 10, content: quoteContext});
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1611,10 +1638,18 @@ fedimbedCommand.options.spoiler = {
 | 
			
		|||
  required: 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.callback = async function (interaction) {
 | 
			
		||||
  let url = this.getOption(interaction, "url");
 | 
			
		||||
  const spoiler = this.getOption(interaction, "spoiler");
 | 
			
		||||
  const minimal = this.getOption(interaction, "minimal");
 | 
			
		||||
 | 
			
		||||
  url = url
 | 
			
		||||
    .replace(/\|/g, "")
 | 
			
		||||
| 
						 | 
				
			
			@ -1644,7 +1679,7 @@ fedimbedCommand.callback = async function (interaction) {
 | 
			
		|||
 | 
			
		||||
  if (hasService || BSKY_DOMAINS.includes(urlObj.hostname.toLowerCase())) {
 | 
			
		||||
    try {
 | 
			
		||||
      const {response} = await processUrl(interaction, url, spoiler, true);
 | 
			
		||||
      const {response} = await processUrl(interaction, url, spoiler, true, false, minimal);
 | 
			
		||||
 | 
			
		||||
      if (!response)
 | 
			
		||||
        return {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue