fix(backend): userbot follows kurigram 2.2.26, user and chat parsing is awaited, missing chat is handled
This commit is contained in:
1 parent
d213dfdf64
commit
945adcf879
11 files changed
+13
-11
No files matched your search
@@ -30,4 +30,4 @@ async def on_deleted_messages(client: PyroClient, messages: list[Message]) -> No
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
handlers = on_deleted_messages.handlers
|
handlers = on_deleted_messages.handlers # ty: ignore[unresolved-attribute]
|
||||||
@@ -49,4 +49,4 @@ async def on_edited_message(client: PyroClient, message: Message) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
handlers = on_edited_message.handlers
|
handlers = on_edited_message.handlers # ty: ignore[unresolved-attribute]
|
||||||
@@ -36,4 +36,4 @@ async def on_message(client: PyroClient, message: Message) -> None:
|
|||||||
await safe_transcribe(client, ctx, meta.chat_id, message.id)
|
await safe_transcribe(client, ctx, meta.chat_id, message.id)
|
||||||
|
|
||||||
|
|
||||||
handlers = on_message.handlers
|
handlers = on_message.handlers # ty: ignore[unresolved-attribute]
|
||||||
@@ -27,4 +27,4 @@ async def on_user_status(client: PyroClient, user: User) -> None:
|
|||||||
await notify_bg_event(ctx.pool, "presence", ctx.account_id, chat_id=user.id)
|
await notify_bg_event(ctx.pool, "presence", ctx.account_id, chat_id=user.id)
|
||||||
|
|
||||||
|
|
||||||
handlers = on_user_status.handlers
|
handlers = on_user_status.handlers # ty: ignore[unresolved-attribute]
|
||||||
@@ -38,4 +38,4 @@ async def dispatch(
|
|||||||
await handler(client, update, users, chats)
|
await handler(client, update, users, chats)
|
||||||
|
|
||||||
|
|
||||||
handlers = dispatch.handlers
|
handlers = dispatch.handlers # ty: ignore[unresolved-attribute]
|
||||||
@@ -21,7 +21,7 @@ async def _handle_user(
|
|||||||
raw_user = users.get(update.user_id)
|
raw_user = users.get(update.user_id)
|
||||||
if raw_user is None:
|
if raw_user is None:
|
||||||
return
|
return
|
||||||
fields, photo_file_id, photo_unique_id = snapshot_from_user(client, raw_user)
|
fields, photo_file_id, photo_unique_id = await snapshot_from_user(client, raw_user)
|
||||||
current = await get_peer(ctx.pool, ctx.account_id, update.user_id)
|
current = await get_peer(ctx.pool, ctx.account_id, update.user_id)
|
||||||
if current == fields:
|
if current == fields:
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ async def on_story(client: PyroClient, story: Story) -> None:
|
|||||||
await save_story(client, client.capture, story)
|
await save_story(client, client.capture, story)
|
||||||
|
|
||||||
|
|
||||||
handlers = on_story.handlers
|
handlers = on_story.handlers # ty: ignore[unresolved-attribute]
|
||||||
@@ -36,6 +36,8 @@ async def _save_user(ctx: CaptureContext, user: User) -> None:
|
|||||||
|
|
||||||
async def _enrich_chat_meta(client: Client, ctx: CaptureContext, chat_id: int) -> None:
|
async def _enrich_chat_meta(client: Client, ctx: CaptureContext, chat_id: int) -> None:
|
||||||
chat = await client.get_chat(chat_id)
|
chat = await client.get_chat(chat_id)
|
||||||
|
if chat is None:
|
||||||
|
return
|
||||||
photo = chat.photo
|
photo = chat.photo
|
||||||
photo_unique_id = photo.big_photo_unique_id if photo else None
|
photo_unique_id = photo.big_photo_unique_id if photo else None
|
||||||
photo_file_id = photo.big_file_id if photo else None
|
photo_file_id = photo.big_file_id if photo else None
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ STALE_FILE_ID = (FileIdInvalid, FileReferenceExpired, FileReferenceInvalid)
|
|||||||
|
|
||||||
async def _fresh_file_id(client: Client, owner_id: int, unique_id: str) -> str | None:
|
async def _fresh_file_id(client: Client, owner_id: int, unique_id: str) -> str | None:
|
||||||
chat = await client.get_chat(owner_id)
|
chat = await client.get_chat(owner_id)
|
||||||
photo = chat.photo
|
photo = chat.photo if chat else None
|
||||||
if photo and photo.big_photo_unique_id == unique_id:
|
if photo and photo.big_photo_unique_id == unique_id:
|
||||||
return photo.big_file_id
|
return photo.big_file_id
|
||||||
photos = client.get_chat_photos(owner_id)
|
photos = client.get_chat_photos(owner_id)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ async def _save_found(
|
|||||||
source = _source(peer, users, chats)
|
source = _source(peer, users, chats)
|
||||||
if source is None:
|
if source is None:
|
||||||
return None
|
return None
|
||||||
chat = Chat._parse_chat(client, source) # noqa: SLF001
|
chat = await Chat._parse_chat(client, source) # noqa: SLF001
|
||||||
if chat is None or chat.id is None:
|
if chat is None or chat.id is None:
|
||||||
return None
|
return None
|
||||||
await save_chat(ctx, chat)
|
await save_chat(ctx, chat)
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ def active_username(usernames: list[raw.types.Username]) -> str | None:
|
|||||||
return usernames[0].username if usernames else None
|
return usernames[0].username if usernames else None
|
||||||
|
|
||||||
|
|
||||||
def snapshot_from_user(
|
async def snapshot_from_user(
|
||||||
client: Client, raw_user: raw.types.User
|
client: Client, raw_user: raw.types.User
|
||||||
) -> tuple[ProfileFields, str | None, str | None]:
|
) -> tuple[ProfileFields, str | None, str | None]:
|
||||||
user = User._parse(client, raw_user) # noqa: SLF001
|
user = await User._parse(client, raw_user) # noqa: SLF001
|
||||||
photo = user.photo if user else None
|
photo = user.photo if user else None
|
||||||
photo_unique_id = photo.big_photo_unique_id if photo else None
|
photo_unique_id = photo.big_photo_unique_id if photo else None
|
||||||
photo_file_id = photo.big_file_id if photo else None
|
photo_file_id = photo.big_file_id if photo else None
|
||||||
|
|||||||
Reference in new issue
Block a user