2021-11-29 05:11:21 +00:00
|
|
|
import re
|
|
|
|
import random
|
|
|
|
|
2022-07-25 09:35:54 +00:00
|
|
|
from datetime import datetime, timedelta
|
2021-11-29 05:11:21 +00:00
|
|
|
from pyrogram import Client, filters
|
2022-07-25 09:35:54 +00:00
|
|
|
from pyrogram.enums import ChatMemberStatus
|
2021-11-29 05:11:21 +00:00
|
|
|
from pyrogram.types import Message, ChatPermissions
|
2021-12-08 09:10:31 +00:00
|
|
|
from init import user_me
|
2021-11-29 05:11:21 +00:00
|
|
|
|
|
|
|
|
2023-01-12 13:19:54 +00:00
|
|
|
@Client.on_message(
|
|
|
|
filters.incoming
|
|
|
|
& filters.group
|
|
|
|
& filters.command(["banme", f"banme@{user_me.username}"])
|
|
|
|
)
|
2021-11-29 05:11:21 +00:00
|
|
|
async def ban_me_command(client: Client, message: Message):
|
|
|
|
args = str(message.text).strip()
|
|
|
|
# 检查是否有倍数参数
|
2023-01-12 13:19:54 +00:00
|
|
|
if multiple_text := re.search(r"^(\d+)倍$", args):
|
2021-11-29 05:11:21 +00:00
|
|
|
multiple = int(multiple_text.groups()[0])
|
|
|
|
else:
|
|
|
|
multiple = 1
|
|
|
|
|
|
|
|
# 检查bot和用户身份
|
2023-01-12 13:19:54 +00:00
|
|
|
if (
|
|
|
|
await client.get_chat_member(message.chat.id, "self")
|
|
|
|
).status != ChatMemberStatus.ADMINISTRATOR:
|
|
|
|
await message.reply("Bot非群管理员, 无法执行禁言操作QAQ")
|
2021-11-29 05:11:21 +00:00
|
|
|
return
|
|
|
|
if not message.from_user:
|
|
|
|
# 频道
|
2023-01-12 13:19:54 +00:00
|
|
|
await message.reply("你是个频道, 别来凑热闹OvO")
|
2021-11-29 05:11:21 +00:00
|
|
|
return
|
2022-07-25 09:35:54 +00:00
|
|
|
|
2023-01-12 13:19:54 +00:00
|
|
|
member = (
|
|
|
|
await client.get_chat_member(message.chat.id, message.from_user.id)
|
|
|
|
).status
|
2022-07-25 09:35:54 +00:00
|
|
|
if member in [ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER]:
|
2023-01-12 13:19:54 +00:00
|
|
|
await message.reply("你也是个管理, 别来凑热闹OvO")
|
2021-11-29 05:11:21 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# 随机禁言时间
|
|
|
|
random_time = 2 * int(random.gauss(128 * multiple, 640 * multiple // 10))
|
2022-07-25 09:35:54 +00:00
|
|
|
act_time = 60 if random_time < 60 else min(random_time, 2591940)
|
2023-01-12 13:19:54 +00:00
|
|
|
msg = f"既然你那么想被口球的话, 那我就成全你吧!\n送你一份{act_time // 60}分{act_time % 60}秒禁言套餐哦, 谢谢惠顾~"
|
2021-11-29 05:11:21 +00:00
|
|
|
|
2023-01-12 13:19:54 +00:00
|
|
|
await client.restrict_chat_member(
|
|
|
|
message.chat.id,
|
|
|
|
message.from_user.id,
|
|
|
|
ChatPermissions(),
|
|
|
|
datetime.now() + timedelta(seconds=act_time),
|
|
|
|
)
|
2021-11-29 05:11:21 +00:00
|
|
|
await message.reply(msg)
|