42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from datetime import UTC, datetime
|
|
|
|
from pyrogram import raw, utils
|
|
|
|
from userbot.modules.client import PyroClient
|
|
from userbot.modules.raw_json import raw_json
|
|
from userbot.modules.read_receipts import repository
|
|
from utils.events import notify_bg_event
|
|
|
|
HANDLES = (raw.types.UpdateReadHistoryOutbox, raw.types.UpdateReadChannelOutbox)
|
|
|
|
|
|
def _watermark(update: raw.base.Update) -> tuple[int, int] | None:
|
|
if isinstance(update, raw.types.UpdateReadHistoryOutbox):
|
|
return utils.get_peer_id(update.peer), update.max_id
|
|
if isinstance(update, raw.types.UpdateReadChannelOutbox):
|
|
peer = raw.types.PeerChannel(channel_id=update.channel_id)
|
|
return utils.get_peer_id(peer), update.max_id
|
|
return None
|
|
|
|
|
|
async def handle(
|
|
client: PyroClient, update: raw.base.Update, _users: dict, _chats: dict
|
|
) -> None:
|
|
ctx = client.capture
|
|
watermark = _watermark(update)
|
|
if ctx is None or watermark is None:
|
|
return
|
|
chat_id, max_id = watermark
|
|
await repository.insert_read(
|
|
ctx.pool,
|
|
ctx.account_id,
|
|
chat_id,
|
|
chat_id,
|
|
datetime.now(UTC),
|
|
max_id,
|
|
raw_json(update),
|
|
)
|
|
await notify_bg_event(
|
|
ctx.pool, "receipt", ctx.account_id, chat_id=chat_id, message_id=max_id
|
|
)
|