Support vx multi-pic refresh

This commit is contained in:
2023-05-05 23:01:11 +00:00
parent a89c59cf76
commit e2f42de8cc
2 changed files with 25 additions and 13 deletions

View File

@@ -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) {