PagerMaid-Pyro/pagermaid/dependence/_scheduler.py
xtaodada a941308d17
Some checks failed
Docker Dev Build / docker build and publish (push) Failing after 13s
Docker Build / docker build and publish (push) Failing after 11s
🔖 Update to v1.5.0
这是一项破坏性变更,目录结构进行了重组,无核心功能变化
2024-09-28 22:01:40 +08:00

33 lines
907 B
Python

import contextlib
import datetime
import pytz
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from typing import TYPE_CHECKING
from pagermaid.config import Config
if TYPE_CHECKING:
from pagermaid.enums import Message
scheduler = AsyncIOScheduler(timezone=Config.TIME_ZONE)
async def delete_message(message: "Message") -> bool:
with contextlib.suppress(Exception):
await message.delete()
return True
return False
def add_delete_message_job(message: "Message", delete_seconds: int = 60):
scheduler.add_job(
delete_message,
"date",
id=f"{message.chat.id}|{message.id}|delete_message",
name=f"{message.chat.id}|{message.id}|delete_message",
args=[message],
run_date=datetime.datetime.now(pytz.timezone(Config.TIME_ZONE))
+ datetime.timedelta(seconds=delete_seconds),
replace_existing=True,
)