Spaces:
Runtime error
Runtime error
File size: 4,366 Bytes
d72100d 494e0ae d72100d bf3b6e4 494e0ae d72100d 494e0ae d72100d 494e0ae bf3b6e4 494e0ae bf3b6e4 494e0ae d72100d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | 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
@dp.message(F.text == "/start")
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
@dp.inline_query()
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)
@dp.callback_query(F.data.startswith("open_"))
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()) |