sycgram/plugins/kick.py

54 lines
1.8 KiB
Python
Raw Permalink Normal View History

2022-04-06 14:39:27 +00:00
import asyncio
from inspect import Parameter
from core import command
2022-04-09 05:47:04 +00:00
from loguru import logger
2022-04-06 14:39:27 +00:00
from pyrogram import Client
from pyrogram.errors import FloodWait, RPCError
from pyrogram.types import Message
2022-04-09 05:47:04 +00:00
from tools.constants import TG_BOT, TG_PRIVATE
from tools.helpers import delete_this, kick_one, show_cmd_tip
2022-04-06 14:39:27 +00:00
@Client.on_message(command('sb'))
async def sb(cli: Client, msg: Message):
"""回复一条消息,将在所有共同且拥有管理踢人权限的群组中踢出目标消息的主人"""
cmd, *_ = Parameter.get(msg)
reply_to_message = msg.reply_to_message
2022-04-09 05:47:04 +00:00
if not reply_to_message or msg.chat.type in [TG_BOT, TG_PRIVATE]:
return await show_cmd_tip(msg, cmd)
2022-04-06 14:39:27 +00:00
counter, target = 0, reply_to_message.from_user
common_groups = await target.get_common_chats()
logger.info(
f"Start to kick <{target.first_name}{target.last_name} <{target.id}>")
for chat in common_groups:
try:
if await kick_one(cli, chat.id, target.id):
counter = counter + 1
except FloodWait as e:
await asyncio.sleep(e.x)
if await kick_one(cli, chat.id, target.id):
counter = counter + 1
logger.success(
f"Kick this user out of <{chat.tile} {chat.id}>"
)
except RPCError as e:
logger.warning(
f"No admin rights in this group <{chat.title} {chat.id}>")
logger.warning(e)
# delete this user all messages
await cli.delete_user_history(msg.chat.id, target.id)
# Inform
text = f"😂 Kick {target.mention(style='md')} in {counter} common groups."
await msg.edit_text(text)
await asyncio.sleep(10)
await delete_this(msg)
# log
logger.success(f"{cmd} | {text}")
await logger.complete()