Commit 8509c63c authored by Marco Boretto's avatar Marco Boretto

Merge pull request #98 from noplanman/command_code_cleanup

Remove any unnecessary code from commands.
parents 9960f62f fba22125
...@@ -13,8 +13,6 @@ namespace Longman\TelegramBot\Commands; ...@@ -13,8 +13,6 @@ namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\DB; use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Chat; use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -50,13 +48,6 @@ class ChatsCommand extends Command ...@@ -50,13 +48,6 @@ class ChatsCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -81,12 +72,13 @@ class ChatsCommand extends Command ...@@ -81,12 +72,13 @@ class ChatsCommand extends Command
//Preparing message //Preparing message
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$data = [ $data = [
'chat_id' => $chat_id, 'chat_id' => $chat_id,
'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.', 'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.',
]; ];
$result = Request::sendMessage($data);
return $result->isOk(); return Request::sendMessage($data)->isOk();
} }
/** /**
...@@ -96,12 +88,9 @@ class ChatsCommand extends Command ...@@ -96,12 +88,9 @@ class ChatsCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
$results = DB::selectChats( $results = DB::selectChats(
true, //Send to groups (group chat) true, //Send to groups (group chat)
...@@ -133,7 +122,7 @@ class ChatsCommand extends Command ...@@ -133,7 +122,7 @@ class ChatsCommand extends Command
} }
} }
if (($user_chats + $group_chats + $super_group_chats) == 0) { if (($user_chats + $group_chats + $super_group_chats) === 0) {
$text = 'No chats found..'; $text = 'No chats found..';
} else { } else {
$text .= "\n" . 'Private Chats: ' . $user_chats; $text .= "\n" . 'Private Chats: ' . $user_chats;
...@@ -146,7 +135,7 @@ class ChatsCommand extends Command ...@@ -146,7 +135,7 @@ class ChatsCommand extends Command
'chat_id' => $chat_id, 'chat_id' => $chat_id,
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data);
return $result->isOk(); return Request::sendMessage($data)->isOk();
} }
} }
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -49,13 +46,6 @@ class SendtoallCommand extends Command ...@@ -49,13 +46,6 @@ class SendtoallCommand extends Command
*/ */
protected $version = '1.2.0'; protected $version = '1.2.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -80,12 +70,13 @@ class SendtoallCommand extends Command ...@@ -80,12 +70,13 @@ class SendtoallCommand extends Command
//Preparing message //Preparing message
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$data = [ $data = [
'chat_id' => $chat_id, 'chat_id' => $chat_id,
'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.', 'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.',
]; ];
$result = Request::sendMessage($data);
return $result->isOk(); return Request::sendMessage($data)->isOk();
} }
/** /**
...@@ -97,12 +88,9 @@ class SendtoallCommand extends Command ...@@ -97,12 +88,9 @@ class SendtoallCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
if (empty($text)) { if (empty($text)) {
$text = 'Write the message to send: /sendall <message>'; $text = 'Write the message to send: /sendall <message>';
...@@ -147,7 +135,7 @@ class SendtoallCommand extends Command ...@@ -147,7 +135,7 @@ class SendtoallCommand extends Command
} }
$text .= 'Delivered: ' . ($tot - $fail) . '/' . $tot . "\n"; $text .= 'Delivered: ' . ($tot - $fail) . '/' . $tot . "\n";
} }
if ($tot == 0) { if ($tot === 0) {
$text = 'No users or chats found..'; $text = 'No users or chats found..';
} }
...@@ -156,7 +144,6 @@ class SendtoallCommand extends Command ...@@ -156,7 +144,6 @@ class SendtoallCommand extends Command
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -49,13 +46,6 @@ class SendtochannelCommand extends Command ...@@ -49,13 +46,6 @@ class SendtochannelCommand extends Command
*/ */
protected $version = '0.1.0'; protected $version = '0.1.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -79,11 +69,9 @@ class SendtochannelCommand extends Command ...@@ -79,11 +69,9 @@ class SendtochannelCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true); $text = $message->getText(true);
if (empty($text)) { if (empty($text)) {
...@@ -109,7 +97,6 @@ class SendtochannelCommand extends Command ...@@ -109,7 +97,6 @@ class SendtochannelCommand extends Command
'text' => $text_back, 'text' => $text_back,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request;
/** /**
* Channel chat created command * Channel chat created command
...@@ -33,13 +31,6 @@ class ChannelchatcreatedCommand extends Command ...@@ -33,13 +31,6 @@ class ChannelchatcreatedCommand extends Command
*/ */
protected $description = 'Channel chat created'; protected $description = 'Channel chat created';
/**
* Usage
*
* @var string
*/
protected $usage = '/';
/** /**
* Version * Version
* *
...@@ -47,13 +38,6 @@ class ChannelchatcreatedCommand extends Command ...@@ -47,13 +38,6 @@ class ChannelchatcreatedCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
...@@ -61,12 +45,10 @@ class ChannelchatcreatedCommand extends Command ...@@ -61,12 +45,10 @@ class ChannelchatcreatedCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate(); //$message = $this->getMessage();
$message = $this->getMessage(); //$channel_chat_created = $message->getChannelChatCreated();
$channel_chat_created = $message->getChannelChatCreated();
//Temporary, do nothing //System command, do nothing
return 1; return true;
} }
} }
...@@ -11,10 +11,6 @@ ...@@ -11,10 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Entity;
use Longman\TelegramBot\Entities\InlineQueryResultArticle;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request;
/** /**
* Chosen inline result command * Chosen inline result command
...@@ -35,13 +31,6 @@ class ChoseninlineresultCommand extends Command ...@@ -35,13 +31,6 @@ class ChoseninlineresultCommand extends Command
*/ */
protected $description = 'Chosen result query'; protected $description = 'Chosen result query';
/**
* Usage
*
* @var string
*/
protected $usage = '';
/** /**
* Version * Version
* *
...@@ -49,20 +38,6 @@ class ChoseninlineresultCommand extends Command ...@@ -49,20 +38,6 @@ class ChoseninlineresultCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/**
* If this command is public
*
* @var boolean
*/
protected $public = false;
/** /**
* Execute command * Execute command
* *
...@@ -70,13 +45,12 @@ class ChoseninlineresultCommand extends Command ...@@ -70,13 +45,12 @@ class ChoseninlineresultCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$inline_query = $update->getChosenInlineResult();
$query = $inline_query->getQuery();
//Information about chosen result is returned //Information about chosen result is returned
//Do nothing //$update = $this->getUpdate();
//$inline_query = $update->getChosenInlineResult();
//$query = $inline_query->getQuery();
return 1; //System command, do nothing
return true;
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException; use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
...@@ -48,13 +47,6 @@ class DateCommand extends Command ...@@ -48,13 +47,6 @@ class DateCommand extends Command
*/ */
protected $version = '1.2.0'; protected $version = '1.2.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -135,7 +127,7 @@ class DateCommand extends Command ...@@ -135,7 +127,7 @@ class DateCommand extends Command
$google_api_key = $this->getConfig('google_api_key'); $google_api_key = $this->getConfig('google_api_key');
if (!empty($google_api_key)) { if (!empty($google_api_key)) {
$params.= '&key=' . $google_api_key; $params .= '&key=' . $google_api_key;
} }
$data = $this->request($url . $params); $data = $this->request($url . $params);
...@@ -214,7 +206,6 @@ class DateCommand extends Command ...@@ -214,7 +206,6 @@ class DateCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
...@@ -238,7 +229,6 @@ class DateCommand extends Command ...@@ -238,7 +229,6 @@ class DateCommand extends Command
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request;
/** /**
* Delete chat photo command * Delete chat photo command
...@@ -33,13 +31,6 @@ class DeletechatphotoCommand extends Command ...@@ -33,13 +31,6 @@ class DeletechatphotoCommand extends Command
*/ */
protected $description = 'Delete chat photo'; protected $description = 'Delete chat photo';
/**
* Usage
*
* @var string
*/
protected $usage = '/';
/** /**
* Version * Version
* *
...@@ -47,13 +38,6 @@ class DeletechatphotoCommand extends Command ...@@ -47,13 +38,6 @@ class DeletechatphotoCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
...@@ -61,12 +45,10 @@ class DeletechatphotoCommand extends Command ...@@ -61,12 +45,10 @@ class DeletechatphotoCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate(); //$message = $this->getMessage();
$message = $this->getMessage(); //$delete_chat_photo = $message->getDeleteChatPhoto();
$delete_chat_photo = $message->getDeleteChatPhoto();
//Temporary, do nothing //System command, do nothing
return 1; return true;
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -47,13 +46,6 @@ class EchoCommand extends Command ...@@ -47,13 +46,6 @@ class EchoCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -68,9 +60,7 @@ class EchoCommand extends Command ...@@ -68,9 +60,7 @@ class EchoCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = $message->getText(true); $text = $message->getText(true);
...@@ -79,7 +69,6 @@ class EchoCommand extends Command ...@@ -79,7 +69,6 @@ class EchoCommand extends Command
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -33,13 +32,6 @@ class GenericCommand extends Command ...@@ -33,13 +32,6 @@ class GenericCommand extends Command
*/ */
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';
/**
* Usage
*
* @var string
*/
protected $usage = '/';
/** /**
* Version * Version
* *
...@@ -47,13 +39,6 @@ class GenericCommand extends Command ...@@ -47,13 +39,6 @@ class GenericCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
...@@ -63,22 +48,17 @@ class GenericCommand extends Command ...@@ -63,22 +48,17 @@ class GenericCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId();
//You can use $command as param //You can use $command as param
$command = $message->getCommand(); $command = $message->getCommand();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$text = $message->getText(true);
$data = [ $data = [
'chat_id' => $chat_id, 'chat_id' => $chat_id,
'text' => 'Command: ' . $command . ' not found.. :(', 'text' => 'Command: ' . $command . ' not found.. :(',
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request;
/** /**
* Generic message command * Generic message command
...@@ -33,13 +31,6 @@ class GenericmessageCommand extends Command ...@@ -33,13 +31,6 @@ class GenericmessageCommand extends Command
*/ */
protected $description = 'Handle generic message'; protected $description = 'Handle generic message';
/**
* Usage
*
* @var string
*/
protected $usage = '/';
/** /**
* Version * Version
* *
...@@ -47,13 +38,6 @@ class GenericmessageCommand extends Command ...@@ -47,13 +38,6 @@ class GenericmessageCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
...@@ -61,17 +45,7 @@ class GenericmessageCommand extends Command ...@@ -61,17 +45,7 @@ class GenericmessageCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate(); //System command, do nothing
$message = $this->getMessage(); return true;
$chat_id = $message->getChat()->getId();
//You can use $command as param
$command = $message->getCommand();
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
//Do nothing
return 1;
} }
} }
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request;
/** /**
* Group chat created command * Group chat created command
...@@ -33,13 +31,6 @@ class GroupchatcreatedCommand extends Command ...@@ -33,13 +31,6 @@ class GroupchatcreatedCommand extends Command
*/ */
protected $description = 'Group chat created'; protected $description = 'Group chat created';
/**
* Usage
*
* @var string
*/
protected $usage = '/';
/** /**
* Version * Version
* *
...@@ -47,13 +38,6 @@ class GroupchatcreatedCommand extends Command ...@@ -47,13 +38,6 @@ class GroupchatcreatedCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
...@@ -61,12 +45,10 @@ class GroupchatcreatedCommand extends Command ...@@ -61,12 +45,10 @@ class GroupchatcreatedCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate(); //$message = $this->getMessage();
$message = $this->getMessage(); //$group_chat_created = $message->getGroupChatCreated();
$group_chat_created = $message->getGroupChatCreated();
//Temporary, do nothing //System command, do nothing
return 1; return true;
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -47,13 +46,6 @@ class HelpCommand extends Command ...@@ -47,13 +46,6 @@ class HelpCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -68,7 +60,6 @@ class HelpCommand extends Command ...@@ -68,7 +60,6 @@ class HelpCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
...@@ -116,7 +107,6 @@ class HelpCommand extends Command ...@@ -116,7 +107,6 @@ class HelpCommand extends Command
'text' => $msg, 'text' => $msg,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,9 +11,7 @@ ...@@ -11,9 +11,7 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Entity;
use Longman\TelegramBot\Entities\InlineQueryResultArticle; use Longman\TelegramBot\Entities\InlineQueryResultArticle;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -35,13 +33,6 @@ class InlinequeryCommand extends Command ...@@ -35,13 +33,6 @@ class InlinequeryCommand extends Command
*/ */
protected $description = 'Reply to inline query'; protected $description = 'Reply to inline query';
/**
* Usage
*
* @var string
*/
protected $usage = '';
/** /**
* Version * Version
* *
...@@ -49,20 +40,6 @@ class InlinequeryCommand extends Command ...@@ -49,20 +40,6 @@ class InlinequeryCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/**
* If this command is public
*
* @var boolean
*/
protected $public = false;
/** /**
* Execute command * Execute command
* *
...@@ -77,19 +54,17 @@ class InlinequeryCommand extends Command ...@@ -77,19 +54,17 @@ class InlinequeryCommand extends Command
$data = ['inline_query_id' => $inline_query->getId()]; $data = ['inline_query_id' => $inline_query->getId()];
$articles = [ $articles = [
['id' => '001' , 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query ], ['id' => '001', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query],
['id' => '002' , 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query ], ['id' => '002', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query],
['id' => '003' , 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query ], ['id' => '003', 'title' => 'https://core.telegram.org/bots/api#answerinlinequery', 'message_text' => 'you enter: ' . $query],
]; ];
$array_article = []; $array_article = [];
foreach ($articles as $article) { foreach ($articles as $article) {
$array_article[] = new InlineQueryResultArticle($article); $array_article[] = new InlineQueryResultArticle($article);
} }
$array_json = '['.implode(',', $array_article).']'; $data['results'] = '[' . implode(',', $array_article) . ']';
$data['results'] = $array_json;
$result = Request::answerInlineQuery($data); return Request::answerInlineQuery($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request;
/** /**
* Left chat participant command * Left chat participant command
...@@ -33,13 +31,6 @@ class LeftchatparticipantCommand extends Command ...@@ -33,13 +31,6 @@ class LeftchatparticipantCommand extends Command
*/ */
protected $description = 'Left Chat Participant'; protected $description = 'Left Chat Participant';
/**
* Usage
*
* @var string
*/
protected $usage = '/';
/** /**
* Version * Version
* *
...@@ -47,13 +38,6 @@ class LeftchatparticipantCommand extends Command ...@@ -47,13 +38,6 @@ class LeftchatparticipantCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
...@@ -61,12 +45,10 @@ class LeftchatparticipantCommand extends Command ...@@ -61,12 +45,10 @@ class LeftchatparticipantCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate(); //$message = $this->getMessage();
$message = $this->getMessage(); //$participant = $message->getLeftChatParticipant();
$participant = $message->getLeftChatParticipant();
//Temporary, do nothing //System command, do nothing
return 1; return true;
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -33,13 +32,6 @@ class NewchatparticipantCommand extends Command ...@@ -33,13 +32,6 @@ class NewchatparticipantCommand extends Command
*/ */
protected $description = 'New Chat Participant'; protected $description = 'New Chat Participant';
/**
* Usage
*
* @var string
*/
protected $usage = '/';
/** /**
* Version * Version
* *
...@@ -47,13 +39,6 @@ class NewchatparticipantCommand extends Command ...@@ -47,13 +39,6 @@ class NewchatparticipantCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
...@@ -61,16 +46,15 @@ class NewchatparticipantCommand extends Command ...@@ -61,16 +46,15 @@ class NewchatparticipantCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$participant = $message->getNewChatParticipant(); $participant = $message->getNewChatParticipant();
if (strtolower($participant->getUsername()) == strtolower($this->getTelegram()->getBotName())) { if (strtolower($participant->getUsername()) === strtolower($this->getTelegram()->getBotName())) {
$text = 'Hi there!'; $text = 'Hi there!';
} else { } else {
$text = 'Hi ' . $participant->tryMention() . ' !'; $text = 'Hi ' . $participant->tryMention() . '!';
} }
$data = [ $data = [
...@@ -78,7 +62,6 @@ class NewchatparticipantCommand extends Command ...@@ -78,7 +62,6 @@ class NewchatparticipantCommand extends Command
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request;
/** /**
* New chat title command * New chat title command
...@@ -33,13 +31,6 @@ class NewchattitleCommand extends Command ...@@ -33,13 +31,6 @@ class NewchattitleCommand extends Command
*/ */
protected $description = 'New chat Title'; protected $description = 'New chat Title';
/**
* Usage
*
* @var string
*/
protected $usage = '/';
/** /**
* Version * Version
* *
...@@ -47,13 +38,6 @@ class NewchattitleCommand extends Command ...@@ -47,13 +38,6 @@ class NewchattitleCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
...@@ -61,12 +45,10 @@ class NewchattitleCommand extends Command ...@@ -61,12 +45,10 @@ class NewchattitleCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate(); //$message = $this->getMessage();
$message = $this->getMessage(); //$new_chat_title = $message->getNewChatTitle();
$new_chat_title = $message->getNewChatTitle();
//Temporary, do nothing //System command, do nothing
return 1; return true;
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -47,13 +46,6 @@ class SlapCommand extends Command ...@@ -47,13 +46,6 @@ class SlapCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
...@@ -61,8 +53,8 @@ class SlapCommand extends Command ...@@ -61,8 +53,8 @@ class SlapCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId(); $message_id = $message->getMessageId();
$text = $message->getText(true); $text = $message->getText(true);
...@@ -82,7 +74,6 @@ class SlapCommand extends Command ...@@ -82,7 +74,6 @@ class SlapCommand extends Command
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -47,20 +46,6 @@ class StartCommand extends Command ...@@ -47,20 +46,6 @@ class StartCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/**
* If this command is public
*
* @var boolean
*/
protected $public = false;
/** /**
* Execute command * Execute command
* *
...@@ -68,7 +53,6 @@ class StartCommand extends Command ...@@ -68,7 +53,6 @@ class StartCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
...@@ -79,7 +63,6 @@ class StartCommand extends Command ...@@ -79,7 +63,6 @@ class StartCommand extends Command
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -33,13 +32,6 @@ class SupergroupchatcreatedCommand extends Command ...@@ -33,13 +32,6 @@ class SupergroupchatcreatedCommand extends Command
*/ */
protected $description = 'Super group chat created'; protected $description = 'Super group chat created';
/**
* Usage
*
* @var string
*/
protected $usage = '/';
/** /**
* Version * Version
* *
...@@ -47,24 +39,16 @@ class SupergroupchatcreatedCommand extends Command ...@@ -47,24 +39,16 @@ class SupergroupchatcreatedCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* Execute command * Execute command
* *
* @todo $chat_id isn't defined!
*
* @return boolean * @return boolean
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId();
$text = ''; $text = '';
if ($message->getSuperGroupChatCreated()) { if ($message->getSuperGroupChatCreated()) {
...@@ -77,7 +61,6 @@ class SupergroupchatcreatedCommand extends Command ...@@ -77,7 +61,6 @@ class SupergroupchatcreatedCommand extends Command
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -47,13 +46,6 @@ class WeatherCommand extends Command ...@@ -47,13 +46,6 @@ class WeatherCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -125,19 +117,19 @@ class WeatherCommand extends Command ...@@ -125,19 +117,19 @@ class WeatherCommand extends Command
switch (strtolower($decode['weather'][0]['main'])) { switch (strtolower($decode['weather'][0]['main'])) {
case 'clear': case 'clear':
$conditions.= ' ☀'; $conditions .= ' ☀';
break; break;
case 'clouds': case 'clouds':
$conditions.= ' ☁☁'; $conditions .= ' ☁☁';
break; break;
case 'rain': case 'rain':
$conditions.= ' ☔'; $conditions .= ' ☔';
break; break;
case 'thunderstorm': case 'thunderstorm':
$conditions.= ' ☔☔☔☔'; $conditions .= ' ☔☔☔☔';
break; break;
} }
...@@ -156,7 +148,6 @@ class WeatherCommand extends Command ...@@ -156,7 +148,6 @@ class WeatherCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
...@@ -180,7 +171,6 @@ class WeatherCommand extends Command ...@@ -180,7 +171,6 @@ class WeatherCommand extends Command
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -14,7 +14,6 @@ namespace Longman\TelegramBot\Commands; ...@@ -14,7 +14,6 @@ namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\Entities\File; use Longman\TelegramBot\Entities\File;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -50,13 +49,6 @@ class WhoamiCommand extends Command ...@@ -50,13 +49,6 @@ class WhoamiCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -71,7 +63,6 @@ class WhoamiCommand extends Command ...@@ -71,7 +63,6 @@ class WhoamiCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$user_id = $message->getFrom()->getId(); $user_id = $message->getFrom()->getId();
...@@ -82,9 +73,9 @@ class WhoamiCommand extends Command ...@@ -82,9 +73,9 @@ class WhoamiCommand extends Command
//Send chat action //Send chat action
Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']); Request::sendChatAction(['chat_id' => $chat_id, 'action' => 'typing']);
$caption = 'Your Id: ' . $message->getFrom()->getId() . "\n"; $caption = 'Your Id: ' . $user_id . "\n";
$caption .= 'Name: ' . $message->getFrom()->getFirstName() $caption .= 'Name: ' . $message->getFrom()->getFirstName()
. ' ' . $message->getFrom()->getLastName() . "\n"; . ' ' . $message->getFrom()->getLastName() . "\n";
$caption .= 'Username: ' . $message->getFrom()->getUsername(); $caption .= 'Username: ' . $message->getFrom()->getUsername();
//Fetch user profile photo //Fetch user profile photo
......
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