Add xFuraffinity support, lint
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Bot\Command\System;
|
||||
|
||||
use Longman\TelegramBot\Commands\SystemCommand;
|
||||
@@ -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,14 +103,14 @@ 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,
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user