From f046a1a8394da42a14d216fdfdc9ba1f38d8511a Mon Sep 17 00:00:00 2001 From: loneshore <57182522+loneshore@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:20:46 +0800 Subject: [PATCH] =?UTF-8?q?autodelcmd=20=E4=B8=BA=E5=B8=B8=E7=94=A8?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=8A=A8=E5=88=A0?= =?UTF-8?q?=E9=99=A4=20(#185)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autodelcmd/DES.md | 1 + autodelcmd/main.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 autodelcmd/DES.md create mode 100644 autodelcmd/main.py diff --git a/autodelcmd/DES.md b/autodelcmd/DES.md new file mode 100644 index 0000000..edea21f --- /dev/null +++ b/autodelcmd/DES.md @@ -0,0 +1 @@ +为常用命令增加自动删除 \ No newline at end of file diff --git a/autodelcmd/main.py b/autodelcmd/main.py new file mode 100644 index 0000000..79bda51 --- /dev/null +++ b/autodelcmd/main.py @@ -0,0 +1,52 @@ +import contextlib + +from pagermaid.enums import Client, Message +from pagermaid.hook import Hook +from pagermaid.single_utils import sqlite + +@Hook.command_postprocessor() +async def auto_delete(client: Client, message: Message, command: str, sub_command: str): + if command in [ + "lang", + "alias", + "apt", + "apt_source", + "reload", + ]: + if message.parameter and message.parameter[0] in [ + "status", + "list", + ]: + await message.delay_delete(60) + else: + await message.delay_delete(10) + elif command in [ + "help", + "help_raw", + "id", + "ping", + "pingdc", + "stats", + "status", + "sysinfo", + ]: + await message.delay_delete(120) + elif command in [ + "speed", + "speedtest", + "v", + ]: + async for msg in client.get_chat_history(message.chat.id, limit=100): + if msg.from_user and msg.from_user.is_self: + await msg.delay_delete(120) + break + +@Hook.on_startup() +async def auto_delete_on_startup(client: Client): + data = sqlite.get("exit_msg", {}) + cid, mid = data.get("cid", 0), data.get("mid", 0) + if data and cid and mid: + with contextlib.suppress(Exception): + message: Message = await client.get_messages(cid, mid) + if message: + await message.delay_delete(10)