File size: 1,160 Bytes
487b853
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from pyrogram import Client, filters
from pyrogram.types import CallbackQuery
from chatbot.plugins.user_database import users_collection
from chatbot.plugins.languages import LANGUAGES
from chatbot.plugins.keyboards import get_language_keyboard

@Client.on_callback_query(filters.regex(r"^lang_"))
async def set_language(client: Client, callback_query: CallbackQuery):
    lang_code = callback_query.data.split("_")[1]
    user_id = callback_query.from_user.id
    await users_collection.update_one(
        {"user_id": user_id},
        {"$set": {"language": lang_code}},
        upsert=True
    )
    await callback_query.answer(f"Language set to {LANGUAGES.get(lang_code, 'Selected Language')}")
    await callback_query.message.edit_text(
        f"Your language has been set to **{LANGUAGES.get(lang_code, 'Selected Language')}**.",
        reply_markup=None  # Remove the keyboard after selection
    )

@Client.on_callback_query(filters.regex("^cancel$"))
async def cancel_selection(client: Client, callback_query: CallbackQuery):
    await callback_query.answer("Language selection canceled.", show_alert=True)
    await callback_query.message.delete()