Created
February 6, 2025 12:47
-
-
Save JamshidbekAkhlidinov/304d96eddf43751c5de23db7a714dd6b to your computer and use it in GitHub Desktop.
User Bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if (!file_exists('madeline.php')) { | |
| copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php'); | |
| } | |
| include 'madeline.php'; | |
| $MadelineProto = new \danog\MadelineProto\API('session.madeline'); | |
| $MadelineProto->start(); | |
| // Foydalanuvchiga doimiy online holatda bo‘lishini ta'minlash | |
| $MadelineProto->account->updateStatus(['offline' => false]); | |
| // Saqlash uchun fayl | |
| $processed_updates_file = 'processed_updates.txt'; | |
| // Agar fayl mavjud bo'lmasa, uni yaratish | |
| if (!file_exists($processed_updates_file)) { | |
| file_put_contents($processed_updates_file, ''); | |
| } | |
| // Yangilanishlarni olish | |
| $updates = $MadelineProto->getUpdates(); | |
| // Qabul qilingan yangilanishlarni faylga o'qish | |
| $processed_updates = explode("\n", file_get_contents($processed_updates_file)); | |
| foreach ($updates as $update) { | |
| if (isset($update['update']) && isset($update['update']['message'])) { | |
| $message = $update['update']['message']; | |
| // Foydalanuvchi tomonidan yuborilgan xabar | |
| $fromId = $message['from_id']; | |
| $peerId = $message['peer_id']; | |
| // Faqat shaxsiy xabarlarga javob berish | |
| if ($peerId < 0) { | |
| // Agar bu guruh yoki kanal bo'lsa, javob bermaymiz | |
| continue; | |
| } | |
| // Xabar ID sini olish | |
| $update_id = $update['update_id']; | |
| // Agar bu xabar ilgari ko‘rilgan bo‘lsa, unga javob bermaymiz | |
| if (in_array($update_id, $processed_updates)) { | |
| continue; | |
| } | |
| $text = strtolower(trim($message['message'])); // Matnni kichik harfga o‘tkazish va bo‘sh joylarni olib tashlash | |
| // Typing xabarini yuborish | |
| $MadelineProto->messages->setTyping([ | |
| 'peer' => $fromId, | |
| 'action' => ['_' => 'sendMessageTypingAction'] | |
| ]); | |
| // Javob berish uchun shartlar | |
| $responses = [ | |
| "salom" => "Assalomu alaykum! ", | |
| "qale" => "Rahmat, yaxshi. O'zingiz qandaysiz?", | |
| "qalesiz" => "Rahmat, yaxshi. O'zingiz qandaysiz?", | |
| "soat nechi bo'ldi?" => "Hozir soat: " . date('H:i'), | |
| "bugun kun nima edi?" => "Bugun " . date('l'), | |
| "usta" => "Ha, men shu yerdaman! Qanday yordam bera olaman?", | |
| "soat" => "Hozir soat: " . date('H:i'), | |
| "kun nima edi?" => "Bugun " . date('l') . ".", | |
| "yaxshi" => "OK ", | |
| "yaxshi emas" => "Nega unday?", | |
| "xush kelibsiz" => "Raxmat kottakom. Sizga ham hush bo'lsin", | |
| "yordam kerak" => "Albatta, qanday yordam bera olaman", | |
| "ismiz nima?" => "Mening ismim ChatBot. Sizni qanday atashimni xohlaysiz?", | |
| "yosh" => "Men yosh emasman, faqat algoritmman!", | |
| "qayerdasiz?" => "Men shu yerda, faqat virtualman.", | |
| "ishlaringiz qanday?" => "Hozirda ishlayapman, yordam kerakmi?", | |
| "bu nima?" => "Bu bot, siz bilan suhbatlashish uchun tayyor.", | |
| "salom, bot" => "Salom! Sizga qanday yordam bera olishim mumkin?", | |
| "salom bot" => "Salom! Sizga qanday yordam bera olishim mumkin?", | |
| "bot" => "Salom! Sizga qanday yordam bera olishim mumkin?", | |
| ]; | |
| // Yangi xabarni javoblash | |
| if (isset($responses[$text])) { | |
| $MadelineProto->messages->sendMessage([ | |
| 'peer' => $fromId, | |
| 'message' => $responses[$text] | |
| ]); | |
| } | |
| // Yangilanishni saqlash (qaysi xabar ko‘rildi) | |
| file_put_contents($processed_updates_file, $update_id . "\n", FILE_APPEND); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment