while (true) { // Get lastUpdate ID $fileOfAuth = $dir . "/authchats.txt"; if (is_file($fileOfAuth)) { $authDialogs = file($fileOfAuth); } else { file_put_contents($fileOfAuth, ""); $authDialogs = array(); } $photos = scandir($dir . "/new"); foreach ($photos as $p => $photo) { if ($photo != ".." && $photo != ".") { echo $photo . "\r\n"; foreach ($authDialogs as $i => $chatId) { $tg->sendChatAction($chatId, 'upload_photo'); $tg->sendPhoto($chatId, $dir . "/new/" . $photo); } unlink($dir . "/new/" . $photo); } } sleep(2); if (is_file($dir . "/stopserver")) { unlink($dir . "/stopserver"); fwrite($fLog, date("d.m.Y H:i:s") . " — Монитор остановлен по команде stopserver!\r\n"); exit; } } } else { fwrite($fLog, " Процесс уже запущен. Остановка!\r\n"); echo "Одновременно может быть запущен только один процесс."; exit;
do { // Get updates the bot has received // Offset to confirm previous updates $updates = $tg->pollUpdates($offset); if ($updates['ok'] && count($updates['result']) > 0) { foreach ($updates['result'] as $data) { if (is_null($chat_id)) { $chat_id = $data['message']['chat']['id']; } if (!$sendQuestion) { // sends an action 'typing' $tg->sendChatAction($chat_id, 'typing'); // send message with a custom reply markup $tg->sendMessage($chat_id, 'Guess the number', null, false, null, $reply_markup); $sendQuestion = true; } if ($data['message']['text'] == 5) { $tg->sendChatAction($chat_id, 'typing'); $tg->sendMessage($chat_id, 'You did it! :)'); $tg->sendChatAction($chat_id, 'upload_photo'); $tg->sendPhoto($chat_id, 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/718smiley.png/220px-718smiley.png'); $guessed = true; } else { $tg->sendMessage($chat_id, 'Wrong number :/ try again', null, false, null, $reply_markup); } } $offset = $updates['result'][count($updates['result']) - 1]['update_id'] + 1; } } while (!$guessed); $offset = $updates['result'][count($updates['result']) - 1]['update_id'] + 1; $updates = $tg->pollUpdates($offset);