47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
from typing import List
|
|
|
|
from pykeyboard import InlineButton, InlineKeyboard
|
|
from pyrogram import filters
|
|
from pyrogram.types import CallbackQuery, Message
|
|
|
|
from classes.callbacks import CallbackLanguage
|
|
from classes.pyroclient import PyroClient
|
|
from modules import custom_filters
|
|
|
|
|
|
@PyroClient.on_message(
|
|
~filters.scheduled & filters.private & filters.command(["language"], prefixes=["/"]) & ~custom_filters.context # type: ignore
|
|
)
|
|
async def command_language(app: PyroClient, message: Message):
|
|
user = await app.find_user(message.from_user)
|
|
|
|
keyboard = InlineKeyboard(row_width=2)
|
|
buttons: List[InlineButton] = []
|
|
|
|
for locale, data in app.in_every_locale("metadata").items():
|
|
buttons.append(
|
|
InlineButton(f"{data['flag']} {data['name']}", f"language:{locale}")
|
|
)
|
|
|
|
keyboard.add(*buttons)
|
|
|
|
await message.reply_text(
|
|
app._("locale_choice", "messages", locale=user.locale),
|
|
reply_markup=keyboard,
|
|
)
|
|
|
|
|
|
@PyroClient.on_callback_query(filters.regex(r"language:[\s\S]*")) # type: ignore
|
|
async def callback_language(app: PyroClient, callback: CallbackQuery):
|
|
user = await app.find_user(callback.from_user)
|
|
parsed = CallbackLanguage.from_callback(callback)
|
|
|
|
await user.update_locale(parsed.language)
|
|
|
|
await callback.answer(
|
|
app._("locale_set", "callbacks", locale=parsed.language).format(
|
|
locale=app._("name", "metadata", locale=parsed.language)
|
|
),
|
|
show_alert=True,
|
|
)
|