Add xFuraffinity support, lint

This commit is contained in:
2025-10-27 00:21:54 +00:00
parent e1a58a966f
commit e36e1e6830
2 changed files with 46 additions and 34 deletions

View File

@@ -1,4 +1,5 @@
<?php
namespace Bot\Command\System;
use Longman\TelegramBot\Commands\SystemCommand;

View File

@@ -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,6 +45,25 @@ class GenericmessageCommand extends SystemCommand
]),
]);
}
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']),
@@ -69,11 +72,19 @@ class GenericmessageCommand extends SystemCommand
'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);
}
}