Commit f533ecd0 authored by MBoretto's avatar MBoretto

Merge branch 'new_command_structure_alpha' into feature/smartinterface

parents 566be6ad 24067d78
...@@ -10,20 +10,10 @@ ...@@ -10,20 +10,10 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Telegram;
/** /**
* Abstract Admin Command Class * Abstract Admin Command Class
*/ */
abstract class AdminCommand extends Command abstract class AdminCommand extends Command
{ {
/**
* Constructor
*
* @param Telegram $telegram
*/
public function __construct(Telegram $telegram)
{
parent::__construct($telegram);
}
} }
...@@ -16,7 +16,7 @@ use Longman\TelegramBot\Entities\Update; ...@@ -16,7 +16,7 @@ use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Entities\User; use Longman\TelegramBot\Entities\User;
/** /**
* Class Command * Abstract Command Class
*/ */
abstract class Command abstract class Command
{ {
......
...@@ -10,20 +10,22 @@ ...@@ -10,20 +10,22 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Telegram;
/** /**
* Abstract System Command Class * Abstract System Command Class
*/ */
abstract class SystemCommand extends Command abstract class SystemCommand extends Command
{ {
/** /**
* Constructor * A system command just executes
*
* Although system commands should just work and return 'true',
* each system command can override this method to add custom functionality.
* *
* @param Telegram $telegram * @return bool
*/ */
public function __construct(Telegram $telegram) public function execute()
{ {
parent::__construct($telegram); //System command, do nothing
return true;
} }
} }
...@@ -8,22 +8,22 @@ ...@@ -8,22 +8,22 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
namespace Longman\TelegramBot\Commands\UserCommands; namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\UserCommand; use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
* Start command * Start command
*/ */
class StartCommand extends UserCommand class StartCommand extends SystemCommand
{ {
/**#@+ /**#@+
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $name = 'start'; protected $name = 'start';
protected $description = 'Start command'; protected $description = 'Start command';
protected $usage = '/'; protected $usage = '/start';
protected $version = '1.0.1'; protected $version = '1.0.1';
/**#@-*/ /**#@-*/
......
...@@ -10,20 +10,10 @@ ...@@ -10,20 +10,10 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Telegram;
/** /**
* Abstract User Command Class * Abstract User Command Class
*/ */
abstract class UserCommand extends Command abstract class UserCommand extends Command
{ {
/**
* Constructor
*
* @param Telegram $telegram
*/
public function __construct(Telegram $telegram)
{
parent::__construct($telegram);
}
} }
...@@ -168,7 +168,7 @@ class Telegram ...@@ -168,7 +168,7 @@ class Telegram
$this->setUploadPath(BASE_PATH . '/../Upload'); $this->setUploadPath(BASE_PATH . '/../Upload');
//Add default system commands path //Add default system commands path
$this->addCommandsPath(BASE_COMMANDS_PATH . '/System'); $this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands');
Request::initialize($this); Request::initialize($this);
} }
...@@ -465,10 +465,10 @@ class Telegram ...@@ -465,10 +465,10 @@ class Telegram
//Load admin commands //Load admin commands
if ($this->isAdmin($message->getFrom()->getId())) { if ($this->isAdmin($message->getFrom()->getId())) {
$this->addCommandsPath(BASE_COMMANDS_PATH . '/Admin', false); $this->addCommandsPath(BASE_COMMANDS_PATH . '/AdminCommands', false);
} }
$this->addCommandsPath(BASE_COMMANDS_PATH . '/User', false); $this->addCommandsPath(BASE_COMMANDS_PATH . '/UserCommands', false);
$type = $message->getType(); $type = $message->getType();
if ($type === 'command') { if ($type === 'command') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment