This repository has been archived on 2024-10-15. You can view files and clone it, but cannot push or open issues or pull requests.
PyrogramBotBase/plugins/language.py

46 lines
1.4 KiB
Python
Raw Normal View History

2023-08-18 00:04:38 +03:00
from typing import List
2023-08-03 22:29:47 +03:00
from pykeyboard import InlineButton, InlineKeyboard
from pyrogram import filters
from pyrogram.types import CallbackQuery, Message
2023-08-17 16:01:35 +03:00
from classes.callbacks import CallbackLanguage
2023-08-03 22:29:47 +03:00
from classes.pyroclient import PyroClient
2023-08-17 16:01:35 +03:00
@PyroClient.on_message(
2023-08-03 22:29:47 +03:00
~filters.scheduled & filters.private & filters.command(["language"], prefixes=["/"]) # type: ignore
)
async def command_language(app: PyroClient, message: Message):
2023-08-17 16:21:08 +03:00
user = await app.find_user(message.from_user)
2023-08-17 16:01:35 +03:00
2023-08-03 22:29:47 +03:00
keyboard = InlineKeyboard(row_width=2)
2023-08-18 00:04:38 +03:00
buttons: List[InlineButton] = []
2023-08-03 22:29:47 +03:00
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,
)
2023-08-17 16:01:35 +03:00
@PyroClient.on_callback_query(filters.regex(r"language:[\s\S]*")) # type: ignore
2023-08-03 22:29:47 +03:00
async def callback_language(app: PyroClient, callback: CallbackQuery):
2023-08-17 16:21:08 +03:00
user = await app.find_user(callback.from_user)
2023-08-17 16:01:35 +03:00
parsed = CallbackLanguage.from_callback(callback)
2023-08-03 22:29:47 +03:00
2023-08-17 16:01:35 +03:00
await user.update_locale(parsed.language)
2023-08-03 22:29:47 +03:00
await callback.answer(
2023-08-17 16:01:35 +03:00
app._("locale_set", "callbacks", locale=parsed.language).format(
locale=app._("name", "metadata", locale=parsed.language)
2023-08-03 22:29:47 +03:00
),
show_alert=True,
)