feat: add realtime capturing
This commit is contained in:
1 parent
920a0235e2
commit
3c1a12750c
29 files changed
+967
-47
No files matched your search
@@ -0,0 +1,49 @@
|
||||
from pyrogram import raw, utils
|
||||
|
||||
from userbot import PyroClient
|
||||
from userbot.modules.capture import repository
|
||||
from userbot.modules.capture.chat_meta import meta_from_peer
|
||||
|
||||
HANDLES = (raw.types.UpdateMessageReactions,)
|
||||
|
||||
|
||||
def _reaction_key(reaction: raw.base.Reaction) -> str | None:
|
||||
if isinstance(reaction, raw.types.ReactionEmoji):
|
||||
return reaction.emoticon
|
||||
if isinstance(reaction, raw.types.ReactionCustomEmoji):
|
||||
return f"custom:{reaction.document_id}"
|
||||
return None
|
||||
|
||||
|
||||
def _parse_recent(reactions: raw.base.MessageReactions) -> list[tuple[int, str]]:
|
||||
recent = getattr(reactions, "recent_reactions", None) or []
|
||||
parsed: list[tuple[int, str]] = []
|
||||
for peer_reaction in recent:
|
||||
key = _reaction_key(peer_reaction.reaction)
|
||||
if key is None:
|
||||
continue
|
||||
try:
|
||||
peer_id = utils.get_peer_id(peer_reaction.peer_id)
|
||||
except (ValueError, AttributeError):
|
||||
continue
|
||||
parsed.append((peer_id, key))
|
||||
return parsed
|
||||
|
||||
|
||||
async def handle(
|
||||
client: PyroClient,
|
||||
update: raw.types.UpdateMessageReactions,
|
||||
users: dict,
|
||||
chats: dict,
|
||||
) -> None:
|
||||
ctx = client.capture
|
||||
if ctx is None:
|
||||
return
|
||||
meta = meta_from_peer(update.peer, chats, users, ctx.contacts.ids)
|
||||
toggles = ctx.resolve(meta)
|
||||
if not toggles.reactions:
|
||||
return
|
||||
current = _parse_recent(update.reactions)
|
||||
await repository.sync_reactions(
|
||||
ctx.pool, ctx.account_id, meta.chat_id, update.msg_id, current
|
||||
)
|
||||
Reference in new issue
Block a user