diff --git a/TL.php b/TL.php index c8086c8a0..63ba7a5b3 100644 Binary files a/TL.php and b/TL.php differ diff --git a/classes/libpy2php b/classes/libpy2php new file mode 120000 index 000000000..acb996604 --- /dev/null +++ b/classes/libpy2php @@ -0,0 +1 @@ +../libpy2php/ \ No newline at end of file diff --git a/classes/shell.php b/classes/shell.php index fe32863fe..d27736572 100644 --- a/classes/shell.php +++ b/classes/shell.php @@ -2,12 +2,12 @@ set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'libpy2php'); require_once ('libpy2php.php'); require_once ('os.php'); -class TelepyShell extends Cmd { +class TelepyShell { public $intro = 'Welcome to telepy interactive shell. Type help or ? for help. '; public $prompt = '>'; function preloop() { - require_once ('classes.telepy.php'); + require_once ('classes/telepy.php'); $this->_telepy = new Telepy(); } function precmd($line) { diff --git a/mtproto.php b/mtproto.php index 31fd83bb2..16ac745fd 100755 Binary files a/mtproto.php and b/mtproto.php differ diff --git a/telepy.php b/telepy.php index 04d8f4ace..9636d2ac4 100644 --- a/telepy.php +++ b/telepy.php @@ -6,13 +6,24 @@ require_once ('classes/shell.php'); -if (($__name__ == '__main__')) { - $parser = py2php_kwargs_function_call('argparse::ArgumentParser', ['telepy'], ["description" => 'Python implementation of telegram API.']); - py2php_kwargs_method_call($parser, 'add_argument', ['command'], ["nargs" => '?', "choices" => (['cmd', 'dialog_list', 'contact_list'] + array_map(function($sub) { return "chat_" . $sub; }, ['info', 'add_user', 'add_user_to_chat', 'del_user', 'set_photo', 'rename']) - ) ]); - py2php_kwargs_method_call($parser, 'add_argument', ['args'], ["nargs" => '*']); - $args = $parser->parse_args(); - if (($args->command == null)) { +if (!debug_backtrace()) { + $clidata = []; + $clidata["description"] = 'MadelineProto: PHP implementation of telegram API. Translated from telepy by Daniil Gentili.'; + $clidata['args']['commands'] = array_merge(['cmd', 'dialog_list', 'contact_list'], array_map(function($sub) { return "chat_" . $sub; }, ['info', 'add_user', 'add_user_to_chat', 'del_user', 'set_photo', 'rename'])); + $clidata['args']['flags'] = "h"; + $clidata["help"] = $clidata["description"] . PHP_EOL . PHP_EOL . "Flags: "; + foreach (str_split($clidata['args']['flags']) as $flag) { + $clidata["help"] .= "-" . $flag . ", "; + } + $clidata["help"] .= PHP_EOL . "Commands: "; + foreach ($clidata['args']['commands'] as $command) { + $clidata["help"] .= $command . ", "; + } + $clidata["help"] .= PHP_EOL; + if(isset(getopt($clidata['args']['flags'])["h"])) { + die($clidata["help"]); + } + if ($argc == 1) { $newTelePyShell = new TelepyShell(); $newTelePyShell->cmdloop(); } diff --git a/testing.php b/testing.php index 4edf589a4..491c3f17f 100644 --- a/testing.php +++ b/testing.php @@ -2,21 +2,15 @@ set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . DIRECTORY_SEPARATOR . 'libpy2php'); require_once ('libpy2php.php'); require_once ('os.php'); -try { - require_once ('configparser.php'); -} -catch(ImportError $e) { - require_once ('ConfigParser.php'); -} require_once ('mtproto.php'); -$config = $configparser->ConfigParser(); -if (!($config->read('credentials'))) { +$config = parse_ini_file('credentials', true); +if (!($config)) { pyjslib_printnl('File \'credentials\' seems to not exist.'); $exit(-1); } -$ip = $config->get('App data', 'ip_address'); -$port = $config->getint('App data', 'port'); -$Session = mtproto::Session($ip, $port); -Session::create_auth_key(); -$future_salts = py2php_kwargs_function_call('Session::method_call', ['get_future_salts'], ["num" => 3]); +$ip = $config['App data']['ip_address']; +$port = $config['App data']['port']; +$Session = new Session($ip, $port); +$Session->create_auth_key(); +$future_salts = $Session->method_call('get_future_salts', 3); pyjslib_printnl($future_salts);