feat demote_all: demote all admins in chat.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
|
||||
from pyrogram.enums import ChatMemberStatus
|
||||
from pyrogram.errors import FloodWait
|
||||
from pyrogram.types import ChatPrivileges, User
|
||||
|
||||
from app import BOT, Message
|
||||
@@ -82,3 +83,37 @@ async def promote_or_demote(bot: BOT, message: Message) -> None:
|
||||
await response.edit(text=response_text)
|
||||
except Exception as e:
|
||||
await response.edit(text=e, del_in=10, block=True)
|
||||
|
||||
|
||||
@BOT.add_cmd(cmd="demote_all", allow_sudo=False)
|
||||
async def demote_all(bot: BOT, message: Message):
|
||||
me = await bot.get_chat_member(message.chat.id, bot.me.id)
|
||||
if me.status != ChatMemberStatus.OWNER:
|
||||
await message.reply("Cannot Demote all without being Chat Owner.")
|
||||
return
|
||||
|
||||
resp = await message.reply("Hang on demoting all Admins...")
|
||||
count = 0
|
||||
|
||||
async for member in bot.get_chat_members(message.chat.id):
|
||||
if member.status != ChatMemberStatus.ADMINISTRATOR:
|
||||
continue
|
||||
|
||||
try:
|
||||
await bot.promote_chat_member(
|
||||
chat_id=message.chat.id,
|
||||
user_id=member.user.id,
|
||||
privileges=DEMOTE_PRIVILEGES,
|
||||
)
|
||||
except FloodWait as f:
|
||||
await asyncio.sleep(f.value + 10)
|
||||
await bot.promote_chat_member(
|
||||
chat_id=message.chat.id,
|
||||
user_id=member.user.id,
|
||||
privileges=DEMOTE_PRIVILEGES,
|
||||
)
|
||||
await asyncio.sleep(0.5)
|
||||
count += 1
|
||||
|
||||
await resp.edit(f"Demoted <b>{count}</b> admins in {message.chat.title}.")
|
||||
await resp.log()
|
||||
|
||||
Reference in New Issue
Block a user