from pydantic import ValidationError from pydurian.db import Config, EmailConfig, SmsConfig from pydurian.db.utils import Depends, User, get_user, inject from pyrogram import Client, filters from pyrogram.types import ( CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message, ReplyKeyboardRemove, ) from .utils import handle_movement @Client.on_message(filters.command(["start"])) @Client.on_callback_query(filters.regex("main_menu")) @inject async def start_message( client: Client, update: Message | CallbackQuery, user: User = Depends(get_user) ) -> None: if not user.is_admin: return if not user.config: await get_initial_data(client, update.message, user) if isinstance( update, CallbackQuery ) else await get_initial_data(client, update, user) else: if isinstance(update, CallbackQuery): func = update.message.reply await update.message.delete() else: func = update.reply main_button = [ [InlineKeyboardButton(text="❇️الدول المضافة", callback_data="get_countries")], [ InlineKeyboardButton(text="🖱فحص الحساب", callback_data="get_info"), InlineKeyboardButton(text="ضبط المعلومات🎛", callback_data="config"), ], ] if user.config.channel: channel_id = str(user.config.channel) channel_id = channel_id.replace("-100", "") main_button.append( [InlineKeyboardButton(text="قناة الإثباتات📣", url=f"https://t.me/c/{channel_id}")] ) await func( "أهلاً وسهلاً بك في بوت الصيد!👋\n" "أرسل\n" "الأمر work/ ثم رمز الدولة ثم عدد الأرقام (اختياري)\n" "مثال:\n" "`/work ru 5`\n" "`/work tr`\n" "أو\n" "/stop\n" "لإيقاف كل العمليات (حذف كل الدول المضافة)\n" "أو\n" "`/stop us`\n" "لإيقاف وحذف دولة معينة", reply_markup=InlineKeyboardMarkup(main_button), ) async def get_initial_data(client: Client, msg: Message, user: User) -> None: await msg.reply( "💠أهلاً بك، يبدو أنّك لم تضبط الإعدادات الضرورية بعد\n" "هيا بنا نبدأ ذلك سيستغرق بضع ثوانٍ فقط 😉" ) try: email_response = await msg.ask(text="أدخل بريد Gmail من فضلك:", timeout=60) await handle_movement(get_initial_data, client, msg, email_response, user) try: EmailConfig(email=email_response.text, password="") except ValidationError: await msg.reply("لقد أدخلت بريد إلكتروني غير صالح \n/config\nللمحاولة مجدداً 🔄") return password_response = await msg.ask(text="🔑 أدخل كلمة المرور:", timeout=60) await handle_movement(get_initial_data, client, msg, password_response, user) email_config = EmailConfig( email=email_response.text, password=password_response.text, ) durianrcs_user_response = await msg.ask(text="أدخل Username من فضلك:", timeout=60) await handle_movement(get_initial_data, client, msg, durianrcs_user_response, user) durianrcs_api_key_response = await msg.ask(text="أدخل ApiKey من فضلك:", timeout=60) await handle_movement(get_initial_data, client, msg, durianrcs_api_key_response, user) user.config = Config( email=email_config, sms=SmsConfig( user=durianrcs_user_response.text, api_key=durianrcs_api_key_response.text ), ) await user.save() await start_message(client=client, update=msg, user=user) except TimeoutError: await msg.reply( "\nلقد تجاوزت المهلة المحددة لإدخال البيانات \n/config\nللمحاولة مجدداً 🔄", reply_markup=ReplyKeyboardRemove(), )