From 3c30bbf39cfd98b17df7f604c92673311d7807ac Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 16 May 2017 21:08:46 +0100 Subject: [PATCH] Small fix --- bot.php | 13 +++++++------ src/danog/MadelineProto/RPCErrorException.php | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bot.php b/bot.php index f21bca4a..4083f9b8 100755 --- a/bot.php +++ b/bot.php @@ -12,24 +12,25 @@ If not, see . */ require 'vendor/autoload.php'; -$settings = []; -// $token="Uncomment and put your Token here"; +$settings = ["app_info" => ["api_id" => 6, "api_hash" => "eb06d4abfb49dc3eeb1aeb98ae0f581e"]]; + try { $MadelineProto = \danog\MadelineProto\Serialization::deserialize('bot.madeline'); } catch (\danog\MadelineProto\Exception $e) { - if (isset($token)) { + if (file_exists('token.php')) { + require_once 'token.php'; $MadelineProto = new \danog\MadelineProto\API($settings); $authorization = $MadelineProto->bot_login($token); \danog\MadelineProto\Logger::log([$authorization], \danog\MadelineProto\Logger::NOTICE); } else { - echo 'token does not exist'; + echo 'token.php does not exist'; die; } } $offset = 0; while (true) { $updates = $MadelineProto->API->get_updates(['offset' => $offset, 'limit' => 50, 'timeout' => 0]); // Just like in the bot API, you can specify an offset, a limit and a timeout - \danog\MadelineProto\Logger::log([$updates]); + //\danog\MadelineProto\Logger::log([$updates]); foreach ($updates as $update) { $offset = $update['update_id'] + 1; // Just like in the bot API, the offset must be set to the last update_id switch ($update['update']['_']) { @@ -43,7 +44,7 @@ while (true) { $res = var_export($update, true); } try { - $MadelineProto->messages->sendMessage(['peer' => $update['update']['message']['to_id'], 'message' => $res, 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]); + $MadelineProto->messages->sendMessage(['peer' => $update['update']['_'] === 'updateNewMessage' ? $update['update']['message']['from_id'] : $update['update']['message']['to_id'], 'message' => $res, 'reply_to_msg_id' => $update['update']['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]); } catch (\danog\MadelineProto\RPCErrorException $e) { $MadelineProto->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]); } diff --git a/src/danog/MadelineProto/RPCErrorException.php b/src/danog/MadelineProto/RPCErrorException.php index 1015d7cf..ea2a8586 100644 --- a/src/danog/MadelineProto/RPCErrorException.php +++ b/src/danog/MadelineProto/RPCErrorException.php @@ -22,7 +22,7 @@ class RPCErrorException extends \Exception case 'RPC_CALL_FAIL': $message = 'Telegram is having internal issues, please try again later.'; break; case 'CHANNEL_PRIVATE':$message = "You haven't joined this channel/supergroup"; break; case 'FLOOD_WAIT_666':$message = 'Spooky af m8'; break; - case 'USER_IS_BOT': + case 'USER_IS_BOT':$message = "Bots can't send messages to themselves"; break; case 'BOT_METHOD_INVALID':$message = 'This method cannot be run by a bot'; break; case 'PHONE_CODE_EXPIRED': $message = 'The phone code you provided has expired, this may happen if it was sent to any chat on telegram (if the code is sent through a telegram chat (not the official account) to avoid it append or prepend to the code some chars)'; break; case 'USERNAME_INVALID': $message = 'The provided username is not valid'; break;