feat: add realtime capturing
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
from pyrogram.types import Message
|
||||
|
||||
from userbot import PyroClient
|
||||
from userbot.modules.capture import repository
|
||||
from userbot.modules.capture.repository import CHANNEL_ID_THRESHOLD
|
||||
|
||||
|
||||
@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)
|
||||
for chat_id, ids in channels.items():
|
||||
await repository.mark_deleted_channel(ctx.pool, ctx.account_id, chat_id, ids)
|
||||
|
||||
|
||||
handlers = on_deleted_messages.handlers
|
||||
Reference in New Issue
Block a user