From a84c36b60fb43be416a73902d2be597eba727540 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 19 May 2017 17:26:35 +0100 Subject: [PATCH 1/6] Fixes --- a.php | 14 -------------- bot.php | 2 ++ src/danog/MadelineProto/DataCenter.php | 2 +- src/danog/MadelineProto/MTProto.php | 12 ++++++++++-- 4 files changed, 13 insertions(+), 17 deletions(-) delete mode 100644 a.php diff --git a/a.php b/a.php deleted file mode 100644 index 250f7f30..00000000 --- a/a.php +++ /dev/null @@ -1,14 +0,0 @@ -a = 'le'; - } -} -$a = new a(); - -var_dump($a); diff --git a/bot.php b/bot.php index 69822978..8f15386a 100755 --- a/bot.php +++ b/bot.php @@ -27,6 +27,8 @@ try { die; } } +var_dump($MadelineProto->rle_decode($MadelineProto->base64url_decode('gRuWfE2EXVJtaecDLpxYs39tElkZtzLo2mwsdmkuRbZQLO6ofKSoTHedbY1N9lAeUfvgE8wqHIF1VJ95YIyCCLswdZlmf-RWdph_C8wcUeSxtNCTE1gdbmiZp77uIT77bDbUHHbNyfgsKwY30aZS91snXwIrOulsGGA_j7VQ0k9TzGO9AczSj0LZt6kVpPpXKqSraHopH59Tpv4UCX3qXPa5XbcyodpOIL_VN5TtpfEUxoF5asavCOgNj6V4KInLDjkpLr-8dgViLUGRZagxr0EFHUs7DT9dW66_A4_qnszPlIw6GHOIlhLxV8emke0JV_hvATN11uT_RlnHNY83vQ'))); + $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 diff --git a/src/danog/MadelineProto/DataCenter.php b/src/danog/MadelineProto/DataCenter.php index e867662c..9ca108b7 100644 --- a/src/danog/MadelineProto/DataCenter.php +++ b/src/danog/MadelineProto/DataCenter.php @@ -60,7 +60,7 @@ class DataCenter extends \Volatile $test = $this->settings[$dc_config_number]['test_mode'] ? 'test' : 'main'; $ipv6 = $this->settings[$dc_config_number]['ipv6'] ? 'ipv6' : 'ipv4'; $address = $this->dclist[$test][$ipv6][$dc_number]['ip_address']; - $address = $this->settings[$dc_config_number]['ipv6'] ? '['.$address.']' : $address; + //$address = $this->settings[$dc_config_number]['ipv6'] ? '['.$address.']' : $address; $port = $this->dclist[$test][$ipv6][$dc_number]['port']; if ($this->settings[$dc_config_number]['protocol'] === 'https') { $subdomain = $this->dclist['ssl_subdomains'][$dc_number]; diff --git a/src/danog/MadelineProto/MTProto.php b/src/danog/MadelineProto/MTProto.php index 71f3c172..512435ee 100644 --- a/src/danog/MadelineProto/MTProto.php +++ b/src/danog/MadelineProto/MTProto.php @@ -99,6 +99,14 @@ class MTProto extends \Volatile private $dialog_params = ['limit' => 0, 'offset_date' => 0, 'offset_id' => 0, 'offset_peer' => ['_' => 'inputPeerEmpty']]; public $storage = []; + private $zero; + private $one; + private $two; + private $three; + private $four; + private $twoe1984; + private $twoe2047; + private $twoe2048; public function ___construct($settings = []) { @@ -161,7 +169,7 @@ class MTProto extends \Volatile public function __sleep() { - return ['encrypted_layer', 'settings', 'config', 'ipv6', 'should_serialize', 'authorization', 'authorized', 'login_temp_status', 'bigint', 'run_workers', 'threads', 'rsa_keys', 'last_recv', 'dh_config', 'chats', 'last_stored', 'qres', 'pending_updates', 'bad_msg_error_codes', 'msgs_info_flags', 'stop', 'updates_state', 'got_state', 'channels_state', 'updates', 'updates_key', 'getting_state', 'full_chats', 'msg_ids', 'dialog_params', 'storage', 'datacenter']; + return ['encrypted_layer', 'settings', 'config', 'ipv6', 'should_serialize', 'authorization', 'authorized', 'login_temp_status', 'bigint', 'run_workers', 'threads', 'rsa_keys', 'last_recv', 'dh_config', 'chats', 'last_stored', 'qres', 'pending_updates', 'bad_msg_error_codes', 'msgs_info_flags', 'stop', 'updates_state', 'got_state', 'channels_state', 'updates', 'updates_key', 'getting_state', 'full_chats', 'msg_ids', 'dialog_params', 'storage', 'datacenter', 'v', 'constructors', 'td_constructors', 'methods', 'td_methods', 'td_descriptions', 'twoe1984', 'twoe2047', 'twoe2048', 'zero', 'one', 'two', 'three', 'four']; } public function __wakeup() @@ -605,7 +613,7 @@ class MTProto extends \Volatile public function getV() { - return 32; + return 34; } public function get_self() From 3ade40944271b5145ce5a6dd1a79af015a5123f2 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 19 May 2017 21:34:33 +0200 Subject: [PATCH 2/6] hotfix --- src/Worker.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Worker.php b/src/Worker.php index 8b58e5f9..b39f793a 100644 --- a/src/Worker.php +++ b/src/Worker.php @@ -64,6 +64,9 @@ if (!extension_loaded('pthreads')) { private function runCollectable($idx, Collectable $collectable) { $collectable->worker = $this; + if (!isset($collectable->state)) { + $collectable->state = 0; + } $collectable->state |= THREAD::RUNNING; $collectable->run(); $collectable->state &= ~THREAD::RUNNING; From baaf08af80acdf323c8e85099468a3ab6a7fba55 Mon Sep 17 00:00:00 2001 From: Hunter Ashton Date: Fri, 19 May 2017 14:34:57 -0500 Subject: [PATCH 3/6] Add an HTML parser for buttons! (#123) --- .../MadelineProto/TL/Conversion/BotAPI.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/danog/MadelineProto/TL/Conversion/BotAPI.php b/src/danog/MadelineProto/TL/Conversion/BotAPI.php index 4c0d9f76..3e0d0176 100644 --- a/src/danog/MadelineProto/TL/Conversion/BotAPI.php +++ b/src/danog/MadelineProto/TL/Conversion/BotAPI.php @@ -407,6 +407,17 @@ trait BotAPI $href = $node->getAttribute('href'); if (preg_match('|mention:|', $href)) { $entities[] = ['_' => 'inputMessageEntityMentionName', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text), 'user_id' => $this->get_info(str_replace('mention:', '', $href))['InputUser']]; + } elseif (preg_match('|buttonurl:|', $href)) { + if (!isset($entities['buttons'])) { + $entities['buttons'] = []; + } + if (preg_match('|:new|', substr($href, -4))) { + $entities['buttons'][] = ['_' => 'keyboardButtonUrl', 'text' => $text, 'url' => str_replace('buttonurl:', '', str_replace(':new', '', $href)), 'new' => true]; + } else { + var_dump(true); + $entities['buttons'][] = ['_' => 'keyboardButtonUrl', 'text' => $text, 'url' => str_replace('buttonurl:', '', $href)]; + } + break; } else { $entities[] = ['_' => 'messageEntityTextUrl', 'offset' => mb_strlen($nmessage), 'length' => mb_strlen($text), 'url' => $href]; } @@ -440,6 +451,10 @@ trait BotAPI foreach ($dom->getElementsByTagName('body')->item(0)->childNodes as $node) { $this->parse_node($node, $arguments['entities'], $nmessage); } + if (isset($arguments['entities']['buttons'])) { + $arguments['reply_markup'] = $this->build_rows($arguments['entities']['buttons']); + unset($arguments['entities']['buttons']); + } unset($arguments['parse_mode']); } catch (\DOMException $e) { } catch (\danog\MadelineProto\Exception $e) { @@ -513,4 +528,33 @@ trait BotAPI return htmlentities($text); } } + + public function build_rows($button_list) + { + $end = false; + $rows = []; + $buttons = []; + $cols = 0; + foreach ($button_list as $button) { + if (isset($button['new'])) { + if (count($buttons) == 0) { + $buttons[] = $button; + } else { + $row = ['_' => 'keyboardButtonRow', 'buttons' => $buttons]; + $rows[] = $row; + $buttons = [$button]; + } + } else { + $buttons[] = $button; + $end = true; + } + } + + if ($end) { + $row = ['_' => 'keyboardButtonRow', 'buttons' => $buttons]; + $rows[] = $row; + } + + return ['_' => 'replyInlineMarkup', 'rows' => $rows]; + } } From f4155bc3a7952640ba0d6ac0b0572172c0288cbf Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 19 May 2017 19:35:03 +0000 Subject: [PATCH 4/6] Apply fixes from StyleCI --- .../MadelineProto/TL/Conversion/BotAPI.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/danog/MadelineProto/TL/Conversion/BotAPI.php b/src/danog/MadelineProto/TL/Conversion/BotAPI.php index 3e0d0176..0ceee759 100644 --- a/src/danog/MadelineProto/TL/Conversion/BotAPI.php +++ b/src/danog/MadelineProto/TL/Conversion/BotAPI.php @@ -536,15 +536,15 @@ trait BotAPI $buttons = []; $cols = 0; foreach ($button_list as $button) { - if (isset($button['new'])) { - if (count($buttons) == 0) { - $buttons[] = $button; - } else { - $row = ['_' => 'keyboardButtonRow', 'buttons' => $buttons]; - $rows[] = $row; - $buttons = [$button]; - } - } else { + if (isset($button['new'])) { + if (count($buttons) == 0) { + $buttons[] = $button; + } else { + $row = ['_' => 'keyboardButtonRow', 'buttons' => $buttons]; + $rows[] = $row; + $buttons = [$button]; + } + } else { $buttons[] = $button; $end = true; } From 1f18cf6ab9c55e5c92fdf1df8a98fc18a89fb2da Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 20 May 2017 14:46:05 +0100 Subject: [PATCH 5/6] Bugfix --- bots/pipesbot.php | 7 +++++-- src/danog/MadelineProto/TL/Conversion/BotAPI.php | 10 +++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/bots/pipesbot.php b/bots/pipesbot.php index 237c7e19..2c3e0a48 100755 --- a/bots/pipesbot.php +++ b/bots/pipesbot.php @@ -18,12 +18,12 @@ $uMadelineProto = false; try { $MadelineProto = \danog\MadelineProto\Serialization::deserialize('pipesbot.madeline'); } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log([$e->getMessage()]); + var_dump($e->getMessage()); } try { $uMadelineProto = \danog\MadelineProto\Serialization::deserialize('pwr.madeline'); } catch (\danog\MadelineProto\Exception $e) { - \danog\MadelineProto\Logger::log([$e->getMessage()]); + var_dump($e->getMessage()); } if (file_exists('token.php') && $MadelineProto === false) { include_once 'token.php'; @@ -108,6 +108,7 @@ 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 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 + try { switch ($update['update']['_']) { case 'updateNewMessage': if (isset($update['update']['message']['out']) && $update['update']['message']['out']) { @@ -217,6 +218,8 @@ while (true) { } } } + } catch (\danog\MadelineProto\RPCErrorException $e) {} + } \danog\MadelineProto\Serialization::serialize('pipesbot.madeline', $MadelineProto); \danog\MadelineProto\Serialization::serialize('pwr.madeline', $uMadelineProto); diff --git a/src/danog/MadelineProto/TL/Conversion/BotAPI.php b/src/danog/MadelineProto/TL/Conversion/BotAPI.php index 0ceee759..3da9ca38 100644 --- a/src/danog/MadelineProto/TL/Conversion/BotAPI.php +++ b/src/danog/MadelineProto/TL/Conversion/BotAPI.php @@ -414,7 +414,6 @@ trait BotAPI if (preg_match('|:new|', substr($href, -4))) { $entities['buttons'][] = ['_' => 'keyboardButtonUrl', 'text' => $text, 'url' => str_replace('buttonurl:', '', str_replace(':new', '', $href)), 'new' => true]; } else { - var_dump(true); $entities['buttons'][] = ['_' => 'keyboardButtonUrl', 'text' => $text, 'url' => str_replace('buttonurl:', '', $href)]; } break; @@ -468,7 +467,12 @@ trait BotAPI public function split_to_chunks($text) { $total_length = 4096; - $text_arr = $this->multipleExplodeKeepDelimiters(["\n"], $text); + $text_arr = []; + foreach ($this->multipleExplodeKeepDelimiters(["\n"], $text) as $word) { + if (strlen($word) > 4096) { + foreach (str_split($word, 4096) as $vv) { $text_arr []= $vv; } + } else $text_arr []= $word; + } $i = 0; $message[0] = ''; foreach ($text_arr as $word) { @@ -497,7 +501,7 @@ trait BotAPI $finalArray = []; foreach ($initialArray as $item) { if (strlen($item) > 0) { - array_push($finalArray, $item.$string[strpos($string, $item) + strlen($item)]); + $finalArray []= $item.$string[strpos($string, $item)+strlen($item)]; } } From 5eddc101dc2d0822ec9f62c35ae9befd19f2534b Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 20 May 2017 13:46:46 +0000 Subject: [PATCH 6/6] Apply fixes from StyleCI --- bots/pipesbot.php | 6 +++--- src/danog/MadelineProto/TL/Conversion/BotAPI.php | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bots/pipesbot.php b/bots/pipesbot.php index 2c3e0a48..fa278c80 100755 --- a/bots/pipesbot.php +++ b/bots/pipesbot.php @@ -109,7 +109,7 @@ while (true) { 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 try { - switch ($update['update']['_']) { + switch ($update['update']['_']) { case 'updateNewMessage': if (isset($update['update']['message']['out']) && $update['update']['message']['out']) { continue; @@ -218,8 +218,8 @@ while (true) { } } } - } catch (\danog\MadelineProto\RPCErrorException $e) {} - + } catch (\danog\MadelineProto\RPCErrorException $e) { + } } \danog\MadelineProto\Serialization::serialize('pipesbot.madeline', $MadelineProto); \danog\MadelineProto\Serialization::serialize('pwr.madeline', $uMadelineProto); diff --git a/src/danog/MadelineProto/TL/Conversion/BotAPI.php b/src/danog/MadelineProto/TL/Conversion/BotAPI.php index 3da9ca38..f883e526 100644 --- a/src/danog/MadelineProto/TL/Conversion/BotAPI.php +++ b/src/danog/MadelineProto/TL/Conversion/BotAPI.php @@ -470,8 +470,12 @@ trait BotAPI $text_arr = []; foreach ($this->multipleExplodeKeepDelimiters(["\n"], $text) as $word) { if (strlen($word) > 4096) { - foreach (str_split($word, 4096) as $vv) { $text_arr []= $vv; } - } else $text_arr []= $word; + foreach (str_split($word, 4096) as $vv) { + $text_arr[] = $vv; + } + } else { + $text_arr[] = $word; + } } $i = 0; $message[0] = ''; @@ -501,7 +505,7 @@ trait BotAPI $finalArray = []; foreach ($initialArray as $item) { if (strlen($item) > 0) { - $finalArray []= $item.$string[strpos($string, $item)+strlen($item)]; + $finalArray[] = $item.$string[strpos($string, $item) + strlen($item)]; } }