import contextlib
from asyncio import sleep
from pyrogram.enums import ChatType
from pyrogram.errors import (
ChatAdminRequired,
FloodWait,
PeerIdInvalid,
UserAdminInvalid,
UsernameInvalid,
)
from pyrogram.types import Chat
from pagermaid.dependence import add_delete_message_job
from pagermaid.listener import listener
from pagermaid.services import bot
from pagermaid.enums import Message
from pagermaid.utils import lang
from pagermaid.utils.bot_utils import log
def mention_group(chat: Chat):
return (
f'{chat.title}'
if chat.username
else f"{chat.title}
"
)
async def ban_one(chat: Chat, uid):
await bot.ban_chat_member(chat.id, uid)
async def delete_all_messages(chat: Chat, uid):
await bot.delete_user_history(chat.id, uid)
async def check_uid(chat: Chat, uid: str):
channel = False
with contextlib.suppress(ValueError):
uid = int(uid)
if uid < 0:
channel = True
try:
await bot.get_chat_member(chat.id, uid)
except ChatAdminRequired:
with contextlib.suppress(PeerIdInvalid):
chat = await bot.get_chat(uid)
uid = chat.id
if chat.type in [ChatType.CHANNEL, ChatType.SUPERGROUP, ChatType.GROUP]:
channel = True
return uid, channel
async def get_uid(chat: Chat, message: Message):
uid = None
channel = False
delete_all = True
sender = None
if reply := message.reply_to_message:
if sender := reply.from_user:
uid = sender.id
if sender := reply.sender_chat:
uid = sender.id
channel = True
if message.arguments:
delete_all = False
elif len(message.parameter) == 2:
uid, channel = await check_uid(chat, message.parameter[0])
delete_all = False
elif len(message.parameter) == 1:
uid, channel = await check_uid(chat, message.parameter[0])
return uid, channel, delete_all, sender
@listener(
command="sb",
description=lang("sb_des"),
need_admin=True,
groups_only=True,
parameters="[reply|id|username>