banme 消息 60s 后自动删除

This commit is contained in:
xtaodada 2023-05-31 22:10:42 +08:00
parent 7950b18020
commit 0137119990
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 13 additions and 3 deletions

View File

@ -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)

View File

@ -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)