45 lines
1.3 KiB
Python
45 lines
1.3 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(["ban_failed"], prefixes=["/"]) # type: ignore
|
||
|
)
|
||
|
async def command_ban_failed(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.ban_failed:
|
||
|
await message.reply_text(
|
||
|
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)
|