2023-08-11 16:04:21 +03:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from pyrogram import filters
|
|
|
|
from pyrogram.enums.chat_member_status import ChatMemberStatus
|
|
|
|
from pyrogram.types import Message
|
|
|
|
|
|
|
|
from classes.pyroclient import PyroClient
|
2023-08-23 12:12:26 +03:00
|
|
|
from modules.utils import is_permitted
|
2023-08-11 16:04:21 +03:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@PyroClient.on_message(
|
|
|
|
~filters.scheduled
|
|
|
|
& filters.group
|
|
|
|
& filters.command(["language_auto"], prefixes=["/"]) # type: ignore
|
|
|
|
)
|
2023-08-14 13:12:07 +03:00
|
|
|
async def command_language_auto(app: PyroClient, message: Message):
|
2023-08-17 17:37:42 +03:00
|
|
|
group = await app.find_group(message.chat.id)
|
2023-08-11 16:04:21 +03:00
|
|
|
locale = group.select_locale(app, message.from_user)
|
|
|
|
|
2023-08-23 12:12:26 +03:00
|
|
|
if not (await is_permitted(app, group, message=message)):
|
2023-08-11 16:04:21 +03:00
|
|
|
await message.reply_text(
|
|
|
|
app._("permission_denied", "messages", locale=locale), quote=True
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
if group.locale_auto:
|
|
|
|
await message.reply_text(
|
|
|
|
app._("locale_auto_disabled", "messages", locale=locale).format(
|
|
|
|
default_locale=f"{app._('flag', 'metadata', locale=app.default_locale)} {app._('name', 'metadata', locale=app.default_locale)}"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
await message.reply_text(
|
|
|
|
app._("locale_auto_enabled", "messages", locale=locale).format(
|
|
|
|
default_locale=f"{app._('flag', 'metadata', locale=app.default_locale)} {app._('name', 'metadata', locale=app.default_locale)}"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
"Automatic locale selection of group %s has been set to %s (group: %s)",
|
|
|
|
group.id,
|
|
|
|
not group.locale_auto,
|
|
|
|
group.locale,
|
|
|
|
)
|
|
|
|
|
|
|
|
await group.set_locale_auto(not group.locale_auto)
|