fix(userbot): encode absent pyrogram raw payloads as empty json
This commit is contained in:
1 parent
6a6e63ff75
commit
676680319b
15 files changed
+63
-25
No files matched your search
@@ -8,6 +8,7 @@ from userbot.modules.capture.context import CaptureContext
|
||||
from userbot.modules.jobs.context import JobContext
|
||||
from userbot.modules.jobs.registry import register
|
||||
from userbot.modules.stories.service import save_story
|
||||
from utils.logging import logger
|
||||
|
||||
SAVE_EVERY = 10
|
||||
|
||||
@@ -38,6 +39,9 @@ async def _drain(
|
||||
raise
|
||||
except RPCError:
|
||||
continue
|
||||
except Exception:
|
||||
logger.exception(f"Failed to save story {story.id} from {name}")
|
||||
continue
|
||||
saved += 1
|
||||
if saved % SAVE_EVERY == 0:
|
||||
await ctx.report_progress({"saved": saved, "source": name})
|
||||
|
||||
@@ -11,6 +11,7 @@ from userbot.modules.jobs.context import JobContext
|
||||
from userbot.modules.jobs.registry import register
|
||||
from userbot.modules.profiles.parse import snapshot_from_high_level
|
||||
from userbot.modules.profiles.repository import write_profile
|
||||
from userbot.modules.raw_json import raw_json
|
||||
|
||||
MEMBER_CAP = 200
|
||||
|
||||
@@ -26,7 +27,7 @@ LIMIT 100
|
||||
|
||||
async def _save_user(ctx: CaptureContext, user: User) -> None:
|
||||
fields, photo_file_id, photo_unique_id = snapshot_from_high_level(user)
|
||||
await write_profile(ctx.pool, ctx.account_id, user.id, fields, str(user))
|
||||
await write_profile(ctx.pool, ctx.account_id, user.id, fields, raw_json(user))
|
||||
if photo_file_id and photo_unique_id:
|
||||
await note_avatar(
|
||||
ctx.pool, ctx.account_id, user.id, "peer", photo_unique_id, photo_file_id
|
||||
@@ -48,7 +49,7 @@ async def _enrich_chat_meta(client: Client, ctx: CaptureContext, chat_id: int) -
|
||||
photo_unique_id,
|
||||
None,
|
||||
datetime.now(UTC),
|
||||
str(chat),
|
||||
raw_json(chat),
|
||||
)
|
||||
if photo_file_id and photo_unique_id:
|
||||
await note_avatar(
|
||||
|
||||
@@ -5,6 +5,7 @@ from userbot.modules.jobs.context import JobContext
|
||||
from userbot.modules.jobs.registry import register
|
||||
from userbot.modules.profiles.parse import snapshot_from_high_level
|
||||
from userbot.modules.profiles.repository import write_profile
|
||||
from userbot.modules.raw_json import raw_json
|
||||
|
||||
|
||||
@register("sync_contacts")
|
||||
@@ -21,7 +22,7 @@ async def sync_contacts(ctx: JobContext) -> None:
|
||||
if not isinstance(user, User):
|
||||
continue
|
||||
fields, photo_file_id, photo_unique_id = snapshot_from_high_level(user)
|
||||
await write_profile(ctx.pool, ctx.account_id, user.id, fields, str(user))
|
||||
await write_profile(ctx.pool, ctx.account_id, user.id, fields, raw_json(user))
|
||||
if photo_file_id and photo_unique_id:
|
||||
await note_avatar(
|
||||
ctx.pool,
|
||||
|
||||
@@ -9,6 +9,8 @@ from userbot.modules.jobs.registry import register
|
||||
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
|
||||
from userbot.modules.raw_json import raw_json
|
||||
from utils.logging import logger
|
||||
|
||||
SAVE_EVERY = 100
|
||||
USERS_BATCH = 200
|
||||
@@ -31,7 +33,9 @@ async def _enrich_users(client: Client, ctx: CaptureContext, ids: list[int]) ->
|
||||
if not isinstance(user, User):
|
||||
continue
|
||||
fields, photo_file_id, photo_unique_id = snapshot_from_high_level(user)
|
||||
await write_profile(ctx.pool, ctx.account_id, user.id, fields, str(user))
|
||||
await write_profile(
|
||||
ctx.pool, ctx.account_id, user.id, fields, raw_json(user)
|
||||
)
|
||||
if photo_file_id and photo_unique_id:
|
||||
await note_avatar(
|
||||
ctx.pool,
|
||||
@@ -66,6 +70,8 @@ async def sync_dialogs(ctx: JobContext) -> None:
|
||||
await save_group(capture, chat)
|
||||
except (BadRequest, Forbidden):
|
||||
pass
|
||||
except Exception:
|
||||
logger.exception(f"Failed to snapshot dialog {chat_id}")
|
||||
await ctx.pool.execute(_UPSERT_DIALOG, ctx.account_id, chat_id)
|
||||
processed += 1
|
||||
if processed % SAVE_EVERY == 0:
|
||||
|
||||
Reference in new issue
Block a user