Add xFuraffinity support, lint
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Bot\Command\System;
|
namespace Bot\Command\System;
|
||||||
|
|
||||||
use Longman\TelegramBot\Commands\SystemCommand;
|
use Longman\TelegramBot\Commands\SystemCommand;
|
||||||
|
|||||||
@@ -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,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([
|
$buttons[] = new InlineKeyboardButton([
|
||||||
'text' => 'FX ↔ VX',
|
'text' => 'FX ↔ VX',
|
||||||
'callback_data' => json_encode(['action' => 'FXVX']),
|
'callback_data' => json_encode(['action' => 'FXVX']),
|
||||||
@@ -69,11 +72,19 @@ class GenericmessageCommand extends SystemCommand
|
|||||||
'text' => '🔄 Refresh',
|
'text' => '🔄 Refresh',
|
||||||
'callback_data' => json_encode(['action' => '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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user