fedimbed: cleanup icon name replacements, twitter verified icons
This commit is contained in:
		
							parent
							
								
									ce7d5571b1
								
							
						
					
					
						commit
						ef3495bff1
					
				
					 2 changed files with 49 additions and 41 deletions
				
			
		| 
						 | 
					@ -319,14 +319,10 @@ function processBlueskyFacets(str, facets) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getStatsBluesky(post) {
 | 
					function getStatsBluesky(post) {
 | 
				
			||||||
  const stats = [];
 | 
					  const stats = [];
 | 
				
			||||||
  if (post.replyCount > 0)
 | 
					  if (post.replyCount > 0) stats.push(`${Icons.fedimbed.reply} ${statsFormatter.format(post.replyCount)}`);
 | 
				
			||||||
    stats.push(`${Icons.fedimbed.reply.replace(":i:", ":Replies:")} ${statsFormatter.format(post.replyCount)}`);
 | 
					  if (post.repostCount > 0) stats.push(`${Icons.fedimbed.repost} ${statsFormatter.format(post.repostCount)}`);
 | 
				
			||||||
  if (post.repostCount > 0)
 | 
					  if (post.quoteCount > 0) stats.push(`${Icons.fedimbed.quote} ${statsFormatter.format(post.quoteCount)}`);
 | 
				
			||||||
    stats.push(`${Icons.fedimbed.repost.replace(":i:", ":Reposts:")} ${statsFormatter.format(post.repostCount)}`);
 | 
					  if (post.likeCount > 0) stats.push(`${Icons.fedimbed.like} ${statsFormatter.format(post.likeCount)}`);
 | 
				
			||||||
  if (post.quoteCount > 0)
 | 
					 | 
				
			||||||
    stats.push(`${Icons.fedimbed.quote.replace(":i:", ":Quotes:")} ${statsFormatter.format(post.quoteCount)}`);
 | 
					 | 
				
			||||||
  if (post.likeCount > 0)
 | 
					 | 
				
			||||||
    stats.push(`${Icons.fedimbed.like.replace(":i:", ":Likes:")} ${statsFormatter.format(post.likeCount)}`);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return stats.join("\u3000");
 | 
					  return stats.join("\u3000");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -387,7 +383,7 @@ async function blueskyQuoteEmbed(quote, minimal = false) {
 | 
				
			||||||
    ? [
 | 
					    ? [
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          type: 10,
 | 
					          type: 10,
 | 
				
			||||||
          content: `### ${Icons.fedimbed.quote.replace(":i:", ":Quoting:")} [${quote.author.displayName} (@${
 | 
					          content: `### ${Icons.fedimbed.quote.replace(":Quotes:", ":Quoting:")} [${quote.author.displayName} (@${
 | 
				
			||||||
            quote.author.handle
 | 
					            quote.author.handle
 | 
				
			||||||
          })](${quoteUrl}) \u2022 <t:${Math.floor(new Date(quote.value.createdAt).getTime() / 1000)}:F>\n${content}`,
 | 
					          })](${quoteUrl}) \u2022 <t:${Math.floor(new Date(quote.value.createdAt).getTime() / 1000)}:F>\n${content}`,
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
| 
						 | 
					@ -669,11 +665,11 @@ async function bluesky(msg, url, spoiler = false, minimal = 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.replace(":i:", minimal ? ":ReplyingTo:" : ":i:")} ${
 | 
					    context = `-# ${Icons.fedimbed.reply.replace(":Replies:", ":ReplyingTo:")} ${minimal ? "" : "Replying to: "}[${
 | 
				
			||||||
      minimal ? "" : "Replying to: "
 | 
					      reply.author.displayName
 | 
				
			||||||
    }[${reply.author.displayName} (@${reply.author.handle})](https://bsky.app/profile/${
 | 
					    } (@${reply.author.handle})](https://bsky.app/profile/${reply.author.did}/post/${reply.uri.substring(
 | 
				
			||||||
      reply.author.did
 | 
					      reply.uri.lastIndexOf("/") + 1
 | 
				
			||||||
    }/post/${reply.uri.substring(reply.uri.lastIndexOf("/") + 1)})`;
 | 
					    )})`;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let content = post.record.text;
 | 
					  let content = post.record.text;
 | 
				
			||||||
| 
						 | 
					@ -945,24 +941,20 @@ async function getStatsAS(post) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const stats = [];
 | 
					  const stats = [];
 | 
				
			||||||
  if (replyCount > 0)
 | 
					  if (replyCount > 0) stats.push(`${Icons.fedimbed.reply} ${statsFormatter.format(replyCount)}`);
 | 
				
			||||||
    stats.push(`${Icons.fedimbed.reply.replace(":i:", ":Replies:")} ${statsFormatter.format(replyCount)}`);
 | 
					 | 
				
			||||||
  if (post.shares?.totalItems ?? 0 > 0)
 | 
					  if (post.shares?.totalItems ?? 0 > 0)
 | 
				
			||||||
    stats.push(`${Icons.fedimbed.repost.replace(":i:", ":Reposts:")} ${statsFormatter.format(post.shares.totalItems)}`);
 | 
					    stats.push(`${Icons.fedimbed.repost} ${statsFormatter.format(post.shares.totalItems)}`);
 | 
				
			||||||
  if (post.likes?.totalItems ?? 0 > 0)
 | 
					  if (post.likes?.totalItems ?? 0 > 0)
 | 
				
			||||||
    stats.push(`${Icons.fedimbed.like.replace(":i:", ":Likes:")} ${statsFormatter.format(post.likes.totalItems)}`);
 | 
					    stats.push(`${Icons.fedimbed.like} ${statsFormatter.format(post.likes.totalItems)}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return stats.join("\u3000");
 | 
					  return stats.join("\u3000");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function getStatsMasto(post) {
 | 
					function getStatsMasto(post) {
 | 
				
			||||||
  const stats = [];
 | 
					  const stats = [];
 | 
				
			||||||
  if (post.replies_count > 0)
 | 
					  if (post.replies_count > 0) stats.push(`${Icons.fedimbed.reply} ${statsFormatter.format(post.replies_count)}`);
 | 
				
			||||||
    stats.push(`${Icons.fedimbed.reply.replace(":i:", ":Replies:")} ${statsFormatter.format(post.replies_count)}`);
 | 
					  if (post.reblogs_count > 0) stats.push(`${Icons.fedimbed.repost} ${statsFormatter.format(post.reblogs_count)}`);
 | 
				
			||||||
  if (post.reblogs_count > 0)
 | 
					  if (post.favourites_count > 0) stats.push(`${Icons.fedimbed.like} ${statsFormatter.format(post.favourites_count)}`);
 | 
				
			||||||
    stats.push(`${Icons.fedimbed.repost.replace(":i:", ":Reposts:")} ${statsFormatter.format(post.reblogs_count)}`);
 | 
					 | 
				
			||||||
  if (post.favourites_count > 0)
 | 
					 | 
				
			||||||
    stats.push(`${Icons.fedimbed.like.replace(":i:", ":Likes:")} ${statsFormatter.format(post.favourites_count)}`);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return stats.join("\u3000");
 | 
					  return stats.join("\u3000");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -1289,6 +1281,7 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
				
			||||||
        handle: `${authorData.preferredUsername}@${authorUrlObj.hostname}`,
 | 
					        handle: `${authorData.preferredUsername}@${authorUrlObj.hostname}`,
 | 
				
			||||||
        url: authorData.url,
 | 
					        url: authorData.url,
 | 
				
			||||||
        avatar: authorData.icon?.url,
 | 
					        avatar: authorData.icon?.url,
 | 
				
			||||||
 | 
					        fields: authorData.attachment ?? authorData.fields,
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      // bootleg author
 | 
					      // bootleg author
 | 
				
			||||||
| 
						 | 
					@ -1299,6 +1292,7 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
				
			||||||
        name,
 | 
					        name,
 | 
				
			||||||
        handle: `${name}@${authorUrlObj.hostname}`,
 | 
					        handle: `${name}@${authorUrlObj.hostname}`,
 | 
				
			||||||
        url: authorUrl,
 | 
					        url: authorUrl,
 | 
				
			||||||
 | 
					        fields: [],
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1325,6 +1319,7 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
				
			||||||
  cw = cw ?? "";
 | 
					  cw = cw ?? "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let quoteRes;
 | 
					  let quoteRes;
 | 
				
			||||||
 | 
					  let twitterVerified = "";
 | 
				
			||||||
  if (platformName == "Nitter") {
 | 
					  if (platformName == "Nitter") {
 | 
				
			||||||
    const quote = content.match(/<blockquote><b>↘ <a href="([^"]+?)">/);
 | 
					    const quote = content.match(/<blockquote><b>↘ <a href="([^"]+?)">/);
 | 
				
			||||||
    if (quote?.[1]) {
 | 
					    if (quote?.[1]) {
 | 
				
			||||||
| 
						 | 
					@ -1340,6 +1335,11 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
				
			||||||
    content = content
 | 
					    content = content
 | 
				
			||||||
      .replaceAll(/tw\.(counter-strike\.gay|c7\.pm)/g, "twitter.com")
 | 
					      .replaceAll(/tw\.(counter-strike\.gay|c7\.pm)/g, "twitter.com")
 | 
				
			||||||
      .replaceAll(/twitter\.com\/t\.co/g, "t.co");
 | 
					      .replaceAll(/twitter\.com\/t\.co/g, "t.co");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const verifiedType = author.fields.find((f) => f.name === "Verified Type");
 | 
				
			||||||
 | 
					    if (verifiedType) {
 | 
				
			||||||
 | 
					      twitterVerified = " " + (Icons.fedimbed.verified[verifiedType.value] ?? "");
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  content = content.replaceAll("`", "\u02cb").replaceAll("*", "\u2217");
 | 
					  content = content.replaceAll("`", "\u02cb").replaceAll("*", "\u2217");
 | 
				
			||||||
| 
						 | 
					@ -1378,12 +1378,12 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
				
			||||||
  if (platformName.includes("Nitter") && platformName.includes(" \u2022 ")) {
 | 
					  if (platformName.includes("Nitter") && platformName.includes(" \u2022 ")) {
 | 
				
			||||||
    const [_, ns] = platformName.split(" \u2022 ");
 | 
					    const [_, ns] = platformName.split(" \u2022 ");
 | 
				
			||||||
    stats = ns
 | 
					    stats = ns
 | 
				
			||||||
      .replace("\u21a9", Icons.fedimbed.reply.replace(":i:", ":Replies:"))
 | 
					      .replace("\u21a9", Icons.fedimbed.reply)
 | 
				
			||||||
      .replace("\ud83d\udd01", Icons.fedimbed.repost.replace(":i:", ":Reposts:"))
 | 
					      .replace("\ud83d\udd01", Icons.fedimbed.repost)
 | 
				
			||||||
      .replace("\u2198", Icons.fedimbed.quote.replace(":i:", ":Quotes:"))
 | 
					      .replace("\u2198", Icons.fedimbed.quote)
 | 
				
			||||||
      .replace("\u2665", Icons.fedimbed.like.replace(":i:", ":Likes:"))
 | 
					      .replace("\u2665", Icons.fedimbed.like)
 | 
				
			||||||
      .replace("\ud83d\udd16", Icons.fedimbed.bookmark.replace(":i:", ":Bookmarks:"))
 | 
					      .replace("\ud83d\udd16", Icons.fedimbed.bookmark)
 | 
				
			||||||
      .replace("\ud83d\udc41", Icons.fedimbed.views.replace(":i:", ":Views:"))
 | 
					      .replace("\ud83d\udc41", Icons.fedimbed.views)
 | 
				
			||||||
      .replaceAll(/ <:(\w):/g, "\u3000<:$1:");
 | 
					      .replaceAll(/ <:(\w):/g, "\u3000<:$1:");
 | 
				
			||||||
    platformName = "Twitter";
 | 
					    platformName = "Twitter";
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -1416,10 +1416,10 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  let headerContent = minimal
 | 
					  let headerContent = minimal
 | 
				
			||||||
    ? `### [${author.name ? `${author.name} (${author.handle})` : author.handle}](${realUrl}) \u2022 <t:${Math.floor(
 | 
					    ? `### [${
 | 
				
			||||||
        new Date(timestamp).getTime() / 1000
 | 
					        author.name ? `${author.name} (${author.handle})` : author.handle
 | 
				
			||||||
      )}:F>`
 | 
					      }](${realUrl})${twitterVerified} \u2022 <t:${Math.floor(new Date(timestamp).getTime() / 1000)}:F>`
 | 
				
			||||||
    : `${author.name ? `## ${author.name}\n` : ""}-# [${author.handle}](${author.url})`;
 | 
					    : `${author.name ? `## ${author.name}${twitterVerified}\n` : ""}-# [${author.handle}](${author.url})`;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (title) headerContent += minimal ? "\n**__" + title + "__**" : "\n### " + title;
 | 
					  if (title) headerContent += minimal ? "\n**__" + title + "__**" : "\n### " + title;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1567,7 +1567,10 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote =
 | 
				
			||||||
    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 = minimal
 | 
					      quoteComponents[0].content = minimal
 | 
				
			||||||
        ? quoteComponents[0].content.replace(/^### /, "$&" + Icons.fedimbed.quote.replace(":i:", ":Quoting:") + " ")
 | 
					        ? quoteComponents[0].content.replace(
 | 
				
			||||||
 | 
					            /^### /,
 | 
				
			||||||
 | 
					            "$&" + Icons.fedimbed.quote.replace(":Quotes:", ":Quoting:") + " "
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
        : quoteContext + "\n" + quoteComponents[0].content;
 | 
					        : quoteContext + "\n" + quoteComponents[0].content;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      quoteComponents.splice(0, 0, {type: 10, content: quoteContext});
 | 
					      quoteComponents.splice(0, 0, {type: 10, content: quoteContext});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -581,14 +581,19 @@ module.exports.Icons = {
 | 
				
			||||||
  blank: "<:i:1273123564173918268>",
 | 
					  blank: "<:i:1273123564173918268>",
 | 
				
			||||||
  boat: "<:i:1273105457661087755>",
 | 
					  boat: "<:i:1273105457661087755>",
 | 
				
			||||||
  fedimbed: {
 | 
					  fedimbed: {
 | 
				
			||||||
    quote: "<:i:1308640087759654922>",
 | 
					    quote: "<:Quotes:1308640087759654922>",
 | 
				
			||||||
    reply: "<:i:1308640078825787412>",
 | 
					    reply: "<:Replies:1308640078825787412>",
 | 
				
			||||||
    repost: "<:i:1362905247181439168>",
 | 
					    repost: "<:Reposts:1362905247181439168>",
 | 
				
			||||||
    like: "<:i:1362907286263300356>",
 | 
					    like: "<:Likes:1362907286263300356>",
 | 
				
			||||||
    bookmark: "<:i:1362908185781997719>",
 | 
					    bookmark: "<:Bookmarks:1362908185781997719>",
 | 
				
			||||||
    views: "<:i:1362909322597765270>",
 | 
					    views: "<:Views:1362909322597765270>",
 | 
				
			||||||
    bluesky: "<:i:1362895346690424832>",
 | 
					    bluesky: "<:i:1362895346690424832>",
 | 
				
			||||||
    twitter: "<:i:1362955359337185410>",
 | 
					    twitter: "<:i:1362955359337185410>",
 | 
				
			||||||
 | 
					    verified: {
 | 
				
			||||||
 | 
					      Blue: "<:VerifiedBlue:1385752129188134962>",
 | 
				
			||||||
 | 
					      Business: "<:VerifiedBusiness:1385752141024723004>",
 | 
				
			||||||
 | 
					      Government: "<:VerifiedGovernment:1385752149706674308>",
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue