Commit 0348c3a3 authored by Jack'lul's avatar Jack'lul

Additional fixes and improvements (thanks to @noplanman)

parent 01893846
...@@ -62,7 +62,7 @@ try { ...@@ -62,7 +62,7 @@ try {
//$telegram->setUploadPath('../Upload'); //$telegram->setUploadPath('../Upload');
// Botan.io integration // Botan.io integration
// Second argument is optional maximum timeout // Second argument are options
//$telegram->enableBotan('your_token'); //$telegram->enableBotan('your_token');
//$telegram->enableBotan('your_token', ['timeout' => 3]); //$telegram->enableBotan('your_token', ['timeout' => 3]);
......
...@@ -61,7 +61,7 @@ try { ...@@ -61,7 +61,7 @@ try {
//$telegram->setUploadPath('../Upload'); //$telegram->setUploadPath('../Upload');
// Botan.io integration // Botan.io integration
// Second argument is optional maximum timeout // Second argument are options
//$telegram->enableBotan('your_token'); //$telegram->enableBotan('your_token');
//$telegram->enableBotan('your_token', ['timeout' => 3]); //$telegram->enableBotan('your_token', ['timeout' => 3]);
......
...@@ -187,17 +187,17 @@ class Botan ...@@ -187,17 +187,17 @@ class Botan
] ]
); );
$response = (string) $response->getBody(); $result = (string) $response->getBody();
} catch (RequestException $e) { } catch (RequestException $e) {
$response = ($e->getResponse()) ? (string) $e->getResponse()->getBody() : ''; $result = $e->getMessage();
} finally { } finally {
$responseData = json_decode($response, true); $responseData = json_decode($result, true);
if ($responseData['status'] !== 'accepted') { if ($responseData['status'] !== 'accepted') {
if (!empty($response)) { if (!empty($result)) {
TelegramLog::debug("Botan.io stats report failed, API reply: $response"); TelegramLog::debug("Botan.io stats report failed: $result\n\n");
} else { } else {
TelegramLog::debug("Botan.io stats report failed, API returned empty response!"); TelegramLog::debug("Botan.io stats report failed: empty response!\n\n");
} }
return false; return false;
...@@ -239,18 +239,18 @@ class Botan ...@@ -239,18 +239,18 @@ class Botan
) )
); );
$response = (string) $response->getBody(); $result = (string) $response->getBody();
} catch (RequestException $e) { } catch (RequestException $e) {
$response = ($e->getResponse()) ? (string) $e->getResponse()->getBody() : ''; $result = $e->getMessage();
} finally { } finally {
if (filter_var($response, FILTER_VALIDATE_URL) !== false) { if (filter_var($result, FILTER_VALIDATE_URL) !== false) {
BotanDB::insertShortUrl($user_id, $url, $response); BotanDB::insertShortUrl($user_id, $url, $result);
return $response; return $result;
} else { } else {
if (!empty($response)) { if (!empty($result)) {
TelegramLog::debug("Botan.io URL shortening failed for '$url', API reply: $response"); TelegramLog::debug("Botan.io URL shortening failed for '$url': $result\n\n");
} else { } else {
TelegramLog::debug("Botan.io URL shortening failed for '$url', API returned empty response!"); TelegramLog::debug("Botan.io URL shortening failed for '$url': empty response!\n\n");
} }
return $url; return $url;
......
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