├── admins.json ├── index.html ├── movies.json └── bot.py /admins.json: -------------------------------------------------------------------------------- 1 | [ 2 | "7678962106", 3 | "6050884020" 4 | ] -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 |A123):",
230 | parse_mode="HTML"
231 | )
232 |
233 | elif query.data == "delete_movie":
234 | context.user_data["admin_mode"] = "delete"
235 | if not movies:
236 | return await query.edit_message_text("📭 Hozircha kino yo'q.")
237 |
238 | keyboard = []
239 | row = []
240 | for i, code in enumerate(movies.keys()):
241 | row.append(InlineKeyboardButton(code, callback_data=f"delete_{code}"))
242 | if (i + 1) % 3 == 0:
243 | keyboard.append(row)
244 | row = []
245 | if row:
246 | keyboard.append(row)
247 |
248 | keyboard.append([InlineKeyboardButton("🔙 Orqaga", callback_data="back_to_admin")])
249 |
250 | await query.edit_message_text(
251 | "🗑 Kino o'chirish\n\nO'chirmoqchi bo'lgan kino kodini tanlang:",
252 | reply_markup=InlineKeyboardMarkup(keyboard),
253 | parse_mode="HTML"
254 | )
255 |
256 | elif query.data.startswith("delete_"):
257 | code = query.data.replace("delete_", "")
258 | if code in movies:
259 | del movies[code]
260 | save_movies()
261 | await query.edit_message_text(f"✅ Kino o'chirildi\n\nKod: {code}", parse_mode="HTML")
262 | else:
263 | await query.edit_message_text("❌ Bunday kod topilmadi.")
264 |
265 | elif query.data == "list_movies":
266 | if not movies:
267 | return await query.edit_message_text("📭 Hozircha kino yo'q.")
268 |
269 | text = "📜 Kinolar ro'yxati:\n\n"
270 | for code, data in movies.items():
271 | text += f"🔑 {code} — {data['desc'][:50]}"
272 | if len(data['desc']) > 50:
273 | text += "..."
274 | text += "\n"
275 |
276 | if len(text) > 4000:
277 | text = text[:4000] + "\n\n...ro'yxat juda uzun, to'liq ko'rish uchun fayl yuklab oling."
278 |
279 | await query.edit_message_text(text, parse_mode="HTML")
280 |
281 | elif query.data == "admin_stats":
282 | total_movies = len(movies)
283 | video_count = sum(1 for m in movies.values() if m.get('type') == 'video')
284 | photo_count = sum(1 for m in movies.values() if m.get('type') == 'photo')
285 | text_count = sum(1 for m in movies.values() if m.get('type') == 'text')
286 | document_count = sum(1 for m in movies.values() if m.get('type') == 'document')
287 |
288 | stats_text = (
289 | f"📊 Admin statistikasi\n\n"
290 | f"🎬 Jami kinolar: {total_movies}\n"
291 | f"🎥 Videolar: {video_count}\n"
292 | f"🖼 Rasmlar: {photo_count}\n"
293 | f"📝 Matnlar: {text_count}\n"
294 | f"📎 Hujjatlar: "
295 | )
296 |
297 | await query.edit_message_text(stats_text, parse_mode="HTML")
298 |
299 | elif query.data == "back_to_admin":
300 | keyboard = [
301 | [InlineKeyboardButton("➕ Kino qo'shish", callback_data="add_movie")],
302 | [InlineKeyboardButton("🗑 Kino o'chirish", callback_data="delete_movie")],
303 | [InlineKeyboardButton("📜 Kinolar ro'yxati", callback_data="list_movies")],
304 | [InlineKeyboardButton("📊 Statistika", callback_data="admin_stats")],
305 | [InlineKeyboardButton("🔙 Bosh menyu", callback_data="main_menu")]
306 | ]
307 |
308 | await query.edit_message_text(
309 | "👑 Admin paneli\n\nQuyidagi amallardan birini tanlang:",
310 | reply_markup=InlineKeyboardMarkup(keyboard),
311 | parse_mode="HTML"
312 | )
313 |
314 | elif query.data == "main_menu":
315 | await main_menu(update, context)
316 |
317 | async def handle_admin_text(update: Update, context: ContextTypes.DEFAULT_TYPE):
318 | user = update.message.from_user
319 |
320 | if not is_admin(user.id):
321 | return await handle_user_code(update, context)
322 |
323 | mode = context.user_data.get("admin_mode")
324 |
325 | if mode == "add_code":
326 | code = update.message.text.strip().upper()
327 | if not code:
328 | return await update.message.reply_text("❌ Kod bo'sh bo'lmasligi kerak.")
329 |
330 | if code in movies:
331 | return await update.message.reply_text("❗ Bu kod allaqachon mavjud. Boshqa kod kiriting.")
332 |
333 | context.user_data["new_code"] = code
334 | context.user_data["admin_mode"] = "add_desc"
335 | return await update.message.reply_text("✏️ Kino tavsifini yozing:")
336 |
337 | elif mode == "add_desc":
338 | desc = update.message.text
339 | if not desc:
340 | return await update.message.reply_text("❌ Tavsif bo'sh bo'lmasligi kerak.")
341 |
342 | context.user_data["new_desc"] = desc
343 | context.user_data["admin_mode"] = "add_file"
344 | return await update.message.reply_text("🎥 Endi video, rasm yoki matn yuboring:")
345 |
346 | elif mode == "delete":
347 | code = update.message.text.strip().upper()
348 | if code in movies:
349 | del movies[code]
350 | save_movies()
351 | context.user_data["admin_mode"] = None
352 | return await update.message.reply_text(f"✅ Kino o'chirildi: {code}")
353 | else:
354 | return await update.message.reply_text("❌ Bunday kod topilmadi.")
355 |
356 | else:
357 | return await handle_user_code(update, context)
358 |
359 | async def handle_admin_media(update: Update, context: ContextTypes.DEFAULT_TYPE):
360 | user = update.message.from_user
361 |
362 | if not is_admin(user.id):
363 | return
364 |
365 | if context.user_data.get("admin_mode") == "add_file":
366 | code = context.user_data.get("new_code")
367 | desc = context.user_data.get("new_desc")
368 |
369 | if not code or not desc:
370 | context.user_data["admin_mode"] = None
371 | return await update.message.reply_text("❌ Xatolik yuz berdi. Qaytadan boshlang.")
372 |
373 | if update.message.video:
374 | movies[code] = {"type": "video", "file_id": update.message.video.file_id, "desc": desc}
375 | elif update.message.photo:
376 | movies[code] = {"type": "photo", "file_id": update.message.photo[-1].file_id, "desc": desc}
377 | elif update.message.document:
378 | movies[code] = {"type": "document", "file_id": update.message.document.file_id, "desc": desc}
379 | elif update.message.text:
380 | movies[code] = {"type": "text", "file_id": update.message.text, "desc": desc}
381 | else:
382 | return await update.message.reply_text("❗ Faqat video, rasm, hujjat yoki matn yuboring.")
383 |
384 | save_movies()
385 | context.user_data["admin_mode"] = None
386 |
387 | keyboard = [
388 | [InlineKeyboardButton("➕ Yangi kino qo'shish", callback_data="add_movie")],
389 | [InlineKeyboardButton("🔙 Admin paneli", callback_data="back_to_admin")]
390 | ]
391 |
392 | await update.message.reply_text(
393 | f"✅ Kino muvaffaqiyatli qo'shildi!\n\n"
394 | f"🔑 Kod: {code}\n"
395 | f"📄 Tavsif: {desc}",
396 | reply_markup=InlineKeyboardMarkup(keyboard),
397 | parse_mode="HTML"
398 | )
399 |
400 | async def handle_user_code(update: Update, context: ContextTypes.DEFAULT_TYPE):
401 | user = update.message.from_user
402 | code = update.message.text.strip().upper()
403 |
404 | if code in movies:
405 | movie = movies[code]
406 | caption = (
407 | f"🎬 Kino topildi!\n\n"
408 | f"🔑 Kod: {code}\n"
409 | f"📄 {movie['desc']}\n\n"
410 | f"⭐️ Yana kodlar yuboring!"
411 | )
412 |
413 | try:
414 | if movie["type"] == "video":
415 | await update.message.reply_video(
416 | movie["file_id"],
417 | caption=caption,
418 | parse_mode="HTML"
419 | )
420 | elif movie["type"] == "photo":
421 | await update.message.reply_photo(
422 | movie["file_id"],
423 | caption=caption,
424 | parse_mode="HTML"
425 | )
426 | elif movie["type"] == "document":
427 | await update.message.reply_document(
428 | movie["file_id"],
429 | caption=caption,
430 | parse_mode="HTML"
431 | )
432 | elif movie["type"] == "text":
433 | full_text = f"{caption}\n\n{movie['file_id']}"
434 | await update.message.reply_text(full_text, parse_mode="HTML")
435 | except Exception as e:
436 | logger.error(f"Xatolik: {e}")
437 | await update.message.reply_text(
438 | "❌ Kontentni yuborishda xatolik yuz berdi. Iltimos, keyinroq urunib ko'ring."
439 | )
440 | else:
441 | keyboard = InlineKeyboardMarkup([
442 | [InlineKeyboardButton("🔍 Boshqa kod orqali izlash", callback_data="search_movie")],
443 | [InlineKeyboardButton("📞 Admin bilan bog'lanish", callback_data="contact_admin")],
444 | [InlineKeyboardButton("🔙 Bosh menyu", callback_data="main_menu")]
445 | ])
446 |
447 | await update.message.reply_text(
448 | f"❌ Bunday koddagi kino topilmadi\n\n"
449 | f"🔍 Kod: {code}\n\n"
450 | f"Kodni tekshirib, qayta yuboring yoki admin bilan bog'laning.",
451 | reply_markup=keyboard,
452 | parse_mode="HTML"
453 | )
454 |
455 | async def handle_other_messages(update: Update, context: ContextTypes.DEFAULT_TYPE):
456 | user = update.message.from_user
457 |
458 | if is_admin(user.id) and context.user_data.get("admin_mode"):
459 | return
460 |
461 | keyboard = [
462 | [InlineKeyboardButton("🔍 Kino qidirish", callback_data="search_movie")],
463 | [InlineKeyboardButton("📞 Admin bilan bog'lanish", callback_data="contact_admin")]
464 | ]
465 |
466 | await update.message.reply_text(
467 | "🎬 Kino botiga xush kelibsiz!\n\n"
468 | "🔍 Kino topish uchun faqat kod yuboring (masalan: A123) yoki quyidagi tugmalardan foydalaning",
469 | reply_markup=InlineKeyboardMarkup(keyboard),
470 | parse_mode="HTML"
471 | )
472 |
473 | def main():
474 | app = ApplicationBuilder().token(BOT_TOKEN).build()
475 |
476 |
477 | app.add_handler(CommandHandler("start", start))
478 | app.add_handler(CommandHandler("admin", admin_command))
479 |
480 | app.add_handler(CallbackQueryHandler(admin_callbacks))
481 |
482 | app.add_handler(MessageHandler(
483 | filters.VIDEO | filters.PHOTO | filters.Document.ALL,
484 | handle_admin_media
485 | ))
486 |
487 | app.add_handler(MessageHandler(
488 | filters.TEXT & filters.ChatType.PRIVATE,
489 | handle_admin_login
490 | ))
491 |
492 | app.add_handler(MessageHandler(
493 | filters.TEXT & ~filters.COMMAND,
494 | handle_user_code
495 | ))
496 |
497 | app.add_handler(MessageHandler(filters.ALL, handle_other_messages))
498 |
499 | print("Bot ishga tushdi...")
500 | app.run_polling()
501 |
502 | if __name__ == '__main__':
503 | main()
--------------------------------------------------------------------------------