feat(api,userbot,frontend): search peers without chats and start tracking them
This commit is contained in:
1 parent
dcf95bd9d4
commit
92fd20137e
21 files changed
+936
-65
No files matched your search
@@ -1,16 +1,14 @@
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from pyrogram import Client
|
||||
from pyrogram.errors import BadRequest, Forbidden
|
||||
from pyrogram.types import Chat, User
|
||||
from pyrogram.types import User
|
||||
|
||||
from userbot.modules.avatars import note_avatar
|
||||
from userbot.modules.capture.context import CaptureContext
|
||||
from userbot.modules.groups.repository import insert_chat_history
|
||||
from userbot.modules.jobs.context import JobContext
|
||||
from userbot.modules.jobs.registry import register
|
||||
from userbot.modules.profiles.parse import snapshot_from_chat, snapshot_from_high_level
|
||||
from userbot.modules.profiles.parse import snapshot_from_high_level
|
||||
from userbot.modules.profiles.repository import write_profile
|
||||
from userbot.modules.profiles.snapshots import save_group, save_private
|
||||
|
||||
SAVE_EVERY = 100
|
||||
USERS_BATCH = 200
|
||||
@@ -21,16 +19,6 @@ ON CONFLICT (account_id, chat_id) DO UPDATE SET updated_at = now()
|
||||
"""
|
||||
|
||||
|
||||
async def _save_private(ctx: CaptureContext, chat: Chat, chat_id: int) -> bool:
|
||||
fields, photo_file_id, photo_unique_id = snapshot_from_chat(chat)
|
||||
await write_profile(ctx.pool, ctx.account_id, chat_id, fields, str(chat))
|
||||
if photo_file_id and photo_unique_id:
|
||||
await note_avatar(
|
||||
ctx.pool, ctx.account_id, chat_id, "peer", photo_unique_id, photo_file_id
|
||||
)
|
||||
return bool(fields.first_name or fields.last_name or fields.username)
|
||||
|
||||
|
||||
async def _enrich_users(client: Client, ctx: CaptureContext, ids: list[int]) -> None:
|
||||
for start in range(0, len(ids), USERS_BATCH):
|
||||
batch = ids[start : start + USERS_BATCH]
|
||||
@@ -55,28 +43,6 @@ async def _enrich_users(client: Client, ctx: CaptureContext, ids: list[int]) ->
|
||||
)
|
||||
|
||||
|
||||
async def _save_group(ctx: CaptureContext, chat: Chat, chat_id: int) -> None:
|
||||
photo = chat.photo
|
||||
photo_unique_id = photo.big_photo_unique_id if photo else None
|
||||
photo_file_id = photo.big_file_id if photo else None
|
||||
await insert_chat_history(
|
||||
ctx.pool,
|
||||
ctx.account_id,
|
||||
chat_id,
|
||||
0,
|
||||
"meta",
|
||||
chat.title,
|
||||
photo_unique_id,
|
||||
None,
|
||||
datetime.now(UTC),
|
||||
str(chat),
|
||||
)
|
||||
if photo_file_id and photo_unique_id:
|
||||
await note_avatar(
|
||||
ctx.pool, ctx.account_id, chat_id, "chat", photo_unique_id, photo_file_id
|
||||
)
|
||||
|
||||
|
||||
@register("sync_dialogs")
|
||||
async def sync_dialogs(ctx: JobContext) -> None:
|
||||
client = ctx.client
|
||||
@@ -94,10 +60,10 @@ async def sync_dialogs(ctx: JobContext) -> None:
|
||||
chat_id = chat.id
|
||||
try:
|
||||
if chat_id > 0:
|
||||
if not await _save_private(capture, chat, chat_id):
|
||||
if not await save_private(capture, chat):
|
||||
nameless.append(chat_id)
|
||||
else:
|
||||
await _save_group(capture, chat, chat_id)
|
||||
await save_group(capture, chat)
|
||||
except (BadRequest, Forbidden):
|
||||
pass
|
||||
await ctx.pool.execute(_UPSERT_DIALOG, ctx.account_id, chat_id)
|
||||
|
||||
Reference in new issue
Block a user