Commit 36787d67 authored by Avtandil Kikabidze's avatar Avtandil Kikabidze

Improved code and doc-blocks in system commands

parent 84cd8f50
......@@ -83,8 +83,8 @@ class ChatsCommand extends AdminCommand
$whois = $chat->getId();
if ($this->telegram->getCommandObject('whois')) {
$whois = '/whois' . str_replace('-', 'g',
$chat->getId()); //We can't use '-' in command because part of it will become unclickable
// We can't use '-' in command because part of it will become unclickable
$whois = '/whois' . str_replace('-', 'g', $chat->getId());
}
if ($chat->isPrivateChat()) {
......
......@@ -18,31 +18,40 @@ use Longman\TelegramBot\Request;
*/
class CallbackqueryCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'callbackquery';
/**
* @var string
*/
protected $description = 'Reply to callback query';
/**
* @var string
*/
protected $version = '1.0.0';
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
$update = $this->getUpdate();
$callback_query = $update->getCallbackQuery();
$update = $this->getUpdate();
$callback_query = $update->getCallbackQuery();
$callback_query_id = $callback_query->getId();
$callback_data = $callback_query->getData();
$callback_data = $callback_query->getData();
$data['callback_query_id'] = $callback_query_id;
if ($callback_data == 'thumb up') {
$data['text'] = 'Hello World!';
$data['text'] = 'Hello World!';
$data['show_alert'] = true;
} else {
$data['text'] = 'Hello World!';
$data['text'] = 'Hello World!';
$data['show_alert'] = false;
}
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class ChannelchatcreatedCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Channelchatcreated';
/**
* @var string
*/
protected $description = 'Channel chat created';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//$message = $this->getMessage();
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class ChoseninlineresultCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'choseninlineresult';
/**
* @var string
*/
protected $name = 'choseninlineresult';
protected $description = 'Chosen result query';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//Information about chosen result is returned
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class DeletechatphotoCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Deletechatphoto';
/**
* @var string
*/
protected $description = 'Delete chat photo';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//$message = $this->getMessage();
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class EditedmessageCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'editedmessage';
/**
* @var string
*/
protected $description = 'User edited message';
protected $version = '1.0.0';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.0';
/*public function execute()
{
$update = $this->getUpdate();
......
......@@ -18,16 +18,25 @@ use Longman\TelegramBot\Request;
*/
class GenericCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Generic';
/**
* @var string
*/
protected $description = 'Handles generic commands or is executed by default when a command is not found';
/**
* @var string
*/
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
......
......@@ -19,19 +19,30 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class GenericmessageCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Genericmessage';
/**
* @var string
*/
protected $description = 'Handle generic message';
/**
* @var string
*/
protected $version = '1.0.2';
/**
* @var bool
*/
protected $need_mysql = true;
/**#@-*/
/**
* Execution if MySQL is required but not available
*
* @return boolean
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
public function executeNoDb()
{
......@@ -42,7 +53,7 @@ class GenericmessageCommand extends SystemCommand
/**
* Execute command
*
* @return boolean
* @return \Longman\TelegramBot\Entities\ServerResponse
*/
public function execute()
{
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class GroupchatcreatedCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Groupchatcreated';
/**
* @var string
*/
protected $description = 'Group chat created';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//$message = $this->getMessage();
......
......@@ -20,31 +20,55 @@ use Longman\TelegramBot\Request;
*/
class InlinequeryCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'inlinequery';
/**
* @var string
*/
protected $description = 'Reply to inline query';
/**
* @var string
*/
protected $version = '1.0.2';
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
$update = $this->getUpdate();
$update = $this->getUpdate();
$inline_query = $update->getInlineQuery();
$query = $inline_query->getQuery();
$query = $inline_query->getQuery();
$data = ['inline_query_id' => $inline_query->getId()];
$data = ['inline_query_id' => $inline_query->getId()];
$results = [];
if ($query !== '') {
$articles = [
['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'description' => 'you enter: ' . $query, 'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query])],
['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'description' => 'you enter: ' . $query, 'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query])],
['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'description' => 'you enter: ' . $query, 'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query])],
[
'id' => '001',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query])
],
[
'id' => '002',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query])
],
[
'id' => '003',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query])
],
];
foreach ($articles as $article) {
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class LeftchatmemberCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Leftchatmember';
/**
* @var string
*/
protected $description = 'Left Chat Member';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//$message = $this->getMessage();
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class MigratefromchatidCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Migratefromchatid';
/**
* @var string
*/
protected $description = 'Migrate from chat id';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//$message = $this->getMessage();
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class MigratetochatidCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Migratetochatid';
/**
* @var string
*/
protected $description = 'Migrate to chat id';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//$message = $this->getMessage();
......
......@@ -18,23 +18,30 @@ use Longman\TelegramBot\Request;
*/
class NewchatmemberCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Newchatmember';
/**
* @var string
*/
protected $description = 'New Chat Member';
/**
* @var string
*/
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @return mixed
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$member = $message->getNewChatMember();
$member = $message->getNewChatMember();
if ($message->botAddedInChat()) {
$text = 'Hi there!';
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class NewchatphotoCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Newchatphoto';
/**
* @var string
*/
protected $description = 'New chat Photo';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//$message = $this->getMessage();
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class NewchattitleCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Newchattitle';
/**
* @var string
*/
protected $description = 'New chat Title';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//$message = $this->getMessage();
......
......@@ -18,24 +18,37 @@ use Longman\TelegramBot\Request;
*/
class StartCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'start';
/**
* @var string
*/
protected $description = 'Start command';
/**
* @var string
*/
protected $usage = '/start';
/**
* @var string
*/
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* Command execute method
*
* @return mixed
*/
public function execute()
{
$message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = 'Hi there!' . "\n" . 'Type /help to see all commands!';
$text = 'Hi there!' . "\n" . 'Type /help to see all commands!';
$data = [
'chat_id' => $chat_id,
......
......@@ -17,17 +17,21 @@ use Longman\TelegramBot\Commands\SystemCommand;
*/
class SupergroupchatcreatedCommand extends SystemCommand
{
/**#@+
* {@inheritdoc}
/**
* @var string
*/
protected $name = 'Supergroupchatcreated';
/**
* @var string
*/
protected $description = 'Super group chat created';
protected $version = '1.0.1';
/**#@-*/
/**
* {@inheritdoc}
* @var string
*/
protected $version = '1.0.1';
/*public function execute()
{
//$message = $this->getMessage();
......
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