mirror of
https://github.com/CompeyDev/fxtwitter-docker.git
synced 2025-04-10 21:10:54 +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) => {
|
export const calculateTimeLeft = (date: Date) => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
@ -22,12 +22,17 @@ export const calculateTimeLeftString = (date: Date) => {
|
||||||
return daysString || hoursString || minutesString || secondsString || 'Final results';
|
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';
|
let str = '\n\n';
|
||||||
const values = card.binding_values;
|
const values = card.binding_values;
|
||||||
|
|
||||||
console.log('rendering poll on ', card);
|
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 choices: { [label: string]: number } = {};
|
||||||
let totalVotes = 0;
|
let totalVotes = 0;
|
||||||
let timeLeft = '';
|
let timeLeft = '';
|
||||||
|
@ -37,6 +42,7 @@ export const renderPoll = async (card: TweetCard): Promise<string> => {
|
||||||
timeLeft = calculateTimeLeftString(date);
|
timeLeft = calculateTimeLeftString(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* TODO: make this cleaner */
|
||||||
if (
|
if (
|
||||||
typeof values !== 'undefined' &&
|
typeof values !== 'undefined' &&
|
||||||
typeof values.choice1_count !== 'undefined' &&
|
typeof values.choice1_count !== 'undefined' &&
|
||||||
|
|
|
@ -29,7 +29,7 @@ const statusRequest = async (request: any) => {
|
||||||
const userAgent = request.headers.get('User-Agent');
|
const userAgent = request.headers.get('User-Agent');
|
||||||
|
|
||||||
if (userAgent.match(/bot/gi) !== null) {
|
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,
|
headers: Constants.RESPONSE_HEADERS,
|
||||||
status: 200
|
status: 200
|
||||||
});
|
});
|
||||||
|
@ -49,6 +49,7 @@ router.get('/owoembed', async (request: any) => {
|
||||||
console.log('oembed hit!');
|
console.log('oembed hit!');
|
||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
|
|
||||||
|
/* Fallbacks */
|
||||||
let text = searchParams.get('text') || 'Twitter';
|
let text = searchParams.get('text') || 'Twitter';
|
||||||
let author = searchParams.get('author') || 'dangeredwolf';
|
let author = searchParams.get('author') || 'dangeredwolf';
|
||||||
let status = searchParams.get('status') || '1547514042146865153';
|
let status = searchParams.get('status') || '1547514042146865153';
|
||||||
|
|
|
@ -8,7 +8,8 @@ import { handleQuote } from './quote';
|
||||||
|
|
||||||
export const handleStatus = async (
|
export const handleStatus = async (
|
||||||
status: string,
|
status: string,
|
||||||
mediaNumber?: number
|
mediaNumber?: number,
|
||||||
|
userAgent?: string
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
const conversation = await fetchUsingGuest(status);
|
const conversation = await fetchUsingGuest(status);
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ export const handleStatus = async (
|
||||||
let authorText = 'Twitter';
|
let authorText = 'Twitter';
|
||||||
|
|
||||||
if (tweet.card) {
|
if (tweet.card) {
|
||||||
text += await renderPoll(tweet.card);
|
text += await renderPoll(tweet.card, userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
text = linkFixer(tweet, text);
|
text = linkFixer(tweet, text);
|
||||||
|
|
Loading…
Add table
Reference in a new issue