Handle FX-VX swapping, support x.com
This commit is contained in:
@@ -16,6 +16,7 @@ class CallbackqueryCommand extends SystemCommand
|
||||
$callbackData = json_decode($callbackQuery->getData(), true);
|
||||
$response = match ($callbackData['action'] ?? null) {
|
||||
'REFRESH' => $this->handleRefresh($callbackQuery, $callbackData),
|
||||
'FXVX' => $this->handleSwapFxVx($callbackQuery, $callbackData),
|
||||
default => $this->handleDelete($callbackQuery, $callbackData),
|
||||
};
|
||||
|
||||
@@ -31,7 +32,9 @@ class CallbackqueryCommand extends SystemCommand
|
||||
{
|
||||
$originalSenderId = $callbackData['sender_id'];
|
||||
$callbackSenderId = $callbackQuery->getFrom()?->getId();
|
||||
if ($originalSenderId === $callbackSenderId || $callbackSenderId === 625413203) { // Me
|
||||
if (
|
||||
$originalSenderId === $callbackSenderId
|
||||
) {
|
||||
return Request::deleteMessage([
|
||||
'chat_id' => $callbackQuery->getMessage()->getChat()->getId(),
|
||||
'message_id' => $callbackQuery->getMessage()->getMessageId(),
|
||||
@@ -47,9 +50,31 @@ class CallbackqueryCommand extends SystemCommand
|
||||
return null;
|
||||
}
|
||||
|
||||
private function handleSwapFxVx(CallbackQuery $callbackQuery, array $callbackData): ?ServerResponse
|
||||
{
|
||||
if (!$callbackQuery->getMessage()?->getText()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$link = $callbackQuery->getMessage()->getText();
|
||||
$count = 1;
|
||||
if (str_starts_with($link, 'https://vx')) {
|
||||
$link = str_replace('https://vx', 'https://fx', $link, $count);
|
||||
} elseif (str_starts_with($link, 'https://fx')) {
|
||||
$link = str_replace('https://fx', 'https://vx', $link, $count);
|
||||
}
|
||||
|
||||
return Request::editMessageText([
|
||||
'chat_id' => $callbackQuery->getMessage()->getChat()->getId(),
|
||||
'message_id' => $callbackQuery->getMessage()->getMessageId(),
|
||||
'text'=> $link,
|
||||
'reply_markup' => $callbackQuery->getMessage()->getReplyMarkup(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function handleRefresh(CallbackQuery $callbackQuery, array $callbackData): ?ServerResponse
|
||||
{
|
||||
if (!$callbackQuery->getMessage()) {
|
||||
if (!$callbackQuery->getMessage()?->getText()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,18 +33,16 @@ class GenericmessageCommand extends SystemCommand
|
||||
return Request::emptyResponse();
|
||||
}
|
||||
|
||||
preg_match('/https?:\/\/(?:mobile\.)?twitter\.com\/(\w+)\/status\/(\d+)(\S*)/', $text, $matches);
|
||||
preg_match('/https?:\/\/(?:mobile\.)?(?:x|twitter)\.com\/(\w+)\/status\/(\d+)(\S*)/', $text, $matches);
|
||||
if (count($matches) < 3) {
|
||||
return Request::emptyResponse();
|
||||
}
|
||||
$author = $matches[1];
|
||||
$tweetId = $matches[2];
|
||||
$photoNo = null;
|
||||
$photoNoText = '';
|
||||
if (!empty($matches[3])) {
|
||||
preg_match('/(\/\d)$/', $matches[3], $photoNoMatches);
|
||||
if (isset($photoNoMatches[1])) {
|
||||
$photoNo = intval($photoNoMatches[1]);
|
||||
$photoNoText = '/photo' . $photoNoMatches[1];
|
||||
}
|
||||
}
|
||||
@@ -63,7 +61,10 @@ class GenericmessageCommand extends SystemCommand
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
$buttons []= new InlineKeyboardButton([
|
||||
'text' => 'FX ↔ VX',
|
||||
'callback_data' => json_encode(['action' => 'FXVX']),
|
||||
]);
|
||||
$buttons []= new InlineKeyboardButton([
|
||||
'text' => '🔄 Refresh',
|
||||
'callback_data' => json_encode(['action' => 'REFRESH']),
|
||||
@@ -73,6 +74,6 @@ class GenericmessageCommand extends SystemCommand
|
||||
$data['reply_markup'] = new InlineKeyboard($buttons);
|
||||
}
|
||||
|
||||
return $this->replyToChat("https://vxtwitter.com/$author/status/$tweetId$photoNoText", $data);
|
||||
return $this->replyToChat("https://fxtwitter.com/$author/status/$tweetId$photoNoText", $data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user