from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove
from telegram.ext import Application, CommandHandler, MessageHandler, ContextTypes, filters, ConversationHandler
# تعریف مراحل گفتگو
CHOOSING, GETTING_NAME = range(2)
# لیست شرکتکنندگان
arrayTlist = []
# مرحله شروع
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = [
["🏓 پدل", "🎾 تنیس"]
]
reply_markup = ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
await update.message.reply_text("لطفاً یکی از گزینهها را انتخاب کنید:", reply_markup=reply_markup)
return CHOOSING # انتقال به مرحله انتخاب
# مرحله انتخاب
async def choose(update: Update, context: ContextTypes.DEFAULT_TYPE):
user_choice = update.message.text
if user_choice == "🎾 تنیس":
await update.message.reply_text(
"شما تنیس را انتخاب کردید! لطفاً نام خود را وارد کنید:",
reply_markup=ReplyKeyboardRemove() # حذف کیبورد
)
return GETTING_NAME # انتقال به مرحله دریافت نام
elif user_choice == "🏓 پدل":
await update.message.reply_text("شما پدل را انتخاب کردید! این گزینه فعلاً پشتیبانی نمیشود.")
#return ConversationHandler.END # پایان گفتگو
else:
await update.message.reply_text("لطفاً یکی از گزینههای موجود را انتخاب کنید.")
return CHOOSING # بازگشت به مرحله انتخاب
# مرحله دریافت نام
async def get_name(update: Update, context: ContextTypes.DEFAULT_TYPE):
global arrayTlist
name = update.message.text
arrayTlist.append(name) # اضافه کردن نام به لیست
await update.message.reply_text(f"نام شما ({name}) با موفقیت ثبت شد! 🎉")
await update.message.reply_text(f"لینگ پرداخت برای شما ارسال می شود")
return ConversationHandler.END # پایان گفتگو
# نمایش لیست شرکتکنندگان
async def show_participants(update: Update, context: ContextTypes.DEFAULT_TYPE):
if arrayTlist:
participants = "\n".join(arrayTlist)
await update.message.reply_text(f"لیست شرکتکنندگان:\n{participants}")
else:
await update.message.reply_text("هنوز هیچ کسی ثبتنام نکرده است.")
# لغو گفتگو
async def cancel(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("عملیات لغو شد.", reply_markup=ReplyKeyboardRemove())
return ConversationHandler.END # پایان گفتگو
# تنظیمات اصلی برنامه
application = Application.builder().token("7978811171:AAGt25UoUeBmk-2tT88Om4n15-0IkMhvNeo").build()
# تعریف گفتگوها
conv_handler = ConversationHandler(
entry_points=[CommandHandler("start", start)],
states={
CHOOSING: [MessageHandler(filters.TEXT & ~filters.COMMAND, choose)],
GETTING_NAME: [MessageHandler(filters.TEXT & ~filters.COMMAND, get_name)],
},
fallbacks=[CommandHandler("cancel", cancel)],
)
# اضافه کردن هندلرها
application.add_handler(conv_handler)
application.add_handler(CommandHandler("list", show_participants)) # هندلر برای نمایش لیست شرکتکنندگان
# اجرای برنامه
application.run_polling()