feat zombies: use until_date to clean up restriced users section.
This commit is contained in:
@@ -1,37 +1,49 @@
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from pyrogram.enums import ChatMemberStatus
|
||||
from pyrogram.errors import FloodWait
|
||||
|
||||
from app import BOT, Message, bot
|
||||
from app import BOT, Message
|
||||
|
||||
ADMIN_STATUS = {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}
|
||||
|
||||
|
||||
@bot.add_cmd(cmd="zombies")
|
||||
@BOT.add_cmd(cmd="zombies")
|
||||
async def clean_zombies(bot: BOT, message: Message):
|
||||
me = await bot.get_chat_member(message.chat.id, bot.me.id)
|
||||
if me.status not in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
|
||||
if me.status not in ADMIN_STATUS:
|
||||
await message.reply("Cannot clean zombies without being admin.")
|
||||
return
|
||||
|
||||
zombies = 0
|
||||
admin_zombies = 0
|
||||
|
||||
response = await message.reply("Cleaning Zombies....\nthis may take a while")
|
||||
|
||||
async for member in bot.get_chat_members(message.chat.id):
|
||||
try:
|
||||
if member.user.is_deleted:
|
||||
if member.status in {
|
||||
ChatMemberStatus.ADMINISTRATOR,
|
||||
ChatMemberStatus.OWNER,
|
||||
}:
|
||||
|
||||
if member.status in ADMIN_STATUS:
|
||||
admin_zombies += 1
|
||||
continue
|
||||
|
||||
zombies += 1
|
||||
|
||||
await bot.ban_chat_member(
|
||||
chat_id=message.chat.id, user_id=member.user.id
|
||||
chat_id=message.chat.id,
|
||||
user_id=member.user.id,
|
||||
until_date=datetime.utcnow() + timedelta(seconds=60),
|
||||
)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
except FloodWait as e:
|
||||
await asyncio.sleep(e.value + 3)
|
||||
|
||||
resp_str = f"Cleaned <b>{zombies}</b> zombies."
|
||||
|
||||
if admin_zombies:
|
||||
resp_str += f"\n<b>{admin_zombies}</b> Admin Zombie(s) not Removed."
|
||||
|
||||
await response.edit(resp_str)
|
||||
|
||||
Reference in New Issue
Block a user