From 66147807ac438bb942a64d6fbd54339ddced6746 Mon Sep 17 00:00:00 2001 From: dangered wolf Date: Mon, 18 Jul 2022 17:04:26 -0400 Subject: [PATCH] Move poll strings to Strings --- src/card.ts | 31 ++++++++++++++++++++++++++----- src/status.ts | 30 ++++++++++++++++++------------ src/strings.ts | 12 ++++++++++++ src/types.d.ts | 2 +- 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/src/card.ts b/src/card.ts index 5c2a6f2..d5ffcda 100644 --- a/src/card.ts +++ b/src/card.ts @@ -1,3 +1,5 @@ +import { Strings } from './strings'; + let barLength = 36; export const calculateTimeLeft = (date: Date) => { @@ -12,14 +14,33 @@ export const calculateTimeLeft = (date: Date) => { export const calculateTimeLeftString = (date: Date) => { const { days, hours, minutes, seconds } = calculateTimeLeft(date); - const daysString = days > 0 ? `${days} ${days === 1 ? 'day left' : 'days left'}` : ''; + const daysString = + days > 0 + ? `${days} ${days === 1 ? Strings.SINGULAR_DAY_LEFT : Strings.PLURAL_DAYS_LEFT}` + : ''; const hoursString = - hours > 0 ? `${hours} ${hours === 1 ? 'hour left' : 'hours left'}` : ''; + hours > 0 + ? `${hours} ${hours === 1 ? Strings.SINGULAR_HOUR_LEFT : Strings.PLURAL_HOURS_LEFT}` + : ''; const minutesString = - minutes > 0 ? `${minutes} ${minutes === 1 ? 'minute left' : 'minutes left'}` : ''; + minutes > 0 + ? `${minutes} ${ + minutes === 1 ? Strings.SINGULAR_MINUTE_LEFT : Strings.PLURAL_MINUTES_LEFT + }` + : ''; const secondsString = - seconds > 0 ? `${seconds} ${seconds === 1 ? 'second left' : 'seconds left'}` : ''; - return daysString || hoursString || minutesString || secondsString || 'Final results'; + seconds > 0 + ? `${seconds} ${ + seconds === 1 ? Strings.SINGULAR_SECOND_LEFT : Strings.PLURAL_SECONDS_LEFT + }` + : ''; + return ( + daysString || + hoursString || + minutesString || + secondsString || + Strings.FINAL_POLL_RESULTS + ); }; export const renderCard = async ( diff --git a/src/status.ts b/src/status.ts index d4c9f38..0f340ac 100644 --- a/src/status.ts +++ b/src/status.ts @@ -8,13 +8,15 @@ import { sanitizeText } from './utils'; import { Strings } from './strings'; export const returnError = (error: string): StatusResponse => { - return {text: Strings.BASE_HTML.format({ - lang: '', - headers: [ - ``, - `` - ].join('') - })}; + return { + text: Strings.BASE_HTML.format({ + lang: '', + headers: [ + ``, + `` + ].join('') + }) + }; }; export const handleStatus = async ( @@ -135,7 +137,9 @@ export const handleStatus = async ( quoteTweetMaybe.entities?.media?.length || 0) > 0 ) { - console.log(`No media in main tweet, let's try embedding the quote tweet's media instead!`); + console.log( + `No media in main tweet, let's try embedding the quote tweet's media instead!` + ); mediaList = Array.from( quoteTweetMaybe.extended_entities?.media || quoteTweetMaybe.entities?.media || [] ); @@ -328,8 +332,10 @@ export const handleStatus = async ( /* When dealing with a Tweet of unknown lang, fall back to en */ let lang = tweet.lang === 'unk' ? 'en' : tweet.lang || 'en'; - return { text: Strings.BASE_HTML.format({ - lang: `lang="${lang}"`, - headers: headers.join('') - }) }; + return { + text: Strings.BASE_HTML.format({ + lang: `lang="${lang}"`, + headers: headers.join('') + }) + }; }; diff --git a/src/strings.ts b/src/strings.ts index a23080e..eed6140 100644 --- a/src/strings.ts +++ b/src/strings.ts @@ -35,8 +35,20 @@ export const Strings = { --> {headers}`, DEFAULT_AUTHOR_TEXT: 'Twitter', + QUOTE_TEXT: `═ ↘️ Quoting {name} (@{screen_name}) ═════`, PHOTO_COUNT: `Photo {number} of {total}`, + + SINGULAR_DAY_LEFT: 'day left', + PLURAL_DAYS_LEFT: 'days left', + SINGULAR_HOUR_LEFT: 'hour left', + PLURAL_HOURS_LEFT: 'hours left', + SINGULAR_MINUTE_LEFT: 'minute left', + PLURAL_MINUTES_LEFT: 'minutes left', + SINGULAR_SECOND_LEFT: 'second left', + PLURAL_SECONDS_LEFT: 'seconds left', + FINAL_POLL_RESULTS: 'Final results', + ERROR_API_FAIL: 'Tweet failed to load due to an API error :(', ERROR_PRIVATE: `I can't embed Tweets from private accounts, sorry about that :(`, ERROR_TWEET_NOT_FOUND: `Sorry, that Tweet doesn't exist :(`, diff --git a/src/types.d.ts b/src/types.d.ts index 4642a4e..40f8126 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -8,4 +8,4 @@ type InputFlags = { interface StatusResponse { text?: string; response?: Response; -} \ No newline at end of file +}