Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -64,7 +64,7 @@ MESSAGES = {
|
|
64 |
'error_voice_to_mp3': "❌ خطا در تبدیل ویس تلگرام به MP3: ",
|
65 |
'general_error': "متاسفم، مشکلی پیش آمد. لطفاً دوباره تلاش کنید.",
|
66 |
'main_menu_prompt': "چه کاری میخواهید روی فایل خود انجام دهید؟",
|
67 |
-
'btn_convert_format': "تغییر فرمت صدا
|
68 |
'btn_cut_audio': "برش قسمتی از صدا ✂️",
|
69 |
'btn_video_conversion': "تبدیل ویدیو دایرهای 🎥",
|
70 |
'convert_mode_active': "شما در حالت 'تغییر فرمت صدا' هستید. حالا فایل صوتی (ویس یا MP3) خود را برای من ارسال کنید.",
|
@@ -141,7 +141,7 @@ MESSAGES = {
|
|
141 |
'error_video_conversion': "❌ Error converting video: ",
|
142 |
'invalid_file_type_video': "Please send a video file or a video message.",
|
143 |
'membership_required': "To continue using the bot and access unlimited features, please join the following channels first:",
|
144 |
-
'btn_join_channel': "Join Channel
|
145 |
'btn_check_membership': "Check Membership ✅",
|
146 |
'membership_success': "✅ Your membership has been verified! You can now use the bot unlimitedly.",
|
147 |
'membership_failed': "❌ Sorry, you are not yet a member of all required channels. Please join first and then press 'Check Membership' again.",
|
@@ -623,7 +623,7 @@ async def handle_video_conversion(update: Update, context):
|
|
623 |
if processing_message:
|
624 |
await processing_message.edit_text(get_message(context, 'error_video_conversion') + f"FFmpeg Error: {e.stderr.decode()}")
|
625 |
else:
|
626 |
-
await update.message.reply_text(get_message(context, 'error_video_conversion') +
|
627 |
return VIDEO_CONVERSION_MODE
|
628 |
except Exception as e:
|
629 |
print(f"General video conversion error: {e}", file=sys.stderr)
|
@@ -743,79 +743,80 @@ async def admin_handle_remove_channel(update: Update, context):
|
|
743 |
return await admin_link_command(update, context)
|
744 |
|
745 |
app = Flask(__name__)
|
746 |
-
application = None
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
|
|
|
|
|
|
|
|
815 |
|
816 |
-
application.add_handler(conv_handler)
|
817 |
-
application.add_error_handler(error_handler)
|
818 |
-
print("Telegram bot Application initialized.")
|
819 |
|
820 |
@app.route("/")
|
821 |
async def index():
|
@@ -823,14 +824,14 @@ async def index():
|
|
823 |
|
824 |
@app.route("/webhook", methods=["POST"])
|
825 |
async def webhook():
|
826 |
-
await setup_bot()
|
827 |
update = Update.de_json(request.get_json(force=True), application.bot)
|
828 |
await application.process_update(update)
|
829 |
return "ok"
|
830 |
|
831 |
@app.route("/set_webhook", methods=["GET"])
|
832 |
async def set_webhook_route():
|
833 |
-
await setup_bot()
|
834 |
webhook_url = os.getenv("WEBHOOK_URL")
|
835 |
if not webhook_url:
|
836 |
return jsonify({"status": "error", "message": "WEBHOOK_URL environment variable not set."}), 500
|
@@ -846,4 +847,4 @@ async def set_webhook_route():
|
|
846 |
|
847 |
if __name__ == "__main__":
|
848 |
print("Starting Flask app...")
|
849 |
-
app.run(host='0.0.0.0', port=int(os.environ.get("PORT", 7860)))
|
|
|
64 |
'error_voice_to_mp3': "❌ خطا در تبدیل ویس تلگرام به MP3: ",
|
65 |
'general_error': "متاسفم، مشکلی پیش آمد. لطفاً دوباره تلاش کنید.",
|
66 |
'main_menu_prompt': "چه کاری میخواهید روی فایل خود انجام دهید؟",
|
67 |
+
'btn_convert_format': "تغییر فرمت صدا 🎵",
|
68 |
'btn_cut_audio': "برش قسمتی از صدا ✂️",
|
69 |
'btn_video_conversion': "تبدیل ویدیو دایرهای 🎥",
|
70 |
'convert_mode_active': "شما در حالت 'تغییر فرمت صدا' هستید. حالا فایل صوتی (ویس یا MP3) خود را برای من ارسال کنید.",
|
|
|
141 |
'error_video_conversion': "❌ Error converting video: ",
|
142 |
'invalid_file_type_video': "Please send a video file or a video message.",
|
143 |
'membership_required': "To continue using the bot and access unlimited features, please join the following channels first:",
|
144 |
+
'btn_join_channel': "Join Channel �",
|
145 |
'btn_check_membership': "Check Membership ✅",
|
146 |
'membership_success': "✅ Your membership has been verified! You can now use the bot unlimitedly.",
|
147 |
'membership_failed': "❌ Sorry, you are not yet a member of all required channels. Please join first and then press 'Check Membership' again.",
|
|
|
623 |
if processing_message:
|
624 |
await processing_message.edit_text(get_message(context, 'error_video_conversion') + f"FFmpeg Error: {e.stderr.decode()}")
|
625 |
else:
|
626 |
+
await update.message.reply_text(get_message(context, 'error_video_conversion') + str(e))
|
627 |
return VIDEO_CONVERSION_MODE
|
628 |
except Exception as e:
|
629 |
print(f"General video conversion error: {e}", file=sys.stderr)
|
|
|
743 |
return await admin_link_command(update, context)
|
744 |
|
745 |
app = Flask(__name__)
|
746 |
+
# application = None # این خط را حذف یا کامنت کنید
|
747 |
+
|
748 |
+
# مقداردهی اولیه Application در سطح سراسری (Global Scope)
|
749 |
+
# این اطمینان می دهد که Application یک بار در زمان شروع برنامه مقداردهی می شود.
|
750 |
+
application = Application.builder().token(TOKEN).build()
|
751 |
+
|
752 |
+
# اضافه کردن هندلرها به Application در زمان مقداردهی اولیه
|
753 |
+
conv_handler = ConversationHandler(
|
754 |
+
entry_points=[
|
755 |
+
CommandHandler("start", start),
|
756 |
+
CommandHandler("link", admin_link_command)
|
757 |
+
],
|
758 |
+
states={
|
759 |
+
LANGUAGE_SELECTION: [
|
760 |
+
CallbackQueryHandler(set_language, pattern='^set_lang_')
|
761 |
+
],
|
762 |
+
MAIN_MENU: [
|
763 |
+
CallbackQueryHandler(change_format_selected, pattern='^select_convert_format$'),
|
764 |
+
CallbackQueryHandler(cut_audio_selected, pattern='^select_cut_audio$'),
|
765 |
+
CallbackQueryHandler(video_conversion_selected, pattern='^select_video_conversion$')
|
766 |
+
],
|
767 |
+
CONVERT_AUDIO: [
|
768 |
+
MessageHandler(filters.AUDIO & ~filters.COMMAND, handle_audio),
|
769 |
+
MessageHandler(filters.VOICE & ~filters.COMMAND, handle_voice),
|
770 |
+
CommandHandler("start", start),
|
771 |
+
CommandHandler("cancel", cancel)
|
772 |
+
],
|
773 |
+
CUT_AUDIO_FILE: [
|
774 |
+
MessageHandler(filters.AUDIO & ~filters.COMMAND, handle_cut_audio_file),
|
775 |
+
MessageHandler(filters.VOICE & ~filters.COMMAND, handle_cut_audio_file),
|
776 |
+
CommandHandler("start", start),
|
777 |
+
CommandHandler("cancel", cancel)
|
778 |
+
],
|
779 |
+
CUT_AUDIO_RANGE: [
|
780 |
+
MessageHandler(filters.TEXT & ~filters.COMMAND, handle_cut_audio_range),
|
781 |
+
CommandHandler("start", start),
|
782 |
+
CommandHandler("cancel", cancel)
|
783 |
+
],
|
784 |
+
VIDEO_CONVERSION_MODE: [
|
785 |
+
MessageHandler(filters.VIDEO & ~filters.COMMAND, handle_video_conversion),
|
786 |
+
MessageHandler(filters.VIDEO_NOTE & ~filters.COMMAND, handle_video_conversion),
|
787 |
+
CommandHandler("start", start),
|
788 |
+
CommandHandler("cancel", cancel)
|
789 |
+
],
|
790 |
+
WAITING_FOR_MEMBERSHIP: [
|
791 |
+
CallbackQueryHandler(check_membership_callback, pattern='^check_membership$'),
|
792 |
+
CommandHandler("start", start),
|
793 |
+
CommandHandler("cancel", cancel)
|
794 |
+
],
|
795 |
+
ADMIN_MENU: [
|
796 |
+
CallbackQueryHandler(admin_add_channel_prompt, pattern='^admin_add_channel$'),
|
797 |
+
CallbackQueryHandler(admin_list_channels, pattern='^admin_list_channels$'),
|
798 |
+
CommandHandler("start", start),
|
799 |
+
CommandHandler("cancel", cancel)
|
800 |
+
],
|
801 |
+
ADD_CHANNEL: [
|
802 |
+
MessageHandler(filters.TEXT & ~filters.COMMAND, admin_handle_add_channel),
|
803 |
+
CommandHandler("start", start),
|
804 |
+
CommandHandler("cancel", cancel)
|
805 |
+
],
|
806 |
+
LIST_REMOVE_CHANNELS: [
|
807 |
+
CallbackQueryHandler(admin_handle_remove_channel, pattern='^remove_channel_'),
|
808 |
+
CommandHandler("start", start),
|
809 |
+
CommandHandler("cancel", cancel)
|
810 |
+
]
|
811 |
+
},
|
812 |
+
fallbacks=[CommandHandler("cancel", cancel), CommandHandler("start", start)],
|
813 |
+
allow_reentry=True
|
814 |
+
)
|
815 |
+
|
816 |
+
application.add_handler(conv_handler)
|
817 |
+
application.add_error_handler(error_handler)
|
818 |
+
print("Telegram bot Application initialized.")
|
819 |
|
|
|
|
|
|
|
820 |
|
821 |
@app.route("/")
|
822 |
async def index():
|
|
|
824 |
|
825 |
@app.route("/webhook", methods=["POST"])
|
826 |
async def webhook():
|
827 |
+
# await setup_bot() # این خط را حذف کنید
|
828 |
update = Update.de_json(request.get_json(force=True), application.bot)
|
829 |
await application.process_update(update)
|
830 |
return "ok"
|
831 |
|
832 |
@app.route("/set_webhook", methods=["GET"])
|
833 |
async def set_webhook_route():
|
834 |
+
# await setup_bot() # این خط را حذف کنید
|
835 |
webhook_url = os.getenv("WEBHOOK_URL")
|
836 |
if not webhook_url:
|
837 |
return jsonify({"status": "error", "message": "WEBHOOK_URL environment variable not set."}), 500
|
|
|
847 |
|
848 |
if __name__ == "__main__":
|
849 |
print("Starting Flask app...")
|
850 |
+
app.run(host='0.0.0.0', port=int(os.environ.get("PORT", 7860)))
|