feat(backend): watches fire on new, edited and deleted messages and on coming online, legacy keyword included
This commit is contained in:
1 parent
8ed9ca1951
commit
4469938f47
12 files changed
+501
-60
No files matched your search
@@ -25,9 +25,11 @@ async def on_deleted_messages(client: PyroClient, messages: list[Message]) -> No
|
||||
ctx.pending_deletes.remember(chat_id, ids)
|
||||
if box:
|
||||
await repository.mark_deleted_box(ctx.pool, ctx.account_id, box)
|
||||
await ctx.watches.on_deleted(None, 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 ctx.watches.on_deleted(chat_id, ids)
|
||||
await notify_bg_event(
|
||||
ctx.pool, "delete", ctx.account_id, chat_id=chat_id, message_ids=ids
|
||||
)
|
||||
|
||||
@@ -5,6 +5,7 @@ from userbot.modules.capture.chat_meta import meta_from_chat
|
||||
from userbot.modules.capture.message import message_row
|
||||
from userbot.modules.client import PyroClient
|
||||
from userbot.modules.media import capture_media
|
||||
from userbot.modules.watches.seen import seen_message
|
||||
from utils.events import notify_bg_event
|
||||
|
||||
|
||||
@@ -22,6 +23,7 @@ async def on_edited_message(client: PyroClient, message: Message) -> None:
|
||||
chat = message.chat
|
||||
chat_id = chat.id or 0
|
||||
meta = meta_from_chat(chat, ctx.contacts.ids)
|
||||
await ctx.watches.on_edit(seen_message(chat_id, message))
|
||||
toggles = ctx.resolve(meta)
|
||||
if not toggles.track_edits_deletes:
|
||||
return
|
||||
|
||||
@@ -5,6 +5,7 @@ from userbot.modules.capture.chat_meta import meta_from_chat
|
||||
from userbot.modules.client import PyroClient
|
||||
from userbot.modules.stt import is_transcribable
|
||||
from userbot.modules.stt.gate import safe_transcribe
|
||||
from userbot.modules.watches.seen import seen_message
|
||||
from utils.events import notify_bg_event
|
||||
|
||||
|
||||
@@ -20,7 +21,7 @@ async def on_message(client: PyroClient, message: Message) -> None:
|
||||
):
|
||||
return
|
||||
meta = meta_from_chat(message.chat, ctx.contacts.ids)
|
||||
await ctx.watches.on_text(meta.chat_id, message.id, message.text or message.caption)
|
||||
await ctx.watches.on_message(seen_message(meta.chat_id, message))
|
||||
toggles = ctx.resolve(meta)
|
||||
if not toggles.messages:
|
||||
return
|
||||
|
||||
@@ -13,19 +13,21 @@ async def on_user_status(client: PyroClient, user: User) -> None:
|
||||
ctx = client.capture
|
||||
if ctx is None or user.status is None:
|
||||
return
|
||||
at = datetime.now(UTC)
|
||||
status = user.status.name.lower()
|
||||
if ctx.resolve_peer(user.id, is_bot=bool(user.is_bot)).presence:
|
||||
await repository.insert_status(
|
||||
ctx.pool,
|
||||
ctx.account_id,
|
||||
user.id,
|
||||
datetime.now(UTC),
|
||||
user.status.name.lower(),
|
||||
at,
|
||||
status,
|
||||
user.last_online_date,
|
||||
user.next_offline_date,
|
||||
raw_json(user.raw),
|
||||
)
|
||||
await notify_bg_event(ctx.pool, "presence", ctx.account_id, chat_id=user.id)
|
||||
await ctx.watches.on_status(user.id, is_online=user.status.name.lower() == "online")
|
||||
await ctx.watches.on_status(user.id, status, at, user.last_online_date)
|
||||
|
||||
|
||||
handlers = on_user_status.handlers # ty: ignore[unresolved-attribute]
|
||||
@@ -20,4 +20,4 @@ async def handle(
|
||||
await repository.set_extracted_text(
|
||||
ctx.pool, ctx.account_id, meta.chat_id, update.msg_id, update.text
|
||||
)
|
||||
await ctx.watches.on_text(meta.chat_id, update.msg_id, update.text)
|
||||
await ctx.watches.on_transcript(meta.chat_id, update.msg_id, update.text)
|
||||
Reference in new issue
Block a user