diff --git a/README.md b/README.md index 0f84bb8..9629afe 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,10 @@ [![Webpack](https://github.com/dangeredwolf/pxtwitter/actions/workflows/webpack.yml/badge.svg)](https://github.com/dangeredwolf/pxtwitter/actions/workflows/webpack.yml) -## A TwitFix-like solution written in TypeScript for Cloudflare Workers. +## A TwitFix-like solution written in TypeScript for Cloudflare Workers. ### Embed videos, polls, and more on Discord, Telegram, and more! + ### Just add `px` before `twitter.com`. ![https://cdn.discordapp.com/attachments/165560751363325952/997265440868946032/pxtwitter.png](https://cdn.discordapp.com/attachments/165560751363325952/997265440868946032/pxtwitter.png) @@ -23,14 +24,13 @@ Licensed under the permissive MIT license. Feel free to send a pull request! - ### Things to tackle in the future -* Embed profiles! (and maybe more from Twitter?) -* Combining multiple images together (would be outside CF Worker) -* Caching responses (I haven't done this yet as this is still being actively worked on!) -* Caching guest token (So we don't have to bother Twitter for one on every request) +- Embed profiles! (and maybe more from Twitter?) +- Combining multiple images together (would be outside CF Worker) +- Caching responses (I haven't done this yet as this is still being actively worked on!) +- Caching guest token (So we don't have to bother Twitter for one on every request) ### Bugs or issues? -Feel free to [open an issue](https://github.com/dangeredwolf/pxTwitter/issues), or [ping me on Twitter and I'll see what I can do](https://twitter.com/dangeredwolf). \ No newline at end of file +Feel free to [open an issue](https://github.com/dangeredwolf/pxTwitter/issues), or [ping me on Twitter and I'll see what I can do](https://twitter.com/dangeredwolf). diff --git a/src/card.ts b/src/card.ts index 0a0d1d2..a59e1d2 100644 --- a/src/card.ts +++ b/src/card.ts @@ -22,7 +22,11 @@ export const calculateTimeLeftString = (date: Date) => { return daysString || hoursString || minutesString || secondsString || 'Final results'; }; -export const renderCard = async (card: TweetCard, headers: string[], userAgent: string = ''): Promise => { +export const renderCard = async ( + card: TweetCard, + headers: string[], + userAgent: string = '' +): Promise => { let str = '\n\n'; const values = card.binding_values; @@ -39,8 +43,10 @@ export const renderCard = async (card: TweetCard, headers: string[], userAgent: /* TODO: make poll code cleaner */ if (typeof values !== 'undefined') { - if (typeof values.choice1_count !== 'undefined' && - typeof values.choice2_count !== 'undefined') { + if ( + typeof values.choice1_count !== 'undefined' && + typeof values.choice2_count !== 'undefined' + ) { if (typeof values.end_datetime_utc !== 'undefined') { const date = new Date(values.end_datetime_utc.string_value); timeLeft = calculateTimeLeftString(date); @@ -72,26 +78,33 @@ export const renderCard = async (card: TweetCard, headers: string[], userAgent: ${label}  (${Math.round((votes / totalVotes || 0) * 100)}%) `; } - + str += `\n${totalVotes} votes · ${timeLeft}`; - + console.log(str); } - } else if (typeof values.player_url !== "undefined") { + } else if (typeof values.player_url !== 'undefined') { headers.push( ``, - ``, - ``, + ``, + ``, ``, ``, ``, ``, - ``, - ``, - ) + ``, + `` + ); } } - return str; }; diff --git a/src/linkFixer.ts b/src/linkFixer.ts index bf14b04..7c7a48c 100644 --- a/src/linkFixer.ts +++ b/src/linkFixer.ts @@ -4,9 +4,9 @@ export const linkFixer = (tweet: TweetPartial, text: string): string => { tweet.entities?.urls.forEach((url: TcoExpansion) => { text = text.replace(url.url, url.expanded_url); }); - + text = text.replace(/ ?https\:\/\/t\.co\/\w{10}/, ''); } return text; -} \ No newline at end of file +}; diff --git a/src/quote.ts b/src/quote.ts index 1e4fb55..7bb57ef 100644 --- a/src/quote.ts +++ b/src/quote.ts @@ -1,12 +1,12 @@ -import { linkFixer } from "./linkFixer"; +import { linkFixer } from './linkFixer'; export const handleQuote = (quote: TweetPartial): string | null => { console.log('quote tweet: ', quote); - let str = `\n` - str += `↘️ Quoting ${quote.user?.name} (@${quote.user?.screen_name}) ` + let str = `\n`; + str += `↘️ Quoting ${quote.user?.name} (@${quote.user?.screen_name}) `; - str += '═'.repeat(Math.max(60 - str.length, 0)) + str += '═'.repeat(Math.max(60 - str.length, 0)); str += ` \n\n`; str += linkFixer(quote, quote.full_text); diff --git a/src/status.ts b/src/status.ts index b64c058..f8808e2 100644 --- a/src/status.ts +++ b/src/status.ts @@ -69,7 +69,8 @@ export const handleStatus = async ( conversation.globalObjects?.tweets?.[tweet.quoted_status_id_str || '0'] || null; if (quoteTweetMaybe) { - quoteTweetMaybe.user = conversation?.globalObjects?.users?.[quoteTweetMaybe.user_id_str] || {}; + quoteTweetMaybe.user = + conversation?.globalObjects?.users?.[quoteTweetMaybe.user_id_str] || {}; const quoteText = handleQuote(quoteTweetMaybe); console.log('quoteText', quoteText); @@ -78,15 +79,18 @@ export const handleStatus = async ( text += `\n${quoteText}`; } - if (mediaList.length === 0 && (quoteTweetMaybe.extended_entities?.media?.length || quoteTweetMaybe.entities?.media?.length || 0) > 0) { + if ( + mediaList.length === 0 && + (quoteTweetMaybe.extended_entities?.media?.length || + quoteTweetMaybe.entities?.media?.length || + 0) > 0 + ) { console.log('No media in main tweet, maybe we have some media in the quote tweet?'); mediaList = Array.from( - quoteTweetMaybe.extended_entities?.media || - quoteTweetMaybe.entities?.media || - [] + quoteTweetMaybe.extended_entities?.media || quoteTweetMaybe.entities?.media || [] ); - console.log('updated mediaList', mediaList) + console.log('updated mediaList', mediaList); } } diff --git a/src/utils.ts b/src/utils.ts index 3343bd1..3a99f0d 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,3 @@ export const sanitizeText = (text: string) => { return text.replace(/\"/g, '"').replace(/\/g, '>'); -} \ No newline at end of file +};