Skip to content

Commit e7b6630

Browse files
committed
Update
1 parent e11bee3 commit e7b6630

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

lib/Zyberspace/Telegram/Cli/Client.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*

lib/Zyberspace/Telegram/Cli/RawClient.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,18 @@ class RawClient
4242
*
4343
* @throws ClientException Throws an exception if no connection can be established.
4444
*/
45-
public function __construct($deep = false)
45+
public function __construct($params, $deep = false)
4646
{
47+
foreach ($params as $key => $value) {
48+
$this->{$key} = $value;
49+
}
4750
$path = $deep ? "/tmp/deeptg.sck" : "/tmp/tg.sck";
4851
$remoteSocket = "unix://" . $path;
49-
$this->tgpath = $GLOBALS["homedir"] . ($deep ? "/deeptgstorage" : "/tgstorage");
52+
$this->tgpath = $this->homedir . ($deep ? "/deeptgstorage" : "/tgstorage");
53+
$this->tgcmd = "export TELEGRAM_HOME=".$this->tgpath.";".$this->homedir."/tg/bin/telegram-cli ";
5054
$this->_fp = stream_socket_client($remoteSocket);
5155
if ($this->_fp === false) {
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."&");
56+
shell_exec("pkill telegram-cli; rm ".$path.";".$this->tgcmd." --json --permanent-msg-ids -dWS ".$path."&");
5357
$this->_fp = stream_socket_client($remoteSocket);
5458
if ($this->_fp === false) {
5559
throw new ClientException('Could not connect to socket "' . $remoteSocket . '"');

0 commit comments

Comments
 (0)