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 <?php
namespace Bot\Command\System; namespace Bot\Command\System;
use Longman\TelegramBot\Commands\SystemCommand; use Longman\TelegramBot\Commands\SystemCommand;
@@ -67,7 +68,7 @@ class CallbackqueryCommand extends SystemCommand
return Request::editMessageText([ return Request::editMessageText([
'chat_id' => $callbackQuery->getMessage()->getChat()->getId(), 'chat_id' => $callbackQuery->getMessage()->getChat()->getId(),
'message_id' => $callbackQuery->getMessage()->getMessageId(), 'message_id' => $callbackQuery->getMessage()->getMessageId(),
'text'=> $link, 'text' => $link,
'reply_markup' => $callbackQuery->getMessage()->getReplyMarkup(), 'reply_markup' => $callbackQuery->getMessage()->getReplyMarkup(),
]); ]);
} }
@@ -82,7 +83,7 @@ class CallbackqueryCommand extends SystemCommand
$query = '?tmfx'; $query = '?tmfx';
preg_match('/status\/\d+(?:\/photo\/(\d))?(?:\?tmfx(\d))?/', $callbackQuery->getMessage()->getText(), $matches); 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; $photoNo = $matches[1] ?? null;
// The proper way to refresh to a URL is to talk to @WebpageBot // The proper way to refresh to a URL is to talk to @WebpageBot
// A workaround is to just add a query string // A workaround is to just add a query string
@@ -102,14 +103,14 @@ class CallbackqueryCommand extends SystemCommand
if ($currentAttempt >= $attemptLimit) { if ($currentAttempt >= $attemptLimit) {
$keyboard = new InlineKeyboard(array_filter( $keyboard = new InlineKeyboard(array_filter(
$callbackQuery->getMessage()->getReplyMarkup()->getProperty('inline_keyboard')[0], $callbackQuery->getMessage()->getReplyMarkup()->getProperty('inline_keyboard')[0],
static fn ($x) => $x->getProperty('text') !== '🔄 Refresh', static fn($x) => $x->getProperty('text') !== '🔄 Refresh',
)); ));
} }
return Request::editMessageText([ return Request::editMessageText([
'chat_id' => $callbackQuery->getMessage()->getChat()->getId(), 'chat_id' => $callbackQuery->getMessage()->getChat()->getId(),
'message_id' => $callbackQuery->getMessage()->getMessageId(), 'message_id' => $callbackQuery->getMessage()->getMessageId(),
'text'=> $newUrl, 'text' => $newUrl,
'reply_markup' => $keyboard, 'reply_markup' => $keyboard,
]); ]);
} }

View File

@@ -29,28 +29,12 @@ class GenericmessageCommand extends SystemCommand
} }
$text = $message->getText(true); $text = $message->getText(true);
if ($message->getMediaGroupId() || empty($text)) { if ($message->getMediaGroupId() || empty($text)) {
return Request::emptyResponse(); return Request::emptyResponse();
} }
preg_match('/https?:\/\/(?:mobile\.)?(?:x|twitter)\.com\/(\w+)\/status\/(\d+)(\S*)/', $text, $matches); $finalLink = null;
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,
];
$buttons = []; $buttons = [];
if ($message->getFrom() !== null) { if ($message->getFrom() !== null) {
$buttons[] = new InlineKeyboardButton([ $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)) { if (!empty($buttons)) {
$data['reply_markup'] = new InlineKeyboard($buttons); $data['reply_markup'] = new InlineKeyboard($buttons);
} }
return $this->replyToChat("https://fxtwitter.com/$author/status/$tweetId$photoNoText", $data); return $this->replyToChat($finalLink, $data);
} }
} }