Handle FX-VX swapping, support x.com

This commit is contained in:
2024-05-29 00:56:42 +00:00
parent 390606173d
commit dc1541c48d
2 changed files with 33 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ class CallbackqueryCommand extends SystemCommand
$callbackData = json_decode($callbackQuery->getData(), true);
$response = match ($callbackData['action'] ?? null) {
'REFRESH' => $this->handleRefresh($callbackQuery, $callbackData),
'FXVX' => $this->handleSwapFxVx($callbackQuery, $callbackData),
default => $this->handleDelete($callbackQuery, $callbackData),
};
@@ -31,7 +32,9 @@ class CallbackqueryCommand extends SystemCommand
{
$originalSenderId = $callbackData['sender_id'];
$callbackSenderId = $callbackQuery->getFrom()?->getId();
if ($originalSenderId === $callbackSenderId || $callbackSenderId === 625413203) { // Me
if (
$originalSenderId === $callbackSenderId
) {
return Request::deleteMessage([
'chat_id' => $callbackQuery->getMessage()->getChat()->getId(),
'message_id' => $callbackQuery->getMessage()->getMessageId(),
@@ -47,9 +50,31 @@ class CallbackqueryCommand extends SystemCommand
return null;
}
private function handleSwapFxVx(CallbackQuery $callbackQuery, array $callbackData): ?ServerResponse
{
if (!$callbackQuery->getMessage()?->getText()) {
return null;
}
$link = $callbackQuery->getMessage()->getText();
$count = 1;
if (str_starts_with($link, 'https://vx')) {
$link = str_replace('https://vx', 'https://fx', $link, $count);
} elseif (str_starts_with($link, 'https://fx')) {
$link = str_replace('https://fx', 'https://vx', $link, $count);
}
return Request::editMessageText([
'chat_id' => $callbackQuery->getMessage()->getChat()->getId(),
'message_id' => $callbackQuery->getMessage()->getMessageId(),
'text'=> $link,
'reply_markup' => $callbackQuery->getMessage()->getReplyMarkup(),
]);
}
private function handleRefresh(CallbackQuery $callbackQuery, array $callbackData): ?ServerResponse
{
if (!$callbackQuery->getMessage()) {
if (!$callbackQuery->getMessage()?->getText()) {
return null;
}