@@ -84,7 +84,6 @@ public function msg($peer, $msg)
8484 public function replymsg ($ id , $ msg )
8585 {
8686 $ msg = $ this ->escapeStringArgument ($ msg );
87-
8887 return $ this ->exec ('reply ' . $ id . ' ' . $ msg );
8988 }
9089 /**
@@ -454,14 +453,14 @@ public function pwrsendFile($peer, $type, $path, $hash)
454453*/
455454 $ formattedPath = $ this ->formatFileName ($ path );
456455 $ cmd = "send_ " . $ type . " " . $ peer . " " . $ formattedPath ;
457- $ res = shell_exec (" export TELEGRAM_HOME= " . $ this ->tgpath . " ; " . $ GLOBALS [ " homedir " ] . " /tg/bin/telegram-cli --json --permanent-msg-ids -U pwrtelegram -WNRe " . escapeshellarg ($ cmd ) . " 2>&1 " );
456+ $ res = shell_exec ($ this ->tgcmd . " --json --permanent-msg-ids -U pwrtelegram -WNRe " . escapeshellarg ($ cmd ) . " 2>&1 " );
458457 $ newres = null ;
459458 $ finalres = null ;
460459 foreach (explode ("\n" , $ res ) as $ line ) {
461460 if (preg_match ('|^{| ' , $ line ) && !preg_match ('|{"result": "SUCCESS"}| ' , $ line )) $ newres = json_decode (preg_replace (array ('|^[^{]*{| ' , "|}[^}]*$| " ), array ("{ " , "} " ), $ line ), true ); else continue ;
462- if (isset ($ newres ["out " ]) && $ newres ["out " ] && isset ($ newres ["media " ]["type " ]) && $ newres ["media " ]["type " ] == $ type && isset ($ newres ["from " ]["peer_id " ]) && $ newres ["from " ]["peer_id " ] == $ GLOBALS [ " botusername " ] ) $ finalres = $ newres ;
461+ if (isset ($ newres ["out " ]) && $ newres ["out " ] && isset ($ newres ["media " ]["type " ]) && $ newres ["media " ]["type " ] == $ type && isset ($ newres ["from " ]["peer_id " ]) && $ newres ["from " ]["peer_id " ] == $ this -> botusername ) $ finalres = $ newres ;
463462 }
464- return $ newres ;
463+ return $ finalres ;
465464 }
466465
467466 /**
@@ -474,28 +473,16 @@ public function pwrsendFile($peer, $type, $path, $hash)
474473 * @uses exec()
475474 * @uses escapePeer()
476475 */
477- public function getdFile ($ id , $ type )
478- {
479- $ res = shell_exec ("export TELEGRAM_HOME= " .$ this ->tgpath ."; " .$ GLOBALS ["homedir " ] . "/tg/bin/telegram-cli --json --permanent-msg-ids -WNRe 'load_file $ id' 2>&1 | sed 's/[>]//g;/{/!d;/{ \"event \": \"download \"/!d;/^\s*$/d;s/^[^{]*{/{/;s/}[^}]*$/}/' " );
480- error_log ($ res );
481- return json_decode ($ res );
482- }
483476 public function getFile ($ user , $ file_id , $ type )
484477 {
485- $ script = escapeshellarg ($ GLOBALS [ " pwrhomedir " ] . "/lua/download.lua " );
486- $ res = shell_exec (" export TELEGRAM_HOME= " . $ this ->tgpath . " ; " . $ GLOBALS [ " homedir " ] . " /tg/bin/telegram-cli --json -WNRs " . $ script . " --lua-param " .escapeshellarg ($ user ." " .$ file_id ." " .$ type )." 2>&1 " );
478+ $ script = escapeshellarg ($ this -> pwrhomedir . "/lua/download.lua " );
479+ $ res = shell_exec ($ this ->tgcmd . " --json -WNRs " . $ script . " --lua-param " .escapeshellarg ($ user ." " .$ file_id ." " .$ type )." 2>&1 " );
487480 foreach (explode ("\n" , $ res ) as $ line ) {
488481 if (preg_match ('|.*{"event":"download", "result"| ' , $ line )) $ res = preg_replace (array ('|.*{"event":"download", "result"| ' , "|}.*| " ), array ('{"event":"download", "result" ' , "} " ), $ line );
489482 }
490483 return json_decode ($ res );
491484 }
492485
493- public function oldgetFile ($ user , $ id , $ type )
494- {
495-
496- return $ this ->exec ('load_ ' . $ type . ' ' . $ id );
497- }
498-
499486 /**
500487 * Get info about current user
501488 *
0 commit comments