diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..98c3335
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+bot.lock
+madeline.phar*
+*.madeline*
+phar.php
+madeline.php
diff --git a/HttpProxy.php b/HttpProxy.php
deleted file mode 100644
index f091a05..0000000
--- a/HttpProxy.php
+++ /dev/null
@@ -1,153 +0,0 @@
-.
-*/
-
-
-class HttpProxy implements \danog\MadelineProto\Proxy
-{
- private $domain;
- private $type;
- private $protocol;
- private $extra;
- private $sock;
- public function __construct($domain, $type, $protocol) {
- if (!in_array($domain, [AF_INET, AF_INET6])) {
- throw new \danog\MadelineProto\Exception('Wrong protocol family provided');
- }
- if (!in_array($type, [SOCK_STREAM])) {
- throw new \danog\MadelineProto\Exception('Wrong connection type provided');
- }
- if (!in_array($protocol, [getprotobyname('tcp')])) {
- throw new \danog\MadelineProto\Exception('Wrong protocol provided');
- }
- $this->domain = $domain;
- $this->type = $type;
- $this->protocol = $protocol;
- }
- public function setExtra($extra) {
- $this->extra = $extra;
- $this->sock = new \Socket(strlen(@inet_pton($this->extra['address'])) !== 4 ? \AF_INET6 : \AF_INET, \SOCK_STREAM, getprotobyname('tcp'));
- }
- public function setOption($level, $name, $value) {
- return $this->sock->setOption($level, $name, $value);
- }
-
- public function getOption($level, $name) {
- return $this->sock->getOption($level, $name);
- }
-
- public function setBlocking($blocking) {
- return $this->sock->setBlocking($blocking);
- }
-
- public function bind($address, $port = 0) {
- throw new \danog\MadelineProto\Exception('Not Implemented');
- }
-
- public function listen($backlog = 0) {
- throw new \danog\MadelineProto\Exception('Not Implemented');
- }
- public function accept() {
- throw new \danog\MadelineProto\Exception('Not Implemented');
- }
-
-
- public function select(array &$read, array &$write, array &$except, $tv_sec, $tv_usec = 0) {
- throw new \danog\MadelineProto\Exception('Not Implemented');
- }
- public function connect($address, $port = 0) {
- $this->sock->connect($this->extra['address'], $this->extra['port']);
-
- try {
- if (strlen(inet_pton($address)) !== 4) {
- $address = '['.$address.']';
- }
- } catch (\danog\MadelineProto\Exception $e) {
- }
- $this->sock->write("CONNECT $address:$port HTTP/1.1\r\n\r\n");
- $response = $this->read_http_payload();
- if ($response['code'] !== 200) {
- \danog\MadelineProto\Logger::log([$response['body']]);
- throw new \danog\MadelineProto\Exception($response['description'], $response['code']);
- }
- \danog\MadelineProto\Logger::log(['Connected to '.$address.':'.$port.' via http']);
- return true;
- }
- private function http_read($length) {
- $packet = '';
- while (strlen($packet) < $length) {
- $packet .= $this->sock->read($length - strlen($packet));
- if ($packet === false || strlen($packet) === 0) {
- throw new \danog\MadelineProto\NothingInTheSocketException(\danog\MadelineProto\Lang::$current_lang['nothing_in_socket']);
- }
- }
- return $packet;
- }
- public function read_http_line()
- {
- $line = '';
- while (($curchar = $this->http_read(1)) !== "\n") {
- $line .= $curchar;
- }
-
- return rtrim($line);
- }
-
- public function read_http_payload()
- {
- $header = explode(' ', $this->read_http_line(), 3);
- $protocol = $header[0];
- $code = (int) $header[1];
- $description = $header[2];
- $headers = [];
- while (strlen($current_header = $this->read_http_line())) {
- $current_header = explode(':', $current_header, 2);
- $headers[strtolower($current_header[0])] = trim($current_header[1]);
- }
-
- $read = '';
- if (isset($headers['content-length'])) {
- $read = $this->http_read((int) $headers['content-length']);
- }/* elseif (isset($headers['transfer-encoding']) && $headers['transfer-encoding'] === 'chunked') {
- do {
- $length = hexdec($this->read_http_line());
- $read .= $this->http_read($length);
- $this->read_http_line();
- } while ($length);
- }*/
-
- return ['protocol' => $protocol, 'code' => $code, 'description' => $description, 'body' => $read, 'headers' => $headers];
- }
-
- public function read($length, $flags = 0) {
- return $this->sock->read($length, $flags);
- }
-
- public function write($buffer, $length = -1) {
- return $this->sock->write($buffer, $length);
- }
-
- public function send($data, $length, $flags) {
- throw new \danog\MadelineProto\Exception('Not Implemented');
- }
-
- public function close() {
- $this->sock->close();
- }
-
- public function getPeerName($port = true) {
- throw new \danog\MadelineProto\Exception('Not Implemented');
- }
-
- public function getSockName($port = true) {
- throw new \danog\MadelineProto\Exception('Not Implemented');
- }
-}
\ No newline at end of file
diff --git a/README.md b/README.md
index 8518ada..8c84a48 100644
--- a/README.md
+++ b/README.md
@@ -6,12 +6,9 @@ Per sapere come utilizzare questo codice, leggere la guida, oppure seguire quest
1. Creare spazio web altervista
2. Attivare cloudflare, https, s2s
-3. Caricare file in sottocartella
-4. Prendere api_id e api_hash da my.telegram.org
-5. Settare le varie cose in \_config.php
-6. Lanciare login.php e seguire le varie istruzioni (il caricamento è lento)
-7. Lanciare updates.php e chiudere la pagina al termine del caricamento (che darà probabilmente errore 502)
+3. Caricare bot.php
+4. Lanciare bot.php e seguire le varie istruzioni (il primo caricamento è lento)
-Per fare un nuovo login, usare una cartella diversa o cancellare il file check.log
+Per fare un nuovo login, usare una cartella diversa o eliminare la sessione dalle impostazioni telegram.
Per supporto entrare nel gruppo Telegram.
diff --git a/_comandi.php b/_comandi.php
index e759623..cccd0a0 100644
--- a/_comandi.php
+++ b/_comandi.php
@@ -1,61 +1,46 @@
- 5)
- {
- sm($chatID, "Mi spengo.");
- exit;
- }
-
- if(stripos($msg, "!join ")===0)
- {
- joinChat(explode(" ", $msg, 2)[1], $chatID);
- }
-
- if($msg == "!leave" && stripos($chatID, "-100")===0)
- {
- abbandonaChat($chatID);
- }
- //ALTRI COMANDI RISERVATI AGLI ADMIN
-
-
-
-
-
-
- }
-
-
- //COMANDI DESTINATI AL PUBBLICO
-
-
-
-
-
-
-}
+ 5) {
+ sm($chatID, 'Mi spengo.');
+ exit;
+ }
+
+ if (stripos($msg, '!join ') === 0) {
+ joinChat(explode(' ', $msg, 2)[1], $chatID);
+ }
+
+ if ($msg == '!leave' && stripos($chatID, '-100') === 0) {
+ abbandonaChat($chatID);
+ }
+ //ALTRI COMANDI RISERVATI AGLI ADMIN
+ }
+
+ //COMANDI DESTINATI AL PUBBLICO
+}
diff --git a/_config.php b/_config.php
index 2f285cd..ffa7da1 100644
--- a/_config.php
+++ b/_config.php
@@ -1,41 +1,9 @@
-= 30) {
+ exit;
+ }
+ sleep(1);
+ }
+}
+
+require __DIR__.'/madeline.php';
+require __DIR__.'/functions.php';
+require __DIR__.'/_config.php';
+
+$MadelineProto = new \danog\MadelineProto\API('session.madeline', ['logger' => ['logger_level' => 5]]);
+$MadelineProto->start();
+
+register_shutdown_function('shutdown_function', $lock);
+closeConnection();
+
+$running = true;
+$offset = 0;
+$started = time();
+
+try {
+ while ($running) {
+ $updates = $MadelineProto->get_updates(['offset' => $offset]);
+ foreach ($updates as $update) {
+ $offset = $update['update_id'] + 1;
+
+ if (isset($update['update']['message']['out']) && $update['update']['message']['out'] && !$leggi_messaggi_in_uscita) {
+ continue;
+ }
+ $up = $update['update']['_'];
+
+ if ($up == 'updateNewMessage' or $up == 'updateNewChannelMessage') {
+ if (isset($update['update']['message']['message'])) {
+ $msg = $update['update']['message']['message'];
+ }
+
+ try {
+ $chatID = $MadelineProto->get_info($update['update']);
+ $type = $chatID['type'];
+ $chatID = $chatID['bot_api_id'];
+ } catch (Exception $e) {
+ }
+
+ if (isset($update['update']['message']['from_id'])) {
+ $userID = $update['update']['message']['from_id'];
+ }
+
+ try {
+ require '_comandi.php';
+ } catch (Exception $e) {
+ if (isset($chatID)) {
+ try {
+ //sm($chatID, ''.$e.'
');
+ } catch (Exception $e) {
+ }
+ }
+ }
+ }
+
+ if (isset($msg)) {
+ unset($msg);
+ }
+ if (isset($chatID)) {
+ unset($chatID);
+ }
+ if (isset($userID)) {
+ unset($userID);
+ }
+ if (isset($up)) {
+ unset($up);
+ }
+ }
+ }
+} catch (\danog\MadelineProto\RPCErrorException $e) {
+ \danog\MadelineProto\Logger::log((string) $e);
+ if (in_array($e->rpc, ['SESSION_REVOKED', 'AUTH_KEY_UNREGISTERED'])) {
+ foreach (glob('session.madeline*') as $path) {
+ unlink($path);
+ }
+ }
+}
diff --git a/files b/files
new file mode 100644
index 0000000..6fc2ba2
--- /dev/null
+++ b/files
@@ -0,0 +1,4 @@
+functions.php
+bot.php
+LICENSE
+av.version
diff --git a/functions.php b/functions.php
index b9bf720..be5b93f 100644
--- a/functions.php
+++ b/functions.php
@@ -1,89 +1,72 @@
-LOGIN FALLITO";
-}
-
-function failUpdates()
-{
- echo "
'.$e.'
');
- } catch(Exception $e) { }
- }
- }
-
- }
-
-
- if(isset($msg)) unset($msg);
- if(isset($chatID)) unset($chatID);
- if(isset($userID)) unset($userID);
- if(isset($up)) unset($up);
-
-
- }
-}