Make use of the new Keyboard entities.

Some typos, code cleanup.
parent 0001e687
......@@ -33,8 +33,6 @@ class KeyboardCommand extends UserCommand
*/
public function execute()
{
$chat_id = $this->getMessage()->getChat()->getId();
//Keyboard examples
/** @var Keyboard[] $keyboards */
$keyboards = [];
......@@ -77,6 +75,7 @@ class KeyboardCommand extends UserCommand
->setOneTimeKeyboard(true)
->setSelective(false);
$chat_id = $this->getMessage()->getChat()->getId();
$data = [
'chat_id' => $chat_id,
'text' => 'Press a Button:',
......
......@@ -23,7 +23,7 @@ class MarkdownCommand extends UserCommand
* {@inheritdoc}
*/
protected $name = 'markdown';
protected $description = 'Print Markdown tesxt';
protected $description = 'Print Markdown text';
protected $usage = '/markdown';
protected $version = '1.0.1';
/**#@-*/
......
......@@ -12,7 +12,7 @@ namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Entities\ReplyKeyboardHide;
use Longman\TelegramBot\Entities\Keyboard;
use Longman\TelegramBot\Request;
/**
......@@ -85,7 +85,7 @@ class CancelCommand extends UserCommand
{
return Request::sendMessage(
[
'reply_markup' => new ReplyKeyboardHide(['selective' => true]),
'reply_markup' => Keyboard::hide(['selective' => true]),
'chat_id' => $this->getMessage()->getChat()->getId(),
'text' => $text,
]
......
......@@ -15,7 +15,7 @@ namespace Longman\TelegramBot\Entities;
use Longman\TelegramBot\Exception\TelegramException;
/**
* Class ReplyKeyboardMarkup
* Class Keyboard
*
* @link https://core.telegram.org/bots/api#replykeyboardmarkup
*
......
......@@ -149,19 +149,16 @@ class Message extends Entity
*/
public function getFullCommand()
{
if (strpos($this->text, '/') === 0) {
$no_EOL = strtok($this->text, PHP_EOL);
$no_space = strtok($this->text, ' ');
$text = $this->getProperty('text');
if (strpos($text, '/') === 0) {
$no_EOL = strtok($text, PHP_EOL);
$no_space = strtok($text, ' ');
//try to understand which separator \n or space divide /command from text
if (strlen($no_space) < strlen($no_EOL)) {
return $no_space;
} else {
return $no_EOL;
}
} else {
return null;
return strlen($no_space) < strlen($no_EOL) ? $no_space : $no_EOL;
}
return null;
}
/**
......@@ -171,8 +168,9 @@ class Message extends Entity
*/
public function getCommand()
{
if (!empty($this->command)) {
return $this->command;
$command = $this->getProperty('command');
if (!empty($command)) {
return $command;
}
$cmd = $this->getFullCommand();
......@@ -185,11 +183,11 @@ class Message extends Entity
if (isset($split_cmd[1])) {
//command is followed by name check if is addressed to me
if (strtolower($split_cmd[1]) === strtolower($this->bot_name)) {
return $this->command = $split_cmd[0];
return $split_cmd[0];
}
} else {
//command is not followed by name
return $this->command = $cmd;
return $cmd;
}
}
......@@ -205,7 +203,7 @@ class Message extends Entity
*/
public function getText($without_cmd = false)
{
$text = $this->text;
$text = $this->getProperty('text');
if ($without_cmd && $command = $this->getFullCommand()) {
if (strlen($command) + 1 < strlen($text)) {
......@@ -225,13 +223,9 @@ class Message extends Entity
*/
public function botAddedInChat()
{
if (!empty($this->new_chat_member)) {
if ($this->new_chat_member->getUsername() === $this->getBotName()) {
return true;
}
}
$member = $this->getNewChatMember();
return false;
return $member !== null && $member->getUsername() === $this->getBotName();
}
/**
......
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