fix(userbot): presence, story and profile history toggles of the capture policy take effect for each user peer
This commit is contained in:
1 parent
f32b772ddc
commit
92e5e737d2
10 files changed
+100
-25
No files matched your search
@@ -13,18 +13,19 @@ async def on_user_status(client: PyroClient, user: User) -> None:
|
||||
ctx = client.capture
|
||||
if ctx is None or user.status is None:
|
||||
return
|
||||
await repository.insert_status(
|
||||
ctx.pool,
|
||||
ctx.account_id,
|
||||
user.id,
|
||||
datetime.now(UTC),
|
||||
user.status.name.lower(),
|
||||
user.last_online_date,
|
||||
user.next_offline_date,
|
||||
raw_json(user.raw),
|
||||
)
|
||||
if ctx.resolve_peer(user.id, is_bot=bool(user.is_bot)).presence:
|
||||
await repository.insert_status(
|
||||
ctx.pool,
|
||||
ctx.account_id,
|
||||
user.id,
|
||||
datetime.now(UTC),
|
||||
user.status.name.lower(),
|
||||
user.last_online_date,
|
||||
user.next_offline_date,
|
||||
raw_json(user.raw),
|
||||
)
|
||||
await notify_bg_event(ctx.pool, "presence", ctx.account_id, chat_id=user.id)
|
||||
await ctx.watches.on_status(user.id, is_online=user.status.name.lower() == "online")
|
||||
await notify_bg_event(ctx.pool, "presence", ctx.account_id, chat_id=user.id)
|
||||
|
||||
|
||||
handlers = on_user_status.handlers # ty: ignore[unresolved-attribute]
|
||||
@@ -25,8 +25,14 @@ async def _handle_user(
|
||||
current = await get_peer(ctx.pool, ctx.account_id, update.user_id)
|
||||
if current == fields:
|
||||
return
|
||||
is_bot = bool(getattr(raw_user, "bot", False))
|
||||
await write_profile(
|
||||
ctx.pool, ctx.account_id, update.user_id, fields, raw_json(raw_user)
|
||||
ctx.pool,
|
||||
ctx.account_id,
|
||||
update.user_id,
|
||||
fields,
|
||||
raw_json(raw_user),
|
||||
history=ctx.resolve_peer(update.user_id, is_bot=is_bot).profile_history,
|
||||
)
|
||||
changed_photo = current is None or current.photo_unique_id != photo_unique_id
|
||||
if photo_file_id and photo_unique_id and changed_photo:
|
||||
@@ -51,7 +57,14 @@ async def _merge_partial(
|
||||
merged = replace(current or ProfileFields(), **overrides)
|
||||
if merged == current:
|
||||
return
|
||||
await write_profile(ctx.pool, ctx.account_id, peer_id, merged, raw_str)
|
||||
await write_profile(
|
||||
ctx.pool,
|
||||
ctx.account_id,
|
||||
peer_id,
|
||||
merged,
|
||||
raw_str,
|
||||
history=ctx.resolve_peer(peer_id).profile_history,
|
||||
)
|
||||
|
||||
|
||||
async def handle(
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
from pyrogram.types import Story
|
||||
|
||||
from userbot.modules.client import PyroClient
|
||||
from userbot.modules.stories.service import save_story
|
||||
from userbot.modules.stories.service import save_story, story_peer_id
|
||||
|
||||
|
||||
@PyroClient.on_story()
|
||||
async def on_story(client: PyroClient, story: Story) -> None:
|
||||
if client.capture is None:
|
||||
ctx = client.capture
|
||||
if ctx is None:
|
||||
return
|
||||
await save_story(client, client.capture, story)
|
||||
peer_id = story_peer_id(story)
|
||||
is_bot = bool(story.from_user and story.from_user.is_bot)
|
||||
if peer_id > 0 and not ctx.resolve_peer(peer_id, is_bot=is_bot).stories:
|
||||
return
|
||||
await save_story(client, ctx, story)
|
||||
|
||||
|
||||
handlers = on_story.handlers # ty: ignore[unresolved-attribute]
|
||||
Reference in new issue
Block a user