diff --git a/bot.php b/bot.php index 136ef372..f2677b68 100755 --- a/bot.php +++ b/bot.php @@ -28,16 +28,6 @@ if (!file_exists(__DIR__.'/vendor/autoload.php')) { class EventHandler extends \danog\MadelineProto\EventHandler { public function onAny($update) - { - \danog\MadelineProto\Logger::log('Received an update of type '.$update['_']); - } - - public function onUpdateNewChannelMessage($update) - { - $this->onUpdateNewMessage($update); - } - - public function onUpdateNewMessage($update) { if (isset($update['message']['out']) && $update['message']['out']) { return; @@ -46,21 +36,13 @@ class EventHandler extends \danog\MadelineProto\EventHandler if ($res == '') { $res = var_export($update, true); } - try { - $this->messages->sendMessage(['peer' => $update, 'message' => $res, 'reply_to_msg_id' => $update['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]); + $this->messages->sendMessage(['peer' => $update, 'message' => $res, 'reply_to_msg_id' => isset($update['message']['id']) ? $update['message']['id'] : null, 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]); } catch (\danog\MadelineProto\RPCErrorException $e) { - $this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]); - } - - try { - if (isset($update['message']['media']) && ($update['message']['media']['_'] == 'messageMediaPhoto' || $update['message']['media']['_'] == 'messageMediaDocument')) { - $time = microtime(true); - $file = $this->download_to_dir($update, '/tmp'); - $this->messages->sendMessage(['peer' => $update, 'message' => 'Downloaded to '.$file.' in '.(microtime(true) - $time).' seconds', 'reply_to_msg_id' => $update['message']['id'], 'entities' => [['_' => 'messageEntityPre', 'offset' => 0, 'length' => strlen($res), 'language' => 'json']]]); - } - } catch (\danog\MadelineProto\RPCErrorException $e) { - $this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]); + \danog\MadelineProto\Logger::log((string)$e, \danog\MadelineProto\Logger::FATAL_ERROR); + } catch (\danog\MadelineProto\Exception $e) { + \danog\MadelineProto\Logger::log((string)$e, \danog\MadelineProto\Logger::FATAL_ERROR); + //$this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]); } } } diff --git a/docs b/docs index 3a5b18f7..91641122 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 3a5b18f742fa7f2898562aa3e9d7d20a2634bf69 +Subproject commit 916411226dd921657305ee7c344c870f6800f479 diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index 52681b32..b3549a18 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -270,12 +270,56 @@ trait PeerHandler } return $this->secret_chats[$id]; + case 'updateChannelReadMessagesContents': + case 'updateChannelAvailableMessages': + case 'updateChannel': + case 'updateChannelWebPage': + case 'updateChannelMessageViews': + case 'updateChannelTooLong': + case 'updateReadChannelInbox': + case 'updateReadChannelOutbox': + case 'updateDeleteChannelMessages': + case 'updateChannelPinnedMessage': + return $this->get_info($this->to_supergroup($id['channel_id'])); + case 'updateChatParticipants': + $id = $id['participants']; + case 'updateChatUserTyping': + case 'updateChatParticipantAdd': + case 'updateChatParticipantDelete': + case 'updateChatParticipantAdmin': + case 'updateChatAdmins': + return $this->get_info(-$id['chat_id']); + case 'updateUserTyping': + case 'updateUserStatus': + case 'updateUserName': + case 'updateUserPhoto': + case 'updateUserPhone': + case 'updateUserBlocked': + case 'updateContactRegistered': + case 'updateContactLink': + case 'updateBotInlineQuery': + case 'updateInlineBotCallbackQuery': + case 'updateBotInlineSend': + case 'updateBotCallbackQuery': + case 'updateBotPrecheckoutQuery': + case 'updateBotShippingQuery': + return $this->get_info($id['user_id']); + case 'updatePhoneCall': + return $this->get_info($id->getOtherID()); + case 'updateReadHistoryInbox': + case 'updateReadHistoryOutbox': + return $this->get_info($id['peer']); case 'updateNewMessage': case 'updateNewChannelMessage': + case 'updateEditMessage': + case 'updateEditChannelMessage': case 'updateNewEncryptedMessage': return $this->get_info($id['message']); case 'updateEncryption': return $this->get_secret_chat($id['chat']['id']); + case 'updateEncryptedChatTyping': + case 'updateEncryptedMessagesRead': + return $this->get_secret_chat($id['chat_id']); case 'chatForbidden': case 'channelForbidden': throw new \danog\MadelineProto\RPCErrorException('CHAT_FORBIDDEN');