├── admins.json ├── index.html ├── movies.json └── bot.py /admins.json: -------------------------------------------------------------------------------- 1 | [ 2 | "7678962106", 3 | "6050884020" 4 | ] -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Document 7 | 8 | 9 |

salom

10 | 11 | -------------------------------------------------------------------------------- /movies.json: -------------------------------------------------------------------------------- 1 | { 2 | "121": { 3 | "type": "video", 4 | "file_id": "BAACAgIAAxkBAANnaMLxXV2H8OD3c2Ro7cvy5MlpOkcAAiCGAAIEohBKKo7BQgL2dyY2BA", 5 | "desc": "Zor" 6 | }, 7 | "12": { 8 | "type": "video", 9 | "file_id": "BAACAgIAAxkBAANnaMLxXV2H8OD3c2Ro7cvy5MlpOkcAAiCGAAIEohBKKo7BQgL2dyY2BA", 10 | "desc": "Zir" 11 | }, 12 | "13": { 13 | "type": "video", 14 | "file_id": "BAACAgIAAxkBAANnaMLxXV2H8OD3c2Ro7cvy5MlpOkcAAiCGAAIEohBKKo7BQgL2dyY2BA", 15 | "desc": "Grill" 16 | } 17 | } -------------------------------------------------------------------------------- /bot.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import logging 4 | from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton 5 | from telegram.ext import ( 6 | ApplicationBuilder, CommandHandler, MessageHandler, 7 | CallbackQueryHandler, filters, ContextTypes 8 | ) 9 | 10 | logging.basicConfig( 11 | format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 12 | level=logging.INFO 13 | ) 14 | logger = logging.getLogger(__name__) 15 | 16 | BOT_TOKEN = "8250661516:AAHNwNWH1JWFK83FDCv6juuptqUvAqPNA98" 17 | ADMIN_CODE = "60731" 18 | MOVIES_FILE = "movies.json" 19 | ADMINS_FILE = "admins.json" 20 | if os.path.exists(MOVIES_FILE): 21 | try: 22 | with open(MOVIES_FILE, "r", encoding="utf-8") as f: 23 | movies = json.load(f) 24 | except (json.JSONDecodeError, FileNotFoundError): 25 | movies = {} 26 | else: 27 | movies = {} 28 | if os.path.exists(ADMINS_FILE): 29 | try: 30 | with open(ADMINS_FILE, "r", encoding="utf-8") as f: 31 | admins = json.load(f) 32 | except (json.JSONDecodeError, FileNotFoundError): 33 | admins = [] 34 | else: 35 | admins = [] 36 | 37 | def save_movies(): 38 | with open(MOVIES_FILE, "w", encoding="utf-8") as f: 39 | json.dump(movies, f, ensure_ascii=False, indent=4) 40 | 41 | def save_admins(): 42 | with open(ADMINS_FILE, "w", encoding="utf-8") as f: 43 | json.dump(admins, f, ensure_ascii=False, indent=4) 44 | 45 | def is_admin(user_id): 46 | return str(user_id) in admins 47 | 48 | async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): 49 | user = update.message.from_user 50 | 51 | keyboard = [ 52 | [InlineKeyboardButton("🔍 Kino qidirish", callback_data="search_movie")], 53 | [InlineKeyboardButton("📞 Admin bilan bog'lanish", callback_data="contact_admin")] 54 | ] 55 | 56 | text = ( 57 | "🎬 Salom! Xush kelibsiz!\n\n" 58 | "🔍 Kino yoki video topish uchun kod yuboring yoki quyidagi tugmalardan foydalaning." 59 | ) 60 | 61 | await update.message.reply_text( 62 | text, 63 | reply_markup=InlineKeyboardMarkup(keyboard) 64 | ) 65 | 66 | async def admin_command(update: Update, context: ContextTypes.DEFAULT_TYPE): 67 | user = update.message.from_user 68 | 69 | if len(context.args) == 0: 70 | context.user_data["awaiting_admin_code"] = True 71 | await update.message.reply_text( 72 | "🔐 Admin paneliga kirish\n\nIltimos, admin kodini kiriting:", 73 | parse_mode="HTML" 74 | ) 75 | return 76 | 77 | code = context.args[0] 78 | if code == ADMIN_CODE: 79 | if str(user.id) not in admins: 80 | admins.append(str(user.id)) 81 | save_admins() 82 | 83 | keyboard = [ 84 | [InlineKeyboardButton("➕ Kino qo'shish", callback_data="add_movie")], 85 | [InlineKeyboardButton("🗑 Kino o'chirish", callback_data="delete_movie")], 86 | [InlineKeyboardButton("📜 Kinolar ro'yxati", callback_data="list_movies")], 87 | [InlineKeyboardButton("📊 Statistika", callback_data="admin_stats")], 88 | [InlineKeyboardButton("🔙 Bosh menyu", callback_data="main_menu")] 89 | ] 90 | 91 | await update.message.reply_text( 92 | "👑 Admin paneli\n\nQuyidagi amallardan birini tanlang:", 93 | reply_markup=InlineKeyboardMarkup(keyboard), 94 | parse_mode="HTML" 95 | ) 96 | else: 97 | try: 98 | admin_id = admins[0] 99 | await context.bot.send_message( 100 | admin_id, 101 | f"⚠️ Ogohlik!\n\n" 102 | f"Foydalanuvchi admin paneliga kirishga urindi:\n" 103 | f"👤 Ism: {user.first_name}\n" 104 | f"🆔 ID: {user.id}\n" 105 | f"📧 Username: @{user.username if user.username else 'Mavjud emas'}\n" 106 | f"🔐 Kiritilgan kod: {code}", 107 | parse_mode="HTML" 108 | ) 109 | except Exception as e: 110 | logger.error(f"Adminga xabar yuborishda xatolik: {e}") 111 | 112 | await update.message.reply_text("❌ Noto'g'ri admin kodi! Siz admin emassiz.") 113 | 114 | async def handle_admin_login(update: Update, context: ContextTypes.DEFAULT_TYPE): 115 | user = update.message.from_user 116 | 117 | if context.user_data.get("awaiting_admin_code"): 118 | code = update.message.text.strip() 119 | 120 | if code == ADMIN_CODE: 121 | if str(user.id) not in admins: 122 | admins.append(str(user.id)) 123 | save_admins() 124 | 125 | context.user_data["awaiting_admin_code"] = False 126 | 127 | # Admin paneli tugmalari 128 | keyboard = [ 129 | [InlineKeyboardButton("➕ Kino qo'shish", callback_data="add_movie")], 130 | [InlineKeyboardButton("🗑 Kino o'chirish", callback_data="delete_movie")], 131 | [InlineKeyboardButton("📜 Kinolar ro'yxati", callback_data="list_movies")], 132 | [InlineKeyboardButton("📊 Statistika", callback_data="admin_stats")], 133 | [InlineKeyboardButton("🔙 Bosh menyu", callback_data="main_menu")] 134 | ] 135 | 136 | await update.message.reply_text( 137 | "👑 Admin paneli\n\nQuyidagi amallardan birini tanlang:", 138 | reply_markup=InlineKeyboardMarkup(keyboard), 139 | parse_mode="HTML" 140 | ) 141 | else: 142 | try: 143 | admin_id = admins[0] 144 | await context.bot.send_message( 145 | admin_id, 146 | f"⚠️ Ogohlik!\n\n" 147 | f"Foydalanuvchi admin paneliga kirishga urindi:\n" 148 | f"👤 Ism: {user.first_name}\n" 149 | f"🆔 ID: {user.id}\n" 150 | f"📧 Username: @{user.username if user.username else 'Mavjud emas'}\n" 151 | f"🔐 Kiritilgan kod: {code}", 152 | parse_mode="HTML" 153 | ) 154 | except Exception as e: 155 | logger.error(f"Adminga xabar yuborishda xatolik: {e}") 156 | 157 | await update.message.reply_text("❌ Noto'g'ri admin kodi! Siz admin emassiz.") 158 | else: 159 | await handle_user_code(update, context) 160 | 161 | async def main_menu(update: Update, context: ContextTypes.DEFAULT_TYPE): 162 | query = update.callback_query 163 | await query.answer() 164 | user = query.from_user 165 | 166 | keyboard = [ 167 | [InlineKeyboardButton("🔍 Kino qidirish", callback_data="search_movie")], 168 | [InlineKeyboardButton("📞 Admin bilan bog'lanish", callback_data="contact_admin")] 169 | ] 170 | 171 | await query.edit_message_text( 172 | "🏠 Bosh menyu\n\nQuyidagi amallardan birini tanlang:", 173 | reply_markup=InlineKeyboardMarkup(keyboard), 174 | parse_mode="HTML" 175 | ) 176 | 177 | async def search_movie(update: Update, context: ContextTypes.DEFAULT_TYPE): 178 | query = update.callback_query 179 | await query.answer() 180 | 181 | await query.edit_message_text( 182 | "🔍 Kino izlash\n\nIltimos, kino kodini kiriting:", 183 | parse_mode="HTML" 184 | ) 185 | 186 | async def contact_admin(update: Update, context: ContextTypes.DEFAULT_TYPE): 187 | query = update.callback_query 188 | await query.answer() 189 | user = query.from_user 190 | 191 | for admin_id in admins: 192 | try: 193 | await context.bot.send_message( 194 | admin_id, 195 | f"📞 Yangi bog'lanish so'rovi\n\n" 196 | f"👤 Foydalanuvchi: {user.first_name}\n" 197 | f"🆔 ID: {user.id}\n" 198 | f"📧 Username: @{user.username if user.username else 'Mavjud emas'}\n" 199 | f"📞 Telefon raqam: {user.phone_number if hasattr(user, 'phone_number') and user.phone_number else 'Mavjud emas'}", 200 | parse_mode="HTML" 201 | ) 202 | except Exception as e: 203 | logger.error(f"Adminga xabar yuborishda xatolik: {e}") 204 | 205 | await query.edit_message_text( 206 | "📞 Admin bilan bog'lanish\n\n" 207 | "Sizning so'rovingiz adminlarga yuborildi. Tez orada siz bilan bog'lanishadi.\n\n" 208 | "Agar shoshilinch bo'lsa, to'g'ridan-to'g'ri xabar yozishingiz mumkin.", 209 | parse_mode="HTML" 210 | ) 211 | 212 | async def admin_callbacks(update: Update, context: ContextTypes.DEFAULT_TYPE): 213 | query = update.callback_query 214 | await query.answer() 215 | user = query.from_user 216 | 217 | if not is_admin(user.id): 218 | if query.data == "search_movie": 219 | await search_movie(update, context) 220 | elif query.data == "contact_admin": 221 | await contact_admin(update, context) 222 | elif query.data == "main_menu": 223 | await main_menu(update, context) 224 | return 225 | 226 | if query.data == "add_movie": 227 | context.user_data["admin_mode"] = "add_code" 228 | await query.edit_message_text( 229 | "🔑 Yangi kino qo'shish\n\nKod kiriting (masalan: 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() --------------------------------------------------------------------------------