fedimbed: add embed image alt text even though bots cant use it yet
This commit is contained in:
		
							parent
							
								
									38ef4d1c2f
								
							
						
					
					
						commit
						28fab3823a
					
				
					 4 changed files with 45 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -1 +1,2 @@
 | 
			
		|||
data/
 | 
			
		||||
pnpm-lock.yaml
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,5 +41,11 @@
 | 
			
		|||
    "#lib/*.js": "./src/lib/*.js",
 | 
			
		||||
    "#util/*.js": "./src/util/*.js",
 | 
			
		||||
    "#modules/*.js": "./src/modules/*.js"
 | 
			
		||||
  },
 | 
			
		||||
  "pnpm": {
 | 
			
		||||
    "onlyBuiltDependencies": [
 | 
			
		||||
      "sharp",
 | 
			
		||||
      "sqlite3"
 | 
			
		||||
    ]
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										10
									
								
								pnpm-lock.yaml
									
										
									
										generated
									
									
									
								
							
							
						
						
									
										10
									
								
								pnpm-lock.yaml
									
										
									
										generated
									
									
									
								
							| 
						 | 
				
			
			@ -16,7 +16,7 @@ importers:
 | 
			
		|||
        version: 1.7.0
 | 
			
		||||
      '@projectdysnomia/dysnomia':
 | 
			
		||||
        specifier: github:projectdysnomia/dysnomia#dev
 | 
			
		||||
        version: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/23aff37eb15c71c5a9188f5cafa99cbe8412e4dc
 | 
			
		||||
        version: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/450795bb5b38c8dc6940eec7f2ef6655138e0600
 | 
			
		||||
      dumpy:
 | 
			
		||||
        specifier: github:Cynosphere/dumpy.js
 | 
			
		||||
        version: https://codeload.github.com/Cynosphere/dumpy.js/tar.gz/5fc22353cdcb97084bab572266390e780d9f7a7b(encoding@0.1.13)
 | 
			
		||||
| 
						 | 
				
			
			@ -459,9 +459,9 @@ packages:
 | 
			
		|||
    resolution: {integrity: sha512-aGQIwo6/sWtyyqhVK4e1MtxYz4N1X8CNt6SOtCc+Wnczs5S5ONaLHDDR8LYaGn0MgOwvGgXyuZ5sJIfd7iyoUw==}
 | 
			
		||||
    engines: {node: '>=0.10'}
 | 
			
		||||
 | 
			
		||||
  '@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/23aff37eb15c71c5a9188f5cafa99cbe8412e4dc':
 | 
			
		||||
    resolution: {tarball: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/23aff37eb15c71c5a9188f5cafa99cbe8412e4dc}
 | 
			
		||||
    version: 0.2.1
 | 
			
		||||
  '@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/450795bb5b38c8dc6940eec7f2ef6655138e0600':
 | 
			
		||||
    resolution: {tarball: https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/450795bb5b38c8dc6940eec7f2ef6655138e0600}
 | 
			
		||||
    version: 0.2.2
 | 
			
		||||
    engines: {node: '>=18.0.0'}
 | 
			
		||||
    peerDependencies:
 | 
			
		||||
      '@discordjs/opus': ^0.9.0
 | 
			
		||||
| 
						 | 
				
			
			@ -2136,7 +2136,7 @@ snapshots:
 | 
			
		|||
      jsprim: 1.4.2
 | 
			
		||||
      sshpk: 1.17.0
 | 
			
		||||
 | 
			
		||||
  '@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/23aff37eb15c71c5a9188f5cafa99cbe8412e4dc':
 | 
			
		||||
  '@projectdysnomia/dysnomia@https://codeload.github.com/projectdysnomia/dysnomia/tar.gz/450795bb5b38c8dc6940eec7f2ef6655138e0600':
 | 
			
		||||
    dependencies:
 | 
			
		||||
      ws: 8.18.0
 | 
			
		||||
    optionalDependencies:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -271,7 +271,9 @@ async function blueskyQuoteEmbed(quote) {
 | 
			
		|||
    const embed = quote.embeds[0];
 | 
			
		||||
    switch (embed.$type) {
 | 
			
		||||
      case "app.bsky.embed.images#view": {
 | 
			
		||||
        embeds.push(...embed.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}})));
 | 
			
		||||
        embeds.push(
 | 
			
		||||
          ...embed.images.map((image) => ({...mainEmbed, image: {url: image.fullsize, description: image.alt}}))
 | 
			
		||||
        );
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
      case "app.bsky.embed.video#view": {
 | 
			
		||||
| 
						 | 
				
			
			@ -290,7 +292,9 @@ async function blueskyQuoteEmbed(quote) {
 | 
			
		|||
      }
 | 
			
		||||
      case "app.bsky.embed.recordWithMedia#view": {
 | 
			
		||||
        if (embed.media.$type === "app.bsky.embed.images#view") {
 | 
			
		||||
          embeds.push(...embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}})));
 | 
			
		||||
          embeds.push(
 | 
			
		||||
            ...embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize, description: image.alt}}))
 | 
			
		||||
          );
 | 
			
		||||
        } else if (embed.media.$type === "app.bsky.embed.video#view") {
 | 
			
		||||
          const lookup = await fetch(`https://plc.directory/${quote.author.did}`).then((res) => res.json());
 | 
			
		||||
          const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint;
 | 
			
		||||
| 
						 | 
				
			
			@ -426,7 +430,9 @@ async function bluesky(msg, url, spoiler = false) {
 | 
			
		|||
  if (post.embed) {
 | 
			
		||||
    switch (post.embed.$type) {
 | 
			
		||||
      case "app.bsky.embed.images#view": {
 | 
			
		||||
        embeds.push(...post.embed.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}})));
 | 
			
		||||
        embeds.push(
 | 
			
		||||
          ...post.embed.images.map((image) => ({...mainEmbed, image: {url: image.fullsize, description: image.alt}}))
 | 
			
		||||
        );
 | 
			
		||||
        break;
 | 
			
		||||
      }
 | 
			
		||||
      case "app.bsky.embed.video#view": {
 | 
			
		||||
| 
						 | 
				
			
			@ -463,7 +469,12 @@ async function bluesky(msg, url, spoiler = false) {
 | 
			
		|||
        hasQuote = true;
 | 
			
		||||
 | 
			
		||||
        if (post.embed.media.$type === "app.bsky.embed.images#view") {
 | 
			
		||||
          embeds.push(...post.embed.media.images.map((image) => ({...mainEmbed, image: {url: image.fullsize}})));
 | 
			
		||||
          embeds.push(
 | 
			
		||||
            ...post.embed.media.images.map((image) => ({
 | 
			
		||||
              ...mainEmbed,
 | 
			
		||||
              image: {url: image.fullsize, description: image.alt},
 | 
			
		||||
            }))
 | 
			
		||||
          );
 | 
			
		||||
        } else if (post.embed.media.$type === "app.bsky.embed.video#view") {
 | 
			
		||||
          const lookup = await fetch(`https://plc.directory/${post.author.did}`).then((res) => res.json());
 | 
			
		||||
          const domain = lookup.service.find((service) => service.id === "#atproto_pds").serviceEndpoint;
 | 
			
		||||
| 
						 | 
				
			
			@ -535,7 +546,10 @@ async function bluesky(msg, url, spoiler = false) {
 | 
			
		|||
        },
 | 
			
		||||
      }).then((res) => Number(res.headers.get("Content-Length")));
 | 
			
		||||
 | 
			
		||||
      if (size <= getUploadLimit(guild)) {
 | 
			
		||||
      let limit = getUploadLimit(guild);
 | 
			
		||||
      if (msg.attachmentSizeLimit != null) limit = msg.attachmentSizeLimit;
 | 
			
		||||
 | 
			
		||||
      if (size <= limit) {
 | 
			
		||||
        const file = await fetch(attachment.url, {
 | 
			
		||||
          headers: {
 | 
			
		||||
            "User-Agent": FRIENDLY_USERAGENT,
 | 
			
		||||
| 
						 | 
				
			
			@ -551,6 +565,7 @@ async function bluesky(msg, url, spoiler = false) {
 | 
			
		|||
              ? attachment.type.replace("/", ".").replace("quicktime", "mov")
 | 
			
		||||
              : attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp4")),
 | 
			
		||||
          file,
 | 
			
		||||
          description: attachment.desc,
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1291,12 +1306,16 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
 | 
			
		||||
  const guild = msg.channel?.guild ?? (msg.guildID ? hf.bot.guilds.get(msg.guildID) : false);
 | 
			
		||||
 | 
			
		||||
  let limit = getUploadLimit(guild);
 | 
			
		||||
  if (msg.attachmentSizeLimit != null) limit = msg.attachmentSizeLimit;
 | 
			
		||||
 | 
			
		||||
  if (images.length > 0) {
 | 
			
		||||
    if (images.length <= 4) {
 | 
			
		||||
      for (const attachment of images) {
 | 
			
		||||
        const embed = Object.assign({}, baseEmbed);
 | 
			
		||||
        embed.image = {
 | 
			
		||||
          url: attachment.url,
 | 
			
		||||
          description: attachment.desc,
 | 
			
		||||
        };
 | 
			
		||||
        embeds.push(embed);
 | 
			
		||||
      }
 | 
			
		||||
| 
						 | 
				
			
			@ -1309,7 +1328,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
          },
 | 
			
		||||
        }).then((res) => Number(res.headers.get("Content-Length")));
 | 
			
		||||
 | 
			
		||||
        if (size <= getUploadLimit(guild)) {
 | 
			
		||||
        if (size <= limit) {
 | 
			
		||||
          const file = await fetch(attachment.url, {
 | 
			
		||||
            headers: {
 | 
			
		||||
              "User-Agent": FRIENDLY_USERAGENT,
 | 
			
		||||
| 
						 | 
				
			
			@ -1341,7 +1360,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
          },
 | 
			
		||||
        }).then((res) => Number(res.headers.get("Content-Length")));
 | 
			
		||||
 | 
			
		||||
        if (size <= getUploadLimit(guild)) {
 | 
			
		||||
        if (size <= limit) {
 | 
			
		||||
          const file = await fetch(attachment.url, {
 | 
			
		||||
            headers: {
 | 
			
		||||
              "User-Agent": FRIENDLY_USERAGENT,
 | 
			
		||||
| 
						 | 
				
			
			@ -1369,6 +1388,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
          const embed = Object.assign({}, baseEmbed);
 | 
			
		||||
          embed.image = {
 | 
			
		||||
            url: attachment.url,
 | 
			
		||||
            description: attachment.desc,
 | 
			
		||||
          };
 | 
			
		||||
          embeds.push(embed);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1379,6 +1399,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
          const embed = Object.assign({}, baseEmbed);
 | 
			
		||||
          embed.image = {
 | 
			
		||||
            url: attachment.url,
 | 
			
		||||
            description: attachment.desc,
 | 
			
		||||
          };
 | 
			
		||||
          embeds.push(embed);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1394,6 +1415,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
          const embed = Object.assign({}, _embed);
 | 
			
		||||
          embed.image = {
 | 
			
		||||
            url: attachment.url,
 | 
			
		||||
            description: attachment.desc,
 | 
			
		||||
          };
 | 
			
		||||
          embeds.push(embed);
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -1412,7 +1434,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
        },
 | 
			
		||||
      }).then((res) => Number(res.headers.get("Content-Length")));
 | 
			
		||||
 | 
			
		||||
      if (size <= getUploadLimit(guild)) {
 | 
			
		||||
      if (size <= limit) {
 | 
			
		||||
        const file = await fetch(attachment.url, {
 | 
			
		||||
          headers: {
 | 
			
		||||
            "User-Agent": FRIENDLY_USERAGENT,
 | 
			
		||||
| 
						 | 
				
			
			@ -1428,6 +1450,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
              ? attachment.type.replace("/", ".").replace("quicktime", "mov")
 | 
			
		||||
              : attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp4")),
 | 
			
		||||
          file,
 | 
			
		||||
          description: attachment.desc,
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -1441,7 +1464,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
        },
 | 
			
		||||
      }).then((res) => Number(res.headers.get("Content-Length")));
 | 
			
		||||
 | 
			
		||||
      if (size <= getUploadLimit(guild)) {
 | 
			
		||||
      if (size <= limit) {
 | 
			
		||||
        const file = await fetch(attachment.url, {
 | 
			
		||||
          headers: {
 | 
			
		||||
            "User-Agent": FRIENDLY_USERAGENT,
 | 
			
		||||
| 
						 | 
				
			
			@ -1457,6 +1480,7 @@ async function processUrl(msg, url, spoiler = false, command = false) {
 | 
			
		|||
              ? attachment.type.replace("/", ".").replace("mpeg", "mp3").replace("vnd.wave", "wav").replace("x-", "")
 | 
			
		||||
              : attachment.type + "." + (url.match(/\.([a-z0-9]{3,4})$/)?.[0] ?? "mp3")),
 | 
			
		||||
          file,
 | 
			
		||||
          description: attachment.desc,
 | 
			
		||||
        });
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue