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
@@ -15,6 +15,7 @@ from userbot.modules.capture import capture_message
|
||||
from userbot.modules.capture.chat_meta import meta_from_chat
|
||||
from userbot.modules.client import PyroClient
|
||||
from userbot.modules.jobs import JobConsumer
|
||||
from userbot.modules.watches.seen import seen_message
|
||||
from utils.events import notify_bg_event
|
||||
from utils.jobs import enqueue
|
||||
from utils.logging import logger
|
||||
@@ -51,9 +52,11 @@ def _handlers(pool: asyncpg.Pool) -> tuple:
|
||||
if ctx is None or message.empty or message.chat is None or message.date is 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
|
||||
)
|
||||
seen = seen_message(meta.chat_id, message)
|
||||
if message.edit_date is None:
|
||||
await ctx.watches.on_message(seen)
|
||||
else:
|
||||
await ctx.watches.on_edit(seen)
|
||||
toggles = ctx.resolve(meta)
|
||||
if not toggles.messages:
|
||||
return
|
||||
@@ -115,6 +118,12 @@ class BotRegistry:
|
||||
for bot_id in list(self._running):
|
||||
await self._stop(bot_id)
|
||||
|
||||
async def refresh_watches(self) -> None:
|
||||
for running in list(self._running.values()):
|
||||
capture = getattr(running.client, "capture", None)
|
||||
if capture is not None:
|
||||
await capture.watches.refresh()
|
||||
|
||||
async def _adopt_dropped_in(self) -> None:
|
||||
unknown = tokens.stored_bot_ids() - await bots.known_bot_ids(self._pool)
|
||||
for bot_id in unknown:
|
||||
|
||||
Reference in new issue
Block a user