mirror of
https://github.com/TeamPGM/PagerMaid_Plugins_Pyro.git
synced 2024-11-25 10:02:17 +00:00
clear_blocked 清理所有已拉黑用户
This commit is contained in:
parent
631c3c5d6d
commit
34b32a2048
50
clear_blocked/main.py
Normal file
50
clear_blocked/main.py
Normal file
@ -0,0 +1,50 @@
|
||||
import contextlib
|
||||
|
||||
from asyncio import sleep
|
||||
|
||||
from pyrogram.errors import FloodWait
|
||||
from pyrogram.raw.functions.contacts import GetBlocked
|
||||
|
||||
from pagermaid.listener import listener
|
||||
from pagermaid.enums import Client, Message
|
||||
|
||||
|
||||
async def clear_blocked_func(client: Client, message: Message):
|
||||
offset = 0
|
||||
success, failed, skipped = 0, 0, 0
|
||||
while True:
|
||||
blocked = await client.invoke(GetBlocked(offset=offset, limit=100))
|
||||
if not blocked.users:
|
||||
break
|
||||
for user in blocked.users:
|
||||
if (user.bot or user.scam or user.fake) and not user.deleted:
|
||||
skipped += 1
|
||||
continue
|
||||
try:
|
||||
await client.unblock_user(user.id)
|
||||
success += 1
|
||||
except FloodWait as e:
|
||||
with contextlib.suppress(Exception):
|
||||
await message.edit(f"🧹 Clearing blocked users...\n\nWill run after {e.value} seconds.")
|
||||
await sleep(e.value + 1)
|
||||
await client.unblock_user(user.id)
|
||||
success += 1
|
||||
except Exception:
|
||||
failed += 1
|
||||
offset += 100
|
||||
if offset > blocked.count:
|
||||
break
|
||||
return success, failed, skipped
|
||||
|
||||
|
||||
@listener(command="clear_blocked", description="Clear blocked users.", need_admin=True)
|
||||
async def clear_blocked(client: Client, message: Message):
|
||||
""" Clear blocked users. """
|
||||
message: Message = await message.edit("🧹 Clearing blocked users...")
|
||||
try:
|
||||
success, failed, skipped = await clear_blocked_func(client, message)
|
||||
except Exception as e:
|
||||
await message.edit(f"❌ Failed to clear blocked users: {e}")
|
||||
return
|
||||
await message.edit(f"🧹 Clear blocked users complete. \n"
|
||||
f"Success: {success}, Failed: {failed}, Skipped: {skipped}")
|
Loading…
Reference in New Issue
Block a user