2018-03-27 17:08:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require '_config.php';
|
|
|
|
|
|
|
|
$MadelineProto = new \danog\MadelineProto\API('session.madeline');
|
2018-03-27 20:23:15 +02:00
|
|
|
$MadelineProto->start();
|
2018-03-27 17:08:11 +02:00
|
|
|
|
2018-03-27 20:23:15 +02:00
|
|
|
ob_end_clean();
|
2018-03-27 20:23:34 +02:00
|
|
|
header('Connection: close');
|
2018-03-27 20:23:15 +02:00
|
|
|
ignore_user_abort(true);
|
|
|
|
ob_start();
|
2018-03-27 20:23:34 +02:00
|
|
|
echo '<html><body><h1>OK!</h1></body</html>';
|
2018-03-27 20:23:15 +02:00
|
|
|
$size = ob_get_length();
|
|
|
|
header("Content-Length: $size");
|
2018-03-27 20:23:34 +02:00
|
|
|
header('Content-Type: text/html');
|
2018-03-27 20:23:15 +02:00
|
|
|
ob_end_flush();
|
|
|
|
flush();
|
2018-03-27 17:08:11 +02:00
|
|
|
|
|
|
|
$running = true;
|
|
|
|
$offset = 0;
|
2018-03-27 20:23:15 +02:00
|
|
|
$started = time();
|
2018-03-27 17:08:11 +02:00
|
|
|
|
|
|
|
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'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($update['update']['message']['to_id']['channel_id'])) {
|
|
|
|
$chatID = $update['update']['message']['to_id']['channel_id'];
|
|
|
|
$chatID = '-100'.$chatID;
|
|
|
|
$type = 'supergruppo';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($update['update']['message']['to_id']['chat_id'])) {
|
|
|
|
$chatID = $update['update']['message']['to_id']['chat_id'];
|
|
|
|
$chatID = '-'.$chatID;
|
|
|
|
$type = 'gruppo';
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
require '_comandi.php';
|
|
|
|
} catch (Exception $e) {
|
|
|
|
if (isset($chatID)) {
|
|
|
|
try {
|
|
|
|
sm($chatID, '<code>'.$e.'</code>');
|
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($update['update']['message']['to_id']['user_id'])) {
|
|
|
|
$chatID = $update['update']['message']['from_id'];
|
|
|
|
$type = 'privato';
|
|
|
|
}
|
|
|
|
|
|
|
|
@include '_comandi.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|