Skip to content

Autoselect SystemCommand from existing Commands #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ 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.
- Most built-in System Commands will be handled by GenericmessageCommand by default in a future release and will require a custom implementation.
### Removed
### Fixed
- Constraint errors in `/cleanup` command.
Expand Down
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/ChannelchatcreatedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Channel chat created command
*
* @todo Remove due to deprecation!
*/
class ChannelchatcreatedCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/ChannelpostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Channel post command
*
* @todo Remove due to deprecation!
*/
class ChannelpostCommand extends SystemCommand
{
Expand Down Expand Up @@ -42,6 +44,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/ChoseninlineresultCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Chosen inline result command
*
* @todo Remove due to deprecation!
*/
class ChoseninlineresultCommand extends SystemCommand
{
Expand Down Expand Up @@ -45,6 +47,8 @@ public function execute()
//$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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/DeletechatphotoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Delete chat photo command
*
* @todo Remove due to deprecation!
*/
class DeletechatphotoCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/EditedchannelpostCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Edited channel post command
*
* @todo Remove due to deprecation!
*/
class EditedchannelpostCommand extends SystemCommand
{
Expand Down Expand Up @@ -42,6 +44,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/EditedmessageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Edited message command
*
* @todo Remove due to deprecation!
*/
class EditedmessageCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/GroupchatcreatedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Group chat created command
*
* @todo Remove due to deprecation!
*/
class GroupchatcreatedCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/LeftchatmemberCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Left chat member command
*
* @todo Remove due to deprecation!
*/
class LeftchatmemberCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/MigratefromchatidCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Migrate from chat id command
*
* @todo Remove due to deprecation!
*/
class MigratefromchatidCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/MigratetochatidCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Migrate to chat id command
*
* @todo Remove due to deprecation!
*/
class MigratetochatidCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/NewchatmembersCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* New chat members command
*
* @todo Remove due to deprecation!
*/
class NewchatmembersCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/NewchatphotoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* New chat photo command
*
* @todo Remove due to deprecation!
*/
class NewchatphotoCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/NewchattitleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* New chat title command
*
* @todo Remove due to deprecation!
*/
class NewchattitleCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/PinnedmessageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Pinned message command
*
* @todo Remove due to deprecation!
*/
class PinnedmessageCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/StartCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

/**
* Start command
*
* @todo Remove due to deprecation!
*/
class StartCommand extends SystemCommand
{
Expand Down Expand Up @@ -50,6 +52,8 @@ public function execute()
//$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();
}
}
4 changes: 4 additions & 0 deletions src/Commands/SystemCommands/SupergroupchatcreatedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

/**
* Super group chat created command
*
* @todo Remove due to deprecation!
*/
class SupergroupchatcreatedCommand extends SystemCommand
{
Expand Down Expand Up @@ -43,6 +45,8 @@ 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();
}
}
45 changes: 17 additions & 28 deletions src/Telegram.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down