<?php require '../src/Telegram.php'; $token = ''; // HERE YOUR TOKEN // You will need a file called quotes (without extension) // from there it will take the quotes and send them to your subscribers :) $tg = new telegramBot($token); $offset = 0; $response = $tg->pollUpdates($offset, 60); $response = json_decode($response, true); if ($response['ok']) { foreach ($response['result'] as $data) { $chatID = $data['message']['chat']['id']; switch ($data['message']['text']) { case '/start': addContact($chatID); break; case '/remove': deleteContact($chatID); break; } } $offset = $response['result'][count($response['result']) - 1]['update_id'] + 1; } $chats = allChats(); $quotes = readQuotes(); $i = 0; for ($i; $i < count($chats); $i++) { $tg->sendMessage($chats[$i]['chat_id'], $quotes[$chats[$i]['init']]); updateInit($chats[$i]['chat_id']);
if (is_file($fileOfUpdate)) { $updateIdFrom = intval(file_get_contents($fileOfUpdate)) + 1; } else { file_put_contents($fileOfUpdate, "0"); $updateIdFrom = 0; } $fileOfAuth = $dir . "/authchats.txt"; if (is_file($fileOfAuth)) { $authDialogs = file($fileOfAuth); } else { file_put_contents($fileOfAuth, ""); $authDialogs = array(); } // Get Updates with 30 sec Long-Poll //$updates=$bot->GetUpdates($updateIdFrom,null,60)->result; $updates = $tg->pollUpdates($updateIdFrom, 60); foreach ($updates['result'] as $data) { $updateId = $updates['result'][count($updates['result']) - 1]['update_id']; $chatId = $data['message']['chat']['id']; $message = ""; if ($data['message']['voice']) { $voice = $data['message']['voice']; } if ($data['message']['text']) { $message = $data['message']['text']; } //var_dump($data); print "\r\n"; if (in_array($chatId, $authDialogs)) { if ($message == "/reboot") { $tg->sendMessage($chatId, 'Сервер будет перезапущен в течение минуты!');
if (is_file($tbRootDir . "/stopserver")) { unlink($tbRootDir . "/stopserver"); echo "\r\nСервер остановлен по команде stopserver!"; fwrite($fLog, date("d.m.Y H:i:s") . " — Сервер остановлен по команде stopserver!\r\n"); exit; } // В обычном файле мы будем хранить ID последнего обновления $fileOfLastUpdate = $tbRootDir . "/lastUpdateId"; if (is_file($fileOfLastUpdate)) { $lastUpdateId = intval(file_get_contents($fileOfLastUpdate)) + 1; } else { file_put_contents($fileOfLastUpdate, "0"); $lastUpdateId = 0; } // Делаем long-poll запрос 60 секунд к серверу телеграм $updates = $tg->pollUpdates($lastUpdateId, 60); // Обрабатываем Updates, если они есть. foreach ($updates['result'] as $data) { $updateId = $updates['result'][count($updates['result']) - 1]['update_id']; $message = $data['message']['text']; $chatId = $data['message']['chat']['id']; // Эта команда для дебага, чтобы не перезапускать apache каждый раз, когда нужно перезапустить tbServer.php // Отправляешь боту команду /reboot и сервер останавливается. // В рабочей версии - нужно закоментить этот IF(){} if ($message == "/reboot") { $tg->sendMessage($chatId, 'Сервер будет перезапущен в течение минуты!'); file_put_contents($fileOfLastUpdate, $updateId); exit; } $db = tbDatabase(); // Проверим, авторизован ли пользователь
echo "####################################\n\n"; $tg = new telegramBot($token); $chat_id = null; $guessed = false; $sendQuestion = false; $offset = 0; echo "Get Bot Information:\n"; $updates = $tg->getMe(); echo json_encode($updates) . "\n"; // Custom keyboard $customKeyboard = [['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['0']]; $reply_markup = $tg->replyKeyboardMarkup($customKeyboard, true, true); 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! :)');