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

Additional fixes and improvements (thanks to @noplanman)

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