diff --git a/src/Commands/CallbackqueryCommand.php b/src/Commands/CallbackqueryCommand.php index 87179ab..8fd6b8a 100644 --- a/src/Commands/CallbackqueryCommand.php +++ b/src/Commands/CallbackqueryCommand.php @@ -1,4 +1,5 @@ $this->handleSwapFxVx($callbackQuery, $callbackData), default => $this->handleDelete($callbackQuery, $callbackData), }; - + if ($response !== null) { return $response; } @@ -67,7 +68,7 @@ class CallbackqueryCommand extends SystemCommand return Request::editMessageText([ 'chat_id' => $callbackQuery->getMessage()->getChat()->getId(), 'message_id' => $callbackQuery->getMessage()->getMessageId(), - 'text'=> $link, + 'text' => $link, 'reply_markup' => $callbackQuery->getMessage()->getReplyMarkup(), ]); } @@ -82,7 +83,7 @@ class CallbackqueryCommand extends SystemCommand $query = '?tmfx'; preg_match('/status\/\d+(?:\/photo\/(\d))?(?:\?tmfx(\d))?/', $callbackQuery->getMessage()->getText(), $matches); - $currentAttempt = empty($matches[2]) ? 1 : intval($matches[2])+1; + $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 @@ -102,15 +103,15 @@ class CallbackqueryCommand extends SystemCommand if ($currentAttempt >= $attemptLimit) { $keyboard = new InlineKeyboard(array_filter( $callbackQuery->getMessage()->getReplyMarkup()->getProperty('inline_keyboard')[0], - static fn ($x) => $x->getProperty('text') !== '🔄 Refresh', + static fn($x) => $x->getProperty('text') !== '🔄 Refresh', )); } return Request::editMessageText([ 'chat_id' => $callbackQuery->getMessage()->getChat()->getId(), 'message_id' => $callbackQuery->getMessage()->getMessageId(), - 'text'=> $newUrl, + 'text' => $newUrl, 'reply_markup' => $keyboard, ]); } -} \ No newline at end of file +} diff --git a/src/Commands/GenericmessageCommand.php b/src/Commands/GenericmessageCommand.php index 094061a..99c0d1f 100755 --- a/src/Commands/GenericmessageCommand.php +++ b/src/Commands/GenericmessageCommand.php @@ -21,7 +21,7 @@ class GenericmessageCommand extends SystemCommand public function execute(): ServerResponse { global $allowed_chat_ids; - + $message = $this->getMessage(); $chatId = $message->getChat()->getId(); if(count($allowed_chat_ids) > 0 && !in_array($chatId, $allowed_chat_ids)) { @@ -29,28 +29,12 @@ class GenericmessageCommand extends SystemCommand } $text = $message->getText(true); + if ($message->getMediaGroupId() || empty($text)) { return Request::emptyResponse(); } - 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]; - $photoNoText = ''; - if (!empty($matches[3])) { - preg_match('/(\/\d)$/', $matches[3], $photoNoMatches); - if (isset($photoNoMatches[1])) { - $photoNoText = '/photo' . $photoNoMatches[1]; - } - } - - $data = [ - 'reply_to_message_id' => $message->getMessageId(), - 'disable_notification' => true, - ]; + $finalLink = null; $buttons = []; if ($message->getFrom() !== null) { $buttons[] = new InlineKeyboardButton([ @@ -61,19 +45,46 @@ 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']), - ]); + preg_match('/https:\/\/www.furaffinity.net\/view\/(\d+)\/?/', $text, $matches); + if (count($matches) >= 2) { + $imageId = $matches[1]; + $finalLink = "https://www.xfuraffinity.net/view/$imageId"; + } + + preg_match('/https?:\/\/(?:mobile\.)?(?:x|twitter)\.com\/(\w+)\/status\/(\d+)(\S*)/', $text, $matches); + if (count($matches) >= 3) { + $author = $matches[1]; + $tweetId = $matches[2]; + $photoNoText = ''; + if (!empty($matches[3])) { + preg_match('/(\/\d)$/', $matches[3], $photoNoMatches); + if (isset($photoNoMatches[1])) { + $photoNoText = '/photo' . $photoNoMatches[1]; + } + } + $finalLink = "https://fxtwitter.com/$author/status/$tweetId$photoNoText"; + $buttons[] = new InlineKeyboardButton([ + 'text' => 'FX ↔ VX', + 'callback_data' => json_encode(['action' => 'FXVX']), + ]); + $buttons[] = new InlineKeyboardButton([ + 'text' => '🔄 Refresh', + 'callback_data' => json_encode(['action' => 'REFRESH']), + ]); + } + if ($finalLink === null) { + return Request::emptyResponse(); + } + + $data = [ + 'reply_to_message_id' => $message->getMessageId(), + 'disable_notification' => true, + ]; if (!empty($buttons)) { $data['reply_markup'] = new InlineKeyboard($buttons); } - return $this->replyToChat("https://fxtwitter.com/$author/status/$tweetId$photoNoText", $data); + return $this->replyToChat($finalLink, $data); } }