mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-04 10:00:55 +01:00
Add user-agent parameter to handleStatus
This commit is contained in:
parent
901bda578a
commit
280a2d0376
3 changed files with 13 additions and 5 deletions
10
src/poll.ts
10
src/poll.ts
|
@ -1,4 +1,4 @@
|
|||
const barLength = 36;
|
||||
let barLength = 36;
|
||||
|
||||
export const calculateTimeLeft = (date: Date) => {
|
||||
const now = new Date();
|
||||
|
@ -22,12 +22,17 @@ export const calculateTimeLeftString = (date: Date) => {
|
|||
return daysString || hoursString || minutesString || secondsString || 'Final results';
|
||||
};
|
||||
|
||||
export const renderPoll = async (card: TweetCard): Promise<string> => {
|
||||
export const renderPoll = async (card: TweetCard, userAgent: string = ''): Promise<string> => {
|
||||
let str = '\n\n';
|
||||
const values = card.binding_values;
|
||||
|
||||
console.log('rendering poll on ', card);
|
||||
|
||||
// Telegram's bars need to be a lot smaller to fit its bubbles
|
||||
if (userAgent.indexOf('Telegram') > -1) {
|
||||
barLength = 24;
|
||||
}
|
||||
|
||||
let choices: { [label: string]: number } = {};
|
||||
let totalVotes = 0;
|
||||
let timeLeft = '';
|
||||
|
@ -37,6 +42,7 @@ export const renderPoll = async (card: TweetCard): Promise<string> => {
|
|||
timeLeft = calculateTimeLeftString(date);
|
||||
}
|
||||
|
||||
/* TODO: make this cleaner */
|
||||
if (
|
||||
typeof values !== 'undefined' &&
|
||||
typeof values.choice1_count !== 'undefined' &&
|
||||
|
|
|
@ -29,7 +29,7 @@ const statusRequest = async (request: any) => {
|
|||
const userAgent = request.headers.get('User-Agent');
|
||||
|
||||
if (userAgent.match(/bot/gi) !== null) {
|
||||
return new Response(await handleStatus(id, parseInt(mediaNumber || 1)), {
|
||||
return new Response(await handleStatus(id, parseInt(mediaNumber || 1), userAgent), {
|
||||
headers: Constants.RESPONSE_HEADERS,
|
||||
status: 200
|
||||
});
|
||||
|
@ -49,6 +49,7 @@ router.get('/owoembed', async (request: any) => {
|
|||
console.log('oembed hit!');
|
||||
const { searchParams } = new URL(request.url);
|
||||
|
||||
/* Fallbacks */
|
||||
let text = searchParams.get('text') || 'Twitter';
|
||||
let author = searchParams.get('author') || 'dangeredwolf';
|
||||
let status = searchParams.get('status') || '1547514042146865153';
|
||||
|
|
|
@ -8,7 +8,8 @@ import { handleQuote } from './quote';
|
|||
|
||||
export const handleStatus = async (
|
||||
status: string,
|
||||
mediaNumber?: number
|
||||
mediaNumber?: number,
|
||||
userAgent?: string
|
||||
): Promise<string> => {
|
||||
const conversation = await fetchUsingGuest(status);
|
||||
|
||||
|
@ -58,7 +59,7 @@ export const handleStatus = async (
|
|||
let authorText = 'Twitter';
|
||||
|
||||
if (tweet.card) {
|
||||
text += await renderPoll(tweet.card);
|
||||
text += await renderPoll(tweet.card, userAgent);
|
||||
}
|
||||
|
||||
text = linkFixer(tweet, text);
|
||||
|
|
Loading…
Add table
Reference in a new issue