30 lines
807 B
Python
30 lines
807 B
Python
import json
|
|
from typing import Literal
|
|
|
|
import asyncpg
|
|
|
|
BG_EVENTS_CHANNEL = "bg_events"
|
|
|
|
EventKind = Literal["message", "edit", "delete", "reaction", "presence", "receipt"]
|
|
|
|
|
|
async def notify_bg_event( # noqa: PLR0913
|
|
pool: asyncpg.Pool,
|
|
kind: EventKind,
|
|
account_id: int,
|
|
*,
|
|
chat_id: int | None = None,
|
|
message_id: int | None = None,
|
|
message_ids: list[int] | None = None,
|
|
) -> None:
|
|
payload: dict[str, object] = {"kind": kind, "account_id": account_id}
|
|
if chat_id is not None:
|
|
payload["chat_id"] = chat_id
|
|
if message_id is not None:
|
|
payload["message_id"] = message_id
|
|
if message_ids is not None:
|
|
payload["message_ids"] = message_ids
|
|
await pool.execute(
|
|
"SELECT pg_notify($1, $2)", BG_EVENTS_CHANNEL, json.dumps(payload)
|
|
)
|