from pydantic import ValidationError from pydurian.db import EmailConfig, SmsConfig from pydurian.db.utils import Depends, User, get_user, inject from pydurian.helpers import get_locker from pyrogram import Client, filters from pyrogram.types import ( CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message, ReplyKeyboardRemove, ) from .utils import CANCEL_BUTTON, canceled_message @Client.on_message(filters.command(["config"])) @Client.on_callback_query(filters.regex("config")) async def send_config_message(client: Client, message: Message | CallbackQuery) -> None: keyboard = InlineKeyboardMarkup( [ [ InlineKeyboardButton(text="📬Gmail معلومات", callback_data="gmail_info"), InlineKeyboardButton(text="✏️", callback_data="update_gmail"), ], [ InlineKeyboardButton(text="معلومات الموقع📨", callback_data="durianrcs_info"), InlineKeyboardButton(text="✏️", callback_data="update_durianrcs"), ], [ InlineKeyboardButton(text="قناة الإثباتات📣", callback_data="channel_info"), InlineKeyboardButton(text="✏️", callback_data="update_channel"), ], [InlineKeyboardButton(text="🔙 عودة", callback_data="main_menu")], ] ) if isinstance(message, CallbackQuery): await message.message.edit( text="يُمكنك تعديل أي قسم من خلال النقر على قلم التعديل ✏️", reply_markup=keyboard ) else: await message.reply( text="يُمكنك تعديل أي قسم من خلال النقر على قلم التعديل ✏️", reply_markup=keyboard ) @Client.on_callback_query(filters.regex("update_gmail")) @inject async def update_gmail_info( client: Client, update: CallbackQuery, user: User = Depends(get_user) ) -> None: try: email_response = await update.message.ask( text="أدخل بريد Gmail من فضلك:", reply_markup=CANCEL_BUTTON, timeout=60, ) email = email_response.text if (email) in ["إلغاء ❌"]: await canceled_message(update.message) await send_config_message(client, update.message) return password_response = await update.message.ask( text="🔑 أدخل كلمة المرور:", reply_markup=CANCEL_BUTTON, timeout=60 ) password = password_response.text if (password) in ["إلغاء ❌"]: await canceled_message(update.message) await send_config_message(client, update.message) return try: # noqa: SIM105 email_config = EmailConfig( email=email_response.text, password=password_response.text, ) except ValidationError: await update.message.reply( "لقد أدخلت بريد إلكتروني غير صالح \n/config\nللمحاولة مجدداً 🔄" ) return async with get_locker(user.user_id): await user.sync() user.config.email = email_config await user.save() except TimeoutError: await update.message.reply( "\nلقد تجاوزت المهلة المحددة لإدخال البيانات الجديدة\n/config\nللمحاولة مجدداً 🔄", reply_markup=ReplyKeyboardRemove(), ) await send_config_message(client, update.message) return await update.message.reply( f"تم تحديث البيانات بنجاح وهي:\nEmail {email}\nPassword: {password}\n\n/start", reply_markup=ReplyKeyboardRemove(), ) ## Handle Add Email Password to Database :) @Client.on_callback_query(filters.regex("update_durianrcs")) @inject async def update_durianrcs_info( client: Client, update: CallbackQuery, user: User = Depends(get_user) ) -> None: try: api_key_response = await update.message.ask( text="أدخل ApiKey من فضلك:", reply_markup=CANCEL_BUTTON, timeout=60 ) api_key = api_key_response.text if (api_key) in ["إلغاء ❌"]: await canceled_message(update.message) await send_config_message(client, update.message) return username_response = await update.message.ask( text="أدخل Username من فضلك:", reply_markup=CANCEL_BUTTON, timeout=60 ) username = username_response.text if (username) in ["إلغاء ❌"]: await canceled_message(update.message) await send_config_message(client, update.message) return async with get_locker(user.user_id): await user.sync() user.config.sms = SmsConfig(user=username, api_key=api_key) await user.save() except TimeoutError: await update.message.reply( "\nلقد تجاوزت المهلة المحددة لإدخال البيانات الجديدة\n/config\nللمحاولة مجدداً 🔄", reply_markup=ReplyKeyboardRemove(), ) return await update.message.reply( f"حسناً تم اعتماد اسم المستخدم `{username}`\nApiKey: `{api_key}`\n/start", reply_markup=ReplyKeyboardRemove(), ) ## Handle Add durianrcs Info to Database :) @Client.on_callback_query(filters.regex("update_channel")) @inject async def update_channel_info( client: Client, update: CallbackQuery, user: User = Depends(get_user) ) -> None: try: channel_id_response = await update.message.ask( text=( "أعد توجيه المنشور من القناة، أو أرسل `0` لضبط الإعداد كمحادثة خاصة (هنا)" "\nيُرجى التأكّد أن البوت لديه صلاحيات بالقناة." ), reply_markup=CANCEL_BUTTON, timeout=60, ) if (channel_id_response.text) in ["إلغاء ❌"]: await canceled_message(update.message) await send_config_message(client, update.message) return if channel_id_response.forward_from_chat: channel_id = channel_id_response.forward_from_chat.id else: channel_id = int(channel_id_response.text) except TimeoutError: await update.message.reply( "\nلقد تجاوزت المهلة المحددة لإدخال البيانات الجديدة\n/config\nللمحاولة مجدداً 🔄", reply_markup=ReplyKeyboardRemove(), ) return if channel_id != 0: try: m = await client.send_message(channel_id, "Test") await m.delete() except: # noqa: E722 await update.message.reply( "لم أتمكن من إرسال رسالة للقناة.\nتأكد أنّ البوت لديه صلاحيات أدمن المناسبة.", reply_markup=ReplyKeyboardRemove(), ) return async with get_locker(user.user_id): await user.sync() user.config.channel = channel_id if channel_id != 0 else None await user.save() if channel_id == 0: await update.message.reply( "حسناً سيتم توجيه رسائل الصيد لك هنا ضمن البوت\n/start", reply_markup=ReplyKeyboardRemove(), ) else: await update.message.reply( f"حسناً تم ضبط القناة الخاصة بك `{channel_id}`\n/start", reply_markup=ReplyKeyboardRemove(), ) ## Handle Add durianrcs Info to Database :)