iq7se2 commited on
Commit
fc28f55
Β·
verified Β·
1 Parent(s): d76fdae

Update bot.py

Browse files
Files changed (1) hide show
  1. bot.py +24 -9
bot.py CHANGED
@@ -494,10 +494,10 @@ async def cmd_get(update: Update, ctx: ContextTypes.DEFAULT_TYPE):
494
  # ΨͺΨ΄ΨΊΩŠΩ„ Ψ§Ω„Ψ¨ΩˆΨͺ
495
  # ══════════════════════════════════════════════
496
 
497
- def main():
498
- app = ApplicationBuilder().token(BOT_TOKEN).build()
 
499
 
500
- # conversation handler Ω„Ω„Ψ¨Ψ­Ψ« Ψ§Ω„ΨͺΩΨ§ΨΉΩ„ΩŠ
501
  conv = ConversationHandler(
502
  entry_points=[CommandHandler("search", cmd_search)],
503
  states={
@@ -511,15 +511,30 @@ def main():
511
  ],
512
  },
513
  fallbacks=[CommandHandler("cancel", cmd_cancel)],
 
514
  )
515
 
516
- app.add_handler(CommandHandler("start", cmd_start))
517
- app.add_handler(CommandHandler("sites", cmd_sites))
518
- app.add_handler(CommandHandler("get", cmd_get))
519
- app.add_handler(conv)
520
-
 
 
 
 
 
 
 
 
 
 
521
  print("βœ… Ψ§Ω„Ψ¨ΩˆΨͺ Ψ΄ΨΊΨ§Ω„!")
522
- app.run_polling(allowed_updates=Update.ALL_TYPES, drop_pending_updates=True)
 
 
 
 
523
 
524
  if __name__ == "__main__":
525
  main()
 
494
  # ΨͺΨ΄ΨΊΩŠΩ„ Ψ§Ω„Ψ¨ΩˆΨͺ
495
  # ══════════════════════════════════════════════
496
 
497
+ def build_app():
498
+ """Ψ¨Ω†Ψ§Ψ‘ Ψ§Ω„ΨͺΨ·Ψ¨ΩŠΩ‚ فقط β€” Ψ¨Ψ―ΩˆΩ† ΨͺΨ΄ΨΊΩŠΩ„"""
499
+ application = ApplicationBuilder().token(BOT_TOKEN).build()
500
 
 
501
  conv = ConversationHandler(
502
  entry_points=[CommandHandler("search", cmd_search)],
503
  states={
 
511
  ],
512
  },
513
  fallbacks=[CommandHandler("cancel", cmd_cancel)],
514
+ per_message=False,
515
  )
516
 
517
+ application.add_handler(CommandHandler("start", cmd_start))
518
+ application.add_handler(CommandHandler("sites", cmd_sites))
519
+ application.add_handler(CommandHandler("get", cmd_get))
520
+ application.add_handler(conv)
521
+ return application
522
+
523
+ async def run_async():
524
+ """ΨͺΨ΄ΨΊΩŠΩ„ Ψ§Ω„Ψ¨ΩˆΨͺ Ψ¨Ψ―ΩˆΩ† signal handlers β€” يشΨͺΨΊΩ„ Ω…Ω† أي thread"""
525
+ application = build_app()
526
+ await application.initialize()
527
+ await application.start()
528
+ await application.updater.start_polling(
529
+ drop_pending_updates=True,
530
+ allowed_updates=Update.ALL_TYPES,
531
+ )
532
  print("βœ… Ψ§Ω„Ψ¨ΩˆΨͺ Ψ΄ΨΊΨ§Ω„!")
533
+ # Ψ§Ω†ΨͺΨΈΨ± Ψ₯Ω„Ω‰ Ψ§Ω„Ψ£Ψ¨Ψ―
534
+ await asyncio.Event().wait()
535
+
536
+ def main():
537
+ asyncio.run(run_async())
538
 
539
  if __name__ == "__main__":
540
  main()