2018-03-27 17:08:11 +02:00
|
|
|
<?php
|
|
|
|
|
2018-03-27 20:26:53 +02:00
|
|
|
ini_set('display_errors', true);
|
|
|
|
error_reporting(E_ALL);
|
|
|
|
|
2018-03-27 20:58:19 +02:00
|
|
|
chdir(__DIR__);
|
2018-03-27 20:26:53 +02:00
|
|
|
if (!file_exists(__DIR__.'/madeline.php') || !filesize(__DIR__.'/madeline.php')) {
|
|
|
|
copy('https://phar.madelineproto.xyz/madeline.php', __DIR__.'/madeline.php');
|
|
|
|
}
|
|
|
|
|
2018-03-28 16:24:25 +02:00
|
|
|
$remote = 'bruninoit/AltervistaUserBot';
|
2018-03-27 20:36:39 +02:00
|
|
|
$branch = 'master';
|
2018-03-27 20:26:53 +02:00
|
|
|
$url = "https://raw.githubusercontent.com/$remote/$branch";
|
|
|
|
|
2018-03-27 21:36:20 +02:00
|
|
|
$version = file_get_contents("$url/av.version?v=new");
|
|
|
|
if (!file_exists(__DIR__.'/av.version') || file_get_contents(__DIR__.'/av.version') !== $version) {
|
2018-03-27 20:36:39 +02:00
|
|
|
foreach (explode("\n", file_get_contents("$url/files?v=new")) as $file) {
|
2018-03-27 20:30:53 +02:00
|
|
|
if ($file) {
|
2018-03-27 20:54:56 +02:00
|
|
|
copy("$url/$file?v=new", __DIR__."/$file");
|
2018-03-27 20:30:53 +02:00
|
|
|
}
|
2018-03-27 20:26:53 +02:00
|
|
|
}
|
2018-03-27 21:36:20 +02:00
|
|
|
foreach (explode("\n", file_get_contents("$url/basefiles?v=new")) as $file) {
|
|
|
|
if ($file && !file_exists(__DIR__."/$file")) {
|
|
|
|
copy("$url/$file?v=new", __DIR__."/$file");
|
|
|
|
}
|
|
|
|
}
|
2018-03-27 20:26:53 +02:00
|
|
|
}
|
|
|
|
|
2018-03-29 20:34:24 +02:00
|
|
|
require __DIR__.'/madeline.php';
|
|
|
|
require __DIR__.'/functions.php';
|
|
|
|
require __DIR__.'/_config.php';
|
|
|
|
|
2018-03-27 22:14:22 +02:00
|
|
|
if (!file_exists('bot.lock')) {
|
|
|
|
touch('bot.lock');
|
|
|
|
}
|
|
|
|
$lock = fopen('bot.lock', 'r+');
|
|
|
|
|
|
|
|
$try = 1;
|
|
|
|
$locked = false;
|
|
|
|
while (!$locked) {
|
|
|
|
$locked = flock($lock, LOCK_EX | LOCK_NB);
|
|
|
|
if (!$locked) {
|
|
|
|
closeConnection();
|
|
|
|
|
|
|
|
if ($try++ >= 30) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 00:44:51 +02:00
|
|
|
$MadelineProto = new \danog\MadelineProto\API('session.madeline', ['logger' => ['logger_level' => 5]]);
|
2018-03-27 20:23:15 +02:00
|
|
|
$MadelineProto->start();
|
2018-03-27 17:08:11 +02:00
|
|
|
|
2018-03-27 21:53:10 +02:00
|
|
|
register_shutdown_function('shutdown_function', $lock);
|
|
|
|
closeConnection();
|
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'];
|
|
|
|
}
|
|
|
|
|
2018-03-28 00:44:51 +02:00
|
|
|
try {
|
|
|
|
$chatID = $MadelineProto->get_info($update['update']);
|
|
|
|
$type = $chatID['type'];
|
|
|
|
$chatID = $chatID['bot_api_id'];
|
2018-03-28 00:50:24 +02:00
|
|
|
} catch (Exception $e) {
|
|
|
|
}
|
2018-03-28 00:44:51 +02:00
|
|
|
|
|
|
|
if (isset($update['update']['message']['from_id'])) {
|
|
|
|
$userID = $update['update']['message']['from_id'];
|
2018-03-27 17:08:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
require '_comandi.php';
|
|
|
|
} catch (Exception $e) {
|
|
|
|
if (isset($chatID)) {
|
|
|
|
try {
|
2018-03-28 00:44:51 +02:00
|
|
|
//sm($chatID, '<code>'.$e.'</code>');
|
2018-03-27 17:08:11 +02:00
|
|
|
} 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) {
|
2018-03-28 00:44:51 +02:00
|
|
|
\danog\MadelineProto\Logger::log((string) $e);
|
2018-03-27 17:08:11 +02:00
|
|
|
if (in_array($e->rpc, ['SESSION_REVOKED', 'AUTH_KEY_UNREGISTERED'])) {
|
|
|
|
foreach (glob('session.madeline*') as $path) {
|
|
|
|
unlink($path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|