From 01371199907e3bd477ec9950a654acafef70d730 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Wed, 31 May 2023 22:10:42 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20banme=20=E6=B6=88=E6=81=AF=2060s=20?= =?UTF-8?q?=E5=90=8E=E8=87=AA=E5=8A=A8=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/banme.py | 9 ++++++--- scheduler.py | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/banme.py b/modules/banme.py index de21f97..123fa89 100644 --- a/modules/banme.py +++ b/modules/banme.py @@ -6,6 +6,7 @@ from pyrogram import Client, filters from pyrogram.enums import ChatMemberStatus from pyrogram.types import Message, ChatPermissions from init import user_me +from scheduler import reply_message @Client.on_message( @@ -20,6 +21,8 @@ async def ban_me_command(client: Client, message: Message): multiple = int(multiple_text.groups()[0]) else: multiple = 1 + if multiple > 5 or multiple < 1: + multiple = 1 # 检查bot和用户身份 if ( @@ -29,14 +32,14 @@ async def ban_me_command(client: Client, message: Message): return if not message.from_user: # 频道 - await message.reply("你是个频道, 别来凑热闹OvO") + await reply_message(message, "你是个频道, 别来凑热闹OvO") return member = ( await client.get_chat_member(message.chat.id, message.from_user.id) ).status if member in [ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER]: - await message.reply("你也是个管理, 别来凑热闹OvO") + await reply_message(message, "你也是个管理, 别来凑热闹OvO") return # 随机禁言时间 @@ -50,4 +53,4 @@ async def ban_me_command(client: Client, message: Message): ChatPermissions(), datetime.now() + timedelta(seconds=act_time), ) - await message.reply(msg) + await reply_message(message, msg) diff --git a/scheduler.py b/scheduler.py index 6092264..6f4925b 100644 --- a/scheduler.py +++ b/scheduler.py @@ -26,3 +26,10 @@ def add_delete_message_job(message: Message, delete_seconds: int = 60): + datetime.timedelta(seconds=delete_seconds), replace_existing=True, ) + + +async def reply_message(msg: Message, text: str, delete_origin: bool = True, *args, **kwargs): + reply_msg = await msg.reply(text, *args, **kwargs) + add_delete_message_job(reply_msg) + if delete_origin: + add_delete_message_job(msg)