autodelcmd 为常用命令增加自动删除 (#185)
All checks were successful
Github commit to telegram / build (push) Successful in 12s

This commit is contained in:
loneshore 2024-08-15 14:20:46 +08:00 committed by GitHub
parent 2698831a2a
commit f046a1a839
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 53 additions and 0 deletions

1
autodelcmd/DES.md Normal file
View File

@ -0,0 +1 @@
为常用命令增加自动删除

52
autodelcmd/main.py Normal file
View File

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