import math from pydurian.db import CountryConfig from pydurian.db.utils import Depends, User, get_user, inject from pydurian.helpers import get_locker from pydurian.helpers.countries import COUNTRIES from pyrogram import Client, filters from pyrogram.types import CallbackQuery, InlineKeyboardButton, InlineKeyboardMarkup, Message TASKS: dict[int, dict[str, int]] = {} @Client.on_callback_query(filters.regex("get_countries")) @inject async def current_countries( client: Client, update: CallbackQuery, user: User = Depends(get_user) ) -> None: m = "🌐جارٍ العمل على هذه الدول:" for index, country in enumerate(user.config.countries): m += f"\n{index+1}. {COUNTRIES[country.code]} [{country.numbers_count}] (`{country.code}`)" await update.edit_message_text( m, reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text="🔙 عودة", callback_data="main_menu")]] ), ) @Client.on_message(filters.regex(r"^\/work (?P\w{2})\s?(?P\d+)?$")) @inject async def start_work(client: Client, update: Message, user: User = Depends(get_user)) -> None: country_code: str = update.matches[0].group("country_code") numbers_count = update.matches[0].group("numbers_count") if country_code not in COUNTRIES: await update.reply("يبدو أنّك أرسلت رمز دولة غير صالح⚠️ ") return if not numbers_count or numbers_count == 0: numbers_count = math.inf async with get_locker(user.user_id): await user.sync() user.config.countries.append(CountryConfig(code=country_code, numbers_count=numbers_count)) await user.save() await update.reply("حسناً بدأت عمليّة الصيد 🎣") @Client.on_message(filters.regex(r"^\/stop\s?(?P\w{2})?$")) @inject async def stop_work(client: Client, update: Message, user: User = Depends(get_user)) -> None: country_code = update.matches[0].group("country_code") if country_code and country_code not in COUNTRIES: await update.reply("يبدو أنّك أرسلت رمز دولة غير صالح⚠️ ") return async with get_locker(user.user_id): await user.sync() if country_code: index = None for i, country in enumerate(user.config.countries): index = i if country.code == country_code else index if index is not None: user.config.countries.pop(index) await update.reply(f"تم إيقاف العمل على أرقام من {COUNTRIES[country_code]}") break if index is None: await update.reply(f"العمل على هذا البلد غير موجود مسبقاً {COUNTRIES[country_code]}") else: user.config.countries = [] await update.reply("تم إيقاف جميع العمليات لكل الدول 🛑") await user.save()