import logging
from pyrogram import filters
from pyrogram.enums.chat_member_status import ChatMemberStatus
from pyrogram.types import Message
from classes.pyroclient import PyroClient
logger = logging.getLogger(__name__)
@PyroClient.on_message(
~filters.scheduled
& filters.group
& filters.command(["ban_failed"], prefixes=["/"]) # type: ignore
)
async def command_ban_failed(app: PyroClient, message: Message):
group = await app.find_group(message.chat.id)
locale = group.select_locale(app, message.from_user)
if (message.sender_chat is not None and (message.sender_chat.id != group.id)) or (
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.ban_failed:
app._("ban_failed_disabled", "messages", locale=locale)
else:
await message.reply_text(app._("ban_failed_enabled", "messages", locale=locale))
logger.info(
"Ban on fail in group %s has been set to %s",
group.id,
not group.ban_failed,
await group.set_ban_failed(not group.ban_failed)