Page Menu
Home
Phabricator (Chris)
Search
Configure Global Search
Log In
Files
F145062
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/Commands/SystemCommand.php b/src/Commands/SystemCommand.php
index e5b7779..47972e7 100644
--- a/src/Commands/SystemCommand.php
+++ b/src/Commands/SystemCommand.php
@@ -1,123 +1,72 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
abstract class SystemCommand extends Command
{
- /**
- * @var bool Try to execute any deprecated system command.
- */
- public static $execute_deprecated = false;
/**
* @{inheritdoc}
*
*/
protected $usage = '';
/**
* A system command just executes
*
* Although system commands should just work and return a successful ServerResponse,
* each system command can override this method to add custom functionality.
*
* @return ServerResponse
*/
public function execute(): ServerResponse
{
// System command, return empty ServerResponse by default
return Request::emptyResponse();
}
/**
* Method to execute any active conversation.
*
* @return ServerResponse|null
* @throws TelegramException
* @internal
*/
protected function executeActiveConversation(): ?ServerResponse
{
$message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
if ($message === null) {
return null;
}
$user = $message->getFrom();
$chat = $message->getChat();
if ($user === null || $chat === null) {
return null;
}
// If a conversation is busy, execute the conversation command after handling the message.
$conversation = new Conversation($user->getId(), $chat->getId());
// Fetch conversation command if it exists and execute it.
if ($conversation->exists() && ($command = $conversation->getCommand())) {
return $this->getTelegram()->executeCommand($command);
}
return null;
}
-
- /**
- * BC helper method to execute deprecated system commands.
- *
- * @return ServerResponse|null
- * @throws TelegramException
- * @internal
- */
- protected function executeDeprecatedSystemCommand(): ?ServerResponse
- {
- $message = $this->getMessage() ?: $this->getEditedMessage() ?: $this->getChannelPost() ?: $this->getEditedChannelPost();
- if ($message === null) {
- return null;
- }
-
- // List of service messages previously handled internally.
- $service_message_getters = [
- 'newchatmembers' => 'getNewChatMembers',
- 'leftchatmember' => 'getLeftChatMember',
- 'newchattitle' => 'getNewChatTitle',
- 'newchatphoto' => 'getNewChatPhoto',
- 'deletechatphoto' => 'getDeleteChatPhoto',
- 'groupchatcreated' => 'getGroupChatCreated',
- 'supergroupchatcreated' => 'getSupergroupChatCreated',
- 'channelchatcreated' => 'getChannelChatCreated',
- 'migratefromchatid' => 'getMigrateFromChatId',
- 'migratetochatid' => 'getMigrateToChatId',
- 'pinnedmessage' => 'getPinnedMessage',
- 'successfulpayment' => 'getSuccessfulPayment',
- ];
-
- foreach ($service_message_getters as $command => $service_message_getter) {
- // Let's check if this message is a service message.
- if ($message->$service_message_getter() === null) {
- continue;
- }
-
- // Make sure the command exists otherwise GenericCommand would be executed.
- if ($this->getTelegram()->getCommandObject($command) === null) {
- break;
- }
-
- return $this->getTelegram()->executeCommand($command);
- }
-
- return null;
- }
}
diff --git a/src/Commands/SystemCommands/GenericmessageCommand.php b/src/Commands/SystemCommands/GenericmessageCommand.php
index 9ac3195..ce1b410 100644
--- a/src/Commands/SystemCommands/GenericmessageCommand.php
+++ b/src/Commands/SystemCommands/GenericmessageCommand.php
@@ -1,81 +1,70 @@
<?php
/**
* This file is part of the TelegramBot package.
*
* (c) Avtandil Kikabidze aka LONGMAN <akalongman@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Entities\ServerResponse;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request;
use Longman\TelegramBot\Telegram;
/**
* Generic message command
*/
class GenericmessageCommand extends SystemCommand
{
/**
* @var string
*/
protected $name = Telegram::GENERIC_MESSAGE_COMMAND;
/**
* @var string
*/
protected $description = 'Handle generic message';
/**
* @var string
*/
protected $version = '1.2.0';
/**
* @var bool
*/
protected $need_mysql = true;
/**
* Execution if MySQL is required but not available
*
* @return ServerResponse
- * @throws TelegramException
*/
public function executeNoDb(): ServerResponse
{
- // Try to execute any deprecated system commands.
- if (self::$execute_deprecated && $deprecated_system_command_response = $this->executeDeprecatedSystemCommand()) {
- return $deprecated_system_command_response;
- }
-
return Request::emptyResponse();
}
/**
* Execute command
*
* @return ServerResponse
* @throws TelegramException
*/
public function execute(): ServerResponse
{
// Try to continue any active conversation.
if ($active_conversation_response = $this->executeActiveConversation()) {
return $active_conversation_response;
}
- // Try to execute any deprecated system commands.
- if (self::$execute_deprecated && $deprecated_system_command_response = $this->executeDeprecatedSystemCommand()) {
- return $deprecated_system_command_response;
- }
-
return Request::emptyResponse();
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Fri, Aug 14, 6:54 AM (3 h, 42 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
77269
Default Alt Text
(6 KB)
Attached To
Mode
R123 php-telegram-bot
Attached
Detach File
Event Timeline