Commit 3a579eab authored by LONGMAN's avatar LONGMAN

Fixes

parent e7c9e56f
...@@ -13,14 +13,22 @@ use Longman\TelegramBot\Entities\Update; ...@@ -13,14 +13,22 @@ use Longman\TelegramBot\Entities\Update;
abstract class Command abstract class Command
{ {
protected $telegram;
protected $update; protected $update;
protected $message; protected $message;
protected $command; protected $command;
public function __construct(Update $update) { protected $usage = 'Command help text';
protected $version = '1.0.0';
public function __construct(Telegram $telegram) {
$this->telegram = $telegram;
}
public function setUpdate(Update $update) {
$this->update = $update; $this->update = $update;
$this->message = $this->update->getMessage(); $this->message = $this->update->getMessage();
return $this;
} }
...@@ -35,11 +43,26 @@ abstract class Command ...@@ -35,11 +43,26 @@ abstract class Command
return $this->message; return $this->message;
} }
public function getTelegram() {
return $this->telegram;
}
public function setCommand($command) { public function setCommand($command) {
$this->command = $command; $this->command = $command;
return $this; return $this;
} }
public function getUsage() {
return $this->usage;
}
public function getVersion() {
return $this->version;
}
public function getHelp() {
return $this->getUsage()."\n".$this->getVersion();
}
} }
...@@ -15,6 +15,8 @@ use Longman\TelegramBot\Entities\Update; ...@@ -15,6 +15,8 @@ use Longman\TelegramBot\Entities\Update;
class HelpCommand extends Command class HelpCommand extends Command
{ {
protected $usage = 'Usage: /help <command>';
protected $version = '1.0.0';
public function execute() { public function execute() {
$update = $this->getUpdate(); $update = $this->getUpdate();
......
...@@ -128,6 +128,29 @@ class Telegram ...@@ -128,6 +128,29 @@ class Telegram
return $this->update; return $this->update;
} }
/**
* Get commands list
*
* @return string $update
*/
public function getCommandsList() {
// iterate files
// getCommandClass
return $this->update;
}
/** /**
* Set log requests * Set log requests
* *
...@@ -229,7 +252,7 @@ class Telegram ...@@ -229,7 +252,7 @@ class Telegram
* *
* @return object * @return object
*/ */
protected function getCommandClass($command, Update $update) { protected function getCommandClass($command, Update $update = null) {
$this->commands_dir = array_unique($this->commands_dir); $this->commands_dir = array_unique($this->commands_dir);
$this->commands_dir = array_reverse($this->commands_dir); $this->commands_dir = array_reverse($this->commands_dir);
$class_name = ucfirst($command).'Command'; $class_name = ucfirst($command).'Command';
...@@ -237,13 +260,21 @@ class Telegram ...@@ -237,13 +260,21 @@ class Telegram
foreach($this->commands_dir as $dir) { foreach($this->commands_dir as $dir) {
if (is_file($dir.'/'.$class_name.'.php')) { if (is_file($dir.'/'.$class_name.'.php')) {
require_once($dir.'/'.$class_name.'.php'); require_once($dir.'/'.$class_name.'.php');
$class = new $class_name($update); $class = new $class_name($this);
if (!empty($update)) {
$class->setUpdate($update);
}
return $class; return $class;
} }
} }
$class_name = __NAMESPACE__ . '\\Commands\\' . $class_name; $class_name = __NAMESPACE__ . '\\Commands\\' . $class_name;
$class = new $class_name($update); $class = new $class_name($this);
if (!empty($update)) {
$class->setUpdate($update);
}
if (is_object($class)) { if (is_object($class)) {
return $class; return $class;
} }
......
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