Fix example commands.

parent ae619a1b
...@@ -25,7 +25,7 @@ class ForceReplyCommand extends UserCommand ...@@ -25,7 +25,7 @@ class ForceReplyCommand extends UserCommand
protected $name = 'forcereply'; protected $name = 'forcereply';
protected $description = 'Force reply with reply markup'; protected $description = 'Force reply with reply markup';
protected $usage = '/forcereply'; protected $usage = '/forcereply';
protected $version = '0.0.5'; protected $version = '0.0.6';
/**#@-*/ /**#@-*/
/** /**
...@@ -36,10 +36,11 @@ class ForceReplyCommand extends UserCommand ...@@ -36,10 +36,11 @@ class ForceReplyCommand extends UserCommand
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$data = []; $data = [
$data['chat_id'] = $chat_id; 'chat_id' => $chat_id,
$data['text'] = 'Write something:'; 'text' => 'Write something:',
$data['reply_markup'] = new ForceReply(['selective' => false]); 'reply_markup' => new ForceReply(['selective' => false]),
];
return Request::sendMessage($data); return Request::sendMessage($data);
} }
......
...@@ -25,7 +25,7 @@ class ImageCommand extends UserCommand ...@@ -25,7 +25,7 @@ class ImageCommand extends UserCommand
protected $name = 'image'; protected $name = 'image';
protected $description = 'Send Image'; protected $description = 'Send Image';
protected $usage = '/image'; protected $usage = '/image';
protected $version = '1.0.0'; protected $version = '1.0.1';
/**#@-*/ /**#@-*/
/** /**
...@@ -37,18 +37,26 @@ class ImageCommand extends UserCommand ...@@ -37,18 +37,26 @@ class ImageCommand extends UserCommand
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = $message->getText(true); $text = $message->getText(true);
$data = []; $data = [
$data['chat_id'] = $chat_id; 'chat_id' => $chat_id,
$data['caption'] = $text; 'caption' => $text,
];
//return Request::sendPhoto($data, $this->telegram->getUploadPath().'/'.'image.jpg'); //Return a random picture from the telegram->getUploadPath().
return Request::sendPhoto($data, $this->ShowRandomImage($this->telegram->getUploadPath())); return Request::sendPhoto($data, $this->ShowRandomImage($this->telegram->getUploadPath()));
} }
//return random picture from the telegram->getUploadPath();
private function ShowRandomImage($dir) { /**
* Return the path to a random image in the passed directory.
*
* @param string $dir
*
* @return string
*/
private function ShowRandomImage($dir)
{
$image_list = scandir($dir); $image_list = scandir($dir);
return $dir . "/" . $image_list[mt_rand(2, count($image_list) - 1)];
}
return $dir . '/' . $image_list[mt_rand(2, count($image_list) - 1)];
}
} }
...@@ -26,7 +26,7 @@ class InlinekeyboardCommand extends UserCommand ...@@ -26,7 +26,7 @@ class InlinekeyboardCommand extends UserCommand
protected $name = 'Inlinekeyboard'; protected $name = 'Inlinekeyboard';
protected $description = 'Show inline keyboard'; protected $description = 'Show inline keyboard';
protected $usage = '/inlinekeyboard'; protected $usage = '/inlinekeyboard';
protected $version = '0.0.1'; protected $version = '0.0.2';
/**#@-*/ /**#@-*/
/** /**
......
...@@ -23,9 +23,9 @@ class KeyboardCommand extends UserCommand ...@@ -23,9 +23,9 @@ class KeyboardCommand extends UserCommand
* {@inheritdoc} * {@inheritdoc}
*/ */
protected $name = 'keyboard'; protected $name = 'keyboard';
protected $description = 'Show a custom keybord with reply markup'; protected $description = 'Show a custom keyboard with reply markup';
protected $usage = '/keyboard'; protected $usage = '/keyboard';
protected $version = '0.0.6'; protected $version = '0.1.0';
/**#@-*/ /**#@-*/
/** /**
...@@ -35,70 +35,67 @@ class KeyboardCommand extends UserCommand ...@@ -35,70 +35,67 @@ class KeyboardCommand extends UserCommand
{ {
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = []; $data = [
$data['chat_id'] = $chat_id; 'chat_id' => $chat_id,
$data['text'] = 'Press a Button:'; 'text' => 'Press a Button:',
];
//Keyboard examples //Keyboard examples
$keyboards = []; $keyboards = [];
//0 //Example 0
$keyboard[] = ['7','8','9']; $keyboard = [];
$keyboard[] = ['4','5','6']; $keyboard[] = ['7', '8', '9'];
$keyboard[] = ['1','2','3']; $keyboard[] = ['4', '5', '6'];
$keyboard[] = [' ','0',' ']; $keyboard[] = ['1', '2', '3'];
$keyboard[] = [' ', '0', ' '];
$keyboards[] = $keyboard; $keyboards[] = $keyboard;
unset($keyboard);
//1
$keyboard[] = ['7','8','9','+'];
$keyboard[] = ['4','5','6','-'];
$keyboard[] = ['1','2','3','*'];
$keyboard[] = [' ','0',' ','/'];
//Example 1
$keyboard = [];
$keyboard[] = ['7', '8', '9', '+'];
$keyboard[] = ['4', '5', '6', '-'];
$keyboard[] = ['1', '2', '3', '*'];
$keyboard[] = [' ', '0', ' ', '/'];
$keyboards[] = $keyboard; $keyboards[] = $keyboard;
unset($keyboard);
//2 //Example 2
$keyboard = [];
$keyboard[] = ['A']; $keyboard[] = ['A'];
$keyboard[] = ['B']; $keyboard[] = ['B'];
$keyboard[] = ['C']; $keyboard[] = ['C'];
$keyboards[] = $keyboard; $keyboards[] = $keyboard;
unset($keyboard);
//3 //Example 3
$keyboard = [];
$keyboard[] = ['A']; $keyboard[] = ['A'];
$keyboard[] = ['B']; $keyboard[] = ['B'];
$keyboard[] = ['C','D']; $keyboard[] = ['C', 'D'];
$keyboards[] = $keyboard; $keyboards[] = $keyboard;
unset($keyboard);
//4 (bots 2.0) //Example 4 (bots version 2.0)
$keyboard = [];
$keyboard[] = [ $keyboard[] = [
[ [
'text' => 'request_contact', 'text' => 'Send my contact',
'request_contact' => true 'request_contact' => true,
], ],
[ [
'text' => 'request_location', 'text' => 'Send my location',
'request_location' => true 'request_location' => true,
] ],
]; ];
$keyboards[] = $keyboard; $keyboards[] = $keyboard;
unset($keyboard);
//Return a random keyboard.
$keyboard = $keyboards[mt_rand(0, count($keyboards) - 1)];
$data['reply_markup'] = new ReplyKeyboardMarkup( $data['reply_markup'] = new ReplyKeyboardMarkup(
[ [
'keyboard' => $keyboards[1] , 'keyboard' => $keyboard,
'resize_keyboard' => true, 'resize_keyboard' => true,
'one_time_keyboard' => false, 'one_time_keyboard' => false,
'selective' => false 'selective' => false,
] ]
); );
......
...@@ -25,7 +25,7 @@ class MarkdownCommand extends UserCommand ...@@ -25,7 +25,7 @@ class MarkdownCommand extends UserCommand
protected $name = 'markdown'; protected $name = 'markdown';
protected $description = 'Print Markdown tesxt'; protected $description = 'Print Markdown tesxt';
protected $usage = '/markdown'; protected $usage = '/markdown';
protected $version = '1.0.0'; protected $version = '1.0.1';
/**#@-*/ /**#@-*/
/** /**
...@@ -35,17 +35,18 @@ class MarkdownCommand extends UserCommand ...@@ -35,17 +35,18 @@ class MarkdownCommand extends UserCommand
{ {
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = []; $data = [
$data['chat_id'] = $chat_id; 'chat_id' => $chat_id,
$data['parse_mode'] = 'MARKDOWN'; 'parse_mode' => 'MARKDOWN',
$data['text'] = "*bold* _italic_ `inline fixed width code` ```preformatted code block 'text' => '*bold* _italic_ `inline fixed width code`
```
preformatted code block
code block code block
``` ```
[Best Telegram bot api!!](https://github.com/akalongman/php-telegram-bot) [Best Telegram bot api!!](https://github.com/akalongman/php-telegram-bot)
',
"; ];
return Request::sendMessage($data); return Request::sendMessage($data);
} }
......
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