Spaces:
Runtime error
Runtime error
Download bot.py from shadowtext/README: direct link, hf CLI and curl.
- Browser
- Download file 4.37 kB
-
https://huggingface.co/spaces/shadowtext/README/resolve/main/bot.py
- Command line
-
hf download hf://spaces/shadowtext/README/bot.py
-
curl -L -o bot.py https://huggingface.co/spaces/shadowtext/README/resolve/main/bot.py
4.37 kB
| import uuid | |
| from aiogram import Bot, Dispatcher, types, F | |
| from aiogram.types import ( | |
| InlineQuery, | |
| InlineQueryResultArticle, | |
| InputTextMessageContent, | |
| InlineKeyboardMarkup, | |
| InlineKeyboardButton, | |
| CallbackQuery | |
| ) | |
| from aiogram.client.session.aiohttp import AiohttpSession | |
| import asyncio | |
| # 🤖 Aktiv tokeningiz | |
| BOT_TOKEN = "8985882342:AAEu4YPcjV-roqGNOm0Hqkx-5A6XDxGOD9Q" | |
| # Sessiyani qo'shimcha murakkab obyektlarsiz, oddiy va toza holatda yaratamiz | |
| session = AiohttpSession() | |
| bot = Bot(token=BOT_TOKEN, session=session) | |
| dp = Dispatcher() | |
| # 📦 Xabarlarni vaqtinchalik saqlash bazasi | |
| messages_db = {} | |
| # 1. Lichkada /start bosilganda ko'rsatma | |
| async def start_cmd(message: types.Message): | |
| await message.answer( | |
| "⚡ <b>ShadowText Botiga xush kelibsiz!</b>\n\n" | |
| "Guruhlarda kimdir uchun maxfiy, anonim xabarlar qoldiring.\n\n" | |
| "<b>Ishlatish tartibi:</b>\n" | |
| "Istalgan chatda quyidagicha yozing:\n" | |
| "<code>@ShdwTextBot @username maxfiy xabar matni</code>\n\n" | |
| "<i>Misol: @ShdwTextBot @ali_88 Salom, guruhdagilar ko'rmasin...</i>", | |
| parse_mode="HTML" | |
| ) | |
| # 2. INLINE REJIM: Guruhda @ShdwTextBot @username xabar yozilganda | |
| async def inline_handler(query: InlineQuery): | |
| query_text = query.query.strip() | |
| # Kamida username va matn bo'lishi kerak | |
| parts = query_text.split(maxsplit=1) | |
| if len(parts) < 2: | |
| return | |
| target_username = parts[0].replace("@", "").lower() | |
| secret_text = parts[1] | |
| # Unikal ID yaratish | |
| msg_id = str(uuid.uuid4())[:8] | |
| # Ma'lumotlarni bazaga saqlash | |
| messages_db[msg_id] = { | |
| "target": target_username, | |
| "text": secret_text | |
| } | |
| # CALLBACK_DATA (Guruhda qolish uchun) | |
| keyboard = InlineKeyboardMarkup(inline_keyboard=[ | |
| [ | |
| InlineKeyboardButton( | |
| text=f"🔒 Faqat @{target_username} uchun", | |
| callback_data=f"open_{msg_id}" | |
| ) | |
| ] | |
| ]) | |
| results = [ | |
| InlineQueryResultArticle( | |
| id=msg_id, | |
| title=f"🔒 @{target_username} uchun maxfiy xabar", | |
| description=f"Xabar: {secret_text[:25]}...", | |
| input_message_content=InputTextMessageContent( | |
| message_text=f"<b>🕵️♂️ Guruhda kimdir @{target_username} uchun yashirin xabar qoldirdi!</b>\n" | |
| f"<i>Uni faqat o‘z egasi quyidagi tugmani bosib, guruhdan chiqmasdan o‘qiy oladi.</i>", | |
| parse_mode="HTML" | |
| ), | |
| reply_markup=keyboard | |
| ) | |
| ] | |
| await query.answer(results, cache_time=0) | |
| # 3. GURUHDA TUGMA BOSILGANDA (CALLBACK QUERY HANDLER) | |
| async def open_secret_msg(callback: CallbackQuery): | |
| msg_id = callback.data.split("open_")[1] | |
| data = messages_db.get(msg_id) | |
| if not data: | |
| await callback.answer(text="❌ Kechirasiz, bu xabar muddati eskirgan yoki o‘chirilgan!", show_alert=True) | |
| return | |
| user_username = callback.from_user.username | |
| # Agar foydalanuvchining usernamesi bo'lmasa | |
| if not user_username: | |
| await callback.answer( | |
| text="❌ Xabarni o‘qish uchun profilingizda username (@...) sozlangan bo‘lishi kerak!", | |
| show_alert=True | |
| ) | |
| return | |
| # Foydalanuvchi usernamesini solishtiramiz | |
| if user_username.lower() == data["target"]: | |
| await callback.answer( | |
| text=f"🔒 Sizga kelgan maxfiy xabar:\n\n{data['text']}", | |
| show_alert=True | |
| ) | |
| else: | |
| await callback.answer( | |
| text=f"❌ Bu xabar siz uchun emas!\nU faqat @{data['target']} uchun yuborilgan.", | |
| show_alert=True | |
| ) | |
| # Botni ishga tushirish | |
| async def main(): | |
| print("🚀 @ShdwTextBot guruh rejimida muvaffaqiyatli ishga tushdi!") | |
| try: | |
| # Eski vebhuklarni tozalash | |
| await bot.delete_webhook(drop_pending_updates=True) | |
| # 🔥 Polling kutish vaqtini (timeout) shu yerda to'g'ri raqam ko'rinishida beramiz | |
| # Bu HF serveridagi uzilishlarni va koddagi TypeError xatosini birdek tuzatadi | |
| await dp.start_polling(bot, polling_timeout=60) | |
| finally: | |
| await bot.session.close() | |
| if __name__ == "__main__": | |
| asyncio.run(main()) |