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
@@ -0,0 +1,50 @@
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from pyrogram.types import Chat
|
||||
|
||||
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.profiles.parse import snapshot_from_chat
|
||||
from userbot.modules.profiles.repository import write_profile
|
||||
|
||||
|
||||
async def save_private(ctx: CaptureContext, chat: Chat) -> bool:
|
||||
chat_id = chat.id or 0
|
||||
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 save_group(ctx: CaptureContext, chat: Chat) -> None:
|
||||
chat_id = chat.id or 0
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
async def save_chat(ctx: CaptureContext, chat: Chat) -> None:
|
||||
if (chat.id or 0) > 0:
|
||||
await save_private(ctx, chat)
|
||||
else:
|
||||
await save_group(ctx, chat)
|
||||
Reference in new issue
Block a user