v1
This commit is contained in:
42
src/Commands/GenericmessageCommand.php
Executable file
42
src/Commands/GenericmessageCommand.php
Executable file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Longman\TelegramBot\Commands\SystemCommands;
|
||||
|
||||
use Longman\TelegramBot\Commands\SystemCommand;
|
||||
use Longman\TelegramBot\Entities\ServerResponse;
|
||||
use Longman\TelegramBot\Request;
|
||||
// This class name is magic
|
||||
class GenericmessageCommand extends SystemCommand
|
||||
{
|
||||
/** @var string */
|
||||
protected $name = 'genericmessage';
|
||||
/** @var string */
|
||||
protected $description = 'Handle generic message';
|
||||
/** @var string */
|
||||
protected $version = '1.0.0';
|
||||
|
||||
public function execute(): ServerResponse
|
||||
{
|
||||
$message = $this->getMessage();
|
||||
|
||||
$text = $message->getText(true);
|
||||
if ($message->getMediaGroupId() || empty($text)) {
|
||||
return Request::emptyResponse();
|
||||
}
|
||||
|
||||
preg_match('/https?:\/\/(?:mobile\.)?twitter\.com\/(\w+)\/status\/(\d+)(\/photo\/\d)?/', $text, $matches);
|
||||
if (count($matches) < 3) {
|
||||
return Request::emptyResponse();
|
||||
}
|
||||
$author = $matches[1];
|
||||
$tweetId = $matches[2];
|
||||
$tail = $matches[3] ?? '';
|
||||
|
||||
return Request::sendMessage([
|
||||
'chat_id' => $message->getChat()->getId(),
|
||||
'reply_to_message_id' => $message->getMessageId(),
|
||||
'text' => "https://fxtwitter.com/$author/status/$tweetId$tail",
|
||||
'disable_notification' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user