Commit 4ed9660b authored by Armando Lüscher's avatar Armando Lüscher

ALL commands now return a ServerResponse object instead of a bool.

parent 4fbb6a56
...@@ -31,9 +31,7 @@ class ChatsCommand extends AdminCommand ...@@ -31,9 +31,7 @@ class ChatsCommand extends AdminCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -85,6 +83,6 @@ class ChatsCommand extends AdminCommand ...@@ -85,6 +83,6 @@ class ChatsCommand extends AdminCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -95,6 +95,6 @@ class SendtoallCommand extends AdminCommand ...@@ -95,6 +95,6 @@ class SendtoallCommand extends AdminCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -52,8 +52,7 @@ class SendtochannelCommand extends AdminCommand ...@@ -52,8 +52,7 @@ class SendtochannelCommand extends AdminCommand
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); if (Request::sendMessage($data)->isOk()) {
if ($result->isOk()) {
$text_back = 'Message sent succesfully to: ' . $your_channel; $text_back = 'Message sent succesfully to: ' . $your_channel;
} else { } else {
$text_back = 'Sorry message not sent to: ' . $your_channel; $text_back = 'Sorry message not sent to: ' . $your_channel;
...@@ -65,6 +64,6 @@ class SendtochannelCommand extends AdminCommand ...@@ -65,6 +64,6 @@ class SendtochannelCommand extends AdminCommand
'text' => $text_back, 'text' => $text_back,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -122,7 +122,7 @@ abstract class Command ...@@ -122,7 +122,7 @@ abstract class Command
/** /**
* Pre-execute command * Pre-execute command
* *
* @return mixed * @return Entities\ServerResponse
*/ */
public function preExecute() public function preExecute()
{ {
...@@ -134,13 +134,15 @@ abstract class Command ...@@ -134,13 +134,15 @@ abstract class Command
/** /**
* Execute command * Execute command
*
* @return Entities\ServerResponse
*/ */
abstract public function execute(); abstract public function execute();
/** /**
* Execution if MySQL is required but not available * Execution if MySQL is required but not available
* *
* @return boolean * @return Entities\ServerResponse
*/ */
public function executeNoDB() public function executeNoDB()
{ {
...@@ -153,7 +155,7 @@ abstract class Command ...@@ -153,7 +155,7 @@ abstract class Command
'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.', 'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.',
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Entities\ServerResponse;
/** /**
* Abstract System Command Class * Abstract System Command Class
*/ */
...@@ -18,14 +20,14 @@ abstract class SystemCommand extends Command ...@@ -18,14 +20,14 @@ abstract class SystemCommand extends Command
/** /**
* A system command just executes * A system command just executes
* *
* Although system commands should just work and return 'true', * Although system commands should just work and return a successful ServerResponse,
* each system command can override this method to add custom functionality. * each system command can override this method to add custom functionality.
* *
* @return bool * @return Entities\ServerResponse
*/ */
public function execute() public function execute()
{ {
//System command, do nothing //System command, return successful ServerResponse
return true; return new ServerResponse(['ok' => true, 'result' => true], null);
} }
} }
...@@ -26,16 +26,11 @@ class ChannelchatcreatedCommand extends SystemCommand ...@@ -26,16 +26,11 @@ class ChannelchatcreatedCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() /*public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$channel_chat_created = $message->getChannelChatCreated(); //$channel_chat_created = $message->getChannelChatCreated();
}*/
//System command, do nothing
return true;
}
} }
...@@ -26,18 +26,13 @@ class ChoseninlineresultCommand extends SystemCommand ...@@ -26,18 +26,13 @@ class ChoseninlineresultCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() /*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();
}*/
//System command, do nothing
return true;
}
} }
...@@ -26,16 +26,11 @@ class DeletechatphotoCommand extends SystemCommand ...@@ -26,16 +26,11 @@ class DeletechatphotoCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() /*public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$delete_chat_photo = $message->getDeleteChatPhoto(); //$delete_chat_photo = $message->getDeleteChatPhoto();
}*/
//System command, do nothing
return true;
}
} }
...@@ -27,9 +27,7 @@ class GenericCommand extends SystemCommand ...@@ -27,9 +27,7 @@ class GenericCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -44,6 +42,6 @@ class GenericCommand extends SystemCommand ...@@ -44,6 +42,6 @@ class GenericCommand extends SystemCommand
'text' => 'Command /' . $command . ' not found.. :(', 'text' => 'Command /' . $command . ' not found.. :(',
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -26,13 +26,10 @@ class GenericmessageCommand extends SystemCommand ...@@ -26,13 +26,10 @@ class GenericmessageCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() /*public function execute()
{ {
//System command, do nothing
return true; }*/
}
} }
...@@ -26,16 +26,11 @@ class GroupchatcreatedCommand extends SystemCommand ...@@ -26,16 +26,11 @@ class GroupchatcreatedCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() /*public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$group_chat_created = $message->getGroupChatCreated(); //$group_chat_created = $message->getGroupChatCreated();
}*/
//System command, do nothing
return true;
}
} }
...@@ -28,9 +28,7 @@ class InlinequeryCommand extends SystemCommand ...@@ -28,9 +28,7 @@ class InlinequeryCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -52,6 +50,6 @@ class InlinequeryCommand extends SystemCommand ...@@ -52,6 +50,6 @@ class InlinequeryCommand extends SystemCommand
} }
$data['results'] = '[' . implode(',', $array_article) . ']'; $data['results'] = '[' . implode(',', $array_article) . ']';
return Request::answerInlineQuery($data)->isOk(); return Request::answerInlineQuery($data);
} }
} }
...@@ -26,16 +26,11 @@ class LeftchatparticipantCommand extends SystemCommand ...@@ -26,16 +26,11 @@ class LeftchatparticipantCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() /*public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$participant = $message->getLeftChatParticipant(); //$participant = $message->getLeftChatParticipant();
}*/
//System command, do nothing
return true;
}
} }
...@@ -27,9 +27,7 @@ class NewchatparticipantCommand extends SystemCommand ...@@ -27,9 +27,7 @@ class NewchatparticipantCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -49,6 +47,6 @@ class NewchatparticipantCommand extends SystemCommand ...@@ -49,6 +47,6 @@ class NewchatparticipantCommand extends SystemCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -26,16 +26,11 @@ class NewchattitleCommand extends SystemCommand ...@@ -26,16 +26,11 @@ class NewchattitleCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() /*public function execute()
{ {
//$message = $this->getMessage(); //$message = $this->getMessage();
//$new_chat_title = $message->getNewChatTitle(); //$new_chat_title = $message->getNewChatTitle();
}*/
//System command, do nothing
return true;
}
} }
...@@ -28,9 +28,7 @@ class StartCommand extends SystemCommand ...@@ -28,9 +28,7 @@ class StartCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -44,6 +42,6 @@ class StartCommand extends SystemCommand ...@@ -44,6 +42,6 @@ class StartCommand extends SystemCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -27,9 +27,7 @@ class SupergroupchatcreatedCommand extends SystemCommand ...@@ -27,9 +27,7 @@ class SupergroupchatcreatedCommand extends SystemCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -48,6 +46,6 @@ class SupergroupchatcreatedCommand extends SystemCommand ...@@ -48,6 +46,6 @@ class SupergroupchatcreatedCommand extends SystemCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -175,9 +175,7 @@ class DateCommand extends UserCommand ...@@ -175,9 +175,7 @@ class DateCommand extends UserCommand
} }
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -204,6 +202,6 @@ class DateCommand extends UserCommand ...@@ -204,6 +202,6 @@ class DateCommand extends UserCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -28,9 +28,7 @@ class EchoCommand extends UserCommand ...@@ -28,9 +28,7 @@ class EchoCommand extends UserCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -47,6 +45,6 @@ class EchoCommand extends UserCommand ...@@ -47,6 +45,6 @@ class EchoCommand extends UserCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -28,9 +28,7 @@ class HelpCommand extends UserCommand ...@@ -28,9 +28,7 @@ class HelpCommand extends UserCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -72,6 +70,6 @@ class HelpCommand extends UserCommand ...@@ -72,6 +70,6 @@ class HelpCommand extends UserCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -28,9 +28,7 @@ class SlapCommand extends UserCommand ...@@ -28,9 +28,7 @@ class SlapCommand extends UserCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -55,6 +53,6 @@ class SlapCommand extends UserCommand ...@@ -55,6 +53,6 @@ class SlapCommand extends UserCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -110,9 +110,7 @@ class WeatherCommand extends UserCommand ...@@ -110,9 +110,7 @@ class WeatherCommand extends UserCommand
} }
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function execute()
{ {
...@@ -139,6 +137,6 @@ class WeatherCommand extends UserCommand ...@@ -139,6 +137,6 @@ class WeatherCommand extends UserCommand
'text' => $text, 'text' => $text,
]; ];
return Request::sendMessage($data)->isOk(); return Request::sendMessage($data);
} }
} }
...@@ -32,9 +32,7 @@ class WhoamiCommand extends UserCommand ...@@ -32,9 +32,7 @@ class WhoamiCommand extends UserCommand
/**#@-*/ /**#@-*/
/** /**
* Execute command * {@inheritdoc}
*
* @return boolean
*/ */
public function execute() public function 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