From 1612832fc4f782a29988d2c9a1b928cfc00429e3 Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Sun, 3 Sep 2023 15:28:33 -0400 Subject: add facebook, and add steam fields --- src/api/util/utility/EmbedHandlers.ts | 57 +++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts index b1e6b866..430ca4aa 100644 --- a/src/api/util/utility/EmbedHandlers.ts +++ b/src/api/util/utility/EmbedHandlers.ts @@ -226,8 +226,23 @@ export const EmbedHandlers: { "c.tenor.com": genericImageHandler, "media.tenor.com": genericImageHandler, - // TODO: facebook - // have to use their APIs or something because they don't send the metas in initial html + "facebook.com": (url) => EmbedHandlers["www.facebook.com"](url), + "www.facebook.com": async (url: URL) => { + const response = await doFetch(url); + if (!response) return null; + const metas = getMetaDescriptions(await response.text()); + + return { + url: url.href, + type: EmbedType.link, + title: metas.title, + description: metas.description, + thumbnail: makeEmbedImage(metas.image, 640, 640), + provider: { + name: "Facebook", + }, + }; + }, "twitter.com": (url) => EmbedHandlers["www.twitter.com"](url), "www.twitter.com": async (url: URL) => { @@ -385,6 +400,42 @@ export const EmbedHandlers: { const response = await doFetch(url); if (!response) return null; const metas = getMetaDescriptions(await response.text()); + const numReviews = metas.$("#review_summary_num_reviews").val() as + | string + | undefined; + const price = metas + .$(".game_purchase_price.price") + .data("price-final") as number | undefined; + const releaseDate = metas + .$(".release_date") + .find("div.date") + .text() + .trim(); + const isReleased = new Date(releaseDate) < new Date(); + + const fields: Embed["fields"] = []; + + if (numReviews) + fields.push({ + name: "Reviews", + value: numReviews, + inline: true, + }); + + if (price) + fields.push({ + name: "Price", + value: `$${price / 100}`, + inline: true, + }); + + // if the release date is in the past, it's already out + if (releaseDate && !isReleased) + fields.push({ + name: "Release Date", + value: releaseDate, + inline: true, + }); return { url: url.href, @@ -405,7 +456,7 @@ export const EmbedHandlers: { url: "https://store.steampowered.com", name: "Steam", }, - // TODO: fields for release date + fields, // TODO: Video }; }, -- cgit 1.4.1 From 8a35664ae630e960bf44f01497100e318231effb Mon Sep 17 00:00:00 2001 From: Puyodead1 Date: Sun, 3 Sep 2023 15:48:55 -0400 Subject: [fb] remove provider obj, add color --- src/api/util/utility/EmbedHandlers.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/api/util/utility/EmbedHandlers.ts b/src/api/util/utility/EmbedHandlers.ts index 430ca4aa..ab953613 100644 --- a/src/api/util/utility/EmbedHandlers.ts +++ b/src/api/util/utility/EmbedHandlers.ts @@ -238,9 +238,7 @@ export const EmbedHandlers: { title: metas.title, description: metas.description, thumbnail: makeEmbedImage(metas.image, 640, 640), - provider: { - name: "Facebook", - }, + color: 16777215, }; }, -- cgit 1.4.1