Fix and improve System commands.

parent e67d9b73
...@@ -31,12 +31,13 @@ class CallbackqueryCommand extends SystemCommand ...@@ -31,12 +31,13 @@ class CallbackqueryCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.0'; protected $version = '1.1.0';
/** /**
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
...@@ -45,15 +46,11 @@ class CallbackqueryCommand extends SystemCommand ...@@ -45,15 +46,11 @@ class CallbackqueryCommand extends SystemCommand
$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') { 'text' => 'Hello World!',
$data['text'] = 'Hello World!'; 'show_alert' => $callback_data === 'thumb up',
$data['show_alert'] = true; ];
} else {
$data['text'] = 'Hello World!';
$data['show_alert'] = false;
}
return Request::answerCallbackQuery($data); return Request::answerCallbackQuery($data);
} }
......
...@@ -20,7 +20,7 @@ class ChannelchatcreatedCommand extends SystemCommand ...@@ -20,7 +20,7 @@ class ChannelchatcreatedCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $name = 'Channelchatcreated'; protected $name = 'Channelchatcreated';
/** /**
* @var string * @var string
...@@ -30,11 +30,19 @@ class ChannelchatcreatedCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class ChannelchatcreatedCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$channel_chat_created = $message->getChannelChatCreated(); //$channel_chat_created = $message->getChannelChatCreated();
}*/
return parent::execute();
}
} }
...@@ -30,13 +30,21 @@ class ChoseninlineresultCommand extends SystemCommand ...@@ -30,13 +30,21 @@ class ChoseninlineresultCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//Information about chosen result is returned //Information about chosen result is returned
//$update = $this->getUpdate(); //$update = $this->getUpdate();
//$inline_query = $update->getChosenInlineResult(); //$inline_query = $update->getChosenInlineResult();
//$query = $inline_query->getQuery(); //$query = $inline_query->getQuery();
}*/
return parent::execute();
}
} }
...@@ -30,11 +30,19 @@ class DeletechatphotoCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class DeletechatphotoCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$delete_chat_photo = $message->getDeleteChatPhoto(); //$delete_chat_photo = $message->getDeleteChatPhoto();
}*/
return parent::execute();
}
} }
...@@ -30,11 +30,19 @@ class EditedmessageCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class EditedmessageCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.0'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
$update = $this->getUpdate(); //$update = $this->getUpdate();
$edited_message = $update->getEditedMessage(); //$edited_message = $update->getEditedMessage();
}*/
return parent::execute();
}
} }
...@@ -31,12 +31,13 @@ class GenericCommand extends SystemCommand ...@@ -31,12 +31,13 @@ class GenericCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/** /**
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
...@@ -47,8 +48,9 @@ class GenericCommand extends SystemCommand ...@@ -47,8 +48,9 @@ class GenericCommand extends SystemCommand
$user_id = $message->getFrom()->getId(); $user_id = $message->getFrom()->getId();
$command = $message->getCommand(); $command = $message->getCommand();
if (in_array($user_id, $this->telegram->getAdminList()) && strtolower(substr($command, 0, 5)) == 'whois') { //If the user is and admin and the command is in the format "/whoisXYZ", call the /whois command
return $this->telegram->executeCommand('whois', $this->update); if (stripos($command, 'whois') === 0 && $this->telegram->isAdmin($user_id)) {
return $this->telegram->executeCommand('whois');
} }
$data = [ $data = [
......
...@@ -32,7 +32,7 @@ class GenericmessageCommand extends SystemCommand ...@@ -32,7 +32,7 @@ class GenericmessageCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.2'; protected $version = '1.1.0';
/** /**
* @var bool * @var bool
...@@ -54,6 +54,7 @@ class GenericmessageCommand extends SystemCommand ...@@ -54,6 +54,7 @@ class GenericmessageCommand extends SystemCommand
* Execute command * Execute command
* *
* @return \Longman\TelegramBot\Entities\ServerResponse * @return \Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
...@@ -64,7 +65,7 @@ class GenericmessageCommand extends SystemCommand ...@@ -64,7 +65,7 @@ class GenericmessageCommand extends SystemCommand
); );
//Fetch conversation command if it exists and execute it //Fetch conversation command if it exists and execute it
if ($conversation->exists() && ($command = $conversation->getCommand())) { if ($conversation->exists() && ($command = $conversation->getCommand())) {
return $this->telegram->executeCommand($command, $this->update); return $this->telegram->executeCommand($command);
} }
return Request::emptyResponse(); return Request::emptyResponse();
......
...@@ -30,11 +30,19 @@ class GroupchatcreatedCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class GroupchatcreatedCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$group_chat_created = $message->getGroupChatCreated(); //$group_chat_created = $message->getGroupChatCreated();
}*/
return parent::execute();
}
} }
...@@ -33,12 +33,13 @@ class InlinequeryCommand extends SystemCommand ...@@ -33,12 +33,13 @@ class InlinequeryCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.2'; protected $version = '1.1.0';
/** /**
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
...@@ -55,19 +56,19 @@ class InlinequeryCommand extends SystemCommand ...@@ -55,19 +56,19 @@ class InlinequeryCommand extends SystemCommand
'id' => '001', 'id' => '001',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query, 'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]) 'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]),
], ],
[ [
'id' => '002', 'id' => '002',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query, 'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]) 'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]),
], ],
[ [
'id' => '003', 'id' => '003',
'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery',
'description' => 'you enter: ' . $query, 'description' => 'you enter: ' . $query,
'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]) 'input_message_content' => new InputTextMessageContent(['message_text' => ' ' . $query]),
], ],
]; ];
......
...@@ -30,11 +30,19 @@ class LeftchatmemberCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class LeftchatmemberCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$member = $message->getLeftChatMember(); //$member = $message->getLeftChatMember();
}*/
return parent::execute();
}
} }
...@@ -30,11 +30,19 @@ class MigratefromchatidCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class MigratefromchatidCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$migrate_from_chat_id = $message->getMigrateFromChatId(); //$migrate_from_chat_id = $message->getMigrateFromChatId();
}*/
return parent::execute();
}
} }
...@@ -30,11 +30,19 @@ class MigratetochatidCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class MigratetochatidCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$migrate_to_chat_id = $message->getMigrateToChatId(); //$migrate_to_chat_id = $message->getMigrateToChatId();
}*/
return parent::execute();
}
} }
...@@ -31,10 +31,13 @@ class NewchatmemberCommand extends SystemCommand ...@@ -31,10 +31,13 @@ class NewchatmemberCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/** /**
* Command execute method
*
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function execute() public function execute()
{ {
...@@ -42,10 +45,9 @@ class NewchatmemberCommand extends SystemCommand ...@@ -42,10 +45,9 @@ class NewchatmemberCommand extends SystemCommand
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$member = $message->getNewChatMember(); $member = $message->getNewChatMember();
$text = 'Hi there!';
if ($message->botAddedInChat()) { if (!$message->botAddedInChat()) {
$text = 'Hi there!';
} else {
$text = 'Hi ' . $member->tryMention() . '!'; $text = 'Hi ' . $member->tryMention() . '!';
} }
......
...@@ -30,11 +30,19 @@ class NewchatphotoCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class NewchatphotoCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$new_chat_photo = $message->getNewChatPhoto(); //$new_chat_photo = $message->getNewChatPhoto();
}*/
return parent::execute();
}
} }
...@@ -30,11 +30,19 @@ class NewchattitleCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class NewchattitleCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$new_chat_title = $message->getNewChatTitle(); //$new_chat_title = $message->getNewChatTitle();
}*/
return parent::execute();
}
} }
...@@ -36,19 +36,20 @@ class StartCommand extends SystemCommand ...@@ -36,19 +36,20 @@ class StartCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/** /**
* Command execute method * Command execute method
* *
* @return mixed * @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
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!' . PHP_EOL . 'Type /help to see all commands!';
$data = [ $data = [
'chat_id' => $chat_id, 'chat_id' => $chat_id,
......
...@@ -30,11 +30,19 @@ class SupergroupchatcreatedCommand extends SystemCommand ...@@ -30,11 +30,19 @@ class SupergroupchatcreatedCommand extends SystemCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.0.1'; protected $version = '1.1.0';
/*public function execute() /**
* Command execute method
*
* @return mixed
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$supergroup_chat_created = $message->getSuperGroupChatCreated(); //$supergroup_chat_created = $message->getSuperGroupChatCreated();
}*/
return parent::execute();
}
} }
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