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

Merge branch 'develop' into patch-1

parents 1e887c8f 80e7e5d5
......@@ -5,9 +5,12 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
## [Unreleased]
### Added
- Documents can be sent by providing its contents via Psr7 stream (as opposed to passing a file path).
- Allow setting a custom Guzzle HTTP Client for requests (#511).
### Changed
### Deprecated
### Removed
- [:exclamation:][unreleased-bc-up-download-directory] Upload and download directories are not set any more by default and must be set manually.
### Fixed
### Security
......@@ -24,7 +27,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Removed
- All examples have been moved to a [dedicated repository](https://github.com/php-telegram-bot/example-bot).
### Fixed
- [:exclamation:](https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#0440) Format of Update content type using `$update->getUpdateContent()`.
- [:exclamation:][0.44.0-bc-update-content-type] Format of Update content type using `$update->getUpdateContent()`.
## [0.43.0] - 2017-04-17
### Added
......@@ -99,3 +102,6 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Logging improvements to Botan integration.
### Deprecated
- Move `hideKeyboard` to `removeKeyboard`.
[unreleased-bc-up-download-directory]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased
[0.44.0-bc-update-content-type]: https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#update-getupdatecontent
......@@ -364,7 +364,7 @@ $results = Request::sendToActiveChats(
true, // Send to chats (super group chat)
true, // Send to users (single chat)
null, // 'yyyy-mm-dd hh:mm:ss' date range from
null, // 'yyyy-mm-dd hh:mm:ss' date range to
null // 'yyyy-mm-dd hh:mm:ss' date range to
);
```
......
......@@ -63,8 +63,8 @@ class DebugCommand extends AdminCommand
$debug_info = [];
$debug_info[] = sprintf('*TelegramBot version:* `%s`', $this->telegram->getVersion());
$debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath());
$debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath());
$debug_info[] = sprintf('*Download path:* `%s`', $this->telegram->getDownloadPath() ?: '`_Not set_`');
$debug_info[] = sprintf('*Upload path:* `%s`', $this->telegram->getUploadPath() ?: '`_Not set_`');
// Commands paths.
$debug_info[] = '*Commands paths:*';
......
......@@ -1105,7 +1105,7 @@ class DB
(SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :created_at_1) as LIMIT_PER_SEC_ALL,
(SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :created_at_2 AND ((`chat_id` = :chat_id_1 AND `inline_message_id` IS NULL) OR (`inline_message_id` = :inline_message_id AND `chat_id` IS NULL))) as LIMIT_PER_SEC,
(SELECT COUNT(*) FROM `' . TB_REQUEST_LIMITER . '` WHERE `created_at` >= :created_at_minute AND `chat_id` = :chat_id_2) as LIMIT_PER_MINUTE
');
');
$date = self::getTimestamp();
$date_minute = self::getTimestamp(strtotime('-1 minute'));
......
......@@ -104,16 +104,32 @@ class Request
*
* @param \Longman\TelegramBot\Telegram $telegram
*
* @throws \Longman\TelegramBot\Exception\TelegramException
* @throws TelegramException
*/
public static function initialize(Telegram $telegram)
{
if (is_object($telegram)) {
self::$telegram = $telegram;
self::$client = new Client(['base_uri' => self::$api_base_uri]);
} else {
throw new TelegramException('Telegram pointer is empty!');
if (!($telegram instanceof Telegram)) {
throw new TelegramException('Invalid Telegram pointer!');
}
self::$telegram = $telegram;
self::setClient(new Client(['base_uri' => self::$api_base_uri]));
}
/**
* Set a custom Guzzle HTTP Client object
*
* @param Client $client
*
* @throws TelegramException
*/
public static function setClient(Client $client)
{
if (!($client instanceof Client)) {
throw new TelegramException('Invalid GuzzleHttp\Client pointer!');
}
self::$client = $client;
}
/**
......@@ -201,7 +217,7 @@ class Request
//Reformat data array in multipart way if it contains a resource
foreach ($data as $key => $item) {
$has_resource |= is_resource($item);
$has_resource |= (is_resource($item) || $item instanceof \GuzzleHttp\Psr7\Stream);
$multipart[] = ['name' => $key, 'contents' => $item];
}
if ($has_resource) {
......@@ -262,8 +278,12 @@ class Request
*/
public static function downloadFile(File $file)
{
if (empty($download_path = self::$telegram->getDownloadPath())) {
throw new TelegramException('Download path not set!');
}
$tg_file_path = $file->getFilePath();
$file_path = self::$telegram->getDownloadPath() . '/' . $tg_file_path;
$file_path = $download_path . '/' . $tg_file_path;
$file_dir = dirname($file_path);
//For safety reasons, first try to create the directory, then check that it exists.
......
......@@ -161,10 +161,6 @@ class Telegram
$this->bot_username = $bot_username;
}
//Set default download and upload path
$this->setDownloadPath(BASE_PATH . '/../Download');
$this->setUploadPath(BASE_PATH . '/../Upload');
//Add default system commands path
$this->addCommandsPath(BASE_COMMANDS_PATH . '/SystemCommands');
......
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