This repository has been archived on 2024-08-21. You can view files and clone it, but cannot push or open issues or pull requests.
EmojiCaptchaBot/plugins/commands/language_auto.py
2023-08-14 12:12:07 +02:00

52 lines
1.7 KiB
Python

import logging
from pyrogram import filters
from pyrogram.enums.chat_member_status import ChatMemberStatus
from pyrogram.types import Message
from classes.pyroclient import PyroClient
from classes.pyrogroup import PyroGroup
logger = logging.getLogger(__name__)
@PyroClient.on_message(
~filters.scheduled
& filters.group
& filters.command(["language_auto"], prefixes=["/"]) # type: ignore
)
async def command_language_auto(app: PyroClient, message: Message):
group = await PyroGroup.create_if_not_exists(message.chat.id, None, True)
locale = group.select_locale(app, message.from_user)
if (await app.get_chat_member(group.id, message.from_user.id)).status not in [
ChatMemberStatus.ADMINISTRATOR,
ChatMemberStatus.OWNER,
]:
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)