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;
|
||||||
@@ -19,7 +20,7 @@ class CallbackqueryCommand extends SystemCommand
|
|||||||
'FXVX' => $this->handleSwapFxVx($callbackQuery, $callbackData),
|
'FXVX' => $this->handleSwapFxVx($callbackQuery, $callbackData),
|
||||||
default => $this->handleDelete($callbackQuery, $callbackData),
|
default => $this->handleDelete($callbackQuery, $callbackData),
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($response !== null) {
|
if ($response !== null) {
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
@@ -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,15 +103,15 @@ 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,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class GenericmessageCommand extends SystemCommand
|
|||||||
public function execute(): ServerResponse
|
public function execute(): ServerResponse
|
||||||
{
|
{
|
||||||
global $allowed_chat_ids;
|
global $allowed_chat_ids;
|
||||||
|
|
||||||
$message = $this->getMessage();
|
$message = $this->getMessage();
|
||||||
$chatId = $message->getChat()->getId();
|
$chatId = $message->getChat()->getId();
|
||||||
if(count($allowed_chat_ids) > 0 && !in_array($chatId, $allowed_chat_ids)) {
|
if(count($allowed_chat_ids) > 0 && !in_array($chatId, $allowed_chat_ids)) {
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user