PagerMaid_Plugins_Pyro/getdel/main.py

47 lines
1.7 KiB
Python
Raw Normal View History

2022-07-22 05:20:13 +00:00
from datetime import datetime, timedelta
from pyrogram.errors import FloodWait, ChatAdminRequired, UserAdminInvalid
from pagermaid.listener import listener
2022-09-01 08:28:48 +00:00
from pagermaid.enums import Client, Message
2022-07-22 05:20:13 +00:00
2023-07-01 12:18:58 +00:00
@listener(
command="getdel",
groups_only=True,
need_admin=True,
parameters="清理",
description="获取当前群组的死号数。",
)
2022-09-01 08:28:48 +00:00
async def get_del(client: Client, message: Message):
2023-07-01 12:18:58 +00:00
"""PagerMaid get_del."""
2022-07-22 05:20:13 +00:00
need_kick = message.arguments
member_count = 0
try:
2023-07-01 12:18:58 +00:00
await message.edit("遍历成员中。。。")
2022-07-22 05:20:13 +00:00
if need_kick:
2023-07-01 12:18:58 +00:00
user = await client.get_chat_member(
message.chat.id, (await client.get_me()).id
)
2022-07-22 05:20:13 +00:00
need_kick = bool(user.privileges and user.privileges.can_restrict_members)
2022-09-01 08:28:48 +00:00
async for member in client.get_chat_members(message.chat.id):
2022-07-22 05:20:13 +00:00
if member.user.is_deleted:
member_count += 1
if need_kick:
try:
2022-09-01 08:28:48 +00:00
await client.ban_chat_member(
2022-07-22 05:20:13 +00:00
message.chat.id,
member.user.id,
2023-07-01 12:18:58 +00:00
datetime.now() + timedelta(minutes=5),
)
2022-07-22 05:20:13 +00:00
except FloodWait:
2023-07-01 12:18:58 +00:00
return await message.edit("处理失败,您已受到 TG 服务器限制。")
2022-07-22 05:20:13 +00:00
except UserAdminInvalid:
pass
if need_kick:
2023-07-01 12:18:58 +00:00
await message.edit(f"此群组的死号数:`{member_count}`,并且已经清理完毕。")
2022-07-22 05:20:13 +00:00
else:
2023-07-01 12:18:58 +00:00
await message.edit(f"此群组的死号数:`{member_count}`。")
2022-07-22 05:20:13 +00:00
except ChatAdminRequired:
await message.edit("你好像并不拥有封禁用户权限。")