2022-06-20 13:55:14 +00:00
|
|
|
import contextlib
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
import pytz
|
|
|
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
2024-09-28 13:57:55 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2023-01-16 06:31:04 +00:00
|
|
|
from pagermaid.config import Config
|
2024-09-28 13:57:55 +00:00
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
from pagermaid.enums import Message
|
2022-06-20 13:55:14 +00:00
|
|
|
|
2023-01-16 06:31:04 +00:00
|
|
|
scheduler = AsyncIOScheduler(timezone=Config.TIME_ZONE)
|
2022-06-20 13:55:14 +00:00
|
|
|
|
|
|
|
|
2024-09-28 13:57:55 +00:00
|
|
|
async def delete_message(message: "Message") -> bool:
|
2022-06-20 13:55:14 +00:00
|
|
|
with contextlib.suppress(Exception):
|
|
|
|
await message.delete()
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2024-09-28 13:57:55 +00:00
|
|
|
def add_delete_message_job(message: "Message", delete_seconds: int = 60):
|
2022-06-20 13:55:14 +00:00
|
|
|
scheduler.add_job(
|
2023-03-12 03:56:01 +00:00
|
|
|
delete_message,
|
|
|
|
"date",
|
2022-06-20 13:55:14 +00:00
|
|
|
id=f"{message.chat.id}|{message.id}|delete_message",
|
|
|
|
name=f"{message.chat.id}|{message.id}|delete_message",
|
|
|
|
args=[message],
|
2023-03-12 03:56:01 +00:00
|
|
|
run_date=datetime.datetime.now(pytz.timezone(Config.TIME_ZONE))
|
|
|
|
+ datetime.timedelta(seconds=delete_seconds),
|
|
|
|
replace_existing=True,
|
|
|
|
)
|