Remove empty response method from client

parent be3f6059
...@@ -17,6 +17,7 @@ use Longman\TelegramBot\Entities\InlineQuery; ...@@ -17,6 +17,7 @@ use Longman\TelegramBot\Entities\InlineQuery;
use Longman\TelegramBot\Entities\Message; use Longman\TelegramBot\Entities\Message;
use Longman\TelegramBot\Entities\Update; use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Http\Client; use Longman\TelegramBot\Http\Client;
use Longman\TelegramBot\Http\Response;
use Longman\TelegramBot\Telegram; use Longman\TelegramBot\Telegram;
/** /**
...@@ -167,7 +168,7 @@ abstract class Command ...@@ -167,7 +168,7 @@ abstract class Command
]); ]);
} }
return Client::emptyResponse(); return new Response(['ok' => true, 'result' => true]);
} }
return $this->execute(); return $this->execute();
...@@ -404,7 +405,7 @@ abstract class Command ...@@ -404,7 +405,7 @@ abstract class Command
], $data)); ], $data));
} }
return Client::emptyResponse(); return new Response(['ok' => true, 'result' => true]);
} }
/** /**
...@@ -424,6 +425,6 @@ abstract class Command ...@@ -424,6 +425,6 @@ abstract class Command
], $data)); ], $data));
} }
return Client::emptyResponse(); return new Response(['ok' => true, 'result' => true]);
} }
} }
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Http\Client; use Longman\TelegramBot\Http\Client;
use Longman\TelegramBot\Http\Response;
abstract class SystemCommand extends Command abstract class SystemCommand extends Command
{ {
...@@ -25,6 +26,6 @@ abstract class SystemCommand extends Command ...@@ -25,6 +26,6 @@ abstract class SystemCommand extends Command
public function execute() public function execute()
{ {
//System command, return empty ServerResponse by default //System command, return empty ServerResponse by default
return Client::emptyResponse(); return new Response(['ok' => true, 'result' => true]);
} }
} }
...@@ -13,6 +13,7 @@ namespace Longman\TelegramBot\Commands\SystemCommands; ...@@ -13,6 +13,7 @@ namespace Longman\TelegramBot\Commands\SystemCommands;
use Longman\TelegramBot\Commands\SystemCommand; use Longman\TelegramBot\Commands\SystemCommand;
use Longman\TelegramBot\Conversation; use Longman\TelegramBot\Conversation;
use Longman\TelegramBot\Http\Client; use Longman\TelegramBot\Http\Client;
use Longman\TelegramBot\Http\Response;
/** /**
* Generic message command * Generic message command
...@@ -47,7 +48,7 @@ class GenericmessageCommand extends SystemCommand ...@@ -47,7 +48,7 @@ class GenericmessageCommand extends SystemCommand
public function executeNoDb() public function executeNoDb()
{ {
//Do nothing //Do nothing
return Client::emptyResponse(); return new Response(['ok' => true, 'result' => true]);
} }
/** /**
...@@ -69,6 +70,6 @@ class GenericmessageCommand extends SystemCommand ...@@ -69,6 +70,6 @@ class GenericmessageCommand extends SystemCommand
return $this->telegram->executeCommand($command); return $this->telegram->executeCommand($command);
} }
return Client::emptyResponse(); return new Response(['ok' => true, 'result' => true]);
} }
} }
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
namespace Longman\TelegramBot\Console; namespace Longman\TelegramBot\Console;
use Longman\TelegramBot\DB; use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Http\Client; use Longman\TelegramBot\Http\Client;
use Longman\TelegramBot\Http\Request; use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Response; use Longman\TelegramBot\Http\Response;
...@@ -57,18 +56,18 @@ class Kernel ...@@ -57,18 +56,18 @@ class Kernel
'ok' => false, 'ok' => false,
'description' => 'getUpdates needs MySQL connection! (This can be overridden - see documentation)', 'description' => 'getUpdates needs MySQL connection! (This can be overridden - see documentation)',
], ],
$this->bot_username $this->app->getBotUsername()
); );
} }
$offset = 0; $offset = 0;
//Take custom input into account. // Take custom input into account.
if ($custom_input = $this->app->getCustomInput()) { if ($custom_input = $this->app->getCustomInput()) {
$response = new Response(json_decode($custom_input, true), $this->app->getBotUsername()); $response = new Response(json_decode($custom_input, true), $this->app->getBotUsername());
} else { } else {
if (DB::isDbConnected()) { if (DB::isDbConnected()) {
//Get last update id from the database // Get last update id from the database
$last_update = DB::selectTelegramUpdate(1); $last_update = DB::selectTelegramUpdate(1);
$last_update = reset($last_update); $last_update = reset($last_update);
...@@ -91,14 +90,14 @@ class Kernel ...@@ -91,14 +90,14 @@ class Kernel
if ($response->isOk()) { if ($response->isOk()) {
$results = $response->getResult(); $results = $response->getResult();
//Process all updates // Process all updates
/** @var Update $result */ /** @var \Longman\TelegramBot\Entities\Update $result */
foreach ($results as $result) { foreach ($results as $result) {
$this->app->processUpdate($result); $this->app->processUpdate($result);
} }
if (! DB::isDbConnected() && ! $custom_input && $this->app->last_update_id !== null && $offset === 0) { if (! DB::isDbConnected() && ! $custom_input && $this->app->last_update_id !== null && $offset === 0) {
//Mark update(s) as read after handling // Mark update(s) as read after handling
Client::getUpdates( Client::getUpdates(
[ [
'offset' => $this->app->last_update_id + 1, 'offset' => $this->app->last_update_id + 1,
......
...@@ -625,20 +625,6 @@ class Client ...@@ -625,20 +625,6 @@ class Client
return call_user_func_array('static::send', $data); return call_user_func_array('static::send', $data);
} }
/**
* Return an empty Server Response
*
* No request to telegram are sent, this function is used in commands that
* don't need to fire a message after execution
*
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function emptyResponse()
{
return new Response(['ok' => true, 'result' => true], null);
}
/** /**
* Send message to all active chats * Send message to all active chats
* *
......
...@@ -34,7 +34,7 @@ class Response ...@@ -34,7 +34,7 @@ class Response
* *
* @throws \Longman\TelegramBot\Exception\TelegramException * @throws \Longman\TelegramBot\Exception\TelegramException
*/ */
public function __construct(array $data, $bot_username) public function __construct(array $data, $bot_username = '')
{ {
// Make sure we don't double-save the raw_data // Make sure we don't double-save the raw_data
unset($data['raw_data']); unset($data['raw_data']);
...@@ -227,4 +227,18 @@ class Response ...@@ -227,4 +227,18 @@ class Response
return $results; return $results;
} }
/**
* Return an empty Server Response
*
* No request to telegram are sent, this function is used in commands that
* don't need to fire a message after execution
*
* @return \Longman\TelegramBot\Http\Response
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public static function createEmpty()
{
return new static(['ok' => true, 'result' => true]);
}
} }
...@@ -22,6 +22,7 @@ use Longman\TelegramBot\Exception\TelegramException; ...@@ -22,6 +22,7 @@ use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Http\Client; use Longman\TelegramBot\Http\Client;
use Longman\TelegramBot\Http\Kernel; use Longman\TelegramBot\Http\Kernel;
use Longman\TelegramBot\Http\Request; use Longman\TelegramBot\Http\Request;
use Longman\TelegramBot\Http\Response;
use PDO; use PDO;
use RecursiveDirectoryIterator; use RecursiveDirectoryIterator;
use RecursiveIteratorIterator; use RecursiveIteratorIterator;
...@@ -462,7 +463,7 @@ class Telegram extends Container ...@@ -462,7 +463,7 @@ class Telegram extends Container
if ($last_id && count($last_id) === 1) { if ($last_id && count($last_id) === 1) {
TelegramLog::debug('Duplicate update received, processing aborted!'); TelegramLog::debug('Duplicate update received, processing aborted!');
return Client::emptyResponse(); return new Response(['ok' => true, 'result' => true]);
} }
DB::insertRequest($this->update); DB::insertRequest($this->update);
......
...@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\UserCommands; ...@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand; use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Http\Client; use Longman\TelegramBot\Http\Client;
use Longman\TelegramBot\Http\Response;
/** /**
* Test "/hidden" command to test $show_in_help * Test "/hidden" command to test $show_in_help
...@@ -51,6 +52,6 @@ class HiddenCommand extends UserCommand ...@@ -51,6 +52,6 @@ class HiddenCommand extends UserCommand
*/ */
public function execute() public function execute()
{ {
return Client::emptyResponse(); return new Response(['ok' => true, 'result' => true]);
} }
} }
...@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\UserCommands; ...@@ -12,6 +12,7 @@ namespace Longman\TelegramBot\Commands\UserCommands;
use Longman\TelegramBot\Commands\UserCommand; use Longman\TelegramBot\Commands\UserCommand;
use Longman\TelegramBot\Http\Client; use Longman\TelegramBot\Http\Client;
use Longman\TelegramBot\Http\Response;
/** /**
* Test "/visible" command to test $show_in_help * Test "/visible" command to test $show_in_help
...@@ -51,6 +52,6 @@ class VisibleCommand extends UserCommand ...@@ -51,6 +52,6 @@ class VisibleCommand extends UserCommand
*/ */
public function execute() public function execute()
{ {
return Client::emptyResponse(); return new Response(['ok' => true, 'result' => true]);
} }
} }
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