Skip to content

Commit e11bee3

Browse files
committed
Adapted for deep telegram
1 parent 5862152 commit e11bee3

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/Zyberspace/Telegram/Cli/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ public function pwrsendFile($peer, $type, $path, $hash)
454454
*/
455455
$formattedPath = $this->formatFileName($path);
456456
$cmd = "send_" . $type . " " . $peer . " " . $formattedPath;
457-
$res = shell_exec($GLOBALS["homedir"] . "/tg/bin/telegram-cli --json --permanent-msg-ids -U pwrtelegram -WNRe " . escapeshellarg($cmd) . " 2>&1");
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");
458458
$newres = null;
459459
$finalres = null;
460460
foreach (explode("\n", $res) as $line) {
@@ -476,14 +476,14 @@ public function pwrsendFile($peer, $type, $path, $hash)
476476
*/
477477
public function getdFile($id, $type)
478478
{
479-
$res = shell_exec($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/}[^}]*$/}/'");
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/}[^}]*$/}/'");
480480
error_log($res);
481481
return json_decode($res);
482482
}
483483
public function getFile($user, $file_id, $type)
484484
{
485485
$script = escapeshellarg($GLOBALS["pwrhomedir"] . "/lua/download.lua");
486-
$res = shell_exec($GLOBALS["homedir"] . "/tg/bin/telegram-cli --json -WNRs " . $script . " --lua-param ".escapeshellarg($user." ".$file_id." ".$type)." 2>&1");
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");
487487
foreach(explode("\n", $res) as $line) {
488488
if(preg_match('|.*{"event":"download", "result"|', $line)) $res = preg_replace(array('|.*{"event":"download", "result"|', "|}.*|"), array('{"event":"download", "result"', "}"), $line);
489489
}

lib/Zyberspace/Telegram/Cli/RawClient.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ class RawClient
4242
*
4343
* @throws ClientException Throws an exception if no connection can be established.
4444
*/
45-
public function __construct($remoteSocket)
45+
public function __construct($deep = false)
4646
{
47+
$path = $deep ? "/tmp/deeptg.sck" : "/tmp/tg.sck";
48+
$remoteSocket = "unix://" . $path;
49+
$this->tgpath = $GLOBALS["homedir"] . ($deep ? "/deeptgstorage" : "/tgstorage");
4750
$this->_fp = stream_socket_client($remoteSocket);
4851
if ($this->_fp === false) {
49-
shell_exec("pkill telegram-cli; rm /tmp/tg.sck; " . $GLOBALS["homedir"] . "/tg/bin/telegram-cli --json --permanent-msg-ids -dWS /tmp/tg.sck&");
52+
shell_exec("pkill telegram-cli; rm ".$path."; export TELEGRAM_HOME=".$this->tgpath."; ". $GLOBALS["homedir"] . "/tg/bin/telegram-cli --json --permanent-msg-ids -dWS ".$path."&");
5053
$this->_fp = stream_socket_client($remoteSocket);
5154
if ($this->_fp === false) {
5255
throw new ClientException('Could not connect to socket "' . $remoteSocket . '"');

0 commit comments

Comments
 (0)