Create handlers.py
Browse files- chatbot/plugins/handlers.py +25 -0
chatbot/plugins/handlers.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pyrogram import Client, filters
|
2 |
+
from pyrogram.types import CallbackQuery
|
3 |
+
from chatbot.plugins.user_database import users_collection
|
4 |
+
from chatbot.plugins.languages import LANGUAGES
|
5 |
+
from chatbot.plugins.keyboards import get_language_keyboard
|
6 |
+
|
7 |
+
@Client.on_callback_query(filters.regex(r"^lang_"))
|
8 |
+
async def set_language(client: Client, callback_query: CallbackQuery):
|
9 |
+
lang_code = callback_query.data.split("_")[1]
|
10 |
+
user_id = callback_query.from_user.id
|
11 |
+
await users_collection.update_one(
|
12 |
+
{"user_id": user_id},
|
13 |
+
{"$set": {"language": lang_code}},
|
14 |
+
upsert=True
|
15 |
+
)
|
16 |
+
await callback_query.answer(f"Language set to {LANGUAGES.get(lang_code, 'Selected Language')}")
|
17 |
+
await callback_query.message.edit_text(
|
18 |
+
f"Your language has been set to **{LANGUAGES.get(lang_code, 'Selected Language')}**.",
|
19 |
+
reply_markup=None # Remove the keyboard after selection
|
20 |
+
)
|
21 |
+
|
22 |
+
@Client.on_callback_query(filters.regex("^cancel$"))
|
23 |
+
async def cancel_selection(client: Client, callback_query: CallbackQuery):
|
24 |
+
await callback_query.answer("Language selection canceled.", show_alert=True)
|
25 |
+
await callback_query.message.delete()
|