import logging import asyncio from aiogram import Bot, Dispatcher, types, F from aiogram.types import CallbackQuery import firebase_admin from firebase_admin import credentials, firestore # 1. Firebase-ni sozlash cred = credentials.Certificate("serviceAccountKey.json") # Fayl nomi to'g'ri bo'lsin firebase_admin.initialize_app(cred) db = firestore.client() # 2. Bot sozlamalari API_TOKEN = '5714791266:AAEpc1YGClxn0e5u9BReEsiWrr66APqSYbk' bot = Bot(token=API_TOKEN) dp = Dispatcher() logging.basicConfig(level=logging.INFO) # --- TASDIQLASH (APPROVE) TUGMASI BOSILGANDA --- @dp.callback_query(F.data.startswith("approve_")) async def process_approve(callback: CallbackQuery): # data formati: approve_USERID_AMOUNT data = callback.data.split("_") user_id = data[1] amount = int(data[2]) try: # Firebase-da foydalanuvchi balansini yangilash user_ref = db.collection("users").document(user_id) # Tranzaksiya orqali xavfsiz oshirish user_doc = user_ref.get() if user_doc.exists: current_balance = user_doc.to_dict().get("balance", 0) new_balance = current_balance + amount user_ref.update({"balance": new_balance}) # Xabarni yangilash await callback.message.edit_caption( caption=callback.message.caption + f"\n\nāœ… TASDIQLANDI!\nšŸ’° Yangi balans: {new_balance} so'm", reply_markup=None # Tugmalarni olib tashlash ) await callback.answer("To'lov tasdiqlandi! āœ…", show_alert=True) else: await callback.answer("Foydalanuvchi topilmadi! āŒ", show_alert=True) except Exception as e: logging.error(f"Xato: {e}") await callback.answer("Xatolik yuz berdi! āš ļø", show_alert=True) # --- RAD ETISH (REJECT) TUGMASI BOSILGANDA --- @dp.callback_query(F.data.startswith("reject_")) async def process_reject(callback: CallbackQuery): await callback.message.edit_caption( caption=callback.message.caption + "\n\nāŒ TO'LOV RAD ETILDI!", reply_markup=None ) await callback.answer("Rad etildi.", show_alert=True) async def main(): await dp.start_polling(bot) if __name__ == '__main__': asyncio.run(main()) r(--border); color: white; padding: 10px; border-radius: 5px; width: 90%; text-align: center; } .hidden { display: none; } .timer { position: sticky; top: 0; background: #e63946; padding: 8px; text-align: center; font-weight: bold; border-radius: 5px; z-index: 100; margin-bottom: 10px; } .subject-badge { background: #2a9d8f; color: white; padding: 5px 10px; border-radius: 5px; font-size: 14px; margin-top: 5px; display: inline-block; } .unanswered { border: 2px solid #ff4d4d !important; border-radius: 5px; }
Milliy Sertifikat Bot