Esempio n. 1
0
async def set_language_callback(bot: Amime, callback: CallbackQuery):
    message = callback.message
    chat = message.chat
    user = callback.from_user
    if not user:
        return
    lang = callback._lang
    code: str = ""
    user_code = user.language_code or "en"
    if "." in user_code:
        user_code = user_code.split(".")[0]
    if user_code not in lang.strings.keys():
        user_code = "en"

    if await filters.private(bot, message):
        code = (await Users.get_or_create(
            {
                "name": user.first_name,
                "username": user.username or "",
                "language_bot": user_code,
                "language_anime": user_code,
                "is_collaborator": False,
            },
            id=user.id,
        ))[0].language_bot
    else:
        code = (await Chats.get_or_create(
            {
                "title": chat.title,
                "username": chat.username or "",
                "language": "en",
            },
            id=chat.id,
        ))[0].language
    callback._lang = lang.get_language(code)
Esempio n. 2
0
async def deflang(c: Client, cq: CallbackQuery):
    cq._lang = langs.get_language(os.getenv("LANGUAGE"))