|
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 |
|
) |
|
|
|
@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() |