34 lines
1.2 KiB
Python
34 lines
1.2 KiB
Python
from pyrogram.types import Message
|
|
|
|
from userbot import PyroClient
|
|
from userbot.modules.capture import repository
|
|
from userbot.modules.capture.repository import CHANNEL_ID_THRESHOLD
|
|
from utils.events import notify_bg_event
|
|
|
|
|
|
@PyroClient.on_deleted_messages()
|
|
async def on_deleted_messages(client: PyroClient, messages: list[Message]) -> None:
|
|
ctx = client.capture
|
|
if ctx is None:
|
|
return
|
|
box: list[int] = []
|
|
channels: dict[int, list[int]] = {}
|
|
for message in messages:
|
|
chat = message.chat
|
|
chat_id = chat.id if chat is not None else None
|
|
if chat_id is None or chat_id > CHANNEL_ID_THRESHOLD:
|
|
box.append(message.id)
|
|
else:
|
|
channels.setdefault(chat_id, []).append(message.id)
|
|
if box:
|
|
await repository.mark_deleted_box(ctx.pool, ctx.account_id, box)
|
|
await notify_bg_event(ctx.pool, "delete", ctx.account_id, message_ids=box)
|
|
for chat_id, ids in channels.items():
|
|
await repository.mark_deleted_channel(ctx.pool, ctx.account_id, chat_id, ids)
|
|
await notify_bg_event(
|
|
ctx.pool, "delete", ctx.account_id, chat_id=chat_id, message_ids=ids
|
|
)
|
|
|
|
|
|
handlers = on_deleted_messages.handlers
|