From da604d8a130ac4e6b3ac368c5f1b9d4edb63985d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Fri, 22 Mar 2019 23:15:59 +0100 Subject: [PATCH 1/2] Autoselect appropriate SystemCommand to execute Message field types. Remove all dummy commands from library. This may break backwards compat!! --- CHANGELOG.md | 1 + .../ChannelchatcreatedCommand.php | 48 ---------------- .../SystemCommands/ChannelpostCommand.php | 47 ---------------- .../ChoseninlineresultCommand.php | 50 ----------------- .../SystemCommands/DeletechatphotoCommand.php | 48 ---------------- .../EditedchannelpostCommand.php | 47 ---------------- .../SystemCommands/EditedmessageCommand.php | 48 ---------------- .../GroupchatcreatedCommand.php | 48 ---------------- .../SystemCommands/LeftchatmemberCommand.php | 48 ---------------- .../MigratefromchatidCommand.php | 48 ---------------- .../SystemCommands/MigratetochatidCommand.php | 48 ---------------- .../SystemCommands/NewchatmembersCommand.php | 48 ---------------- .../SystemCommands/NewchatphotoCommand.php | 48 ---------------- .../SystemCommands/NewchattitleCommand.php | 48 ---------------- .../SystemCommands/PinnedmessageCommand.php | 48 ---------------- src/Commands/SystemCommands/StartCommand.php | 55 ------------------- .../SupergroupchatcreatedCommand.php | 48 ---------------- src/Telegram.php | 45 ++++++--------- 18 files changed, 18 insertions(+), 803 deletions(-) delete mode 100644 src/Commands/SystemCommands/ChannelchatcreatedCommand.php delete mode 100644 src/Commands/SystemCommands/ChannelpostCommand.php delete mode 100644 src/Commands/SystemCommands/ChoseninlineresultCommand.php delete mode 100644 src/Commands/SystemCommands/DeletechatphotoCommand.php delete mode 100644 src/Commands/SystemCommands/EditedchannelpostCommand.php delete mode 100644 src/Commands/SystemCommands/EditedmessageCommand.php delete mode 100644 src/Commands/SystemCommands/GroupchatcreatedCommand.php delete mode 100644 src/Commands/SystemCommands/LeftchatmemberCommand.php delete mode 100644 src/Commands/SystemCommands/MigratefromchatidCommand.php delete mode 100644 src/Commands/SystemCommands/MigratetochatidCommand.php delete mode 100644 src/Commands/SystemCommands/NewchatmembersCommand.php delete mode 100644 src/Commands/SystemCommands/NewchatphotoCommand.php delete mode 100644 src/Commands/SystemCommands/NewchattitleCommand.php delete mode 100644 src/Commands/SystemCommands/PinnedmessageCommand.php delete mode 100644 src/Commands/SystemCommands/StartCommand.php delete mode 100644 src/Commands/SystemCommands/SupergroupchatcreatedCommand.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 5042d6a0e..bed01c272 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ## [Unreleased] ### Added ### Changed +- All Message field types dynamically search for an existing Command class that can handle them. ### Deprecated - Botan.io service has been discontinued. ### Removed diff --git a/src/Commands/SystemCommands/ChannelchatcreatedCommand.php b/src/Commands/SystemCommands/ChannelchatcreatedCommand.php deleted file mode 100644 index 614a703ff..000000000 --- a/src/Commands/SystemCommands/ChannelchatcreatedCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * Channel chat created command - */ -class ChannelchatcreatedCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'channelchatcreated'; - - /** - * @var string - */ - protected $description = 'Channel chat created'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$channel_chat_created = $message->getChannelChatCreated(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/ChannelpostCommand.php b/src/Commands/SystemCommands/ChannelpostCommand.php deleted file mode 100644 index 89613c2c2..000000000 --- a/src/Commands/SystemCommands/ChannelpostCommand.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * 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; - -/** - * Channel post command - */ -class ChannelpostCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'channelpost'; - - /** - * @var string - */ - protected $description = 'Handle channel post'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Execute command - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$channel_post = $this->getUpdate()->getChannelPost(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/ChoseninlineresultCommand.php b/src/Commands/SystemCommands/ChoseninlineresultCommand.php deleted file mode 100644 index 2bd147e71..000000000 --- a/src/Commands/SystemCommands/ChoseninlineresultCommand.php +++ /dev/null @@ -1,50 +0,0 @@ - - * - * 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; - -/** - * Chosen inline result command - */ -class ChoseninlineresultCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'choseninlineresult'; - - /** - * @var string - */ - protected $description = 'Chosen result query'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //Information about chosen result is returned - //$update = $this->getUpdate(); - //$inline_query = $update->getChosenInlineResult(); - //$query = $inline_query->getQuery(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/DeletechatphotoCommand.php b/src/Commands/SystemCommands/DeletechatphotoCommand.php deleted file mode 100644 index 03799679d..000000000 --- a/src/Commands/SystemCommands/DeletechatphotoCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * Delete chat photo command - */ -class DeletechatphotoCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'deletechatphoto'; - - /** - * @var string - */ - protected $description = 'Delete chat photo'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$delete_chat_photo = $message->getDeleteChatPhoto(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/EditedchannelpostCommand.php b/src/Commands/SystemCommands/EditedchannelpostCommand.php deleted file mode 100644 index 127502dea..000000000 --- a/src/Commands/SystemCommands/EditedchannelpostCommand.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * 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; - -/** - * Edited channel post command - */ -class EditedchannelpostCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'editedchannelpost'; - - /** - * @var string - */ - protected $description = 'Handle edited channel post'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Execute command - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$edited_channel_post = $this->getUpdate()->getEditedChannelPost(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/EditedmessageCommand.php b/src/Commands/SystemCommands/EditedmessageCommand.php deleted file mode 100644 index 89c896380..000000000 --- a/src/Commands/SystemCommands/EditedmessageCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * Edited message command - */ -class EditedmessageCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'editedmessage'; - - /** - * @var string - */ - protected $description = 'User edited message'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$update = $this->getUpdate(); - //$edited_message = $update->getEditedMessage(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/GroupchatcreatedCommand.php b/src/Commands/SystemCommands/GroupchatcreatedCommand.php deleted file mode 100644 index 4b7b854f8..000000000 --- a/src/Commands/SystemCommands/GroupchatcreatedCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * Group chat created command - */ -class GroupchatcreatedCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'groupchatcreated'; - - /** - * @var string - */ - protected $description = 'Group chat created'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$group_chat_created = $message->getGroupChatCreated(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/LeftchatmemberCommand.php b/src/Commands/SystemCommands/LeftchatmemberCommand.php deleted file mode 100644 index 2a3e67890..000000000 --- a/src/Commands/SystemCommands/LeftchatmemberCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * Left chat member command - */ -class LeftchatmemberCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'leftchatmember'; - - /** - * @var string - */ - protected $description = 'Left Chat Member'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$member = $message->getLeftChatMember(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/MigratefromchatidCommand.php b/src/Commands/SystemCommands/MigratefromchatidCommand.php deleted file mode 100644 index 2d318f788..000000000 --- a/src/Commands/SystemCommands/MigratefromchatidCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * Migrate from chat id command - */ -class MigratefromchatidCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'migratefromchatid'; - - /** - * @var string - */ - protected $description = 'Migrate from chat id'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$migrate_from_chat_id = $message->getMigrateFromChatId(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/MigratetochatidCommand.php b/src/Commands/SystemCommands/MigratetochatidCommand.php deleted file mode 100644 index bac69e6a7..000000000 --- a/src/Commands/SystemCommands/MigratetochatidCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * Migrate to chat id command - */ -class MigratetochatidCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'migratetochatid'; - - /** - * @var string - */ - protected $description = 'Migrate to chat id'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$migrate_to_chat_id = $message->getMigrateToChatId(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/NewchatmembersCommand.php b/src/Commands/SystemCommands/NewchatmembersCommand.php deleted file mode 100644 index 460b29686..000000000 --- a/src/Commands/SystemCommands/NewchatmembersCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * New chat members command - */ -class NewchatmembersCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'newchatmembers'; - - /** - * @var string - */ - protected $description = 'New Chat Member(s)'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$members = $message->getNewChatMembers(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/NewchatphotoCommand.php b/src/Commands/SystemCommands/NewchatphotoCommand.php deleted file mode 100644 index 39246b0c4..000000000 --- a/src/Commands/SystemCommands/NewchatphotoCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * New chat photo command - */ -class NewchatphotoCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'newchatphoto'; - - /** - * @var string - */ - protected $description = 'New chat Photo'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$new_chat_photo = $message->getNewChatPhoto(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/NewchattitleCommand.php b/src/Commands/SystemCommands/NewchattitleCommand.php deleted file mode 100644 index 36b0cc268..000000000 --- a/src/Commands/SystemCommands/NewchattitleCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * New chat title command - */ -class NewchattitleCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'newchattitle'; - - /** - * @var string - */ - protected $description = 'New chat Title'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$new_chat_title = $message->getNewChatTitle(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/PinnedmessageCommand.php b/src/Commands/SystemCommands/PinnedmessageCommand.php deleted file mode 100644 index e328d896d..000000000 --- a/src/Commands/SystemCommands/PinnedmessageCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * Pinned message command - */ -class PinnedmessageCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'pinnedmessage'; - - /** - * @var string - */ - protected $description = 'Message was pinned'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Execute command - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$pinned_message = $message->getPinnedMessage(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/StartCommand.php b/src/Commands/SystemCommands/StartCommand.php deleted file mode 100644 index b471a7410..000000000 --- a/src/Commands/SystemCommands/StartCommand.php +++ /dev/null @@ -1,55 +0,0 @@ - - * - * 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\Request; - -/** - * Start command - */ -class StartCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'start'; - - /** - * @var string - */ - protected $description = 'Start command'; - - /** - * @var string - */ - protected $usage = '/start'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$chat_id = $message->getChat()->getId(); - //$user_id = $message->getFrom()->getId(); - - return parent::execute(); - } -} diff --git a/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php b/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php deleted file mode 100644 index e72179ff9..000000000 --- a/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * 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; - -/** - * Super group chat created command - */ -class SupergroupchatcreatedCommand extends SystemCommand -{ - /** - * @var string - */ - protected $name = 'supergroupchatcreated'; - - /** - * @var string - */ - protected $description = 'Super group chat created'; - - /** - * @var string - */ - protected $version = '1.0.0'; - - /** - * Command execute method - * - * @return mixed - * @throws \Longman\TelegramBot\Exception\TelegramException - */ - public function execute() - { - //$message = $this->getMessage(); - //$supergroup_chat_created = $message->getSuperGroupChatCreated(); - - return parent::execute(); - } -} diff --git a/src/Telegram.php b/src/Telegram.php index 8660e250b..929c45466 100644 --- a/src/Telegram.php +++ b/src/Telegram.php @@ -445,47 +445,36 @@ public function processUpdate(Update $update) $this->update = $update; $this->last_update_id = $update->getUpdateId(); + //Load admin commands + if ($this->isAdmin()) { + $this->addCommandsPath(TB_BASE_COMMANDS_PATH . '/AdminCommands', false); + } + + //Make sure we have an up-to-date command list + //This is necessary to "require" all the necessary command files! + $this->getCommandsList(); + //If all else fails, it's a generic message. $command = 'genericmessage'; $update_type = $this->update->getUpdateType(); if ($update_type === 'message') { $message = $this->update->getMessage(); - - //Load admin commands - if ($this->isAdmin()) { - $this->addCommandsPath(TB_BASE_COMMANDS_PATH . '/AdminCommands', false); - } - - $type = $message->getType(); + $type = $message->getType(); if ($type === 'command') { $command = $message->getCommand(); - } elseif (in_array($type, [ - 'new_chat_members', - 'left_chat_member', - 'new_chat_title', - 'new_chat_photo', - 'delete_chat_photo', - 'group_chat_created', - 'supergroup_chat_created', - 'channel_chat_created', - 'migrate_to_chat_id', - 'migrate_from_chat_id', - 'pinned_message', - 'invoice', - 'successful_payment', - ], true) - ) { - $command = $this->getCommandFromType($type); + } else { + // Let's check if the message object has the type field we're looking for + // and if a fitting command class is available. + $command_tmp = $this->getCommandFromType($type); + if ($this->getCommandObject($command_tmp) !== null) { + $command = $command_tmp; + } } } else { $command = $this->getCommandFromType($update_type); } - //Make sure we have an up-to-date command list - //This is necessary to "require" all the necessary command files! - $this->getCommandsList(); - //Make sure we don't try to process update that was already processed $last_id = DB::selectTelegramUpdate(1, $this->update->getUpdateId()); if ($last_id && count($last_id) === 1) { From 268d3bab11e89d3f9980ce43aa8afe8607d5efbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20L=C3=BCscher?= Date: Sat, 23 Mar 2019 21:50:22 +0100 Subject: [PATCH 2/2] Instead of deleting existing commands, add deprecation notice to preserve backwards compatibility. --- CHANGELOG.md | 1 + .../ChannelchatcreatedCommand.php | 52 ++++++++++++++++ .../SystemCommands/ChannelpostCommand.php | 51 ++++++++++++++++ .../ChoseninlineresultCommand.php | 54 +++++++++++++++++ .../SystemCommands/DeletechatphotoCommand.php | 52 ++++++++++++++++ .../EditedchannelpostCommand.php | 51 ++++++++++++++++ .../SystemCommands/EditedmessageCommand.php | 52 ++++++++++++++++ .../GroupchatcreatedCommand.php | 52 ++++++++++++++++ .../SystemCommands/LeftchatmemberCommand.php | 52 ++++++++++++++++ .../MigratefromchatidCommand.php | 52 ++++++++++++++++ .../SystemCommands/MigratetochatidCommand.php | 52 ++++++++++++++++ .../SystemCommands/NewchatmembersCommand.php | 52 ++++++++++++++++ .../SystemCommands/NewchatphotoCommand.php | 52 ++++++++++++++++ .../SystemCommands/NewchattitleCommand.php | 52 ++++++++++++++++ .../SystemCommands/PinnedmessageCommand.php | 52 ++++++++++++++++ src/Commands/SystemCommands/StartCommand.php | 59 +++++++++++++++++++ .../SupergroupchatcreatedCommand.php | 52 ++++++++++++++++ 17 files changed, 840 insertions(+) create mode 100644 src/Commands/SystemCommands/ChannelchatcreatedCommand.php create mode 100644 src/Commands/SystemCommands/ChannelpostCommand.php create mode 100644 src/Commands/SystemCommands/ChoseninlineresultCommand.php create mode 100644 src/Commands/SystemCommands/DeletechatphotoCommand.php create mode 100644 src/Commands/SystemCommands/EditedchannelpostCommand.php create mode 100644 src/Commands/SystemCommands/EditedmessageCommand.php create mode 100644 src/Commands/SystemCommands/GroupchatcreatedCommand.php create mode 100644 src/Commands/SystemCommands/LeftchatmemberCommand.php create mode 100644 src/Commands/SystemCommands/MigratefromchatidCommand.php create mode 100644 src/Commands/SystemCommands/MigratetochatidCommand.php create mode 100644 src/Commands/SystemCommands/NewchatmembersCommand.php create mode 100644 src/Commands/SystemCommands/NewchatphotoCommand.php create mode 100644 src/Commands/SystemCommands/NewchattitleCommand.php create mode 100644 src/Commands/SystemCommands/PinnedmessageCommand.php create mode 100644 src/Commands/SystemCommands/StartCommand.php create mode 100644 src/Commands/SystemCommands/SupergroupchatcreatedCommand.php diff --git a/CHANGELOG.md b/CHANGELOG.md index bed01c272..f28bbfa71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c - All Message field types dynamically search for an existing Command class that can handle them. ### Deprecated - Botan.io service has been discontinued. +- Most built-in System Commands will be handled by GenericmessageCommand by default in a future release and will require a custom implementation. ### Removed ### Fixed ### Security diff --git a/src/Commands/SystemCommands/ChannelchatcreatedCommand.php b/src/Commands/SystemCommands/ChannelchatcreatedCommand.php new file mode 100644 index 000000000..c815f12de --- /dev/null +++ b/src/Commands/SystemCommands/ChannelchatcreatedCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * Channel chat created command + * + * @todo Remove due to deprecation! + */ +class ChannelchatcreatedCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'channelchatcreated'; + + /** + * @var string + */ + protected $description = 'Channel chat created'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$channel_chat_created = $message->getChannelChatCreated(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/ChannelpostCommand.php b/src/Commands/SystemCommands/ChannelpostCommand.php new file mode 100644 index 000000000..502df1c31 --- /dev/null +++ b/src/Commands/SystemCommands/ChannelpostCommand.php @@ -0,0 +1,51 @@ + + * + * 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; + +/** + * Channel post command + * + * @todo Remove due to deprecation! + */ +class ChannelpostCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'channelpost'; + + /** + * @var string + */ + protected $description = 'Handle channel post'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Execute command + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$channel_post = $this->getUpdate()->getChannelPost(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/ChoseninlineresultCommand.php b/src/Commands/SystemCommands/ChoseninlineresultCommand.php new file mode 100644 index 000000000..0334720e5 --- /dev/null +++ b/src/Commands/SystemCommands/ChoseninlineresultCommand.php @@ -0,0 +1,54 @@ + + * + * 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; + +/** + * Chosen inline result command + * + * @todo Remove due to deprecation! + */ +class ChoseninlineresultCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'choseninlineresult'; + + /** + * @var string + */ + protected $description = 'Chosen result query'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //Information about chosen result is returned + //$update = $this->getUpdate(); + //$inline_query = $update->getChosenInlineResult(); + //$query = $inline_query->getQuery(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/DeletechatphotoCommand.php b/src/Commands/SystemCommands/DeletechatphotoCommand.php new file mode 100644 index 000000000..79b9a9d3f --- /dev/null +++ b/src/Commands/SystemCommands/DeletechatphotoCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * Delete chat photo command + * + * @todo Remove due to deprecation! + */ +class DeletechatphotoCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'deletechatphoto'; + + /** + * @var string + */ + protected $description = 'Delete chat photo'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$delete_chat_photo = $message->getDeleteChatPhoto(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/EditedchannelpostCommand.php b/src/Commands/SystemCommands/EditedchannelpostCommand.php new file mode 100644 index 000000000..1ac718634 --- /dev/null +++ b/src/Commands/SystemCommands/EditedchannelpostCommand.php @@ -0,0 +1,51 @@ + + * + * 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; + +/** + * Edited channel post command + * + * @todo Remove due to deprecation! + */ +class EditedchannelpostCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'editedchannelpost'; + + /** + * @var string + */ + protected $description = 'Handle edited channel post'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Execute command + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$edited_channel_post = $this->getUpdate()->getEditedChannelPost(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/EditedmessageCommand.php b/src/Commands/SystemCommands/EditedmessageCommand.php new file mode 100644 index 000000000..06cee9205 --- /dev/null +++ b/src/Commands/SystemCommands/EditedmessageCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * Edited message command + * + * @todo Remove due to deprecation! + */ +class EditedmessageCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'editedmessage'; + + /** + * @var string + */ + protected $description = 'User edited message'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$update = $this->getUpdate(); + //$edited_message = $update->getEditedMessage(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/GroupchatcreatedCommand.php b/src/Commands/SystemCommands/GroupchatcreatedCommand.php new file mode 100644 index 000000000..8871f2468 --- /dev/null +++ b/src/Commands/SystemCommands/GroupchatcreatedCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * Group chat created command + * + * @todo Remove due to deprecation! + */ +class GroupchatcreatedCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'groupchatcreated'; + + /** + * @var string + */ + protected $description = 'Group chat created'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$group_chat_created = $message->getGroupChatCreated(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/LeftchatmemberCommand.php b/src/Commands/SystemCommands/LeftchatmemberCommand.php new file mode 100644 index 000000000..5326e0186 --- /dev/null +++ b/src/Commands/SystemCommands/LeftchatmemberCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * Left chat member command + * + * @todo Remove due to deprecation! + */ +class LeftchatmemberCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'leftchatmember'; + + /** + * @var string + */ + protected $description = 'Left Chat Member'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$member = $message->getLeftChatMember(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/MigratefromchatidCommand.php b/src/Commands/SystemCommands/MigratefromchatidCommand.php new file mode 100644 index 000000000..754b397cc --- /dev/null +++ b/src/Commands/SystemCommands/MigratefromchatidCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * Migrate from chat id command + * + * @todo Remove due to deprecation! + */ +class MigratefromchatidCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'migratefromchatid'; + + /** + * @var string + */ + protected $description = 'Migrate from chat id'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$migrate_from_chat_id = $message->getMigrateFromChatId(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/MigratetochatidCommand.php b/src/Commands/SystemCommands/MigratetochatidCommand.php new file mode 100644 index 000000000..220a260c7 --- /dev/null +++ b/src/Commands/SystemCommands/MigratetochatidCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * Migrate to chat id command + * + * @todo Remove due to deprecation! + */ +class MigratetochatidCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'migratetochatid'; + + /** + * @var string + */ + protected $description = 'Migrate to chat id'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$migrate_to_chat_id = $message->getMigrateToChatId(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/NewchatmembersCommand.php b/src/Commands/SystemCommands/NewchatmembersCommand.php new file mode 100644 index 000000000..b618f499b --- /dev/null +++ b/src/Commands/SystemCommands/NewchatmembersCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * New chat members command + * + * @todo Remove due to deprecation! + */ +class NewchatmembersCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'newchatmembers'; + + /** + * @var string + */ + protected $description = 'New Chat Member(s)'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$members = $message->getNewChatMembers(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/NewchatphotoCommand.php b/src/Commands/SystemCommands/NewchatphotoCommand.php new file mode 100644 index 000000000..d5b0e2a6f --- /dev/null +++ b/src/Commands/SystemCommands/NewchatphotoCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * New chat photo command + * + * @todo Remove due to deprecation! + */ +class NewchatphotoCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'newchatphoto'; + + /** + * @var string + */ + protected $description = 'New chat Photo'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$new_chat_photo = $message->getNewChatPhoto(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/NewchattitleCommand.php b/src/Commands/SystemCommands/NewchattitleCommand.php new file mode 100644 index 000000000..abc2d5ff6 --- /dev/null +++ b/src/Commands/SystemCommands/NewchattitleCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * New chat title command + * + * @todo Remove due to deprecation! + */ +class NewchattitleCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'newchattitle'; + + /** + * @var string + */ + protected $description = 'New chat Title'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$new_chat_title = $message->getNewChatTitle(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/PinnedmessageCommand.php b/src/Commands/SystemCommands/PinnedmessageCommand.php new file mode 100644 index 000000000..dbf53e620 --- /dev/null +++ b/src/Commands/SystemCommands/PinnedmessageCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * Pinned message command + * + * @todo Remove due to deprecation! + */ +class PinnedmessageCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'pinnedmessage'; + + /** + * @var string + */ + protected $description = 'Message was pinned'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Execute command + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$pinned_message = $message->getPinnedMessage(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/StartCommand.php b/src/Commands/SystemCommands/StartCommand.php new file mode 100644 index 000000000..6c0ae60e6 --- /dev/null +++ b/src/Commands/SystemCommands/StartCommand.php @@ -0,0 +1,59 @@ + + * + * 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\Request; + +/** + * Start command + * + * @todo Remove due to deprecation! + */ +class StartCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'start'; + + /** + * @var string + */ + protected $description = 'Start command'; + + /** + * @var string + */ + protected $usage = '/start'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$chat_id = $message->getChat()->getId(); + //$user_id = $message->getFrom()->getId(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +} diff --git a/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php b/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php new file mode 100644 index 000000000..e19194807 --- /dev/null +++ b/src/Commands/SystemCommands/SupergroupchatcreatedCommand.php @@ -0,0 +1,52 @@ + + * + * 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; + +/** + * Super group chat created command + * + * @todo Remove due to deprecation! + */ +class SupergroupchatcreatedCommand extends SystemCommand +{ + /** + * @var string + */ + protected $name = 'supergroupchatcreated'; + + /** + * @var string + */ + protected $description = 'Super group chat created'; + + /** + * @var string + */ + protected $version = '1.0.0'; + + /** + * Command execute method + * + * @return mixed + * @throws \Longman\TelegramBot\Exception\TelegramException + */ + public function execute() + { + //$message = $this->getMessage(); + //$supergroup_chat_created = $message->getSuperGroupChatCreated(); + + trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED); + + return parent::execute(); + } +}