Move poll strings to Strings

This commit is contained in:
dangered wolf 2022-07-18 17:04:26 -04:00
parent 0e44e2c721
commit 66147807ac
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
4 changed files with 57 additions and 18 deletions

View file

@ -1,3 +1,5 @@
import { Strings } from './strings';
let barLength = 36; let barLength = 36;
export const calculateTimeLeft = (date: Date) => { export const calculateTimeLeft = (date: Date) => {
@ -12,14 +14,33 @@ export const calculateTimeLeft = (date: Date) => {
export const calculateTimeLeftString = (date: Date) => { export const calculateTimeLeftString = (date: Date) => {
const { days, hours, minutes, seconds } = calculateTimeLeft(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 = 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 = 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 = const secondsString =
seconds > 0 ? `${seconds} ${seconds === 1 ? 'second left' : 'seconds left'}` : ''; seconds > 0
return daysString || hoursString || minutesString || secondsString || 'Final results'; ? `${seconds} ${
seconds === 1 ? Strings.SINGULAR_SECOND_LEFT : Strings.PLURAL_SECONDS_LEFT
}`
: '';
return (
daysString ||
hoursString ||
minutesString ||
secondsString ||
Strings.FINAL_POLL_RESULTS
);
}; };
export const renderCard = async ( export const renderCard = async (

View file

@ -8,13 +8,15 @@ import { sanitizeText } from './utils';
import { Strings } from './strings'; import { Strings } from './strings';
export const returnError = (error: string): StatusResponse => { export const returnError = (error: string): StatusResponse => {
return {text: Strings.BASE_HTML.format({ return {
lang: '', text: Strings.BASE_HTML.format({
headers: [ lang: '',
`<meta content="${Constants.BRANDING_NAME}" property="og:title"/>`, headers: [
`<meta content="${error}" property="og:description"/>` `<meta content="${Constants.BRANDING_NAME}" property="og:title"/>`,
].join('') `<meta content="${error}" property="og:description"/>`
})}; ].join('')
})
};
}; };
export const handleStatus = async ( export const handleStatus = async (
@ -135,7 +137,9 @@ export const handleStatus = async (
quoteTweetMaybe.entities?.media?.length || quoteTweetMaybe.entities?.media?.length ||
0) > 0 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( mediaList = Array.from(
quoteTweetMaybe.extended_entities?.media || quoteTweetMaybe.entities?.media || [] 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 */ /* When dealing with a Tweet of unknown lang, fall back to en */
let lang = tweet.lang === 'unk' ? 'en' : tweet.lang || 'en'; let lang = tweet.lang === 'unk' ? 'en' : tweet.lang || 'en';
return { text: Strings.BASE_HTML.format({ return {
lang: `lang="${lang}"`, text: Strings.BASE_HTML.format({
headers: headers.join('') lang: `lang="${lang}"`,
}) }; headers: headers.join('')
})
};
}; };

View file

@ -35,8 +35,20 @@ export const Strings = {
--> -->
<head>{headers}</head>`, <head>{headers}</head>`,
DEFAULT_AUTHOR_TEXT: 'Twitter', DEFAULT_AUTHOR_TEXT: 'Twitter',
QUOTE_TEXT: `═ ↘️ Quoting {name} (@{screen_name}) ═════`, QUOTE_TEXT: `═ ↘️ Quoting {name} (@{screen_name}) ═════`,
PHOTO_COUNT: `Photo {number} of {total}`, 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_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_PRIVATE: `I can't embed Tweets from private accounts, sorry about that :(`,
ERROR_TWEET_NOT_FOUND: `Sorry, that Tweet doesn't exist :(`, ERROR_TWEET_NOT_FOUND: `Sorry, that Tweet doesn't exist :(`,

2
src/types.d.ts vendored
View file

@ -8,4 +8,4 @@ type InputFlags = {
interface StatusResponse { interface StatusResponse {
text?: string; text?: string;
response?: Response; response?: Response;
} }