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