Add support for nearly all update types in get_info

This commit is contained in:
Daniil Gentili 2018-04-18 15:16:33 +00:00
parent 771e34d332
commit ff0f5d00f3
3 changed files with 50 additions and 24 deletions

28
bot.php
View File

@ -28,16 +28,6 @@ if (!file_exists(__DIR__.'/vendor/autoload.php')) {
class EventHandler extends \danog\MadelineProto\EventHandler class EventHandler extends \danog\MadelineProto\EventHandler
{ {
public function onAny($update) 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']) { if (isset($update['message']['out']) && $update['message']['out']) {
return; return;
@ -46,21 +36,13 @@ class EventHandler extends \danog\MadelineProto\EventHandler
if ($res == '') { if ($res == '') {
$res = var_export($update, true); $res = var_export($update, true);
} }
try { 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) { } 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);
try { //$this->messages->sendMessage(['peer' => '@danogentili', 'message' => $e->getCode().': '.$e->getMessage().PHP_EOL.$e->getTraceAsString()]);
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()]);
} }
} }
} }

2
docs

@ -1 +1 @@
Subproject commit 3a5b18f742fa7f2898562aa3e9d7d20a2634bf69 Subproject commit 916411226dd921657305ee7c344c870f6800f479

View File

@ -270,12 +270,56 @@ trait PeerHandler
} }
return $this->secret_chats[$id]; 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 'updateNewMessage':
case 'updateNewChannelMessage': case 'updateNewChannelMessage':
case 'updateEditMessage':
case 'updateEditChannelMessage':
case 'updateNewEncryptedMessage': case 'updateNewEncryptedMessage':
return $this->get_info($id['message']); return $this->get_info($id['message']);
case 'updateEncryption': case 'updateEncryption':
return $this->get_secret_chat($id['chat']['id']); return $this->get_secret_chat($id['chat']['id']);
case 'updateEncryptedChatTyping':
case 'updateEncryptedMessagesRead':
return $this->get_secret_chat($id['chat_id']);
case 'chatForbidden': case 'chatForbidden':
case 'channelForbidden': case 'channelForbidden':
throw new \danog\MadelineProto\RPCErrorException('CHAT_FORBIDDEN'); throw new \danog\MadelineProto\RPCErrorException('CHAT_FORBIDDEN');