Unverified Commit c5a5923d authored by Armando Lüscher's avatar Armando Lüscher Committed by GitHub

Merge pull request #810 from noplanman/improve_admin_send_commands

Improve admin send commands
parents db530e2a e6aca7a3
...@@ -13,6 +13,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -13,6 +13,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Updated Travis to use Trusty containers (for HHVM) and add PHP 7.2 to the tests. - Updated Travis to use Trusty containers (for HHVM) and add PHP 7.2 to the tests.
- Add debug log entry instead of throwing an exception for duplicate updates. - Add debug log entry instead of throwing an exception for duplicate updates.
- `Telegram::handleGetUpdates()` can now work without a database connection (not enabled by default). - `Telegram::handleGetUpdates()` can now work without a database connection (not enabled by default).
- Improved `/sendtochannel` and `/sendtoall` commands, using new message helpers.
### Deprecated ### Deprecated
### Removed ### Removed
### Fixed ### Fixed
......
...@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand ...@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand
/** /**
* @var string * @var string
*/ */
protected $version = '1.4.0'; protected $version = '1.5.0';
/** /**
* @var bool * @var bool
...@@ -53,14 +53,13 @@ class SendtoallCommand extends AdminCommand ...@@ -53,14 +53,13 @@ class SendtoallCommand extends AdminCommand
*/ */
public function execute() public function execute()
{ {
$message = $this->getMessage(); $text = $this->getMessage()->getText(true);
$chat_id = $message->getChat()->getId();
$text = $message->getText(true);
if ($text === '') { if ($text === '') {
$text = 'Write the message to send: /sendtoall <message>'; return $this->replyToChat('Usage: ' . $this->getUsage());
} else { }
/** @var ServerResponse[] $results */
$results = Request::sendToActiveChats( $results = Request::sendToActiveChats(
'sendMessage', //callback function to execute (see Request.php methods) 'sendMessage', //callback function to execute (see Request.php methods)
['text' => $text], //Param to evaluate the request ['text' => $text], //Param to evaluate the request
...@@ -72,12 +71,15 @@ class SendtoallCommand extends AdminCommand ...@@ -72,12 +71,15 @@ class SendtoallCommand extends AdminCommand
] ]
); );
if (empty($results)) {
return $this->replyToChat('No users or chats found.');
}
$total = 0; $total = 0;
$failed = 0; $failed = 0;
$text = 'Message sent to:' . PHP_EOL; $text = 'Message sent to:' . PHP_EOL;
/** @var ServerResponse $result */
foreach ($results as $result) { foreach ($results as $result) {
$name = ''; $name = '';
$type = ''; $type = '';
...@@ -104,16 +106,6 @@ class SendtoallCommand extends AdminCommand ...@@ -104,16 +106,6 @@ class SendtoallCommand extends AdminCommand
} }
$text .= 'Delivered: ' . ($total - $failed) . '/' . $total . PHP_EOL; $text .= 'Delivered: ' . ($total - $failed) . '/' . $total . PHP_EOL;
if ($total === 0) { return $this->replyToChat($text);
$text = 'No users or chats found..';
}
}
$data = [
'chat_id' => $chat_id,
'text' => $text,
];
return Request::sendMessage($data);
} }
} }
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