Support vx multi-pic refresh
This commit is contained in:
@@ -56,11 +56,22 @@ class CallbackqueryCommand extends SystemCommand
|
||||
$attemptLimit = 3;
|
||||
$query = '?tmfx';
|
||||
|
||||
$parts = explode($query, $callbackQuery->getMessage()->getText());
|
||||
$currentAttempt = isset($parts[1]) ? intval($parts[1])+1 : 1;
|
||||
preg_match('/status\/\d+(?:\/photo\/(\d))?(?:\?tmfx(\d))?/', $callbackQuery->getMessage()->getText(), $matches);
|
||||
$currentAttempt = empty($matches[2]) ? 1 : intval($matches[2])+1;
|
||||
$photoNo = $matches[1] ?? null;
|
||||
// The proper way to refresh to a URL is to talk to @WebpageBot
|
||||
// A workaround is to just add a query string
|
||||
$newUrl = $parts[0] . $query . $currentAttempt;
|
||||
// But VXTwitter check for /photo/1, /photo/2, ... by looking at URI (including query string) ending with /1, /2
|
||||
// To maintain compatibility with both fx/vx, we will use https://vxtwitter.com/aaa/status/1234567890/photo/3?tmfx1/3
|
||||
$newUrl = explode($query, $callbackQuery->getMessage()->getText())[0];
|
||||
$newUrl = explode('/photo/', $newUrl)[0];
|
||||
if ($photoNo) {
|
||||
$newUrl .= '/photo/' . $photoNo;
|
||||
}
|
||||
$newUrl .= $query . $currentAttempt;
|
||||
if ($photoNo) {
|
||||
$newUrl .= '/' . $photoNo;
|
||||
}
|
||||
|
||||
$keyboard = $callbackQuery->getMessage()->getReplyMarkup();
|
||||
if ($currentAttempt >= $attemptLimit) {
|
||||
|
||||
@@ -39,11 +39,13 @@ class GenericmessageCommand extends SystemCommand
|
||||
}
|
||||
$author = $matches[1];
|
||||
$tweetId = $matches[2];
|
||||
$photoNo = '';
|
||||
$photoNo = null;
|
||||
$photoNoText = '';
|
||||
if (!empty($matches[3])) {
|
||||
preg_match('/(\/\d)$/', $matches[3], $photoNoMatches);
|
||||
if (isset($photoNoMatches[1])) {
|
||||
$photoNo = '/photo' . $photoNoMatches[1];
|
||||
$photoNo = intval($photoNoMatches[1]);
|
||||
$photoNoText = '/photo' . $photoNoMatches[1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,17 +63,16 @@ class GenericmessageCommand extends SystemCommand
|
||||
]),
|
||||
]);
|
||||
}
|
||||
// VXTwitter /photo/n doesn't work with any query string, will revert to multiple images
|
||||
if ($photoNo === '') {
|
||||
$buttons []= new InlineKeyboardButton([
|
||||
'text' => '🔄 Refresh',
|
||||
'callback_data' => json_encode(['action' => 'REFRESH']),
|
||||
]);
|
||||
}
|
||||
|
||||
$buttons []= new InlineKeyboardButton([
|
||||
'text' => '🔄 Refresh',
|
||||
'callback_data' => json_encode(['action' => 'REFRESH']),
|
||||
]);
|
||||
|
||||
if (!empty($buttons)) {
|
||||
$data['reply_markup'] = new InlineKeyboard($buttons);
|
||||
}
|
||||
|
||||
return $this->replyToChat("https://vxtwitter.com/$author/status/$tweetId$photoNo", $data);
|
||||
return $this->replyToChat("https://vxtwitter.com/$author/status/$tweetId$photoNoText", $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user